@@ -15,7 +15,7 @@ static const char HONK_CONTRACT_SOURCE[] = R"(
1515pragma solidity ^0.8.27;
1616
1717interface IVerifier {
18- function verify(bytes calldata _proof, bytes32[] calldata _publicInputs) external view returns (bool);
18+ function verify(bytes calldata _proof, bytes32[] calldata _publicInputs) external returns (bool);
1919}
2020
2121type Fr is uint256;
@@ -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) {
@@ -674,6 +674,7 @@ library RelationsLib {
674674 accumulateNnfRelation(purportedEvaluations, evaluations, powPartialEval);
675675 accumulatePoseidonExternalRelation(purportedEvaluations, evaluations, powPartialEval);
676676 accumulatePoseidonInternalRelation(purportedEvaluations, evaluations, powPartialEval);
677+
677678 // batch the subrelations with the alpha challenges to obtain the full honk relation
678679 accumulator = scaleAndBatchSubrelations(evaluations, alphas);
679680 }
@@ -1051,7 +1052,7 @@ library RelationsLib {
10511052 ap.index_delta = wire(p, WIRE.W_L_SHIFT) - wire(p, WIRE.W_L);
10521053 ap.record_delta = wire(p, WIRE.W_4_SHIFT) - wire(p, WIRE.W_4);
10531054
1054- ap.index_is_monotonically_increasing = ap.index_delta * ap.index_delta - ap.index_delta ; // deg 2
1055+ ap.index_is_monotonically_increasing = ap.index_delta * ( ap.index_delta - Fr.wrap(1)) ; // deg 2
10551056
10561057 ap.adjacent_values_match_if_adjacent_indices_match = (ap.index_delta * MINUS_ONE + ONE) * ap.record_delta; // deg 2
10571058
@@ -1082,7 +1083,7 @@ library RelationsLib {
10821083 * with a WRITE operation.
10831084 */
10841085 Fr access_type = (wire(p, WIRE.W_4) - ap.partial_record_check); // will be 0 or 1 for honest Prover; deg 1 or 4
1085- ap.access_check = access_type * access_type - access_type ; // check value is 0 or 1; deg 2 or 8
1086+ ap.access_check = access_type * ( access_type - Fr.wrap(1)) ; // check value is 0 or 1; deg 2 or 8
10861087
10871088 // reverse order we could re-use `ap.partial_record_check` 1 - ((w3' * eta + w2') * eta + w1') * eta
10881089 // deg 1 or 4
@@ -1256,7 +1257,7 @@ library RelationsLib {
12561257 function accumulatePoseidonExternalRelation(
12571258 Fr[NUMBER_OF_ENTITIES] memory p,
12581259 Fr[NUMBER_OF_SUBRELATIONS] memory evals,
1259- Fr domainSep // i guess this is the scaling factor?
1260+ Fr domainSep
12601261 ) internal pure {
12611262 PoseidonExternalParams memory ep;
12621263
@@ -1354,7 +1355,7 @@ library RelationsLib {
13541355 Fr[NUMBER_OF_SUBRELATIONS] memory evaluations,
13551356 Fr[NUMBER_OF_ALPHAS] memory subrelationChallenges
13561357 ) internal pure returns (Fr accumulator) {
1357- accumulator = accumulator + evaluations[0];
1358+ accumulator = evaluations[0];
13581359
13591360 for (uint256 i = 1; i < NUMBER_OF_SUBRELATIONS; ++i) {
13601361 accumulator = accumulator + evaluations[i] * subrelationChallenges[i - 1];
@@ -1421,10 +1422,9 @@ library CommitmentSchemeLib {
14211422 );
14221423 // Divide by the denominator
14231424 batchedEvalRoundAcc = batchedEvalRoundAcc * (challengePower * (ONE - u) + u).invert();
1424- if (i <= logSize) {
1425- batchedEvalAccumulator = batchedEvalRoundAcc;
1426- foldPosEvaluations[i - 1] = batchedEvalRoundAcc;
1427- }
1425+
1426+ batchedEvalAccumulator = batchedEvalRoundAcc;
1427+ foldPosEvaluations[i - 1] = batchedEvalRoundAcc;
14281428 }
14291429 return foldPosEvaluations;
14301430 }
@@ -2073,27 +2073,24 @@ abstract contract BaseHonkVerifier is IVerifier {
20732073 // Compute Shplonk constant term contributions from Aₗ(± r^{2ˡ}) for l = 1, ..., m-1;
20742074 // Compute scalar multipliers for each fold commitment
20752075 for (uint256 i = 0; i < $LOG_N - 1; ++i) {
2076- bool dummy_round = i >= ($LOG_N - 1);
2077-
2078- if (!dummy_round) {
2079- // Update inverted denominators
2080- mem.posInvertedDenominator = (tp.shplonkZ - powers_of_evaluation_challenge[i + 1]).invert();
2081- mem.negInvertedDenominator = (tp.shplonkZ + powers_of_evaluation_challenge[i + 1]).invert();
2082-
2083- // Compute the scalar multipliers for Aₗ(± r^{2ˡ}) and [Aₗ]
2084- mem.scalingFactorPos = mem.batchingChallenge * mem.posInvertedDenominator;
2085- mem.scalingFactorNeg = mem.batchingChallenge * tp.shplonkNu * mem.negInvertedDenominator;
2086- // [Aₗ] is multiplied by -v^{2l}/(z-r^{2^l}) - v^{2l+1} /(z+ r^{2^l})
2087- scalars[NUMBER_UNSHIFTED + 1 + i] = mem.scalingFactorNeg.neg() + mem.scalingFactorPos.neg();
2088-
2089- // Accumulate the const term contribution given by
2090- // v^{2l} * Aₗ(r^{2ˡ}) /(z-r^{2^l}) + v^{2l+1} * Aₗ(-r^{2ˡ}) /(z+ r^{2^l})
2091- Fr accumContribution = mem.scalingFactorNeg * proof.geminiAEvaluations[i + 1];
2092- accumContribution = accumContribution + mem.scalingFactorPos * foldPosEvaluations[i + 1];
2093- mem.constantTermAccumulator = mem.constantTermAccumulator + accumContribution;
2094- // Update the running power of v
2095- mem.batchingChallenge = mem.batchingChallenge * tp.shplonkNu * tp.shplonkNu;
2096- }
2076+ // Update inverted denominators
2077+ mem.posInvertedDenominator = (tp.shplonkZ - powers_of_evaluation_challenge[i + 1]).invert();
2078+ mem.negInvertedDenominator = (tp.shplonkZ + powers_of_evaluation_challenge[i + 1]).invert();
2079+
2080+ // Compute the scalar multipliers for Aₗ(± r^{2ˡ}) and [Aₗ]
2081+ mem.scalingFactorPos = mem.batchingChallenge * mem.posInvertedDenominator;
2082+ mem.scalingFactorNeg = mem.batchingChallenge * tp.shplonkNu * mem.negInvertedDenominator;
2083+ // [Aₗ] is multiplied by -v^{2l}/(z-r^{2^l}) - v^{2l+1} /(z+ r^{2^l})
2084+ scalars[NUMBER_UNSHIFTED + 1 + i] = mem.scalingFactorNeg.neg() + mem.scalingFactorPos.neg();
2085+
2086+ // Accumulate the const term contribution given by
2087+ // v^{2l} * Aₗ(r^{2ˡ}) /(z-r^{2^l}) + v^{2l+1} * Aₗ(-r^{2ˡ}) /(z+ r^{2^l})
2088+ Fr accumContribution = mem.scalingFactorNeg * proof.geminiAEvaluations[i + 1];
2089+
2090+ accumContribution = accumContribution + mem.scalingFactorPos * foldPosEvaluations[i + 1];
2091+ mem.constantTermAccumulator = mem.constantTermAccumulator + accumContribution;
2092+ // Update the running power of v
2093+ mem.batchingChallenge = mem.batchingChallenge * tp.shplonkNu * tp.shplonkNu;
20972094
20982095 commitments[NUMBER_UNSHIFTED + 1 + i] = proof.geminiFoldComms[i];
20992096 }
0 commit comments