Skip to content

Commit

Permalink
chore
Browse files Browse the repository at this point in the history
  • Loading branch information
nulltea committed Feb 21, 2024
1 parent 5df36c7 commit 5e058f8
Show file tree
Hide file tree
Showing 14 changed files with 205 additions and 214 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ members = [
"preprocessor",
"eth-types",
"contract-tests",
# "test-utils",
# "contracts",
"test-utils",
"contracts",
]

resolver = "2"
Expand Down
8 changes: 2 additions & 6 deletions contract-tests/tests/spectre.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,8 @@ async fn deploy_spectre_mock_verifiers<M: Middleware + 'static>(
initial_sync_committee_poseidon: U256,
slots_per_period: usize,
) -> anyhow::Result<Spectre<M>> {
let step_verifier = MockVerifier::deploy(ethclient.clone(), ())?
.send()
.await?;
let update_verifier = MockVerifier::deploy(ethclient.clone(), ())?
.send()
.await?;
let step_verifier = MockVerifier::deploy(ethclient.clone(), ())?.send().await?;
let update_verifier = MockVerifier::deploy(ethclient.clone(), ())?.send().await?;
Ok(Spectre::deploy(
ethclient,
(
Expand Down
9 changes: 5 additions & 4 deletions contract-tests/tests/step_input_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,16 @@ async fn test_step_instance_commitment_evm_equivalence(
use contract_tests::decode_solidity_u256_array;

let (witness, _) = read_test_files_and_gen_witness(&path);
let instance = lightclient_circuits::sync_step_circuit::StepCircuit:: <Minimal,bn256::Fr> ::get_instances(&witness, LIMB_BITS);
let instance =
lightclient_circuits::sync_step_circuit::StepCircuit::<Minimal, bn256::Fr>::get_instances(
&witness, LIMB_BITS,
);

let (_anvil_instance, ethclient) = make_client();
let contract = StepExternal::deploy(ethclient, ())?.send().await?;

let result = contract
.to_public_inputs_commitment(
StepInput::from(witness),
)
.to_public_inputs_commitment(StepInput::from(witness))
.call()
.await?;
let result_decoded = decode_solidity_u256_array(&[result]);
Expand Down
2 changes: 0 additions & 2 deletions lightclient-circuits/src/committee_update_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ impl<S: Spec, F: Field> CommitteeUpdateCircuit<S, F> {
S::SYNC_COMMITTEE_PUBKEYS_ROOT_INDEX,
)?;

println!("ffinalized_header_root: {:?}", finalized_header_root.iter().map(|v| v.value()).collect_vec());

let finalized_header_root_lo_hi = bytes_be_to_u128(
builder.main(),
&range.gate,
Expand Down
5 changes: 0 additions & 5 deletions lightclient-circuits/src/gadget/crypto/sha256_flex/gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Code: https://github.com/ChainSafe/Spectre
// SPDX-License-Identifier: LGPL-3.0-only

use std::any::TypeId;

use eth_types::Field;
use getset::CopyGetters;
use halo2_base::{
Expand All @@ -22,9 +20,6 @@ use super::SpreadConfig;

pub const FIRST_PHASE: usize = 0;

struct Dence;
struct Spread;

/// `ShaFlexGateManager` keeps track of halo2-lib virtual cells and assigns them to the region corresponding to the `SpreadConfig`.
/// It also loads of the copy (permutation) constraints between halo2-lib and vanilla cells in Plonk table.
#[derive(Clone, Debug, Default, CopyGetters)]
Expand Down
3 changes: 2 additions & 1 deletion lightclient-circuits/src/gadget/crypto/sha256_wide/gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use halo2_base::{
},
virtual_region::{
copy_constraints::SharedCopyConstraintManager, manager::VirtualRegionManager,
}, AssignedValue,
},
AssignedValue,
};
use itertools::Itertools;
use zkevm_hashes::{
Expand Down
3 changes: 1 addition & 2 deletions lightclient-circuits/src/poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ pub fn fq_array_poseidon<'a, F: Field>(
let zero = ctx.load_zero();
ctx.constrain_equal(extra, &zero);
}

limbs
.chunks(2)
.into_iter()
.map(|limbs| gate.inner_product(ctx, limbs.to_vec(), limbs_bases.clone()))
.collect_vec()
})
Expand Down
2 changes: 1 addition & 1 deletion lightclient-circuits/src/sync_step_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ impl<S: Spec, F: Field> StepCircuit<S, F> {
let poseidon_commitment =
poseidon_hash_fq_array::<bn256::Fr>(pubkey_affines.iter().map(|p| p.x), limb_bits);

let mut public_input_commitment = sha2::Sha256::digest(&input).to_vec();
let mut public_input_commitment = sha2::Sha256::digest(input).to_vec();
// Truncate to 253 bits
public_input_commitment[31] &= 0b00011111;

Expand Down
8 changes: 6 additions & 2 deletions lightclient-circuits/src/util/bytes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use halo2_base::{gates::GateInstructions, safe_types::SafeByte, utils::BigPrimeField, AssignedValue, Context, QuantumCell};
use halo2_base::{
gates::GateInstructions, safe_types::SafeByte, utils::BigPrimeField, AssignedValue, Context,
QuantumCell,
};
use itertools::Itertools;

pub fn bytes_be_to_u128<F: BigPrimeField>(
Expand All @@ -23,7 +26,8 @@ pub(crate) fn limbs_be_to_u128<F: BigPrimeField>(
gate.inner_product(
ctx,
chunk.iter().rev().map(|a| *a.as_ref()),
(0..chunk.len()).map(|idx| QuantumCell::Constant(gate.pow_of_two()[limb_bits * idx])),
(0..chunk.len())
.map(|idx| QuantumCell::Constant(gate.pow_of_two()[limb_bits * idx])),
)
})
.collect_vec()
Expand Down
2 changes: 1 addition & 1 deletion lightclient-circuits/src/util/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use halo2_base::halo2_proofs::{
};
use serde::{Deserialize, Serialize};
use snark_verifier_sdk::evm::{
encode_calldata, evm_verify, gen_evm_proof_shplonk, gen_evm_verifier_shplonk
encode_calldata, evm_verify, gen_evm_proof_shplonk, gen_evm_verifier_shplonk,
};
use snark_verifier_sdk::halo2::gen_proof_shplonk;
use snark_verifier_sdk::{gen_pk, halo2::gen_snark_shplonk, read_pk};
Expand Down
4 changes: 1 addition & 3 deletions lightclient-circuits/src/witness/multiproof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ pub fn calculate_multi_merkle_root(
hasher.update(left_input.as_ref());
hasher.update(right_input.as_ref());

let parent = objects
.entry(parent_index)
.or_default();
let parent = objects.entry(parent_index).or_default();
parent.as_mut().copy_from_slice(&hasher.finalize_reset());
keys.push(parent_index);
}
Expand Down
4 changes: 2 additions & 2 deletions lightclient-circuits/src/witness/rotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl<S: Spec> Default for CommitteeUpdateArgs<S> {
let sync_committee_branch = vec![vec![0; 32]; S::SYNC_COMMITTEE_PUBKEYS_DEPTH];

let hashed_pk = sha2::Sha256::digest(
&dummy_x_bytes
dummy_x_bytes
.iter()
.copied()
.pad_using(64, |_| 0)
Expand All @@ -48,7 +48,7 @@ impl<S: Spec> Default for CommitteeUpdateArgs<S> {
chunks = chunks
.into_iter()
.tuples()
.map(|(left, right)| sha2::Sha256::digest(&[left, right].concat()).to_vec())
.map(|(left, right)| sha2::Sha256::digest([left, right].concat()).to_vec())
.collect();
}

Expand Down
Loading

0 comments on commit 5e058f8

Please sign in to comment.