Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Balance verification final layer circuits - don't register public inputs manually #359

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use circuit_derive::{CircuitTarget, SerdeCircuitTarget};
use plonky2::{
field::{extension::Extendable, goldilocks_field::GoldilocksField},
hash::hash_types::{HashOut, RichField},
iop::target::Target,
plonk::{
circuit_builder::CircuitBuilder,
circuit_data::{CircuitConfig, CircuitData},
Expand Down Expand Up @@ -80,6 +81,9 @@ pub struct DepositAccumulatorBalanceAggregatorDivaFinalLayerTarget {
#[target(in)]
#[serde(with = "serde_bool_array_to_hex_string_nested")]
pub slot_branch: Sha256MerkleBranchTarget<5>,

#[target(out)]
pub public_inputs_hash_bytes: [Target; 32],
}

pub struct DepositAccumulatorBalanceAggregatorDivaFinalLayer;
Expand Down Expand Up @@ -179,8 +183,9 @@ impl Circuit for DepositAccumulatorBalanceAggregatorDivaFinalLayer {
public_inputs_hash[1] = builder._false();
public_inputs_hash[2] = builder._false();

let public_inputs_hash_bytes = bits_to_bytes_target(builder, &public_inputs_hash);
builder.register_public_inputs(&public_inputs_hash_bytes);
let public_inputs_hash_bytes = bits_to_bytes_target(builder, &public_inputs_hash)
.try_into()
.unwrap();

Self::Target {
balance_aggregation_proof,
Expand All @@ -196,6 +201,7 @@ impl Circuit for DepositAccumulatorBalanceAggregatorDivaFinalLayer {
execution_block_number_branch: input.execution_block_number_branch,
slot: input.slot,
slot_branch: input.slot_branch,
public_inputs_hash_bytes,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
},
utils::circuit::{
assert_slot_is_in_epoch::assert_slot_is_in_epoch,
biguint_to_bits_target,
biguint_to_bits_target, bits_to_bytes_target,
hashing::{
merkle::{sha256::assert_merkle_proof_is_valid_const_sha256, ssz::ssz_num_to_bits},
sha256::sha256,
Expand All @@ -22,6 +22,7 @@ use itertools::Itertools;
use plonky2::{
field::{extension::Extendable, goldilocks_field::GoldilocksField},
hash::hash_types::RichField,
iop::target::Target,
plonk::{
circuit_builder::CircuitBuilder,
circuit_data::{CircuitConfig, CircuitData},
Expand Down Expand Up @@ -64,6 +65,9 @@ pub struct FinalCircuitTargets<const WITHDRAWAL_CREDENTIALS_COUNT: usize> {
#[serde(with = "serde_bool_array_to_hex_string_nested")]
pub balances_branch: Sha256MerkleBranchTarget<6>,

#[target(out)]
pub public_inputs_hash_bytes: [Target; 32],

pub balance_verification_proof: ProofWithPublicInputsTarget<D>,
pub validators_commitment_mapper_proof: ProofWithPublicInputsTarget<D>,
}
Expand Down Expand Up @@ -164,12 +168,9 @@ impl<const WITHDRAWAL_CREDENTIALS_COUNT: usize> Circuit
public_inputs_hash[1] = builder._false();
public_inputs_hash[2] = builder._false();

let public_inputs_hash_bytes = public_inputs_hash
.chunks(8)
.map(|x| builder.le_sum(x.iter().rev()))
.collect_vec();

builder.register_public_inputs(&public_inputs_hash_bytes);
let public_inputs_hash_bytes = bits_to_bytes_target(builder, &public_inputs_hash)
.try_into()
.unwrap();

Self::Target {
block_root: input.block_root,
Expand All @@ -181,6 +182,7 @@ impl<const WITHDRAWAL_CREDENTIALS_COUNT: usize> Circuit
validators_branch: input.validators_branch,
balance_verification_proof,
validators_commitment_mapper_proof,
public_inputs_hash_bytes,
}
}
}
Expand Down