From 7283beeabe4973163b40d397d63be4a66821ba03 Mon Sep 17 00:00:00 2001 From: Einar Rasmussen Date: Sun, 30 Jun 2024 00:57:25 +0800 Subject: [PATCH] review: clippy --- .../src/fixed_recursive_verifier.rs | 60 ++++++++----------- evm_arithmetization/tests/two_to_one_block.rs | 16 +++-- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/evm_arithmetization/src/fixed_recursive_verifier.rs b/evm_arithmetization/src/fixed_recursive_verifier.rs index 0120305a2..4e3d57467 100644 --- a/evm_arithmetization/src/fixed_recursive_verifier.rs +++ b/evm_arithmetization/src/fixed_recursive_verifier.rs @@ -330,7 +330,6 @@ where rhs: AggregationChildTarget, mix_pv_hash: HashOutTarget, dummy_pis: Vec, - vk_len: usize, cyclic_vk: VerifierCircuitTarget, } @@ -372,7 +371,6 @@ where mix_pv_hash, dummy_pis, cyclic_vk, - vk_len: todo!(), }) } } @@ -989,25 +987,17 @@ where { let mut builder = CircuitBuilder::::new(block_circuit.circuit.common.config.clone()); - let mix_pv_hash_output = builder.add_virtual_hash(); - builder.register_public_inputs(&mix_pv_hash_output.elements); + let mix_pv_hash = builder.add_virtual_hash(); + builder.register_public_inputs(&mix_pv_hash.elements); // The number of PIS that will be added after padding by // `builder.add_verifier_data_public_inputs()`. - let verification_key_len = block_circuit - .circuit - .verifier_only - .circuit_digest - .elements - .len() - + (1 << block_circuit.circuit.common.config.fri_config.cap_height) - * (NUM_HASH_OUT_ELTS); + let verification_key_len = verification_key_len(&block_circuit.circuit); // We need to pad by PIS to match the count of PIS of the `base_proof`. let mut padding = block_circuit.circuit.common.num_public_inputs; padding -= verification_key_len; padding -= builder.num_public_inputs(); - //padding -= mix_pv_hash_output.elements.len(); let mut dummy_pis = vec![]; for _ in 0..padding { @@ -1047,19 +1037,18 @@ where mix_vec.extend(&lhs_hash); mix_vec.extend(&rhs_hash); - let mix_pv_hash = builder.hash_n_to_hash_no_pad::(mix_vec); + let mix_pv_hash_intermediate = builder.hash_n_to_hash_no_pad::(mix_vec); - builder.connect_hashes(mix_pv_hash_output, mix_pv_hash); + builder.connect_hashes(mix_pv_hash, mix_pv_hash_intermediate); let circuit = builder.build::(); TwoToOneBlockCircuitData { circuit, lhs, rhs, - mix_pv_hash: mix_pv_hash_output, + mix_pv_hash, dummy_pis, cyclic_vk, - vk_len: verification_key_len, } } @@ -1681,20 +1670,11 @@ where &self.two_to_one_block.circuit.verifier_only, ); - // TODO - let verification_key_len = self.two_to_one_block.vk_len; - - // // The number of PIS that will be added after padding by - // // `builder.add_verifier_data_public_inputs()`. - // let verification_key_len = block_circuit - // .circuit - // .verifier_only - // .circuit_digest - // .elements - // .len() - // + (1 << block_circuit.circuit.common.config.fri_config.cap_height) - // * (NUM_HASH_OUT_ELTS); - + // The number of PIS that will be added after padding by + // [`builder.add_verifier_data_public_inputs`]. + let verification_key_len = verification_key_len(&self.block.circuit); + assert_eq!(verification_key_len, 68); + debug_assert_eq!(lhs.public_inputs.len(), rhs.public_inputs.len()); let user_pis_len = lhs.public_inputs.len() - verification_key_len; log::info!("user_pis_len: {user_pis_len}"); @@ -2059,9 +2039,21 @@ fn shrinking_config() -> CircuitConfig { } } -pub fn extract_two_to_one_block_hash(public_inputs: &Vec) -> &[F; NUM_HASH_OUT_ELTS] -{ +/// Extracts the two-to-one block aggregation hash from a predefined location. +pub fn extract_two_to_one_block_hash(public_inputs: &[F]) -> &[F; NUM_HASH_OUT_ELTS] { public_inputs[0..NUM_HASH_OUT_ELTS] .try_into() - .expect("Public Inputs were malformed") + .expect("Public inputs vector was malformed.") +} + +/// Computes the length added to the public inputs vector by +/// [`CircuitBuilder::add_verifier_data_public_inputs`]. +pub fn verification_key_len(circuit: &CircuitData) -> usize +where + F: RichField + Extendable, + C: GenericConfig, + C::Hasher: AlgebraicHasher, +{ + circuit.verifier_only.circuit_digest.elements.len() + + (1 << circuit.common.config.fri_config.cap_height) * (NUM_HASH_OUT_ELTS) } diff --git a/evm_arithmetization/tests/two_to_one_block.rs b/evm_arithmetization/tests/two_to_one_block.rs index c2eeee28a..6fbd6cd66 100644 --- a/evm_arithmetization/tests/two_to_one_block.rs +++ b/evm_arithmetization/tests/two_to_one_block.rs @@ -3,7 +3,9 @@ use std::str::FromStr; use env_logger::{try_init_from_env, Env, DEFAULT_FILTER_ENV}; use ethereum_types::{Address, BigEndianHash, H256, U256}; -use evm_arithmetization::fixed_recursive_verifier::extract_two_to_one_block_hash; +use evm_arithmetization::fixed_recursive_verifier::{ + extract_two_to_one_block_hash, verification_key_len, +}; use evm_arithmetization::generation::mpt::{AccountRlp, LegacyReceiptRlp}; use evm_arithmetization::generation::{GenerationInputs, TrieInputs}; use evm_arithmetization::proof::{BlockHashes, BlockMetadata, PublicValues, TrieRoots}; @@ -297,18 +299,24 @@ fn test_two_to_one_block_aggregation() -> anyhow::Result<()> { let two_to_one = >::InnerHasher::two_to_one; // TODO: compute this - let user_pis_len = 2201; + + let verification_key_len = verification_key_len(&all_circuits.block.circuit); log::info!("Leaf hashes"); let mut hashes: Vec<_> = bp .iter() .map(|block_proof| { + let user_pis_len = block_proof.public_inputs.len() - verification_key_len; + log::info!("{:#?}", user_pis_len); + log::info!("{:#?}", verification_key_len); + log::info!("{:#?}", block_proof.public_inputs.len()); + assert_eq!(user_pis_len, 2201); log::info!( "bppis: {:?} + vk: {:?} total_len: {}, vk_len: {}", &block_proof.public_inputs, &block_proof.public_inputs[user_pis_len..], - &block_proof.public_inputs.len(), - &block_proof.public_inputs.len() - user_pis_len + block_proof.public_inputs.len(), + block_proof.public_inputs.len() - user_pis_len ); hash_no_pad(&block_proof.public_inputs[..user_pis_len]) })