Try   HackMD

Constructing and passing BeaconState to zkVM

TLDR

  1. Able to construct a full BeaconState from consensus-spec-tests yaml files.
  2. Able to pass a BeamState constructed with a subset of BeaconState fields, pass it into the guest zkVM, and journaled back to the host machine.
  3. See the work at https://github.com/unnawut/consenzero/pull/1/

Details

  • After being stuck trying to construct a BeaconState from scratch, I was finally able to escape by constructing it from consensus-spec-tests test data instead. Thanks to Jun's suggestion and Kolby's code in ream/testing/ef-tests that made this straightforward.

  • Initially I tried passing the full BeaconState into the guest VM but the guest threw this error back:

    ​​​​thread 'main' panicked at /Users/unnawut/.cargo/registry/src/index.crates.io-6f17d22bba15001f/risc0-zkvm-1.2.1/src/guest/env/read.rs:78:54:
    ​​​​called `Result::unwrap()` on an `Err` value: NotSupported
    
  • The BeaconState is a huge container so figuring out what went wrong would be hard. So I created BeamState within the consenzero repo and assigned the field over from BeaconState one by one until the error shows. This is the culprit:

    ​​​​#[serde(deserialize_with = "ssz_types::serde_utils::quoted_u64_var_list::deserialize")]
    ​​​​pub balances: VariableList<u64, U1099511627776>,
    
  • It seems that risc0 does not know how to deserialize ssz_types::serde_utils::quoted_u64_var_list hence the error "value: NotSupported". So I've asked Risc0 team on Discord and waiting for their response.

  • For now I'd rather wait for their response than spending more time debugging myself since this is likely from their guest implementation.

  • While waiting for their response, I'll just proceed to build as many BeamState field as possible without errors then start trying out the state transition.

Next

  • Wait for RiscZero team's response on the guest::env::FdReader::read() behavior
  • Continue to construct BeamState and see there are more errors elsewhere.
  • Start some state transition with the available fields.