Skip to content

Commit

Permalink
chore: update naming
Browse files Browse the repository at this point in the history
  • Loading branch information
PangZhi committed Aug 24, 2024
1 parent f7c336c commit da4e66c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
30 changes: 15 additions & 15 deletions standalone_circuit/src/circuits/v1/intermediate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ impl WorldcoinIntermediateAggregationInput {
instances
}

/// Sanity check agasint the start & end indexes of two shards, check instances[2..5] (vk_hash_hi, vk_hash_lo, root) are equal.
/// Return new start, end indexes for this aggregated shard and a selector indicating whether the 2nd shard is dummy.
/// Sanity check against the start & end indexes of two proofs, check instances[2..5] (vk_hash_hi, vk_hash_lo, root) are equal.
/// Return new start, end indexes for this aggregated proof and a selector indicating whether the 2nd proof is dummy.
///
/// If the the 2nd shard is not dummy, the shards should link up.
/// If the 2nd shard is dummy, num_proofs should <= max_proofs_prev_depth
/// If the the 2nd proof is not dummy, the proofs should link up.
/// If the 2nd proof is dummy, num_proofs should <= max_proofs_prev_depth
///
/// # Returns a tuple of (new_instances, is_2nd_shard_dummy)
/// # Returns a tuple of (new_instances, is_2nd_proof_dummy)
/// - `new_instances` the first 5 instances (shared by v1/v2 intermediate and root) circuits. [start, end, vk_hash_hi, vk_hash_lo, root]
/// - `is_2nd_shard_dummy` a selector to indicate whether the 2nd shard is dummy
/// - `is_2nd_proof_dummy` a selector to indicate whether the 2nd proof is dummy
pub fn check_and_join_shared_instances<F: Field>(
ctx: &mut Context<F>,
range: &RangeChip<F>,
Expand All @@ -159,18 +159,18 @@ impl WorldcoinIntermediateAggregationInput {
range.check_less_than_safe(ctx, num_proofs0, prev_max_proofs_plus_one);
range.check_less_than_safe(ctx, num_proofs1, prev_max_proofs_plus_one);

// indicator of whether the 2nd shard is a dummy shard
let is_2nd_shard_dummy = range.is_less_than_safe(ctx, num_proofs, prev_max_proofs_plus_one);
// indicator of whether the 2nd proof is a dummy proof
let is_2nd_proof_dummy = range.is_less_than_safe(ctx, num_proofs, prev_max_proofs_plus_one);

// if the 2nd shard is dummy, the end index for the aggregation should be the end index of the
// first shard
// if the 2nd proof is dummy, the end index for the aggregation should be the end index of the
// first proof
end_idx = range
.gate()
.select(ctx, intermed_idx0, end_idx, is_2nd_shard_dummy);
.select(ctx, intermed_idx0, end_idx, is_2nd_proof_dummy);

// make sure shards link up
// make sure proofs link up
let mut eq_check = range.gate().is_equal(ctx, intermed_idx0, intermed_idx1);
eq_check = range.gate().or(ctx, eq_check, is_2nd_shard_dummy);
eq_check = range.gate().or(ctx, eq_check, is_2nd_proof_dummy);

range.gate().assert_is_const(ctx, &eq_check, &F::ONE);

Expand All @@ -179,7 +179,7 @@ impl WorldcoinIntermediateAggregationInput {
let is_max_depth0 = range
.gate()
.is_equal(ctx, num_proofs0, Constant(prev_max_proofs));
eq_check = range.gate().or(ctx, is_max_depth0, is_2nd_shard_dummy);
eq_check = range.gate().or(ctx, is_max_depth0, is_2nd_proof_dummy);
range.gate().assert_is_const(ctx, &eq_check, &F::ONE);

// check num_proofs is correct
Expand All @@ -197,7 +197,7 @@ impl WorldcoinIntermediateAggregationInput {
.into_iter()
.chain(instances0[2..5].iter().cloned())
.collect();
(new_instances, is_2nd_shard_dummy)
(new_instances, is_2nd_proof_dummy)
}

pub fn get_num_instance(max_depth: usize) -> usize {
Expand Down
6 changes: 3 additions & 3 deletions standalone_circuit/src/circuits/v2/intermediate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl WorldcoinIntermediateAggregationInputV2 {
max_depth: usize,
) -> Vec<AssignedValue<F>> {
let num_instance_prev_depth = Self::get_num_instance();
let (mut instances, is_2nd_shard_dummy) =
let (mut instances, is_2nd_proof_dummy) =
WorldcoinIntermediateAggregationInput::check_and_join_shared_instances(
ctx,
range,
Expand Down Expand Up @@ -213,13 +213,13 @@ impl WorldcoinIntermediateAggregationInputV2 {
ctx,
dummy_claim_root_hi,
claim_root_right.hi(),
is_2nd_shard_dummy,
is_2nd_proof_dummy,
);
let claim_root_right_lo = range.gate().select(
ctx,
dummy_claim_root_lo,
claim_root_right.lo(),
is_2nd_shard_dummy,
is_2nd_proof_dummy,
);

claim_root_right = HiLo::from_hi_lo([claim_root_right_hi, claim_root_right_lo]);
Expand Down
2 changes: 1 addition & 1 deletion standalone_circuit/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub const NUM_BYTES_VK: usize = 769;
pub const NUM_LIMBS: usize = 3;
pub const LIMB_BITS: usize = 88;

// batch size of groth16 verifications, we are handling 2 ** INITIAL_DEPTH in one leaf shard
// batch size of groth16 verifications, we are handling 2 ** INITIAL_DEPTH in one leaf circuit
pub const INITIAL_DEPTH: usize = 3;
// extra rounds for evm proof
pub const EXTRA_ROUNDS: usize = 1;
Expand Down

0 comments on commit da4e66c

Please sign in to comment.