Skip to content

Commit

Permalink
Remove absorbing of running instance (#291)
Browse files Browse the repository at this point in the history
* Remove absorbing of running instance

* Update value of NUM_FE_FOR_RO

* Update expected values in tests

* Add comment

* cargo fmt
  • Loading branch information
varunthakore authored and huitseeker committed Jan 20, 2024
1 parent ee89d95 commit 6619ade
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 37 deletions.
12 changes: 6 additions & 6 deletions src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,8 @@ mod tests {
&params2,
ro_consts1,
ro_consts2,
&expect!["9825"],
&expect!["10357"],
&expect!["9817"],
&expect!["10349"],
);
}

Expand All @@ -481,8 +481,8 @@ mod tests {
&params2,
ro_consts1,
ro_consts2,
&expect!["9993"],
&expect!["10546"],
&expect!["9985"],
&expect!["10538"],
);
}

Expand All @@ -498,8 +498,8 @@ mod tests {
&params2,
ro_consts1,
ro_consts2,
&expect!["10272"],
&expect!["10969"],
&expect!["10264"],
&expect!["10961"],
);
}
}
4 changes: 2 additions & 2 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub(crate) const NUM_CHALLENGE_BITS: usize = 128;
pub(crate) const BN_LIMB_WIDTH: usize = 64;
pub(crate) const BN_N_LIMBS: usize = 4;
pub(crate) const NUM_FE_WITHOUT_IO_FOR_CRHF: usize = 17;
pub(crate) const NUM_FE_FOR_RO: usize = 24;
pub(crate) const NUM_FE_FOR_RO: usize = 9;

