From 7eacce099b854d2cb8f59f3b0c4d61ffa15efaa5 Mon Sep 17 00:00:00 2001 From: Timofey Luin Date: Wed, 20 Mar 2024 14:56:17 +0100 Subject: [PATCH] hotfix: poseidon commitment calculation + fix: aggregation circuit pinning --- .../src/aggregation_circuit.rs | 20 ++++++++++++++----- .../src/gadget/crypto/builder.rs | 4 +++- lightclient-circuits/src/ssz_merkle.rs | 2 +- prover/src/utils.rs | 4 ++-- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/lightclient-circuits/src/aggregation_circuit.rs b/lightclient-circuits/src/aggregation_circuit.rs index 9d191a3..389606f 100644 --- a/lightclient-circuits/src/aggregation_circuit.rs +++ b/lightclient-circuits/src/aggregation_circuit.rs @@ -16,7 +16,7 @@ use snark_verifier_sdk::{ halo2::aggregation::{AggregationCircuit, AggregationConfigParams}, Snark, SHPLONK, }; -use std::{fs::File, path::Path}; +use std::{env::var, fs::File, path::Path}; /// Configuration for the aggregation circuit. #[derive(Clone, Debug, Default, Serialize, Deserialize)] @@ -104,10 +104,20 @@ impl AppCircuit for AggregationCircuit { // We assume that `AggregationCircuit` will only be used for a single aggregation/compression layer. circuit.expose_previous_instances(false); - if matches!(stage, CircuitBuilderStage::Prover) { - circuit.set_params(circuit_params); - circuit.set_break_points(pinning.map_or(vec![], |p| p.break_points)); - }; + match stage { + CircuitBuilderStage::Prover => { + circuit.set_params(circuit_params); + circuit.set_break_points(pinning.map_or(vec![], |p| p.break_points)); + } + _ => { + circuit.calculate_params(Some( + var("MINIMUM_ROWS") + .unwrap_or_else(|_| "0".to_string()) + .parse() + .unwrap(), + )); + } + } Ok(circuit) } diff --git a/lightclient-circuits/src/gadget/crypto/builder.rs b/lightclient-circuits/src/gadget/crypto/builder.rs index 09d52f7..4a0784b 100644 --- a/lightclient-circuits/src/gadget/crypto/builder.rs +++ b/lightclient-circuits/src/gadget/crypto/builder.rs @@ -2,7 +2,9 @@ // Code: https://github.com/ChainSafe/Spectre // SPDX-License-Identifier: LGPL-3.0-only -use crate::util::{CommonGateManager, Eth2ConfigPinning, GateBuilderConfig, Halo2ConfigPinning, PinnableCircuit}; +use crate::util::{ + CommonGateManager, Eth2ConfigPinning, GateBuilderConfig, Halo2ConfigPinning, PinnableCircuit, +}; use eth_types::Field; use getset::Getters; use halo2_base::{ diff --git a/lightclient-circuits/src/ssz_merkle.rs b/lightclient-circuits/src/ssz_merkle.rs index 5d272dc..ebd39dd 100644 --- a/lightclient-circuits/src/ssz_merkle.rs +++ b/lightclient-circuits/src/ssz_merkle.rs @@ -42,7 +42,7 @@ pub fn ssz_merkleize_chunks>( } else { chunks.len().next_power_of_two().ilog2() as usize }; - + for depth in 0..height { // Pad to even length using 32 zero bytes assigned as constants. let len_even = chunks.len() + chunks.len() % 2; diff --git a/prover/src/utils.rs b/prover/src/utils.rs index 688d32f..e24670b 100644 --- a/prover/src/utils.rs +++ b/prover/src/utils.rs @@ -5,7 +5,7 @@ use std::{ops::Deref, sync::Arc}; use beacon_api_client::{BlockId, VersionedValue}; -use eth_types::NUM_LIMBS; +use eth_types::LIMB_BITS; use ethereum_consensus_types::LightClientBootstrap; use itertools::Itertools; use lightclient_circuits::poseidon::poseidon_committee_commitment_from_uncompressed; @@ -56,7 +56,7 @@ pub(crate) async fn utils_cli(method: UtilsCmd) -> eyre::Result<()> { println!("SSZ root: {:?}", hex::encode(ssz_root.deref())); let mut committee_poseidon = - poseidon_committee_commitment_from_uncompressed(&pubkeys_uncompressed, NUM_LIMBS) + poseidon_committee_commitment_from_uncompressed(&pubkeys_uncompressed, LIMB_BITS) .to_bytes(); committee_poseidon.reverse(); println!("Poseidon commitment: {}", hex::encode(committee_poseidon));