Skip to content

Commit e3062a0

Browse files
authored
feat: change commit signature make it easy (#1074)
1 parent aaf5c5b commit e3062a0

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
lines changed

ceno_host/tests/test_elf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ fn test_sha256_extend() -> Result<()> {
477477

478478
#[test]
479479
fn test_sha256_full() -> Result<()> {
480-
let public_io: &Vec<u32> = &vec![
480+
let public_io: &[u32; 8] = &[
481481
30689455, 3643278932, 1489987339, 1626711444, 3610619649, 1925764735, 581441152, 321290698,
482482
];
483483
let hints: &Vec<u32> = &vec![0u32; 10];

ceno_rt/src/mmio.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
//! Memory-mapped I/O (MMIO) functions.
22
3-
use rkyv::{Portable, api::high::HighValidator, bytecheck::CheckBytes, rancor::Failure};
3+
use rkyv::{
4+
Archived, Deserialize, Portable,
5+
api::high::{HighDeserializer, HighValidator},
6+
bytecheck::CheckBytes,
7+
rancor::Failure,
8+
};
49

510
use core::slice::from_raw_parts;
611

@@ -90,12 +95,16 @@ pub fn pubio_read_slice<'a>() -> &'a [u8] {
9095
&pubio_region()[..pubio_len()]
9196
}
9297

93-
pub fn commit<'a, T, F: From<&'a T> + core::fmt::Debug + PartialEq>(v: &F)
98+
/// Read a value from public io, deserialize it, and assert that it matches the given value.
99+
pub fn commit<T>(v: &T)
94100
where
95-
T: Portable + for<'c> CheckBytes<HighValidator<'c, Failure>> + 'a,
101+
T: rkyv::Archive + core::fmt::Debug + PartialEq,
102+
T::Archived:
103+
for<'c> CheckBytes<HighValidator<'c, Failure>> + Deserialize<T, HighDeserializer<Failure>>,
96104
{
97-
let expected: F = rkyv::access::<T, Failure>(pubio_read_slice())
98-
.expect("Deserialised access failed.")
99-
.into();
100-
assert_eq!(*v, expected);
105+
let expected = rkyv::access::<Archived<T>, Failure>(pubio_read_slice())
106+
.expect("Deserialised access failed.");
107+
let expected_deserialized: T =
108+
rkyv::deserialize::<T, Failure>(expected).expect("Deserialised value failed.");
109+
assert_eq!(*v, expected_deserialized);
101110
}

examples/examples/fibonacci.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ fn main() {
1515
b = c;
1616
}
1717
// Constrain with public io
18-
ceno_rt::commit::<Archived<u32>, _>(&b);
18+
ceno_rt::commit(&b);
1919
}

examples/examples/sha256.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
extern crate ceno_rt;
2+
23
use ceno_rt::syscalls::syscall_sha256_extend;
34
use rkyv::vec::ArchivedVec;
45

@@ -65,18 +66,10 @@ fn main() {
6566
}
6667

6768
// Output the final hash values one by one
68-
ceno_rt::commit::<ArchivedVec<u32>, SHA256Result>(&SHA256Result(h.to_vec()));
69+
ceno_rt::commit(&h);
6970
// debug_print!("{:x}", h[0]);
7071
}
7172

72-
#[derive(Debug, PartialEq)]
73-
struct SHA256Result(Vec<u32>);
74-
impl From<&ArchivedVec<u32>> for SHA256Result {
75-
fn from(value: &ArchivedVec<u32>) -> Self {
76-
SHA256Result(value.to_vec())
77-
}
78-
}
79-
8073
fn process_block(h: &mut [u32; 8], w: &[u32; 64]) {
8174
// Expand message schedule
8275
let mut w_expanded = *w;

0 commit comments

Comments
 (0)