Skip to content

Commit d72f58f

Browse files
committed
chore: update hpps
1 parent ee86907 commit d72f58f

File tree

5 files changed

+127
-56
lines changed

5 files changed

+127
-56
lines changed

barretenberg/acir_tests/scripts/bb_prove_sol_verify.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ for arg in "$@"; do
1616
flags+=" $arg"
1717
done
1818

19+
USE_OPTIMIZED_CONTRACT=${USE_OPTIMIZED_CONTRACT:-false}
20+
21+
write_contract_flags=$flags
22+
if [[ -z "$USE_OPTIMIZED_CONTRACT" ]]; then
23+
write_contract_flags+=" --optimized"
24+
fi
25+
1926
# Check if --disable_zk is in the flags to determine HAS_ZK
2027
if [[ "$flags" == *"--disable_zk"* ]]; then
2128
has_zk="false"
@@ -29,7 +36,7 @@ trap "rm -rf output-$$" EXIT
2936
# Create a proof, write the solidity contract, write the proof as fields in order to extract the public inputs
3037
$bb prove $flags -b target/program.json --oracle_hash keccak --output_format bytes_and_fields --write_vk -o output-$$
3138
$bb verify $flags --oracle_hash keccak -i output-$$/public_inputs -k output-$$/vk -p output-$$/proof
32-
$bb write_solidity_verifier $flags -k output-$$/vk -o output-$$/Verifier.sol
39+
$bb write_solidity_verifier $write_contract_flags -k output-$$/vk -o output-$$/Verifier.sol
3340

3441
# Use solcjs to compile the generated key contract with the template verifier and test contract
3542
# index.js will start an anvil, on a random port

barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_contract.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ library FrLib {
6868
mstore(add(free, 0x20), 0x20)
6969
mstore(add(free, 0x40), 0x20)
7070
mstore(add(free, 0x60), v)
71-
mstore(add(free, 0x80), sub(MODULUS, 2))
71+
mstore(add(free, 0x80), sub(MODULUS, 2))
7272
mstore(add(free, 0xa0), MODULUS)
7373
let success := staticcall(gas(), 0x05, free, 0xc0, 0x00, 0x20)
7474
if iszero(success) {
@@ -92,7 +92,7 @@ library FrLib {
9292
mstore(add(free, 0x20), 0x20)
9393
mstore(add(free, 0x40), 0x20)
9494
mstore(add(free, 0x60), b)
95-
mstore(add(free, 0x80), v)
95+
mstore(add(free, 0x80), v)
9696
mstore(add(free, 0xa0), MODULUS)
9797
let success := staticcall(gas(), 0x05, free, 0xc0, 0x00, 0x20)
9898
if iszero(success) {
@@ -2091,10 +2091,8 @@ abstract contract BaseHonkVerifier is IVerifier {
20912091
mem.constantTermAccumulator = mem.constantTermAccumulator + accumContribution;
20922092
// Update the running power of v
20932093
mem.batchingChallenge = mem.batchingChallenge * tp.shplonkNu * tp.shplonkNu;
2094-
}
20952094
2096-
for (uint256 i = 0; i < CONST_PROOF_SIZE_LOG_N - 1; ++i) {
2097-
commitments[NUMBER_UNSHIFTED + 1 + i] = convertProofPoint(proof.geminiFoldComms[i]);
2095+
commitments[NUMBER_UNSHIFTED + 1 + i] = proof.geminiFoldComms[i];
20982096
}
20992097
21002098
// Finalize the batch opening claim

barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_optimized_contract.hpp

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ uint256 constant NUMBER_UNSHIFTED = 36;
410410
uint256 constant NUMBER_TO_BE_SHIFTED = 5;
411411
uint256 constant PAIRING_POINTS_SIZE = 16;
412412
413+
uint256 constant VK_HASH = {{ VK_HASH }};
413414
uint256 constant CIRCUIT_SIZE = {{ CIRCUIT_SIZE }};
414415
uint256 constant LOG_N = {{ LOG_CIRCUIT_SIZE }};
415416
uint256 constant NUMBER_PUBLIC_INPUTS = {{ NUM_PUBLIC_INPUTS }};
@@ -466,13 +467,13 @@ contract HonkVerifier is IVerifier {
466467
467468
// Poseidon internal constants
468469
469-
uint256 internal constant POS_INTENAL_MATRIX_D_0 =
470+
uint256 internal constant POS_INTERNAL_MATRIX_D_0 =
470471
0x10dc6e9c006ea38b04b1e03b4bd9490c0d03f98929ca1d7fb56821fd19d3b6e7;
471-
uint256 internal constant POS_INTENAL_MATRIX_D_1 =
472+
uint256 internal constant POS_INTERNAL_MATRIX_D_1 =
472473
0x0c28145b6a44df3e0149b3d0a30b3bb599df9756d4dd9b84a86b38cfb45a740b;
473-
uint256 internal constant POS_INTENAL_MATRIX_D_2 =
474+
uint256 internal constant POS_INTERNAL_MATRIX_D_2 =
474475
0x00544b8338791518b2c7645a50392798b21f75bb60e3596170067d00141cac15;
475-
uint256 internal constant POS_INTENAL_MATRIX_D_3 =
476+
uint256 internal constant POS_INTERNAL_MATRIX_D_3 =
476477
0x222c01175718386f2e2e82eb122789e352e105a3b8fa852613bc534433ee428b;
477478
478479
// Constants inspecting proof components
@@ -498,6 +499,9 @@ contract HonkVerifier is IVerifier {
498499
uint256 internal constant P_SUB_6 = 21888242871839275222246405745257275088548364400416034343698204186575808495611;
499500
uint256 internal constant P_SUB_7 = 21888242871839275222246405745257275088548364400416034343698204186575808495610;
500501
502+
// Constants for computing public input delta
503+
uint256 constant PERMUTATION_ARGUMENT_VALUE_SEPARATOR = 1 << 28;
504+
501505
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
502506
/* ERRORS */
503507
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
@@ -617,34 +621,29 @@ contract HonkVerifier is IVerifier {
617621
* and w1,w2,w3 are all proof points values
618622
*/
619623
620-
let number_of_public_inputs := NUMBER_PUBLIC_INPUTS
621-
622-
mstore(0x00, CIRCUIT_SIZE)
623-
mstore(0x20, NUMBER_PUBLIC_INPUTS)
624-
mstore(0x40, PUBLIC_INPUTS_OFFSET)
624+
mstore(0x00, VK_HASH)
625625
626626
let public_inputs_start := add(calldataload(0x24), 0x24)
627627
let public_inputs_size := mul(REAL_NUMBER_PUBLIC_INPUTS, 0x20)
628628
629629
// Copy the public inputs into the eta buffer
630-
calldatacopy(0x60, public_inputs_start, public_inputs_size)
630+
calldatacopy(0x20, public_inputs_start, public_inputs_size)
631631
632632
// Copy Pairing points into eta buffer
633-
let public_inputs_end := add(0x60, public_inputs_size)
633+
let public_inputs_end := add(0x20, public_inputs_size)
634634
635635
calldatacopy(public_inputs_end, proof_ptr, 0x200)
636636
637637
// 0x20 * 8 = 0x100
638638
// End of public inputs + pairing point
639-
calldatacopy(add(0x260, public_inputs_size), add(proof_ptr, 0x200), 0x100)
639+
calldatacopy(add(0x220, public_inputs_size), add(proof_ptr, 0x200), 0x100)
640640
641-
// 0x1e0 = 3 * 32 bytes + 3 * 64 bytes for (w1,w2,w3) + 0x200 for pairing points
642-
let eta_input_length := add(0x320, public_inputs_size)
641+
// 0x2e0 = 1 * 32 bytes + 3 * 64 bytes for (w1,w2,w3) + 0x200 for pairing points
642+
let eta_input_length := add(0x2e0, public_inputs_size)
643643
644644
let prev_challenge := mod(keccak256(0x00, eta_input_length), p)
645645
mstore(0x00, prev_challenge)
646646
647-
// TODO: remember how to function jump - todo unroll function jumps???
648647
let eta := and(prev_challenge, LOWER_128_MASK)
649648
let etaTwo := shr(128, prev_challenge)
650649
@@ -735,13 +734,19 @@ contract HonkVerifier is IVerifier {
735734
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
736735
/* GATE CHALLENGES */
737736
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
738-
let gate_off := GATE_CHALLENGE_0
737+
738+
// Store the first gate challenge
739+
prev_challenge := mod(keccak256(0x00, 0x20), p)
740+
mstore(0x00, prev_challenge)
741+
let gate_challenge := and(prev_challenge, LOWER_128_MASK)
742+
mstore(GATE_CHALLENGE_0, gate_challenge)
743+
744+
let gate_off := GATE_CHALLENGE_1
739745
for {} lt(gate_off, SUM_U_CHALLENGE_0) {} {
740-
prev_challenge := mod(keccak256(0x00, 0x20), p)
741-
mstore(0x00, prev_challenge)
742-
let gate_challenge := and(prev_challenge, LOWER_128_MASK)
746+
let prev := mload(sub(gate_off, 0x20))
747+
748+
mstore(gate_off, mulmod(prev, prev, p))
743749
744-
mstore(gate_off, gate_challenge)
745750
gate_off := add(gate_off, 0x20)
746751
}
747752
@@ -896,17 +901,17 @@ contract HonkVerifier is IVerifier {
896901
{
897902
let beta := mload(BETA_CHALLENGE)
898903
let gamma := mload(GAMMA_CHALLENGE)
899-
let domain_size := CIRCUIT_SIZE
900904
let pub_off := PUBLIC_INPUTS_OFFSET
901905
902906
let numerator_value := 1
903907
let denominator_value := 1
904908
905909
let p_clone := p // move p to the front of the stack
906910
907-
// Assume both domainSize and offset are less than p
908-
// numerator_acc = gamma + (beta * (domainSize + offset))
909-
let numerator_acc := addmod(gamma, mulmod(beta, add(domain_size, pub_off), p_clone), p_clone)
911+
// Assume offset is less than p
912+
// numerator_acc = gamma + (beta * (PERMUTATION_ARGUMENT_VALUE_SEPARATOR + offset))
913+
let numerator_acc :=
914+
addmod(gamma, mulmod(beta, add(PERMUTATION_ARGUMENT_VALUE_SEPARATOR, pub_off), p_clone), p_clone)
910915
// demonimator_acc = gamma - (beta * (offset + 1))
911916
let beta_x_off := mulmod(beta, add(pub_off, 1), p_clone)
912917
let denominator_acc := addmod(gamma, sub(p_clone, beta_x_off), p_clone)
@@ -962,7 +967,7 @@ contract HonkVerifier is IVerifier {
962967
mstore(0x20, 0x20)
963968
mstore(0x40, 0x20)
964969
mstore(0x60, denominator_value)
965-
mstore(0x80, sub(p, 2))
970+
mstore(0x80, P_SUB_2)
966971
mstore(0xa0, p)
967972
if iszero(staticcall(gas(), 0x05, 0x00, 0xc0, 0x00, 0x20)) {
968973
mstore(0x00, MODEXP_FAILED_SELECTOR)
@@ -1805,7 +1810,7 @@ contract HonkVerifier is IVerifier {
18051810
// scaled_activation_selector = q_arith * q_aux * alpha
18061811
let scaled_activation_selector :=
18071812
mulmod(
1808-
mload(QARITH_EVAL_LOC),
1813+
mload(QO_EVAL_LOC),
18091814
mulmod(mload(QMEMORY_EVAL_LOC), mload(POW_PARTIAL_EVALUATION_LOC), p),
18101815
p
18111816
)
@@ -1829,7 +1834,7 @@ contract HonkVerifier is IVerifier {
18291834
mulmod(next_gate_access_type_is_boolean, scaled_activation_selector, p)
18301835
)
18311836
1832-
mstore(AUX_RAM_CONSISTENCY_CHECK_IDENTITY, mulmod(access_check, mload(QARITH_EVAL_LOC), p))
1837+
mstore(AUX_RAM_CONSISTENCY_CHECK_IDENTITY, mulmod(access_check, mload(QO_EVAL_LOC), p))
18331838
}
18341839
18351840
{
@@ -2113,28 +2118,26 @@ contract HonkVerifier is IVerifier {
21132118
let q_pos_by_scaling :=
21142119
mulmod(mload(QPOSEIDON2_INTERNAL_EVAL_LOC), mload(POW_PARTIAL_EVALUATION_LOC), p)
21152120
2116-
let v1 := addmod(mulmod(u1, POS_INTENAL_MATRIX_D_0, p), u_sum, p)
2121+
let v1 := addmod(mulmod(u1, POS_INTERNAL_MATRIX_D_0, p), u_sum, p)
21172122
21182123
mstore(
21192124
SUBRELATION_EVAL_24_LOC,
21202125
mulmod(q_pos_by_scaling, addmod(v1, sub(p, mload(W1_SHIFT_EVAL_LOC)), p), p)
21212126
)
2122-
2123-
let v2 := addmod(mulmod(u2, POS_INTENAL_MATRIX_D_1, p), u_sum, p)
2127+
let v2 := addmod(mulmod(u2, POS_INTERNAL_MATRIX_D_1, p), u_sum, p)
21242128
21252129
mstore(
21262130
SUBRELATION_EVAL_25_LOC,
21272131
mulmod(q_pos_by_scaling, addmod(v2, sub(p, mload(W2_SHIFT_EVAL_LOC)), p), p)
21282132
)
2129-
2130-
let v3 := addmod(mulmod(u3, POS_INTENAL_MATRIX_D_2, p), u_sum, p)
2133+
let v3 := addmod(mulmod(u3, POS_INTERNAL_MATRIX_D_2, p), u_sum, p)
21312134
21322135
mstore(
21332136
SUBRELATION_EVAL_26_LOC,
21342137
mulmod(q_pos_by_scaling, addmod(v3, sub(p, mload(W3_SHIFT_EVAL_LOC)), p), p)
21352138
)
21362139
2137-
let v4 := addmod(mulmod(u4, POS_INTENAL_MATRIX_D_3, p), u_sum, p)
2140+
let v4 := addmod(mulmod(u4, POS_INTERNAL_MATRIX_D_3, p), u_sum, p)
21382141
mstore(
21392142
SUBRELATION_EVAL_27_LOC,
21402143
mulmod(q_pos_by_scaling, addmod(v4, sub(p, mload(W4_SHIFT_EVAL_LOC)), p), p)
@@ -2253,7 +2256,6 @@ contract HonkVerifier is IVerifier {
22532256
mstore(NEG_INVERTED_DENOM_0_LOC, addmod(eval_challenge, mload(POWERS_OF_EVALUATION_CHALLENGE_0_LOC), p))
22542257
22552258
// Compute Fold Pos Evaluatios
2256-
// TODO: unroll - can do in code gen - probably using handlebars???
22572259
22582260
// In order to compute fold pos evaluations we need
22592261
let store_off := INVERTED_CHALLENEGE_POW_MINUS_U_{{ LOG_N_MINUS_ONE }}_LOC
@@ -2295,7 +2297,6 @@ contract HonkVerifier is IVerifier {
22952297
}
22962298
}
22972299
2298-
// NOTE:
22992300
// To be inverted
23002301
// From: computeFoldPosEvaluations
23012302
// Series of challengePower * (ONE - u)

barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_zk_contract.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ library FrLib {
6868
mstore(add(free, 0x20), 0x20)
6969
mstore(add(free, 0x40), 0x20)
7070
mstore(add(free, 0x60), v)
71-
mstore(add(free, 0x80), sub(MODULUS, 2))
71+
mstore(add(free, 0x80), sub(MODULUS, 2))
7272
mstore(add(free, 0xa0), MODULUS)
7373
let success := staticcall(gas(), 0x05, free, 0xc0, 0x00, 0x20)
7474
if iszero(success) {
@@ -92,7 +92,7 @@ library FrLib {
9292
mstore(add(free, 0x20), 0x20)
9393
mstore(add(free, 0x40), 0x20)
9494
mstore(add(free, 0x60), b)
95-
mstore(add(free, 0x80), v)
95+
mstore(add(free, 0x80), v)
9696
mstore(add(free, 0xa0), MODULUS)
9797
let success := staticcall(gas(), 0x05, free, 0xc0, 0x00, 0x20)
9898
if iszero(success) {

0 commit comments

Comments
 (0)