/// Bit size of Nova field element hashes
pub const NUM_HASH_BITS: usize = 250;
pub const NUM_HASH_BITS: usize = 250;
4 changes: 3 additions & 1 deletion src/gadgets/r1cs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,10 @@ impl<E: Engine> AllocatedRelaxedR1CSInstance<E> {
// Compute r:
let mut ro = E::ROCircuit::new(ro_consts, NUM_FE_FOR_RO);
ro.absorb(params);
self.absorb_in_ro(cs.namespace(|| "absorb running instance"), &mut ro)?;

// running instance `U` does not need to absorbed since u.X[0] = Hash(params, U, i, z0, zi)
u.absorb_in_ro(&mut ro);

ro.absorb(&T.x);
ro.absorb(&T.y);
ro.absorb(&T.is_infinity);
Expand Down
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,13 +1095,13 @@ mod tests {
test_pp_digest_with::<PallasEngine, VestaEngine, _, _, EE<_>, EE<_>>(
&trivial_circuit1,
&trivial_circuit2,
&expect!["f4a04841515b4721519e2671b7ee11e58e2d4a30bb183ded963b71ad2ec80d00"],
&expect!["492fd902cd7174159bc9a6f827d92eb54ff25efa9d0673dffdb0efd02995df01"],
);

test_pp_digest_with::<PallasEngine, VestaEngine, _, _, EE<_>, EE<_>>(
&cubic_circuit1,
&trivial_circuit2,
&expect!["dc1b7c40ab50c5c6877ad027769452870cc28f1d13f140de7ca3a00138c58502"],
&expect!["9b0701d9422658e3f74a85ab3e485c06f3ecca9c2b1800aab80004034d754f01"],
);

let trivial_circuit1_grumpkin = TrivialCircuit::<<Bn256Engine as Engine>::Scalar>::default();
Expand All @@ -1114,22 +1114,22 @@ mod tests {
test_pp_digest_with::<Bn256Engine, GrumpkinEngine, _, _, EE<_>, EE<_>>(
&trivial_circuit1_grumpkin,
&trivial_circuit2_grumpkin,
&expect!["2af2a80ea8a0c21cfc4096e9b2d4822344a29174d88cd86239a99a363efe8702"],
&expect!["1267235eb3d139e466dd9c814eaf73f01b063ccb4cad04848c0eb62f079a9601"],
);
test_pp_digest_with::<Bn256Engine, GrumpkinEngine, _, _, EE<_>, EE<_>>(
&cubic_circuit1_grumpkin,
&trivial_circuit2_grumpkin,
&expect!["9273fd39ed6220ea28e60abca8bdb3180f90e37e6aaf3031e6d670d073e8a002"],
&expect!["57afac2edd20d39b202151906e41154ba186c9dde497448d1332dc6de2f76302"],
);
test_pp_digest_with::<Bn256EngineZM, GrumpkinEngine, _, _, ZMPCS<Bn256, _>, EE<_>>(
&trivial_circuit1_grumpkin,
&trivial_circuit2_grumpkin,
&expect!["eac63861dcbaa924a1bd9721f01528271385dd6ff182c77bc62e03448adc1902"],
&expect!["070d247d83e17411d65c12260980ebcc59df88d3882d84eb62e6ab466e381503"],
);
test_pp_digest_with::<Bn256EngineZM, GrumpkinEngine, _, _, ZMPCS<Bn256, _>, EE<_>>(
&cubic_circuit1_grumpkin,
&trivial_circuit2_grumpkin,
&expect!["21bd7e07175b23e3bd2bbc6a0c3b9efd8603815609dbe93f8df9c174e132de03"],
&expect!["47c2caa008323b588b47ab8b6c0e94f980599188abe117c4d21ffff81494f303"],
);

let trivial_circuit1_secp = TrivialCircuit::<<Secp256k1Engine as Engine>::Scalar>::default();
Expand All @@ -1139,12 +1139,12 @@ mod tests {
test_pp_digest_with::<Secp256k1Engine, Secq256k1Engine, _, _, EE<_>, EE<_>>(
&trivial_circuit1_secp,
&trivial_circuit2_secp,
&expect!["fd2ff9d03e5512c66014399352ce0a8d722fe9c95005067ca05fe5ce84aabb02"],
&expect!["04b5d1798be6d74b3701390b87078e70ebf3ddaad80c375319f320cedf8bca00"],
);
test_pp_digest_with::<Secp256k1Engine, Secq256k1Engine, _, _, EE<_>, EE<_>>(
&cubic_circuit1_secp,
&trivial_circuit2_secp,
&expect!["1e4526ea166c8cccb685bd065ba82438b3ba89e24612d3e071fd30a6065c2b03"],
&expect!["346b5f27cf24c79386f4de7a8bfb58970181ae7f0de7d2e3f10ad5dfd8fc2302"],
);
}

Expand Down
9 changes: 3 additions & 6 deletions src/nifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ impl<E: Engine> NIFS<E> {
// append the digest of pp to the transcript
ro.absorb(scalar_as_base::<E>(*pp_digest));

// append U1 and U2 to transcript
U1.absorb_in_ro(&mut ro);
// append U2 to transcript, U1 does not need to absorbed since U2.X[0] = Hash(params, U1, i, z0, zi)
U2.absorb_in_ro(&mut ro);

// compute a commitment to the cross-term
Expand Down Expand Up @@ -103,8 +102,7 @@ impl<E: Engine> NIFS<E> {
// append the digest of pp to the transcript
ro.absorb(scalar_as_base::<E>(*pp_digest));

// append U1 and U2 to transcript
U1.absorb_in_ro(&mut ro);
// append U2 to transcript, U1 does not need to absorbed since U2.X[0] = Hash(params, U1, i, z0, zi)
U2.absorb_in_ro(&mut ro);

// compute a commitment to the cross-term
Expand Down Expand Up @@ -146,8 +144,7 @@ impl<E: Engine> NIFS<E> {
// append the digest of pp to the transcript
ro.absorb(scalar_as_base::<E>(*pp_digest));

// append U1 and U2 to transcript
U1.absorb_in_ro(&mut ro);
// append U2 to transcript, U1 does not need to absorbed since U2.X[0] = Hash(params, U1, i, z0, zi)
U2.absorb_in_ro(&mut ro);

// append `comm_T` to the transcript and obtain a challenge
Expand Down
12 changes: 6 additions & 6 deletions src/supernova/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,8 +833,8 @@ mod tests {
&params2,
ro_consts1,
ro_consts2,
&expect!["9844"],
&expect!["10392"],
&expect!["9836"],
&expect!["10384"],
1,
);
// TODO: extend to num_augmented_circuits >= 2
Expand All @@ -852,8 +852,8 @@ mod tests {
&params2,
ro_consts1,
ro_consts2,
&expect!["10012"],
&expect!["10581"],
&expect!["10004"],
&expect!["10573"],
1,
);
// TODO: extend to num_augmented_circuits >= 2
Expand All @@ -871,8 +871,8 @@ mod tests {
&params2,
ro_consts1,
ro_consts2,
&expect!["10291"],
&expect!["11004"],
&expect!["10283"],
&expect!["10996"],
1,
);
// TODO: extend to num_augmented_circuits >= 2
Expand Down
16 changes: 8 additions & 8 deletions src/supernova/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,8 @@ fn test_recursive_circuit_with<E1, E2>(
secondary_params: &SuperNovaAugmentedCircuitParams,
ro_consts1: ROConstantsCircuit<E2>,
ro_consts2: ROConstantsCircuit<E1>,
num_constraints_primary: usize,
num_constraints_secondary: usize,
num_constraints_primary: &Expect,
num_constraints_secondary: &Expect,
) where
E1: Engine<Base = <E2 as Engine>::Scalar>,
E2: Engine<Base = <E1 as Engine>::Scalar>,
Expand All @@ -480,7 +480,7 @@ fn test_recursive_circuit_with<E1, E2>(
panic!("{}", e)
}
let (shape1, ck1) = cs.r1cs_shape_and_key(&*default_ck_hint());
assert_eq!(cs.num_constraints(), num_constraints_primary);
num_constraints_primary.assert_eq(&cs.num_constraints().to_string());

// Initialize the shape and ck for the secondary
let step_circuit2 = TrivialSecondaryCircuit::default();
Expand All @@ -498,7 +498,7 @@ fn test_recursive_circuit_with<E1, E2>(
panic!("{}", e)
}
let (shape2, ck2) = cs.r1cs_shape_and_key(&*default_ck_hint());
assert_eq!(cs.num_constraints(), num_constraints_secondary);
num_constraints_secondary.assert_eq(&cs.num_constraints().to_string());

// Execute the base case for the primary
let zero1 = <<E2 as Engine>::Base as Field>::ZERO;
Expand Down Expand Up @@ -565,7 +565,7 @@ fn test_recursive_circuit() {
let ro_consts2: ROConstantsCircuit<PallasEngine> = PoseidonConstantsCircuit::default();

test_recursive_circuit_with::<PallasEngine, VestaEngine>(
&params1, &params2, ro_consts1, ro_consts2, 9844, 12025,
&params1, &params2, ro_consts1, ro_consts2, &expect!["9836"], &expect!["12017"],
);
}

Expand Down Expand Up @@ -613,7 +613,7 @@ fn test_supernova_pp_digest() {

test_pp_digest_with::<PallasEngine, VestaEngine, _, _, _>(
&test_rom,
&expect!["7e203fdfeab0ee8f56f8948497f8de73539d52e64cef89e44fff84711cf8b100"],
&expect!["95f57227c5d62d13b9fe55deac13b8bd099b068bcc785d7b3a054bf376f68e00"],
);

let rom = vec![
Expand All @@ -628,7 +628,7 @@ fn test_supernova_pp_digest() {

test_pp_digest_with::<Bn256Engine, GrumpkinEngine, _, _, _>(
&test_rom_grumpkin,
&expect!["5caf6efbdb5a928b44a6eb4ff597e2b5f6764450ceb86b7065aac6cf965c0203"],
&expect!["d439e957618eb071360f9c87c0014fd0cfa21f1271813004d18f967355912a01"],
);

let rom = vec![
Expand All @@ -643,7 +643,7 @@ fn test_supernova_pp_digest() {

test_pp_digest_with::<Secp256k1Engine, Secq256k1Engine, _, _, _>(
&test_rom_secp,
&expect!["e955513a59f75c63bc0649425045e6e472bddf4490a558e95bfcab14b4911a00"],
&expect!["5dfc2cc21f0a29a67ec3b3cbb7fbff535c876ef51e655f4abf4c00e058175103"],
);
}

Expand Down

0 comments on commit 6619ade

Please sign in to comment.