diff --git a/host/src/interfaces/request.rs b/host/src/interfaces/request.rs index 6349c1afe..06e0fe3bc 100644 --- a/host/src/interfaces/request.rs +++ b/host/src/interfaces/request.rs @@ -6,7 +6,6 @@ use alloy_primitives::{Address, B256}; use clap::{Args, ValueEnum}; use raiko_lib::{ input::{GuestInput, GuestOutput}, - protocol_instance::ProtocolInstance, prover::{Proof, Prover}, }; use serde::{Deserialize, Serialize}; diff --git a/host/src/preflight.rs b/host/src/preflight.rs index 7cc1552e5..fd7112f67 100644 --- a/host/src/preflight.rs +++ b/host/src/preflight.rs @@ -296,7 +296,7 @@ async fn prepare_taiko_chain_input( // Create the transactions from the proposed tx list let transactions = generate_transactions( - &taiko_chain_spec, + taiko_chain_spec, proposal_event.meta.blobUsed, &tx_data, Some(anchor_tx.clone()), diff --git a/host/src/raiko.rs b/host/src/raiko.rs index b23d5ac75..c967523e0 100644 --- a/host/src/raiko.rs +++ b/host/src/raiko.rs @@ -1,4 +1,4 @@ -use alloy_primitives::{FixedBytes, B256}; +use alloy_primitives::{FixedBytes}; use raiko_lib::builder::{BlockBuilderStrategy, TaikoStrategy}; use raiko_lib::consts::{ChainSpec, VerifierType}; use raiko_lib::input::{GuestInput, GuestOutput, TaikoProverData}; @@ -60,12 +60,7 @@ impl Raiko { info!("Verifying final state using provider data ..."); info!("Final block hash derived successfully. {}", header.hash()); info!("Final block header derived successfully. {header:?}"); - let pi = ProtocolInstance::new( - input, - &header, - VerifierType::None, - )? - .instance_hash(); + let pi = ProtocolInstance::new(input, &header, VerifierType::None)?.instance_hash(); // Check against the expected value of all fields for easy debugability let exp = &input.block_header_reference; @@ -169,7 +164,7 @@ impl Prover for NativeProver { return Err(ProverError::GuestError("Unexpected output".to_owned())); }; - ProtocolInstance::new( &input, &header, VerifierType::None) + ProtocolInstance::new(&input, &header, VerifierType::None) .map_err(|e| ProverError::GuestError(e.to_string()))?; to_proof(Ok(NativeResponse { diff --git a/lib/src/consts.rs b/lib/src/consts.rs index e2bcce1c5..88dd0f000 100644 --- a/lib/src/consts.rs +++ b/lib/src/consts.rs @@ -51,7 +51,7 @@ pub struct SupportedChainSpecs(HashMap); impl SupportedChainSpecs { pub fn default() -> Self { - let deserialized: Vec = serde_json::from_str(&DEFAULT_CHAIN_SPECS).unwrap(); + let deserialized: Vec = serde_json::from_str(DEFAULT_CHAIN_SPECS).unwrap(); let chain_spec_list = deserialized .iter() .map(|cs| (cs.name.clone(), cs.clone())) @@ -62,7 +62,7 @@ impl SupportedChainSpecs { #[cfg(feature = "std")] pub fn merge_from_file(file_path: PathBuf) -> Result { let mut known_chain_specs = SupportedChainSpecs::default(); - let file = std::fs::File::open(&file_path)?; + let file = std::fs::File::open(file_path)?; let reader = std::io::BufReader::new(file); let config: Value = serde_json::from_reader(reader)?; let chain_spec_list: Vec = serde_json::from_value(config)?; @@ -87,8 +87,7 @@ impl SupportedChainSpecs { pub fn get_chain_spec_with_chain_id(&self, chain_id: u64) -> Option { self.0 .values() - .find(|spec| spec.chain_id == chain_id) - .map(|spec| spec.clone()) + .find(|spec| spec.chain_id == chain_id).cloned() } } @@ -135,7 +134,6 @@ impl Default for Eip1559Constants { } } - #[repr(u8)] #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] pub enum VerifierType { diff --git a/lib/src/protocol_instance.rs b/lib/src/protocol_instance.rs index 05b59741c..9d703a2f5 100644 --- a/lib/src/protocol_instance.rs +++ b/lib/src/protocol_instance.rs @@ -1,6 +1,6 @@ use alloy_consensus::Header as AlloyConsensusHeader; use alloy_primitives::{Address, TxHash, B256}; -use alloy_sol_types::{sol, SolValue}; +use alloy_sol_types::{SolValue}; use anyhow::{ensure, Result}; use c_kzg::{Blob, KzgCommitment, KzgSettings}; use raiko_primitives::keccak::keccak; @@ -10,7 +10,7 @@ use super::utils::ANCHOR_GAS_LIMIT; #[cfg(not(feature = "std"))] use crate::no_std::*; use crate::{ - consts::{VerifierType, SupportedChainSpecs}, + consts::{SupportedChainSpecs, VerifierType}, input::{BlockMetadata, EthDeposit, GuestInput, Transition}, utils::HeaderHasher, }; @@ -28,7 +28,6 @@ pub struct ProtocolInstance { } impl ProtocolInstance { - pub fn new( input: &GuestInput, header: &AlloyConsensusHeader, @@ -55,7 +54,7 @@ impl ProtocolInstance { } else { TxHash::from(keccak(input.taiko.tx_data.as_slice())) }; - + // If the passed in chain spec contains a known chain id, the chain spec NEEDS to match the // one we expect, because the prover could otherwise just fill in any values. // The chain id is used because that is the value that is put onchain, @@ -91,7 +90,7 @@ impl ProtocolInstance { "unexpected eip_1559_constants" ); } - + let deposits = input .withdrawals .iter() @@ -101,13 +100,13 @@ impl ProtocolInstance { id: w.index, }) .collect::>(); - + let gas_limit: u64 = header.gas_limit.try_into().unwrap(); let verifier_address = input .chain_spec .verifier_address .get(&proof_type) - .expect(&format!("verifier_address not set for {:?}", proof_type)) + .unwrap_or_else(|| panic!("verifier_address not set for {:?}", proof_type)) .unwrap(); let pi = ProtocolInstance { transition: Transition { @@ -142,7 +141,7 @@ impl ProtocolInstance { chain_id: input.chain_spec.chain_id, verifier_address, }; - + // Sanity check if input.chain_spec.is_taiko() { ensure!( @@ -153,7 +152,7 @@ impl ProtocolInstance { ) ); } - + Ok(pi) } @@ -162,7 +161,6 @@ impl ProtocolInstance { self } - pub fn meta_hash(&self) -> B256 { keccak(self.block_metadata.abi_encode()).into() } @@ -171,19 +169,19 @@ impl ProtocolInstance { pub fn instance_hash(&self) -> B256 { /// packages/protocol/contracts/verifiers/libs/LibPublicInput.sol /// "VERIFY_PROOF", _chainId, _verifierContract, _tran, _newInstance, _prover, _metaHash - keccak( - ( + keccak( + ( "VERIFY_PROOF", self.chain_id, self.verifier_address, - self.transition.clone(), + self.transition.clone(), self.sgx_instance, self.prover, - self.meta_hash(), - ) - .abi_encode() - - ).into() + self.meta_hash(), + ) + .abi_encode(), + ) + .into() } } @@ -194,7 +192,6 @@ pub fn kzg_to_versioned_hash(commitment: &KzgCommitment) -> B256 { B256::new(res.into()) } - fn bytes_to_bytes32(input: &[u8]) -> [u8; 32] { let mut bytes = [0u8; 32]; let len = core::cmp::min(input.len(), 32); diff --git a/lib/src/prover.rs b/lib/src/prover.rs index c6e1d6c1d..5f0ac5695 100644 --- a/lib/src/prover.rs +++ b/lib/src/prover.rs @@ -1,12 +1,10 @@ use std::fmt; -use alloy_primitives::B256; use serde::Serialize; use thiserror::Error as ThisError; use crate::{ input::{GuestInput, GuestOutput}, - protocol_instance::ProtocolInstance, }; #[derive(ThisError, Debug)] diff --git a/provers/sgx/guest/src/one_shot.rs b/provers/sgx/guest/src/one_shot.rs index 4e390c298..dd9db865d 100644 --- a/provers/sgx/guest/src/one_shot.rs +++ b/provers/sgx/guest/src/one_shot.rs @@ -8,7 +8,10 @@ use std::{ use anyhow::{anyhow, bail, Context, Error, Result}; use base64_serde::base64_serde_type; use raiko_lib::{ - builder::{BlockBuilderStrategy, TaikoStrategy}, consts::VerifierType, input::GuestInput, protocol_instance::ProtocolInstance + builder::{BlockBuilderStrategy, TaikoStrategy}, + consts::VerifierType, + input::GuestInput, + protocol_instance::ProtocolInstance, }; use raiko_primitives::Address; use secp256k1::{KeyPair, SecretKey}; @@ -134,8 +137,7 @@ pub async fn one_shot(global_opts: GlobalOpts, args: OneShotArgs) -> Result<()> TaikoStrategy::build_from(&input).expect("Failed to build the resulting block"); // Calculate the public input hash - let pi = ProtocolInstance::new(&input, &header, VerifierType::SGX)? - .sgx_instance(new_instance); + let pi = ProtocolInstance::new(&input, &header, VerifierType::SGX)?.sgx_instance(new_instance); let pi_hash = pi.instance_hash(); println!( diff --git a/provers/sgx/prover/src/lib.rs b/provers/sgx/prover/src/lib.rs index 53ba3f8b2..fd5bdaf11 100644 --- a/provers/sgx/prover/src/lib.rs +++ b/provers/sgx/prover/src/lib.rs @@ -7,14 +7,11 @@ use std::{ str, }; -use alloy_sol_types::SolValue; use once_cell::sync::Lazy; use raiko_lib::{ input::{GuestInput, GuestOutput}, - protocol_instance::ProtocolInstance, prover::{to_proof, Proof, Prover, ProverConfig, ProverError, ProverResult}, }; -use raiko_primitives::{keccak::keccak, B256}; use serde::{Deserialize, Serialize}; use serde_json::Value; use serde_with::serde_as; diff --git a/provers/sp1/driver/src/lib.rs b/provers/sp1/driver/src/lib.rs index 4a197b395..7a2865ff8 100644 --- a/provers/sp1/driver/src/lib.rs +++ b/provers/sp1/driver/src/lib.rs @@ -1,11 +1,8 @@ #![cfg(feature = "enable")] use std::env; -use alloy_primitives::B256; -use alloy_sol_types::SolValue; use raiko_lib::{ input::{GuestInput, GuestOutput}, - protocol_instance::ProtocolInstance, prover::{to_proof, Proof, Prover, ProverConfig, ProverResult}, }; use serde::{Deserialize, Serialize}; @@ -37,8 +34,6 @@ impl Prover for Sp1Prover { let (pk, vk) = client.setup(ELF); let mut proof = client.prove(&pk, stdin).expect("Sp1: proving failed"); - - // Read the output. let output = proof.public_values.read::(); // Verify proof. @@ -76,11 +71,13 @@ mod test { let client = ProverClient::new(); let stdin = SP1Stdin::new(); let (pk, vk) = client.setup(TEST_ELF); - let proof = client.prove_groth16(&pk, stdin).expect("Sp1: proving failed"); + let proof = client + .prove_groth16(&pk, stdin) + .expect("Sp1: proving failed"); // client // .verify(&proof, &vk) // .expect("Sp1: verification failed"); - + let contract_dir = "../contract"; sp1_sdk::artifacts::export_solidity_groth16_verifier(contract_dir) .expect("failed to export verifier");