Skip to content

Commit

Permalink
review: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
einar-polygon committed Jun 29, 2024
1 parent 3c56dca commit 7283bee
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
60 changes: 26 additions & 34 deletions evm_arithmetization/src/fixed_recursive_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ where
rhs: AggregationChildTarget<D>,
mix_pv_hash: HashOutTarget,
dummy_pis: Vec<Target>,
vk_len: usize,
cyclic_vk: VerifierCircuitTarget,
}

Expand Down Expand Up @@ -372,7 +371,6 @@ where
mix_pv_hash,
dummy_pis,
cyclic_vk,
vk_len: todo!(),
})
}
}
Expand Down Expand Up @@ -989,25 +987,17 @@ where
{
let mut builder = CircuitBuilder::<F, D>::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 {
Expand Down Expand Up @@ -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::<C::InnerHasher>(mix_vec);
let mix_pv_hash_intermediate = builder.hash_n_to_hash_no_pad::<C::InnerHasher>(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::<C>();
TwoToOneBlockCircuitData {
circuit,
lhs,
rhs,
mix_pv_hash: mix_pv_hash_output,
mix_pv_hash,
dummy_pis,
cyclic_vk,
vk_len: verification_key_len,
}
}

Expand Down Expand Up @@ -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}");

Expand Down Expand Up @@ -2059,9 +2039,21 @@ fn shrinking_config() -> CircuitConfig {
}
}

pub fn extract_two_to_one_block_hash<F>(public_inputs: &Vec<F>) -> &[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<F>(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<F, C, const D: usize>(circuit: &CircuitData<F, C, D>) -> usize
where
F: RichField + Extendable<D>,
C: GenericConfig<D, F = F>,
C::Hasher: AlgebraicHasher<F>,
{
circuit.verifier_only.circuit_digest.elements.len()
+ (1 << circuit.common.config.fri_config.cap_height) * (NUM_HASH_OUT_ELTS)
}
16 changes: 12 additions & 4 deletions evm_arithmetization/tests/two_to_one_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -297,18 +299,24 @@ fn test_two_to_one_block_aggregation() -> anyhow::Result<()> {
let two_to_one =
<PoseidonGoldilocksConfig as GenericConfig<D>>::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])
})
Expand Down

0 comments on commit 7283bee

Please sign in to comment.