From 092cc389bb680798a5867e63963ab57fb184488c Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 23 Jul 2021 23:13:10 +0100 Subject: [PATCH] More small circuit optimisations - Placing the Poseidon `state` columns after the `partial_sbox` column instead of before it causes them to line up with vast stretch of free space, enabling the pad-and-add region to be layed out there. - Using the `Region::assign_advice_from_constant` API to initialise the Poseidon state removes fixed-column contention between that region and fixed-base scalar multiplication, enabling it to also be layed out within the free space. - If https://github.com/zcash/halo2/issues/334 were implemented then this region would disappear. - The overflow check in variable-base scalar mul is also moved into the columns with free space. --- src/circuit.rs | 6 ++++-- src/circuit/gadget/ecc/chip/mul/overflow.rs | 8 +++++--- src/circuit/gadget/poseidon/pow5t3.rs | 13 ++++--------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/circuit.rs b/src/circuit.rs index 2fa22192..c8c9401a 100644 --- a/src/circuit.rs +++ b/src/circuit.rs @@ -241,8 +241,10 @@ impl plonk::Circuit for Circuit { let poseidon_config = PoseidonChip::configure( meta, poseidon::OrchardNullifier, - advices[5..8].try_into().unwrap(), - advices[8], + // We place the state columns after the partial_sbox column so that the + // pad-and-add region can be layed out more efficiently. + advices[6..9].try_into().unwrap(), + advices[5], rc_a, rc_b, ); diff --git a/src/circuit/gadget/ecc/chip/mul/overflow.rs b/src/circuit/gadget/ecc/chip/mul/overflow.rs index d4336624..4b17d6bc 100644 --- a/src/circuit/gadget/ecc/chip/mul/overflow.rs +++ b/src/circuit/gadget/ecc/chip/mul/overflow.rs @@ -29,10 +29,12 @@ impl From<&EccConfig> for Config { Self { q_mul_overflow: ecc_config.q_mul_overflow, lookup_config: ecc_config.lookup_config.clone(), + // Use advice columns that don't conflict with the either the incomplete + // additions in fixed-base scalar mul, or the lookup range checks. advices: [ - ecc_config.advices[0], - ecc_config.advices[1], - ecc_config.advices[2], + ecc_config.advices[6], + ecc_config.advices[7], + ecc_config.advices[8], ], } } diff --git a/src/circuit/gadget/poseidon/pow5t3.rs b/src/circuit/gadget/poseidon/pow5t3.rs index 5b29358e..de12e04c 100644 --- a/src/circuit/gadget/poseidon/pow5t3.rs +++ b/src/circuit/gadget/poseidon/pow5t3.rs @@ -280,19 +280,12 @@ impl> PoseidonDuplexInstructions