diff --git a/core/src/lib.rs b/core/src/lib.rs index 461130943..fa7adc02d 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -91,7 +91,7 @@ impl Raiko { Ok(GuestOutput { header: header.clone(), - hash: ProtocolInstance::new(input, &header, self.request.proof_type.into())? + hash: ProtocolInstance::new(input, &header, self.request.proof_type)? .instance_hash(), }) } diff --git a/core/src/prover.rs b/core/src/prover.rs index de89d859e..88581a6e0 100644 --- a/core/src/prover.rs +++ b/core/src/prover.rs @@ -1,8 +1,8 @@ use std::path::Path; use raiko_lib::{ - consts::VerifierType, input::{GuestInput, GuestOutput}, + proof_type::ProofType, protocol_instance::ProtocolInstance, prover::{IdStore, IdWrite, Proof, ProofKey, Prover, ProverConfig, ProverError, ProverResult}, }; @@ -49,7 +49,7 @@ impl Prover for NativeProver { trace!("Running the native prover for input {input:?}"); - let pi = ProtocolInstance::new(&input, &output.header, VerifierType::None) + let pi = ProtocolInstance::new(&input, &output.header, ProofType::Native) .map_err(|e| ProverError::GuestError(e.to_string()))?; if pi.instance_hash() != output.hash { return Err(ProverError::GuestError( diff --git a/lib/src/consts.rs b/lib/src/consts.rs index b73ed43f4..983948339 100644 --- a/lib/src/consts.rs +++ b/lib/src/consts.rs @@ -1,23 +1,20 @@ //! Constants for the Ethereum protocol. extern crate alloc; +use crate::primitives::{uint, BlockNumber, ChainId, U256}; +use crate::proof_type::ProofType; use alloc::collections::BTreeMap; - use alloy_primitives::Address; use anyhow::{anyhow, bail, Result}; +use once_cell::sync::Lazy; use reth_primitives::revm_primitives::SpecId; use serde::{Deserialize, Serialize}; use serde_json::Value; - -#[cfg(not(feature = "std"))] -use crate::no_std::*; -use crate::primitives::{uint, BlockNumber, ChainId, U256}; - -use once_cell::sync::Lazy; use std::path::PathBuf; use std::{collections::HashMap, env::var}; -use crate::proof_type::ProofType; +#[cfg(not(feature = "std"))] +use crate::no_std::*; /// U256 representation of 0. pub const ZERO: U256 = U256::ZERO; @@ -129,26 +126,6 @@ impl Default for Eip1559Constants { } } -#[repr(u8)] -#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] -pub enum VerifierType { - None, - SGX, - SP1, - RISC0, -} - -impl From for VerifierType { - fn from(val: ProofType) -> Self { - match val { - ProofType::Native => VerifierType::None, - ProofType::Sgx => VerifierType::SGX, - ProofType::Sp1 => VerifierType::SP1, - ProofType::Risc0 => VerifierType::RISC0, - } - } -} - /// Specification of a specific chain. #[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)] pub struct ChainSpec { @@ -161,7 +138,7 @@ pub struct ChainSpec { pub l2_contract: Option
, pub rpc: String, pub beacon_rpc: Option, - pub verifier_address_forks: BTreeMap>>, + pub verifier_address_forks: BTreeMap>>, pub genesis_time: u64, pub seconds_per_slot: u64, pub is_taiko: bool, @@ -229,14 +206,14 @@ impl ChainSpec { pub fn get_fork_verifier_address( &self, block_num: u64, - verifier_type: VerifierType, + proof_type: ProofType, ) -> Result
{ // fall down to the first fork that is active as default for (spec_id, fork) in self.hard_forks.iter().rev() { if fork.active(block_num, 0u64) { if let Some(fork_verifier) = self.verifier_address_forks.get(spec_id) { return fork_verifier - .get(&verifier_type) + .get(&proof_type) .ok_or_else(|| anyhow!("Verifier type not found")) .and_then(|address| { address.ok_or_else(|| anyhow!("Verifier address not found")) @@ -344,7 +321,7 @@ mod tests { .get_chain_spec(&Network::Ethereum.to_string()) .unwrap(); let verifier_address = eth_mainnet_spec - .get_fork_verifier_address(15_537_394, VerifierType::SGX) + .get_fork_verifier_address(15_537_394, ProofType::Sgx) .unwrap(); assert_eq!( verifier_address, @@ -355,14 +332,14 @@ mod tests { .get_chain_spec(&Network::TaikoA7.to_string()) .unwrap(); let verifier_address = hekla_mainnet_spec - .get_fork_verifier_address(12345, VerifierType::SGX) + .get_fork_verifier_address(12345, ProofType::Sgx) .unwrap(); assert_eq!( verifier_address, address!("532efbf6d62720d0b2a2bb9d11066e8588cae6d9") ); let verifier_address = hekla_mainnet_spec - .get_fork_verifier_address(15_537_394, VerifierType::SGX) + .get_fork_verifier_address(15_537_394, ProofType::Sgx) .unwrap(); assert_eq!( verifier_address, @@ -371,12 +348,12 @@ mod tests { } #[test] - fn forked_none_verifier_address() { + fn forked_native_verifier_address() { let eth_mainnet_spec = SupportedChainSpecs::default() .get_chain_spec(&Network::Ethereum.to_string()) .unwrap(); let verifier_address = eth_mainnet_spec - .get_fork_verifier_address(15_537_394, VerifierType::None) + .get_fork_verifier_address(15_537_394, ProofType::Native) .unwrap_or_default(); assert_eq!(verifier_address, Address::ZERO); } @@ -407,9 +384,9 @@ mod tests { verifier_address_forks: BTreeMap::from([( SpecId::FRONTIER, BTreeMap::from([ - (VerifierType::SGX, Some(Address::default())), - (VerifierType::SP1, None), - (VerifierType::RISC0, Some(Address::default())), + (ProofType::Sgx, Some(Address::default())), + (ProofType::Sp1, None), + (ProofType::Risc0, Some(Address::default())), ]), )]), genesis_time: 0u64, diff --git a/lib/src/protocol_instance.rs b/lib/src/protocol_instance.rs index c779735d6..019812b44 100644 --- a/lib/src/protocol_instance.rs +++ b/lib/src/protocol_instance.rs @@ -6,7 +6,7 @@ use reth_primitives::Header; #[cfg(not(feature = "std"))] use crate::no_std::*; use crate::{ - consts::{SupportedChainSpecs, VerifierType}, + consts::SupportedChainSpecs, input::{ ontake::{BlockMetadataV2, BlockProposedV2}, BlobProofType, BlockMetadata, BlockProposed, BlockProposedFork, EthDeposit, GuestInput, @@ -16,6 +16,7 @@ use crate::{ eip4844::{self, commitment_to_version_hash}, keccak::keccak, }, + proof_type::ProofType, CycleTracker, }; use reth_evm_ethereum::taiko::ANCHOR_GAS_LIMIT; @@ -138,7 +139,7 @@ pub struct ProtocolInstance { } impl ProtocolInstance { - pub fn new(input: &GuestInput, header: &Header, proof_type: VerifierType) -> Result { + pub fn new(input: &GuestInput, header: &Header, proof_type: ProofType) -> Result { let blob_used = input.taiko.block_proposed.blob_used(); // If blob is used, tx_list_hash is the commitment to the blob // and we need to verify the blob hash matches the blob data. @@ -307,16 +308,16 @@ impl ProtocolInstance { // Make sure the verifier supports the blob proof type fn get_blob_proof_type( - proof_type: VerifierType, + proof_type: ProofType, blob_proof_type_hint: BlobProofType, ) -> BlobProofType { // Enforce different blob proof type for different provers // due to performance considerations match proof_type { - VerifierType::None => blob_proof_type_hint, - VerifierType::SGX => BlobProofType::KzgVersionedHash, - VerifierType::SP1 => BlobProofType::ProofOfEquivalence, - VerifierType::RISC0 => BlobProofType::ProofOfEquivalence, + ProofType::Native => blob_proof_type_hint, + ProofType::Sgx => BlobProofType::KzgVersionedHash, + ProofType::Sp1 => BlobProofType::ProofOfEquivalence, + ProofType::Risc0 => BlobProofType::ProofOfEquivalence, } } diff --git a/provers/sgx/guest/src/one_shot.rs b/provers/sgx/guest/src/one_shot.rs index 156f92f9a..31162a277 100644 --- a/provers/sgx/guest/src/one_shot.rs +++ b/provers/sgx/guest/src/one_shot.rs @@ -12,6 +12,7 @@ use raiko_lib::{ consts::VerifierType, input::{GuestInput, RawAggregationGuestInput}, primitives::{keccak, Address, B256}, + proof_type::ProofType, protocol_instance::{aggregation_output_combine, ProtocolInstance}, }; use secp256k1::{Keypair, SecretKey}; @@ -134,7 +135,7 @@ pub async fn one_shot(global_opts: GlobalOpts, args: OneShotArgs) -> Result<()> // Process the block let header = calculate_block_header(&input); // Calculate the public input hash - let pi = ProtocolInstance::new(&input, &header, VerifierType::SGX)?.sgx_instance(new_instance); + let pi = ProtocolInstance::new(&input, &header, ProofType::SGX)?.sgx_instance(new_instance); let pi_hash = pi.instance_hash(); println!( diff --git a/provers/sgx/setup/src/setup_bootstrap.rs b/provers/sgx/setup/src/setup_bootstrap.rs index 1958b1673..2988bbc1d 100644 --- a/provers/sgx/setup/src/setup_bootstrap.rs +++ b/provers/sgx/setup/src/setup_bootstrap.rs @@ -69,8 +69,8 @@ pub(crate) async fn setup_bootstrap( // clean check file remove_instance_id(&config_dir)?; let bootstrap_proof = bootstrap(secret_dir, gramine_cmd()).await?; - let verifier_address = taiko_chain_spec - .get_fork_verifier_address(bootstrap_args.block_num, VerifierType::SGX)?; + let verifier_address = + taiko_chain_spec.get_fork_verifier_address(bootstrap_args.block_num, ProofType::SGX)?; let register_id = register_sgx_instance( &bootstrap_proof.quote, &l1_chain_spec.rpc, diff --git a/provers/sp1/driver/src/verifier.rs b/provers/sp1/driver/src/verifier.rs index 20c760e92..9b5c9533c 100644 --- a/provers/sp1/driver/src/verifier.rs +++ b/provers/sp1/driver/src/verifier.rs @@ -3,6 +3,7 @@ use alloy_primitives::B256; use raiko_lib::builder::calculate_block_header; use raiko_lib::consts::VerifierType; use raiko_lib::input::{BlobProofType, GuestInput, GuestOutput}; +use raiko_lib::proof_type::ProofType; use raiko_lib::protocol_instance::ProtocolInstance; use raiko_lib::prover::Prover; use raiko_lib::Measurement; @@ -39,7 +40,7 @@ async fn main() { let header = calculate_block_header(&input); - let _pi = ProtocolInstance::new(&input, &header, VerifierType::SP1) + let _pi = ProtocolInstance::new(&input, &header, ProofType::SP1) .unwrap() .instance_hash();