Week 10, Proof of attestation on openVM works but gets killed
There were two major issues in my code that prevented it from running. Both of them were difficult to solve because they were syntactically correct. As a result, errors were raised at run time with very few information while the compilation was succesful. The repository for the project is: https://github.com/DimitriosMitsios/openvm-ream.
First issue, reading input on guest from host
This solution is due to Utsav who faced the same issue. On guest directory in order to read input, I was using the read function from openvm::io::read. Instead, the function that should be used is openvm::io::read_vec(). I am not sure why read() was not working on inputs which are given as vectors of bytes. Here is the guest code
use openvm::io::{read_vec};
use ream_consensus::{attestation::Attestation, electra::beacon_state::BeaconState};
use ream_lib::{ssz::from_ssz_bytes};
pub fn main() {
let bytes: Vec<u8> = read_vec();
let arr: [u8;8] = bytes.try_into().unwrap();
let pre_state_len = u64::from_le_bytes(arr) as usize;
let mut pre_state_ssz_bytes: Vec<u8> = vec![0u8; pre_state_len];
pre_state_ssz_bytes = read_vec();
let mut pre_state: BeaconState = from_ssz_bytes(&pre_state_ssz_bytes).unwrap();
let mut attestation_bytes = Vec::new();
attestation_bytes = read_vec();
let attestation: Attestation = from_ssz_bytes(&attestation_bytes).unwrap();
let _ = pre_state.process_attestation(&attestation);
}
For the moment, the input consists of three items:
- the length of the state
- the state itself and
- an attestation
On the host side, the writing is done as
let mut stdin = StdIn::default();
let pre_state_bytes: Vec<u8> =ssz_from_file(&pre_state_path);
stdin.write_bytes(&pre_state_len_bytes);
...
Second issue, using different serialization algorithms
On the host side, I was using openvm::serde::to_vec in order to read attestation and prestate files. In contrast, I was using from_ssz_bytes on the guest side to read them. The use of different algorithms created errors during runtime. Right now, I am using on both sides the ssz library which I call ream-lib and I borrowed from Ream’s repo.
To be done
There are a few tasks to be done:
- Clean up the code such that all warnings are removed
- Generalize guest code to process various inputs (not only attestations)
- Include checks such as
assert_eq!(*new_state_root, recomputed_state_root)and tests - Count RISC-V cycles