Skip to content

Commit 959bdea

Browse files
authored
feat(devnet): update devnet config (#326)
* update devnet config Signed-off-by: smtmfft <[email protected]> * update devnet config Signed-off-by: smtmfft <[email protected]> * update dependency cargo.lock Signed-off-by: smtmfft <[email protected]> * update risc0 binary Signed-off-by: smtmfft <[email protected]> * update sp1 binary Signed-off-by: smtmfft <[email protected]> * update testcase Signed-off-by: smtmfft <[email protected]> * debug CI Signed-off-by: smtmfft <[email protected]> * debug ci * debug CI * fix CI * resolve merge conflict Signed-off-by: smtmfft <[email protected]> * fix test * fix clippy --------- Signed-off-by: smtmfft <[email protected]>
1 parent f6d02b3 commit 959bdea

File tree

14 files changed

+269
-117
lines changed

14 files changed

+269
-117
lines changed

Diff for: Cargo.lock

+41-41
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: core/src/interfaces.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::{merge, prover::NativeProver};
22
use alloy_primitives::{Address, B256};
33
use clap::{Args, ValueEnum};
44
use raiko_lib::{
5+
consts::VerifierType,
56
input::{BlobProofType, GuestInput, GuestOutput},
67
primitives::eip4844::{calc_kzg_proof, commitment_to_version_hash, kzg_proof_to_bytes},
78
prover::{IdStore, IdWrite, Proof, ProofKey, Prover, ProverError},
@@ -153,6 +154,17 @@ impl TryFrom<u8> for ProofType {
153154
}
154155
}
155156

157+
impl From<ProofType> for VerifierType {
158+
fn from(val: ProofType) -> Self {
159+
match val {
160+
ProofType::Native => VerifierType::None,
161+
ProofType::Sp1 => VerifierType::SP1,
162+
ProofType::Sgx => VerifierType::SGX,
163+
ProofType::Risc0 => VerifierType::RISC0,
164+
}
165+
}
166+
}
167+
156168
impl ProofType {
157169
/// Run the prover driver depending on the proof type.
158170
pub async fn run_prover(
@@ -165,7 +177,7 @@ impl ProofType {
165177
let mut proof = match self {
166178
ProofType::Native => NativeProver::run(input.clone(), output, config, store)
167179
.await
168-
.map_err(|e| e.into()),
180+
.map_err(<ProverError as Into<RaikoError>>::into),
169181
ProofType::Sp1 => {
170182
#[cfg(feature = "sp1")]
171183
return sp1_driver::Sp1Prover::run(input.clone(), output, config, store)
@@ -217,7 +229,7 @@ impl ProofType {
217229
match self {
218230
ProofType::Native => NativeProver::cancel(proof_key, read)
219231
.await
220-
.map_err(|e| e.into()),
232+
.map_err(<ProverError as Into<RaikoError>>::into),
221233
ProofType::Sp1 => {
222234
#[cfg(feature = "sp1")]
223235
return sp1_driver::Sp1Prover::cancel(proof_key, read)

Diff for: core/src/lib.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@ use raiko_lib::{
1212
prover::ProofKey,
1313
};
1414
use raiko_lib::{
15-
consts::{ChainSpec, VerifierType},
16-
prover::IdStore,
17-
};
18-
use raiko_lib::{
15+
consts::ChainSpec,
1916
input::{GuestInput, GuestOutput, TaikoProverData},
20-
prover::IdWrite,
17+
prover::{IdStore, IdWrite},
2118
};
2219
use reth_primitives::Header;
2320
use serde_json::Value;
@@ -88,7 +85,7 @@ impl Raiko {
8885

8986
Ok(GuestOutput {
9087
header: header.clone(),
91-
hash: ProtocolInstance::new(input, &header, VerifierType::None)?
88+
hash: ProtocolInstance::new(input, &header, self.request.proof_type.into())?
9289
.instance_hash(),
9390
})
9491
}

Diff for: host/config/chain_spec_list_devnet.json

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
[
2+
{
3+
"name": "taiko_dev_l1",
4+
"chain_id": 32382,
5+
"max_spec_id": "CANCUN",
6+
"hard_forks": {
7+
"FRONTIER": {
8+
"Block": 0
9+
},
10+
"SHANGHAI": {
11+
"Timestamp": 0
12+
},
13+
"CANCUN": {
14+
"Timestamp": 0
15+
}
16+
},
17+
"eip_1559_constants": {
18+
"base_fee_change_denominator": "0x8",
19+
"base_fee_max_increase_denominator": "0x8",
20+
"base_fee_max_decrease_denominator": "0x8",
21+
"elasticity_multiplier": "0x2"
22+
},
23+
"l1_contract": null,
24+
"l2_contract": null,
25+
"rpc": "https://l1rpc.internal.taiko.xyz",
26+
"beacon_rpc": "https://l1beacon.internal.taiko.xyz/",
27+
"verifier_address": {
28+
"SGX": null,
29+
"SP1": null,
30+
"RISC0": null
31+
},
32+
"genesis_time": 1721296000,
33+
"seconds_per_slot": 12,
34+
"is_taiko": false
35+
},
36+
{
37+
"name": "taiko_dev",
38+
"chain_id": 167001,
39+
"max_spec_id": "SHANGHAI",
40+
"hard_forks": {
41+
"SHANGHAI": {
42+
"Block": 0
43+
},
44+
"CANCUN": "TBD"
45+
},
46+
"eip_1559_constants": {
47+
"base_fee_change_denominator": "0x8",
48+
"base_fee_max_increase_denominator": "0x8",
49+
"base_fee_max_decrease_denominator": "0x8",
50+
"elasticity_multiplier": "0x2"
51+
},
52+
"l1_contract": "0xcdE816aFd1B7db50f09831097e71F99877809218",
53+
"l2_contract": "0x1670010000000000000000000000000000010001",
54+
"rpc": "https://rpc.internal.taiko.xyz",
55+
"beacon_rpc": null,
56+
"verifier_address":{
57+
"SGX":"0xC069c3d2a9f2479F559AD34485698ad5199C555f",
58+
"SP1":null,
59+
"RISC0":"0xde28533011Ef2d6484A03beFD8ffbF31d179AE6A"
60+
},
61+
"genesis_time": 0,
62+
"seconds_per_slot": 1,
63+
"is_taiko": true
64+
}
65+
]

Diff for: host/src/cache.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,15 @@ mod test {
8080
use crate::cache;
8181

8282
use alloy_primitives::{Address, B256};
83+
use alloy_provider::Provider;
8384
use raiko_core::{
8485
interfaces::{ProofRequest, ProofType},
8586
provider::rpc::RpcBlockDataProvider,
8687
Raiko,
8788
};
8889
use raiko_lib::input::BlobProofType;
8990
use raiko_lib::{
90-
consts::{Network, SupportedChainSpecs},
91+
consts::{ChainSpec, Network, SupportedChainSpecs},
9192
input::GuestInput,
9293
};
9394

@@ -130,11 +131,18 @@ mod test {
130131
(input, provider.clone())
131132
}
132133

134+
async fn get_a_testable_block_num(chain_spec: &ChainSpec) -> u64 {
135+
let provider = RpcBlockDataProvider::new(&chain_spec.rpc, 0).unwrap();
136+
let height = provider.provider.get_block_number().await.unwrap();
137+
height - 299582 // a hardcode helka & mainnet height diff for the test
138+
}
139+
133140
#[tokio::test]
134141
async fn test_generate_input_from_cache() {
135142
let l1 = &Network::Holesky.to_string();
136143
let l2 = &Network::TaikoA7.to_string();
137-
let block_number: u64 = 123456;
144+
let taiko_chain_spec = SupportedChainSpecs::default().get_chain_spec(l2).unwrap();
145+
let block_number: u64 = get_a_testable_block_num(&taiko_chain_spec).await;
138146
let (input, provider) = create_cache_input(l1, l2, block_number).await;
139147
let cache_path = Some("./".into());
140148
assert!(cache::set_input(&cache_path, block_number, l2, &input).is_ok());

Diff for: lib/src/builder.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
CycleTracker,
1313
};
1414
use anyhow::{bail, ensure, Result};
15-
use reth_chainspec::{ChainSpecBuilder, HOLESKY, MAINNET, TAIKO_A7, TAIKO_MAINNET};
15+
use reth_chainspec::{ChainSpecBuilder, HOLESKY, MAINNET, TAIKO_A7, TAIKO_DEV, TAIKO_MAINNET};
1616
use reth_evm::execute::{BlockExecutionOutput, BlockValidationError, Executor, ProviderError};
1717
use reth_evm_ethereum::execute::{
1818
validate_block_post_execution, Consensus, EthBeaconConsensus, EthExecutorProvider,
@@ -92,6 +92,7 @@ impl<DB: Database<Error = ProviderError> + DatabaseCommit + OptimisticDatabase>
9292
)
9393
}
9494
"holesky" => HOLESKY.clone(),
95+
"taiko_dev" => TAIKO_DEV.clone(),
9596
_ => unimplemented!(),
9697
};
9798

Diff for: provers/risc0/driver/src/lib.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use alloy_primitives::B256;
44
use hex::ToHex;
5+
use log::warn;
56
use raiko_lib::{
67
input::{GuestInput, GuestOutput},
78
prover::{IdStore, IdWrite, Proof, ProofKey, Prover, ProverConfig, ProverError, ProverResult},
@@ -83,7 +84,7 @@ impl Prover for Risc0Prover {
8384
let journal: String = result.clone().unwrap().1.journal.encode_hex();
8485

8586
// Create/verify Groth16 SNARK
86-
if config.snark {
87+
let snark_proof = if config.snark {
8788
let Some((stark_uuid, stark_receipt)) = result else {
8889
return Err(ProverError::GuestError(
8990
"No STARK data to snarkify!".to_owned(),
@@ -97,12 +98,17 @@ impl Prover for Risc0Prover {
9798

9899
traicing_info!("Validating SNARK uuid: {snark_uuid}");
99100

100-
verify_groth16_snark(image_id, snark_receipt)
101+
let enc_proof = verify_groth16_snark(image_id, snark_receipt)
101102
.await
102103
.map_err(|err| format!("Failed to verify SNARK: {err:?}"))?;
103-
}
104104

105-
Ok(Risc0Response { proof: journal }.into())
105+
format!("0x{}", hex::encode(enc_proof))
106+
} else {
107+
warn!("proof is not in snark mode, please check.");
108+
journal
109+
};
110+
111+
Ok(Risc0Response { proof: snark_proof }.into())
106112
}
107113

108114
async fn cancel(key: ProofKey, id_store: Box<&mut dyn IdStore>) -> ProverResult<()> {

Diff for: provers/risc0/driver/src/methods/risc0_guest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pub const RISC0_GUEST_ELF: &[u8] =
22
include_bytes!("../../../guest/target/riscv32im-risc0-zkvm-elf/release/risc0-guest");
33
pub const RISC0_GUEST_ID: [u32; 8] = [
4-
1914784930, 3634152083, 2963332796, 2630159414, 3104046433, 3092402903, 3447446567, 3034579556,
4+
778116790, 3147350329, 3518605327, 2941923414, 1667247192, 584142090, 3914021799, 3838916379,
55
];

Diff for: provers/risc0/driver/src/snarks.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515
use std::{str::FromStr, sync::Arc};
1616

17-
use alloy_sol_types::sol;
17+
use alloy_primitives::B256;
18+
use alloy_sol_types::{sol, SolValue};
1819
use anyhow::Result;
1920
use bonsai_sdk::alpha::responses::SnarkReceipt;
2021
use ethers_contract::abigen;
@@ -154,7 +155,10 @@ pub async fn stark2snark(
154155
Ok(snark_data)
155156
}
156157

157-
pub async fn verify_groth16_snark(image_id: Digest, snark_receipt: SnarkReceipt) -> Result<()> {
158+
pub async fn verify_groth16_snark(
159+
image_id: Digest,
160+
snark_receipt: SnarkReceipt,
161+
) -> Result<Vec<u8>> {
158162
let verifier_rpc_url =
159163
std::env::var("GROTH16_VERIFIER_RPC_URL").expect("env GROTH16_VERIFIER_RPC_URL");
160164
let groth16_verifier_addr = {
@@ -180,7 +184,7 @@ pub async fn verify_groth16_snark(image_id: Digest, snark_receipt: SnarkReceipt)
180184
tracing_info!("Journal Digest: {}", hex::encode(journal_digest));
181185
let verify_call_res = IRiscZeroVerifier::new(groth16_verifier_addr, http_client)
182186
.verify(
183-
seal.into(),
187+
seal.clone().into(),
184188
image_id.as_bytes().try_into().unwrap(),
185189
journal_digest.into(),
186190
)
@@ -192,5 +196,10 @@ pub async fn verify_groth16_snark(image_id: Digest, snark_receipt: SnarkReceipt)
192196
tracing_err!("SNARK verification failed: {:?}!", verify_call_res);
193197
}
194198

195-
Ok(())
199+
Ok((seal, B256::from_slice(image_id.as_bytes()))
200+
.abi_encode()
201+
.iter()
202+
.skip(32)
203+
.copied()
204+
.collect())
196205
}

0 commit comments

Comments
 (0)