mirror of
https://github.com/eth-act/ere.git
synced 2026-04-03 03:00:17 -04:00
zkVK methods return public values (#106)
This commit is contained in:
@@ -6,5 +6,6 @@ edition = "2021"
|
||||
[workspace]
|
||||
|
||||
[dependencies]
|
||||
bincode = "1.3.3"
|
||||
openvm = { git = "https://github.com/openvm-org/openvm.git", features = ["std"], tag = "v1.2.0" }
|
||||
test-utils = { path = "../../../crates/test-utils" }
|
||||
|
||||
@@ -1,16 +1,30 @@
|
||||
use core::array::from_fn;
|
||||
use openvm::io::{read, read_vec, reveal_u32};
|
||||
use test_utils::guest::BasicStruct;
|
||||
use test_utils::guest::{BasicStruct, BASIC_PROGRAM_BYTES_LENGTH};
|
||||
|
||||
fn main() {
|
||||
// Read `Hello world` bytes.
|
||||
// Read `bytes`.
|
||||
let bytes = read_vec();
|
||||
assert_eq!(String::from_utf8_lossy(&bytes), "Hello world");
|
||||
|
||||
// Read `BasicStruct`.
|
||||
// Read `basic_struct`.
|
||||
let basic_struct = read::<BasicStruct>();
|
||||
let output = basic_struct.output();
|
||||
|
||||
output.chunks(4).enumerate().for_each(|(idx, bytes)| {
|
||||
reveal_u32(u32::from_le_bytes(bytes.try_into().unwrap()), idx);
|
||||
});
|
||||
// Check `bytes` length is as expected.
|
||||
assert_eq!(bytes.len(), BASIC_PROGRAM_BYTES_LENGTH);
|
||||
|
||||
// Do some computation on `basic_struct`.
|
||||
let basic_struct_output = basic_struct.output();
|
||||
|
||||
// Write reversed `bytes` and `basic_struct_output`
|
||||
let public_values = core::iter::empty()
|
||||
.chain(bytes.into_iter().rev())
|
||||
.chain(bincode::serialize(&basic_struct_output).unwrap())
|
||||
.collect::<Vec<_>>();
|
||||
public_values
|
||||
.chunks(4)
|
||||
.enumerate()
|
||||
.for_each(|(idx, bytes)| {
|
||||
let bytes = from_fn(|i| bytes.get(i).copied().unwrap_or_default());
|
||||
reveal_u32(u32::from_le_bytes(bytes), idx);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user