11//! Helpers for compiling guest programs and asserting their zkVM execution.
22
3- use std:: {
4- collections:: BTreeMap ,
5- fs,
6- io:: Read ,
7- path:: { Path , PathBuf } ,
8- sync:: LazyLock ,
9- } ;
3+ use std:: { collections:: BTreeMap , fs, path:: PathBuf , sync:: LazyLock } ;
104
115use dashmap:: DashMap ;
126use ere_dockerized:: {
137 Compiler , CompilerKind , DockerizedCompiler , DockerizedzkVM , DockerizedzkVMConfig , Elf , Input ,
148 ProverResource , zkVMKind,
159} ;
1610use serde:: Deserialize ;
17- use stateless_validator_common:: guest:: {
18- StatelessInput , input:: new_payload_request:: NewPayloadRequest ,
19- } ;
2011
2112use crate :: {
2213 execution:: { ExecutionFailure , GuestKind , run_execution} ,
@@ -37,7 +28,7 @@ pub fn resolve_guest(guest_kind: GuestKind, zkvm_kind: zkVMKind) -> Elf {
3728 ELF . entry ( ( guest_kind, zkvm_kind) )
3829 . or_insert_with ( || match guest_kind {
3930 GuestKind :: Ethrex | GuestKind :: Reth => compile_guest ( guest_kind, zkvm_kind) ,
40- GuestKind :: Zesu | GuestKind :: Nethermind => download_guest ( guest_kind, zkvm_kind) ,
31+ GuestKind :: Zesu => download_guest ( guest_kind, zkvm_kind) ,
4132 } )
4233 . clone ( )
4334}
@@ -65,7 +56,6 @@ pub fn download_guest(guest_kind: GuestKind, zkvm_kind: zkVMKind) -> Elf {
6556 #[ derive( Deserialize ) ]
6657 struct GuestSoure {
6758 url : String ,
68- archive_elf_path : Option < String > ,
6959 }
7060
7161 let registry = {
@@ -84,27 +74,7 @@ pub fn download_guest(guest_kind: GuestKind, zkvm_kind: zkVMKind) -> Elf {
8474 . bytes ( )
8575 . unwrap ( )
8676 . to_vec ( ) ;
87- match & source. archive_elf_path {
88- Some ( archive_elf_path) => Elf ( extract_elf_from_tar_gz ( & bytes, archive_elf_path) ) ,
89- None => Elf ( bytes) ,
90- }
91- }
92-
93- /// Extracts the entry at `archive_elf_path` from a gzip-compressed tar archive.
94- /// Some prebuilt guests, such as the nethermind ZisK release, distribute the ELF
95- /// inside a `.tar.gz` under an extensionless name recorded as `archive_elf_path`
96- /// in the registry.
97- fn extract_elf_from_tar_gz ( bytes : & [ u8 ] , archive_elf_path : & str ) -> Vec < u8 > {
98- let mut archive = tar:: Archive :: new ( flate2:: read:: GzDecoder :: new ( bytes) ) ;
99- for entry in archive. entries ( ) . unwrap ( ) {
100- let mut entry = entry. unwrap ( ) ;
101- if entry. path ( ) . unwrap ( ) . as_ref ( ) == Path :: new ( archive_elf_path) {
102- let mut buf = Vec :: new ( ) ;
103- entry. read_to_end ( & mut buf) . unwrap ( ) ;
104- return buf;
105- }
106- }
107- panic ! ( "{archive_elf_path} not found in archive" )
77+ Elf ( bytes)
10878}
10979
11080/// Initializes a CPU-backed zkVM for `elf`.
@@ -128,25 +98,6 @@ pub fn run_stateless_validator_execution(
12898 let elf = resolve_guest ( guest_kind, zkvm_kind) ;
12999 let zkvm = init_zkvm ( zkvm_kind, elf) ;
130100 run_execution ( preset_fixtures ( preset) , & |input| {
131- let input = match guest_kind {
132- GuestKind :: Nethermind => nethermind_input ( input) ?,
133- _ => input,
134- } ;
135101 Ok ( zkvm. execute ( & Input :: new ( ) . with_stdin ( input) ) ?. 0 . to_vec ( ) )
136102 } )
137103}
138-
139- /// Rewrites the schema prefix of `ElectraFulu` variant payload to `0x0000`.
140- /// Reference: https://github.com/NethermindEth/nethermind/blob/zisk-guest-r7/src/Nethermind/Nethermind.Stateless.Executor/IO/InputDecoder.cs#L16-L23.
141- fn nethermind_input ( stateless_input_bytes : Vec < u8 > ) -> anyhow:: Result < Vec < u8 > > {
142- let stateless_input = StatelessInput :: from_schema_prefixed_ssz ( & stateless_input_bytes)
143- . map_err ( |err| anyhow:: anyhow!( "decode stateless_input: {err:?}" ) ) ?;
144- let schema_id = match & stateless_input. new_payload_request {
145- NewPayloadRequest :: ElectraFulu ( _) => [ 0x00 , 0x00 ] ,
146- NewPayloadRequest :: Gloas ( _) => [ 0x00 , 0x01 ] ,
147- _ => anyhow:: bail!( "nethermind r7 supports only ElectraFulu (V3) and Gloas (V4) payloads" ) ,
148- } ;
149- let mut stateless_input_bytes = stateless_input_bytes;
150- stateless_input_bytes[ 0 ..2 ] . copy_from_slice ( & schema_id) ;
151- Ok ( stateless_input_bytes)
152- }
0 commit comments