Skip to content

Commit

Permalink
expose publics in session (#2190)
Browse files Browse the repository at this point in the history
Depends on #2189

This PR exposes the publics of a proof in Session and uses it to commit
the result of Fibonacci in the example.
  • Loading branch information
leonardoalt authored Dec 5, 2024
1 parent 60860b7 commit 9560cc8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions examples/fibonacci/guest/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use powdr_riscv_runtime;
use powdr_riscv_runtime::commit;
use powdr_riscv_runtime::io::{read, write};

fn fib(n: u32) -> u32 {
Expand All @@ -14,4 +15,6 @@ fn main() {
let r = fib(n);
// Write result to stdout.
write(1, r);
// Commit the result as a public.
commit::commit(r);
}
9 changes: 9 additions & 0 deletions powdr-test/examples/fibonacci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,13 @@ fn main() {

let r: u32 = session.stdout();
assert_eq!(r, 89);

let publics = session.publics();
assert_eq!(
publics,
[
555233681, 1854640251, 3298928347, 2857173302, 2660189392, 1608424695, 543896544,
3870154745
]
);
}
13 changes: 12 additions & 1 deletion powdr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub use powdr_riscv_executor as riscv_executor;
pub use powdr_pipeline::Pipeline;

pub use powdr_number::Bn254Field;
pub use powdr_number::FieldElement;
pub use powdr_number::GoldilocksField;
pub use powdr_number::{FieldElement, LargeInt};

use riscv::{CompilerOptions, RuntimeLibs};

Expand Down Expand Up @@ -192,6 +192,17 @@ impl Session {
self.pipeline.export_verification_key(file).unwrap();
}

pub fn publics(&self) -> [u32; 8] {
let pubs: Vec<u32> = self
.pipeline
.publics()
.unwrap()
.iter()
.map(|(_, v)| v.unwrap().to_integer().try_into_u32().unwrap())
.collect();
pubs.try_into().expect("There should be exactly 8 publics")
}

pub fn stdout<S: serde::de::DeserializeOwned>(&self) -> S {
let host = self.pipeline.host_context();
host.read(1).unwrap()
Expand Down

0 comments on commit 9560cc8

Please sign in to comment.