1+ use alloy_genesis:: ChainConfig ;
12use alloy_primitives:: Address ;
23use alloy_rpc_types:: BlockNumberOrTag ;
34use alloy_sol_types:: SolType ;
45use anyhow:: Result ;
56use async_trait:: async_trait;
67use canoe_bindings:: { Journal , StatusCode } ;
78use canoe_provider:: { CanoeInput , CanoeProvider , CertVerifierCall } ;
9+ use rsp_primitives:: genesis:: genesis_from_json;
810use sp1_cc_client_executor:: ContractInput ;
911use sp1_cc_host_executor:: { EvmSketch , Genesis } ;
1012use sp1_sdk:: {
@@ -19,8 +21,6 @@ use std::{
1921use tracing:: { debug, info, warn} ;
2022use url:: Url ;
2123
22- use rsp_primitives:: genesis:: genesis_from_json;
23-
2424/// The ELF we want to execute inside the zkVM.
2525pub const ELF : & [ u8 ] = include_bytes ! ( "../../elf/canoe-sp1-cc-client" ) ;
2626
@@ -62,6 +62,8 @@ pub struct CanoeSp1CCProvider {
6262 pub eth_rpc_url : String ,
6363 /// if true, execute and return a mock proof
6464 pub mock_mode : bool ,
65+ /// optional custom chain configuration for genesis block
66+ pub custom_chain_config : Option < ChainConfig > ,
6567}
6668
6769#[ async_trait]
@@ -77,7 +79,15 @@ impl CanoeProvider for CanoeSp1CCProvider {
7779 return None ;
7880 }
7981
80- Some ( get_sp1_cc_proof ( canoe_inputs, & self . eth_rpc_url , self . mock_mode ) . await )
82+ Some (
83+ get_sp1_cc_proof (
84+ canoe_inputs,
85+ & self . eth_rpc_url ,
86+ self . mock_mode ,
87+ self . custom_chain_config . clone ( ) ,
88+ )
89+ . await ,
90+ )
8191 }
8292}
8393
@@ -92,6 +102,8 @@ pub struct CanoeSp1CCReducedProofProvider {
92102 pub eth_rpc_url : String ,
93103 /// if true, execute and return a mock proof
94104 pub mock_mode : bool ,
105+ /// optional custom chain configuration for genesis block
106+ pub custom_chain_config : Option < ChainConfig > ,
95107}
96108
97109#[ async_trait]
@@ -107,7 +119,14 @@ impl CanoeProvider for CanoeSp1CCReducedProofProvider {
107119 return None ;
108120 }
109121
110- match get_sp1_cc_proof ( canoe_inputs, & self . eth_rpc_url , self . mock_mode ) . await {
122+ match get_sp1_cc_proof (
123+ canoe_inputs,
124+ & self . eth_rpc_url ,
125+ self . mock_mode ,
126+ self . custom_chain_config . clone ( ) ,
127+ )
128+ . await
129+ {
111130 Ok ( proof) => {
112131 let SP1Proof :: Compressed ( proof) = proof. proof else {
113132 panic ! ( "cannot get Sp1ReducedProof" )
@@ -123,6 +142,7 @@ async fn get_sp1_cc_proof(
123142 canoe_inputs : Vec < CanoeInput > ,
124143 eth_rpc_url : & str ,
125144 mock_mode : bool ,
145+ custom_chain_config : Option < ChainConfig > ,
126146) -> Result < sp1_sdk:: SP1ProofWithPublicValues > {
127147 // ensure chain id and l1 block number across all DAcerts are identical
128148 let l1_chain_id = canoe_inputs[ 0 ] . l1_chain_id ;
@@ -147,35 +167,26 @@ async fn get_sp1_cc_proof(
147167
148168 let rpc_url = Url :: from_str ( eth_rpc_url) . unwrap ( ) ;
149169
150- let sketch = match Genesis :: try_from ( l1_chain_id) {
151- Ok ( genesis) => {
152- EvmSketch :: builder ( )
153- . at_block ( block_number)
154- . with_genesis ( genesis)
155- . el_rpc_url ( rpc_url)
156- . build ( )
157- . await ?
158- }
159- // if genesis is not available in the sp1-cc library, the code uses custom genesis config
160- Err ( _) => {
161- let chain_config = match l1_chain_id {
162- 17000 => genesis_from_json ( HOLESKY_GENESIS ) . expect ( "genesis from json" ) ,
163- 3151908 => genesis_from_json ( KURTOSIS_DEVNET_GENESIS ) . expect ( "genesis from json" ) ,
164- _ => panic ! ( "chain id {l1_chain_id} is not supported by canoe sp1 cc" ) ,
165- } ;
166-
167- let genesis = Genesis :: Custom ( chain_config. config ) ;
168-
169- EvmSketch :: builder ( )
170- . at_block ( block_number)
171- . with_genesis ( genesis)
172- . el_rpc_url ( rpc_url)
173- . build ( )
174- . await
175- . expect ( "evm sketch builder" )
176- }
170+ let genesis = if let Some ( chain_config) = custom_chain_config {
171+ Genesis :: Custom ( chain_config)
172+ } else if let Ok ( genesis) = Genesis :: try_from ( l1_chain_id) {
173+ genesis
174+ } else {
175+ let chain_config = match l1_chain_id {
176+ 17000 => genesis_from_json ( HOLESKY_GENESIS ) . expect ( "genesis from json" ) ,
177+ 3151908 => genesis_from_json ( KURTOSIS_DEVNET_GENESIS ) . expect ( "genesis from json" ) ,
178+ _ => panic ! ( "chain id {l1_chain_id} is not supported by canoe sp1 cc" ) ,
179+ } ;
180+ Genesis :: Custom ( chain_config. config )
177181 } ;
178182
183+ let sketch = EvmSketch :: builder ( )
184+ . at_block ( block_number)
185+ . with_genesis ( genesis)
186+ . el_rpc_url ( rpc_url)
187+ . build ( )
188+ . await ?;
189+
179190 let derived_l1_header_hash = sketch. anchor . header ( ) . hash_slow ( ) ;
180191 assert ! ( l1_head_block_hash == derived_l1_header_hash) ;
181192
0 commit comments