diff --git a/Cargo.lock b/Cargo.lock index 580d323fc2..d4746e56aa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -515,6 +515,7 @@ dependencies = [ "rand_chacha", "rand_xorshift", "serde", + "serde_json", "snark-verifier", "snark-verifier-sdk", "zkevm-circuits", diff --git a/circuit-benchmarks/Cargo.toml b/circuit-benchmarks/Cargo.toml index 3591e399b1..5f69870985 100644 --- a/circuit-benchmarks/Cargo.toml +++ b/circuit-benchmarks/Cargo.toml @@ -24,6 +24,7 @@ ethers-signers = "=2.0.0" mock = { path = "../mock" } rand_chacha = "0.3" serde = { version = "1.0.136", features = ["derive"] } +serde_json = "*" hex = "0.4.3" [features] diff --git a/circuit-benchmarks/src/super_circuit.rs b/circuit-benchmarks/src/super_circuit.rs index 910b155e4e..0d4ba0ab29 100644 --- a/circuit-benchmarks/src/super_circuit.rs +++ b/circuit-benchmarks/src/super_circuit.rs @@ -1,6 +1,8 @@ //! SuperCircuit circuit benchmarks +use eth_types::{Bytes, U256}; use halo2_proofs::poly::commitment::Params; +use serde::{Deserialize, Serialize}; use std::{fs, rc::Rc}; use zkevm_circuits::{ root_circuit::{ @@ -14,16 +16,18 @@ use bus_mapping::circuit_input_builder::CircuitsParams; use rand::SeedableRng; +use ark_std::{end_timer, start_timer}; use halo2_proofs::{ - halo2curves::bn256::{Bn256, Fq, Fr, G1Affine}, + halo2curves::{ + bn256::{Bn256, Fq, Fr, G1Affine}, + ff::PrimeField, + }, plonk::{keygen_pk, keygen_vk, ProvingKey, VerifyingKey}, poly::{ commitment::ParamsProver, kzg::commitment::{KZGCommitmentScheme, ParamsKZG}, }, }; - -use ark_std::{end_timer, start_timer}; use std::path::Path; use snark_verifier_sdk::{ @@ -57,6 +61,12 @@ pub type PlonkVerifierSHPLONK = use rand::rngs::StdRng; +#[derive(Serialize, Deserialize, Debug)] +struct BlockProofData { + instances: Vec, + proof: Bytes, +} + /// Fixed rng for testing purposes pub fn fixed_rng() -> StdRng { StdRng::seed_from_u64(9) @@ -255,6 +265,21 @@ fn create_root_super_circuit_prover_sdk } }; + let block_proof_data = BlockProofData { + instances: instances + .iter() + .flatten() + .map(|v| U256::from_little_endian(v.to_repr().as_ref())) + .collect(), + proof: proof_calldata.clone().into(), + }; + + fs::write( + Path::new("./proof.json"), + serde_json::to_vec(&block_proof_data).unwrap(), + ) + .unwrap(); + let deployment_code = gen_verifier( ¶ms, &vk, @@ -314,6 +339,21 @@ fn create_1_level_root_super_circuit_prover_sdk AnchorTxCircuitConfig { ), ( "l1_height", - &anchor_tx.call_data[68..76], + &anchor_tx.call_data[68..100], PiFieldTag::L1Height, ), ( "parent_gas_used", - &anchor_tx.call_data[76..84], + &anchor_tx.call_data[100..132], PiFieldTag::ParentGasUsed, ), ] { diff --git a/zkevm-circuits/src/anchor_tx_circuit/test.rs b/zkevm-circuits/src/anchor_tx_circuit/test.rs index 50367eb676..a57bc8c2c0 100644 --- a/zkevm-circuits/src/anchor_tx_circuit/test.rs +++ b/zkevm-circuits/src/anchor_tx_circuit/test.rs @@ -240,7 +240,7 @@ fn anchor_test() { anchor_gas_cost: 150000, ..Default::default() }; - let block = gen_block::<1>(2, 100, protocol_instance, sign_tx); + let block = gen_block::<1>(2, 200, protocol_instance, sign_tx); assert_eq!(run::(&block, None), Ok(())); } @@ -252,6 +252,6 @@ fn anchor_test_when_sign_r_is_gx2() { }; let msg_hash = *N - *GX1_MUL_PRIVATEKEY; let msg_hash = H256::from(msg_hash.to_le_bytes()); - let block = gen_block::<1>(2, 100, protocol_instance, sign_tx_r_is_gx2); + let block = gen_block::<1>(2, 200, protocol_instance, sign_tx_r_is_gx2); assert_eq!(run::(&block, Some(msg_hash)), Ok(())); } diff --git a/zkevm-circuits/src/witness/protocol_instance.rs b/zkevm-circuits/src/witness/protocol_instance.rs index 0e3d5555bc..734efc148b 100644 --- a/zkevm-circuits/src/witness/protocol_instance.rs +++ b/zkevm-circuits/src/witness/protocol_instance.rs @@ -125,8 +125,8 @@ impl ProtocolInstance { result.extend_from_slice(&ANCHOR_TX_METHOD_SIGNATURE.to_be_bytes()); result.extend_from_slice(&self.meta_hash.l1_hash.to_fixed_bytes()); result.extend_from_slice(&self.signal_root.to_fixed_bytes()); - result.extend_from_slice(&self.meta_hash.l1_height.to_be_bytes()); - result.extend_from_slice(&(self.parent_gas_used as u64).to_be_bytes()); + result.extend_from_slice(&self.meta_hash.l1_height.to_word().to_be_bytes()); + result.extend_from_slice(&(self.parent_gas_used as u64).to_word().to_be_bytes()); result.into() } @@ -160,3 +160,35 @@ impl ProtocolInstance { ] } } + +#[cfg(test)] +mod tests { + use std::str::FromStr; + + use super::*; + #[test] + fn test_left_shift() { + let _field0 = left_shift(1u64, 192) + left_shift(1688574587u64, 128) + left_shift(9u64, 64); + + let _field5 = left_shift(0u32 as u64, 232) + + left_shift(124u32 as u64, 208) + + left_shift(21000u32 as u64, 176) + + left_shift( + Address::from_str("0000777700000000000000000000000000000001").unwrap(), + 16, + ); + let _field6 = left_shift( + Address::from_str("df09A0afD09a63fb04ab3573922437e1e637dE8b").unwrap(), + 96, + ); + + let _field9 = left_shift( + Address::from_str("70997970C51812dc3A010C7d01b50e0d17dc79C8").unwrap(), + 96, + ) + left_shift(0u64, 64) + + left_shift(141003u64, 32); + + let _field10 = + left_shift(6000000u64, 192) + left_shift(79u64, 128) + left_shift(120000u64, 64); + } +}