Skip to content

Commit

Permalink
feat(devnet): update devnet config (#326)
Browse files Browse the repository at this point in the history
* update devnet config

Signed-off-by: smtmfft <smtm@taiko.xyz>

* update devnet config

Signed-off-by: smtmfft <smtm@taiko.xyz>

* update dependency cargo.lock

Signed-off-by: smtmfft <smtm@taiko.xyz>

* update risc0 binary

Signed-off-by: smtmfft <smtm@taiko.xyz>

* update sp1 binary

Signed-off-by: smtmfft <smtm@taiko.xyz>

* update testcase

Signed-off-by: smtmfft <smtm@taiko.xyz>

* debug CI

Signed-off-by: smtmfft <smtm@taiko.xyz>

* debug ci

* debug CI

* fix CI

* resolve merge conflict

Signed-off-by: smtmfft <smtm@taiko.xyz>

* fix test

* fix clippy

---------

Signed-off-by: smtmfft <smtm@taiko.xyz>
  • Loading branch information
smtmfft authored Jul 22, 2024
1 parent f6d02b3 commit 959bdea
Show file tree
Hide file tree
Showing 14 changed files with 269 additions and 117 deletions.
82 changes: 41 additions & 41 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions core/src/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{merge, prover::NativeProver};
use alloy_primitives::{Address, B256};
use clap::{Args, ValueEnum};
use raiko_lib::{
consts::VerifierType,
input::{BlobProofType, GuestInput, GuestOutput},
primitives::eip4844::{calc_kzg_proof, commitment_to_version_hash, kzg_proof_to_bytes},
prover::{IdStore, IdWrite, Proof, ProofKey, Prover, ProverError},
Expand Down Expand Up @@ -153,6 +154,17 @@ impl TryFrom<u8> for ProofType {
}
}

impl From<ProofType> for VerifierType {
fn from(val: ProofType) -> Self {
match val {
ProofType::Native => VerifierType::None,
ProofType::Sp1 => VerifierType::SP1,
ProofType::Sgx => VerifierType::SGX,
ProofType::Risc0 => VerifierType::RISC0,
}
}
}

impl ProofType {
/// Run the prover driver depending on the proof type.
pub async fn run_prover(
Expand All @@ -165,7 +177,7 @@ impl ProofType {
let mut proof = match self {
ProofType::Native => NativeProver::run(input.clone(), output, config, store)
.await
.map_err(|e| e.into()),
.map_err(<ProverError as Into<RaikoError>>::into),
ProofType::Sp1 => {
#[cfg(feature = "sp1")]
return sp1_driver::Sp1Prover::run(input.clone(), output, config, store)
Expand Down Expand Up @@ -217,7 +229,7 @@ impl ProofType {
match self {
ProofType::Native => NativeProver::cancel(proof_key, read)
.await
.map_err(|e| e.into()),
.map_err(<ProverError as Into<RaikoError>>::into),
ProofType::Sp1 => {
#[cfg(feature = "sp1")]
return sp1_driver::Sp1Prover::cancel(proof_key, read)
Expand Down
9 changes: 3 additions & 6 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ use raiko_lib::{
prover::ProofKey,
};
use raiko_lib::{
consts::{ChainSpec, VerifierType},
prover::IdStore,
};
use raiko_lib::{
consts::ChainSpec,
input::{GuestInput, GuestOutput, TaikoProverData},
prover::IdWrite,
prover::{IdStore, IdWrite},
};
use reth_primitives::Header;
use serde_json::Value;
Expand Down Expand Up @@ -88,7 +85,7 @@ impl Raiko {

Ok(GuestOutput {
header: header.clone(),
hash: ProtocolInstance::new(input, &header, VerifierType::None)?
hash: ProtocolInstance::new(input, &header, self.request.proof_type.into())?
.instance_hash(),
})
}
Expand Down
65 changes: 65 additions & 0 deletions host/config/chain_spec_list_devnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
[
{
"name": "taiko_dev_l1",
"chain_id": 32382,
"max_spec_id": "CANCUN",
"hard_forks": {
"FRONTIER": {
"Block": 0
},
"SHANGHAI": {
"Timestamp": 0
},
"CANCUN": {
"Timestamp": 0
}
},
"eip_1559_constants": {
"base_fee_change_denominator": "0x8",
"base_fee_max_increase_denominator": "0x8",
"base_fee_max_decrease_denominator": "0x8",
"elasticity_multiplier": "0x2"
},
"l1_contract": null,
"l2_contract": null,
"rpc": "https://l1rpc.internal.taiko.xyz",
"beacon_rpc": "https://l1beacon.internal.taiko.xyz/",
"verifier_address": {
"SGX": null,
"SP1": null,
"RISC0": null
},
"genesis_time": 1721296000,
"seconds_per_slot": 12,
"is_taiko": false
},
{
"name": "taiko_dev",
"chain_id": 167001,
"max_spec_id": "SHANGHAI",
"hard_forks": {
"SHANGHAI": {
"Block": 0
},
"CANCUN": "TBD"
},
"eip_1559_constants": {
"base_fee_change_denominator": "0x8",
"base_fee_max_increase_denominator": "0x8",
"base_fee_max_decrease_denominator": "0x8",
"elasticity_multiplier": "0x2"
},
"l1_contract": "0xcdE816aFd1B7db50f09831097e71F99877809218",
"l2_contract": "0x1670010000000000000000000000000000010001",
"rpc": "https://rpc.internal.taiko.xyz",
"beacon_rpc": null,
"verifier_address":{
"SGX":"0xC069c3d2a9f2479F559AD34485698ad5199C555f",
"SP1":null,
"RISC0":"0xde28533011Ef2d6484A03beFD8ffbF31d179AE6A"
},
"genesis_time": 0,
"seconds_per_slot": 1,
"is_taiko": true
}
]
12 changes: 10 additions & 2 deletions host/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,15 @@ mod test {
use crate::cache;

use alloy_primitives::{Address, B256};
use alloy_provider::Provider;
use raiko_core::{
interfaces::{ProofRequest, ProofType},
provider::rpc::RpcBlockDataProvider,
Raiko,
};
use raiko_lib::input::BlobProofType;
use raiko_lib::{
consts::{Network, SupportedChainSpecs},
consts::{ChainSpec, Network, SupportedChainSpecs},
input::GuestInput,
};

Expand Down Expand Up @@ -130,11 +131,18 @@ mod test {
(input, provider.clone())
}

async fn get_a_testable_block_num(chain_spec: &ChainSpec) -> u64 {
let provider = RpcBlockDataProvider::new(&chain_spec.rpc, 0).unwrap();
let height = provider.provider.get_block_number().await.unwrap();
height - 299582 // a hardcode helka & mainnet height diff for the test
}

#[tokio::test]
async fn test_generate_input_from_cache() {
let l1 = &Network::Holesky.to_string();
let l2 = &Network::TaikoA7.to_string();
let block_number: u64 = 123456;
let taiko_chain_spec = SupportedChainSpecs::default().get_chain_spec(l2).unwrap();
let block_number: u64 = get_a_testable_block_num(&taiko_chain_spec).await;
let (input, provider) = create_cache_input(l1, l2, block_number).await;
let cache_path = Some("./".into());
assert!(cache::set_input(&cache_path, block_number, l2, &input).is_ok());
Expand Down
3 changes: 2 additions & 1 deletion lib/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
CycleTracker,
};
use anyhow::{bail, ensure, Result};
use reth_chainspec::{ChainSpecBuilder, HOLESKY, MAINNET, TAIKO_A7, TAIKO_MAINNET};
use reth_chainspec::{ChainSpecBuilder, HOLESKY, MAINNET, TAIKO_A7, TAIKO_DEV, TAIKO_MAINNET};
use reth_evm::execute::{BlockExecutionOutput, BlockValidationError, Executor, ProviderError};
use reth_evm_ethereum::execute::{
validate_block_post_execution, Consensus, EthBeaconConsensus, EthExecutorProvider,
Expand Down Expand Up @@ -92,6 +92,7 @@ impl<DB: Database<Error = ProviderError> + DatabaseCommit + OptimisticDatabase>
)
}
"holesky" => HOLESKY.clone(),
"taiko_dev" => TAIKO_DEV.clone(),
_ => unimplemented!(),
};

Expand Down
14 changes: 10 additions & 4 deletions provers/risc0/driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

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

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

verify_groth16_snark(image_id, snark_receipt)
let enc_proof = verify_groth16_snark(image_id, snark_receipt)
.await
.map_err(|err| format!("Failed to verify SNARK: {err:?}"))?;
}

Ok(Risc0Response { proof: journal }.into())
format!("0x{}", hex::encode(enc_proof))
} else {
warn!("proof is not in snark mode, please check.");
journal
};

Ok(Risc0Response { proof: snark_proof }.into())
}

async fn cancel(key: ProofKey, id_store: Box<&mut dyn IdStore>) -> ProverResult<()> {
Expand Down
2 changes: 1 addition & 1 deletion provers/risc0/driver/src/methods/risc0_guest.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub const RISC0_GUEST_ELF: &[u8] =
include_bytes!("../../../guest/target/riscv32im-risc0-zkvm-elf/release/risc0-guest");
pub const RISC0_GUEST_ID: [u32; 8] = [
1914784930, 3634152083, 2963332796, 2630159414, 3104046433, 3092402903, 3447446567, 3034579556,
778116790, 3147350329, 3518605327, 2941923414, 1667247192, 584142090, 3914021799, 3838916379,
];
17 changes: 13 additions & 4 deletions provers/risc0/driver/src/snarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

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

use alloy_sol_types::sol;
use alloy_primitives::B256;
use alloy_sol_types::{sol, SolValue};
use anyhow::Result;
use bonsai_sdk::alpha::responses::SnarkReceipt;
use ethers_contract::abigen;
Expand Down Expand Up @@ -154,7 +155,10 @@ pub async fn stark2snark(
Ok(snark_data)
}

pub async fn verify_groth16_snark(image_id: Digest, snark_receipt: SnarkReceipt) -> Result<()> {
pub async fn verify_groth16_snark(
image_id: Digest,
snark_receipt: SnarkReceipt,
) -> Result<Vec<u8>> {
let verifier_rpc_url =
std::env::var("GROTH16_VERIFIER_RPC_URL").expect("env GROTH16_VERIFIER_RPC_URL");
let groth16_verifier_addr = {
Expand All @@ -180,7 +184,7 @@ pub async fn verify_groth16_snark(image_id: Digest, snark_receipt: SnarkReceipt)
tracing_info!("Journal Digest: {}", hex::encode(journal_digest));
let verify_call_res = IRiscZeroVerifier::new(groth16_verifier_addr, http_client)
.verify(
seal.into(),
seal.clone().into(),
image_id.as_bytes().try_into().unwrap(),
journal_digest.into(),
)
Expand All @@ -192,5 +196,10 @@ pub async fn verify_groth16_snark(image_id: Digest, snark_receipt: SnarkReceipt)
tracing_err!("SNARK verification failed: {:?}!", verify_call_res);
}

Ok(())
Ok((seal, B256::from_slice(image_id.as_bytes()))
.abi_encode()
.iter()
.skip(32)
.copied()
.collect())
}
Loading

0 comments on commit 959bdea

Please sign in to comment.