diff --git a/core/src/preflight.rs b/core/src/preflight.rs index c10f91a7d..e8846f513 100644 --- a/core/src/preflight.rs +++ b/core/src/preflight.rs @@ -14,20 +14,13 @@ use kzg::eip_4844::Blob; use raiko_lib::{ builder::{ prepare::TaikoHeaderPrepStrategy, BlockBuilder, OptimisticDatabase, TkoTxExecStrategy, - }, - clear_line, - consts::ChainSpec, - inplace_print, - input::{ + }, clear_line, commitment_to_version_hash, consts::ChainSpec, inplace_print, input::{ decode_anchor, proposeBlockCall, BlockProposed, GuestInput, TaikoGuestInput, TaikoProverData, - }, - primitives::{ + }, primitives::{ eip4844::{self, set_commitment_proof, MAINNET_KZG_TRUSTED_SETUP}, mpt::proofs_to_tries, - }, - utils::{generate_transactions, to_header, zlib_compress_data}, - Measurement, + }, utils::{generate_transactions, to_header, zlib_compress_data}, Measurement }; use serde::{Deserialize, Serialize}; use std::collections::HashSet; @@ -369,7 +362,7 @@ fn preflight_blob_versioned_hash(blob_str: &str) -> [u8; 32] { kzg_settings, ) .expect("Could not create kzg commitment from blob"); - let version_hash: [u8; 32] = eip4844::commitment_to_version_hash(&commitment.to_bytes()).0; + let version_hash: [u8; 32] = commitment_to_version_hash(&commitment.to_bytes()).0; version_hash } diff --git a/lib/src/input.rs b/lib/src/input.rs index 77ef69f6c..59d8e0b7a 100644 --- a/lib/src/input.rs +++ b/lib/src/input.rs @@ -17,7 +17,6 @@ use std::path::PathBuf; #[cfg(not(feature = "std"))] use crate::no_std::*; -use crate::primitives::eip4844::TaikoKzgSettings; use crate::serde_helper::option_array_48; use crate::{ consts::ChainSpec, @@ -32,6 +31,9 @@ use revm::primitives::HashMap; use serde::{Deserialize, Serialize}; use serde_with::serde_as; +#[cfg(feature = "kzg")] +use crate::primitives::eip4844::TaikoKzgSettings; + /// Represents the state of an account's storage. /// The storage trie together with the used storage slots allow us to reconstruct all the /// required values. @@ -97,6 +99,7 @@ pub struct TaikoGuestInput { pub prover_data: TaikoProverData, #[serde(with = "option_array_48")] pub blob_commitment: Option<[u8; 48]>, + #[cfg(feature = "kzg")] pub kzg_settings: Option, pub skip_verify_blob: bool, } diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 38df3d7ba..52dd0679e 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -29,6 +29,8 @@ mod no_std { }; } +use revm_primitives::{B256, VERSIONED_HASH_VERSION_KZG}; +use sha2::{Digest, Sha256}; use tracing::debug; pub mod builder; @@ -192,6 +194,12 @@ pub fn guest_mem_forget(_t: T) { core::mem::forget(_t) } +pub fn commitment_to_version_hash(commitment: &[u8; 48]) -> B256 { + let mut hash = Sha256::digest(commitment); + hash[0] = VERSIONED_HASH_VERSION_KZG; + B256::new(hash.into()) +} + pub trait RlpBytes: Sized { /// Decodes the blob into the appropriate type. /// The input must contain exactly one value and no trailing data. diff --git a/lib/src/primitives/eip4844.rs b/lib/src/primitives/eip4844.rs index 6f8ccadae..99ae11002 100644 --- a/lib/src/primitives/eip4844.rs +++ b/lib/src/primitives/eip4844.rs @@ -1,3 +1,4 @@ +use crate::commitment_to_version_hash; use crate::input::GuestInput; use kzg::eip_4844::{ blob_to_polynomial, compute_challenge, compute_kzg_proof_rust, @@ -119,12 +120,6 @@ pub fn set_commitment_proof(proof: &KzgGroup, commitment: &KzgGroup) -> Result<( Ok(()) } -pub fn commitment_to_version_hash(commitment: &KzgGroup) -> B256 { - let mut hash = Sha256::digest(commitment); - hash[0] = VERSIONED_HASH_VERSION_KZG; - B256::new(hash.into()) -} - #[cfg(test)] mod test { use std::io::Read; diff --git a/lib/src/protocol_instance.rs b/lib/src/protocol_instance.rs index 411b74dcb..f1a7efb34 100644 --- a/lib/src/protocol_instance.rs +++ b/lib/src/protocol_instance.rs @@ -3,18 +3,15 @@ use alloy_consensus::Header as AlloyConsensusHeader; use alloy_primitives::{Address, TxHash, B256}; use alloy_sol_types::SolValue; use anyhow::{ensure, Result}; -// use c_kzg::{Blob, KzgCommitment, KzgSettings}; -use sha2::Digest as _; +use cfg_if::cfg_if; #[cfg(not(feature = "std"))] use crate::no_std::*; use crate::{ + commitment_to_version_hash, consts::{SupportedChainSpecs, VerifierType}, input::{BlockMetadata, EthDeposit, GuestInput, Transition}, - primitives::{ - eip4844::{self, KzgField}, - keccak::keccak, - }, + primitives::keccak::keccak, utils::HeaderHasher, }; @@ -28,7 +25,7 @@ pub struct ProtocolInstance { pub sgx_instance: Address, // only used for SGX pub chain_id: u64, pub verifier_address: Address, - pub proof_of_equivalence: (KzgField, KzgField), + pub proof_of_equivalence: ([u8; 32], [u8; 32]), } impl ProtocolInstance { @@ -38,12 +35,22 @@ impl ProtocolInstance { proof_type: VerifierType, ) -> Result { let blob_used = input.taiko.block_proposed.meta.blobUsed; - let mut proof_of_equivalence = (KzgField::default(), KzgField::default()); + + // If blob is used, tx_list_hash is the commitment to the blob + // and we need to comput the proof of equivalence when not skipping with the kzg feature enabled + // Otherwise the proof_of_equivalence is 0 + let mut proof_of_equivalence = ([0u8; 32], [0u8; 32]); let tx_list_hash = if blob_used { - if input.taiko.skip_verify_blob { - proof_of_equivalence = eip4844::proof_of_equivalence(input)?; + if !input.taiko.skip_verify_blob { + cfg_if::cfg_if!( + if #[cfg(feature = "kzg")] { + proof_of_equivalence = crate::primitives::eip4844::proof_of_equivalence(input)?; + } else { + return Err(anyhow::anyhow!("kzg feature is not enabled")); + } + ); } - eip4844::commitment_to_version_hash(&input.taiko.blob_commitment.unwrap()) + commitment_to_version_hash(&input.taiko.blob_commitment.unwrap()) } else { TxHash::from(keccak(input.taiko.tx_data.as_slice())) }; @@ -222,7 +229,7 @@ mod tests { graffiti: b256!("0000000000000000000000000000000000000000000000000000000000000000"), }; let meta_hash = b256!("9608088f69e586867154a693565b4f3234f26f82d44ef43fb99fd774e7266024"); - let proof_of_equivalence = (KzgField::default(), KzgField::default()); + let proof_of_equivalence = ([0u8; 32], [0u8; 32]); let pi_hash = keccak::keccak( ( @@ -257,7 +264,7 @@ mod tests { let (meta, trans, _proof) = <(BlockMetadata, Transition, TierProof)>::abi_decode_params(&input, false).unwrap(); let meta_hash: B256 = keccak::keccak(meta.abi_encode()).into(); - let proof_of_equivalence = (KzgField::default(), KzgField::default()); + let proof_of_equivalence = ([0u8; 32], [0u8; 32]); let pi_hash = keccak::keccak( ( diff --git a/provers/risc0/driver/src/methods/risc0_guest.rs b/provers/risc0/driver/src/methods/risc0_guest.rs index 68325b7fd..801cbd463 100644 --- a/provers/risc0/driver/src/methods/risc0_guest.rs +++ b/provers/risc0/driver/src/methods/risc0_guest.rs @@ -1,4 +1,7 @@ - -pub const RISC0_GUEST_ELF: &[u8] = include_bytes!("../../../guest/target/riscv32im-risc0-zkvm-elf/release/risc0-guest"); -pub const RISC0_GUEST_ID: [u32; 8] = [1759551775, 3661761430, 1950818100, 3620390442, 4224211464, 686568881, 1963228835, 1545061903]; -pub const RISC0_GUEST_PATH: &str = r#"/home/ubuntu/raiko/provers/risc0/guest/target/riscv32im-risc0-zkvm-elf/release/risc0-guest"#; +pub const RISC0_GUEST_ELF: &[u8] = + include_bytes!("../../../guest/target/riscv32im-risc0-zkvm-elf/release/risc0-guest"); +pub const RISC0_GUEST_ID: [u32; 8] = [ + 1759551775, 3661761430, 1950818100, 3620390442, 4224211464, 686568881, 1963228835, 1545061903, +]; +pub const RISC0_GUEST_PATH: &str = + r#"/home/ubuntu/raiko/provers/risc0/guest/target/riscv32im-risc0-zkvm-elf/release/risc0-guest"#; diff --git a/provers/sp1/guest/elf/sp1-guest b/provers/sp1/guest/elf/sp1-guest index b67ecb345..f761d1677 100755 Binary files a/provers/sp1/guest/elf/sp1-guest and b/provers/sp1/guest/elf/sp1-guest differ