Skip to content

Commit

Permalink
hotfix: poseidon commitment calculation
Browse files Browse the repository at this point in the history
+ fix: aggregation circuit pinning
  • Loading branch information
nulltea committed Mar 20, 2024
1 parent f9d3e5f commit 7eacce0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
20 changes: 15 additions & 5 deletions lightclient-circuits/src/aggregation_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion lightclient-circuits/src/gadget/crypto/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
2 changes: 1 addition & 1 deletion lightclient-circuits/src/ssz_merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn ssz_merkleize_chunks<F: Field, CircuitBuilder: CommonCircuitBuilder<F>>(
} 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;
Expand Down
4 changes: 2 additions & 2 deletions prover/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 7eacce0

Please sign in to comment.