@@ -10,6 +10,7 @@ import {
1010 NUMBER_OF_SUBRELATIONS,
1111 NUMBER_OF_ALPHAS,
1212 NUMBER_UNSHIFTED,
13+ NUMBER_TO_BE_SHIFTED,
1314 BATCHED_RELATION_PARTIAL_LENGTH,
1415 CONST_PROOF_SIZE_LOG_N,
1516 PAIRING_POINTS_SIZE
@@ -48,6 +49,7 @@ abstract contract BaseHonkVerifier is IVerifier {
4849
4950 // Number of field elements in a ultra honk proof, including pairing point object.
5051 uint256 constant PROOF_SIZE = 457 ;
52+ uint256 constant SHIFTED_COMMITMENTS_START = 29 ;
5153
5254 function loadVerificationKey () internal pure virtual returns (Honk.VerificationKey memory );
5355
@@ -229,8 +231,8 @@ abstract contract BaseHonkVerifier is IVerifier {
229231 CommitmentSchemeLib.computeSquares (tp.geminiR);
230232
231233 // Arrays hold values that will be linearly combined for the gemini and shplonk batch openings
232- Fr[NUMBER_OF_ENTITIES + CONST_PROOF_SIZE_LOG_N + 2 ] memory scalars;
233- Honk.G1Point[NUMBER_OF_ENTITIES + CONST_PROOF_SIZE_LOG_N + 2 ] memory commitments;
234+ Fr[NUMBER_UNSHIFTED + CONST_PROOF_SIZE_LOG_N + 2 ] memory scalars;
235+ Honk.G1Point[NUMBER_UNSHIFTED + CONST_PROOF_SIZE_LOG_N + 2 ] memory commitments;
234236
235237 mem.posInvertedDenominator = (tp.shplonkZ - powers_of_evaluation_challenge[0 ]).invert ();
236238 mem.negInvertedDenominator = (tp.shplonkZ + powers_of_evaluation_challenge[0 ]).invert ();
@@ -278,9 +280,18 @@ abstract contract BaseHonkVerifier is IVerifier {
278280 mem.batchingChallenge = mem.batchingChallenge * tp.rho;
279281 }
280282 // g commitments are accumulated at r
281- for (uint256 i = NUMBER_UNSHIFTED + 1 ; i <= NUMBER_OF_ENTITIES; ++ i) {
282- scalars[i] = mem.shiftedScalar.neg () * mem.batchingChallenge;
283- mem.batchedEvaluation = mem.batchedEvaluation + (proof.sumcheckEvaluations[i - 1 ] * mem.batchingChallenge);
283+ // For each of the to be shifted commitments perform the shift in place by
284+ // adding to the unshifted value.
285+ // We do so, as the values are to be used in batchMul later, and as
286+ // `a * c + b * c = (a + b) * c` this will allow us to reduce memory and compute.
287+ // Applied to w1, w2, w3, w4 and zPerm
288+ for (uint256 i = 0 ; i < NUMBER_TO_BE_SHIFTED; ++ i) {
289+ uint256 scalarOff = i + SHIFTED_COMMITMENTS_START;
290+ uint256 evaluationOff = i + NUMBER_UNSHIFTED;
291+
292+ scalars[scalarOff] = scalars[scalarOff] + (mem.shiftedScalar.neg () * mem.batchingChallenge);
293+ mem.batchedEvaluation =
294+ mem.batchedEvaluation + (proof.sumcheckEvaluations[evaluationOff] * mem.batchingChallenge);
284295 mem.batchingChallenge = mem.batchingChallenge * tp.rho;
285296 }
286297
@@ -323,13 +334,6 @@ abstract contract BaseHonkVerifier is IVerifier {
323334 commitments[35 ] = convertProofPoint (proof.lookupReadCounts);
324335 commitments[36 ] = convertProofPoint (proof.lookupReadTags);
325336
326- // to be Shifted
327- commitments[37 ] = convertProofPoint (proof.w1);
328- commitments[38 ] = convertProofPoint (proof.w2);
329- commitments[39 ] = convertProofPoint (proof.w3);
330- commitments[40 ] = convertProofPoint (proof.w4);
331- commitments[41 ] = convertProofPoint (proof.zPerm);
332-
333337 /* Batch gemini claims from the prover
334338 * place the commitments to gemini aᵢ to the vector of commitments, compute the contributions from
335339 * aᵢ(−r²ⁱ) for i=1, … , n−1 to the constant term accumulator, add corresponding scalars
@@ -383,7 +387,7 @@ abstract contract BaseHonkVerifier is IVerifier {
383387 mem.scalingFactorPos = mem.batchingChallenge * mem.posInvertedDenominator;
384388 mem.scalingFactorNeg = mem.batchingChallenge * tp.shplonkNu * mem.negInvertedDenominator;
385389 // [Aₗ] is multiplied by -v^{2l}/(z-r^{2^l}) - v^{2l+1} /(z+ r^{2^l})
386- scalars[NUMBER_OF_ENTITIES + 1 + i] = mem.scalingFactorNeg.neg () + mem.scalingFactorPos.neg ();
390+ scalars[NUMBER_UNSHIFTED + 1 + i] = mem.scalingFactorNeg.neg () + mem.scalingFactorPos.neg ();
387391
388392 // Accumulate the const term contribution given by
389393 // v^{2l} * Aₗ(r^{2ˡ}) /(z-r^{2^l}) + v^{2l+1} * Aₗ(-r^{2ˡ}) /(z+ r^{2^l})
@@ -394,17 +398,17 @@ abstract contract BaseHonkVerifier is IVerifier {
394398 mem.batchingChallenge = mem.batchingChallenge * tp.shplonkNu * tp.shplonkNu;
395399 }
396400
397- commitments[NUMBER_OF_ENTITIES + 1 + i] = convertProofPoint (proof.geminiFoldComms[i]);
401+ commitments[NUMBER_UNSHIFTED + 1 + i] = convertProofPoint (proof.geminiFoldComms[i]);
398402 }
399403
400404 // Finalise the batch opening claim
401- commitments[NUMBER_OF_ENTITIES + CONST_PROOF_SIZE_LOG_N] = Honk.G1Point ({x: 1 , y: 2 });
402- scalars[NUMBER_OF_ENTITIES + CONST_PROOF_SIZE_LOG_N] = mem.constantTermAccumulator;
405+ commitments[NUMBER_UNSHIFTED + CONST_PROOF_SIZE_LOG_N] = Honk.G1Point ({x: 1 , y: 2 });
406+ scalars[NUMBER_UNSHIFTED + CONST_PROOF_SIZE_LOG_N] = mem.constantTermAccumulator;
403407
404408 Honk.G1Point memory quotient_commitment = convertProofPoint (proof.kzgQuotient);
405409
406- commitments[NUMBER_OF_ENTITIES + CONST_PROOF_SIZE_LOG_N + 1 ] = quotient_commitment;
407- scalars[NUMBER_OF_ENTITIES + CONST_PROOF_SIZE_LOG_N + 1 ] = tp.shplonkZ; // evaluation challenge
410+ commitments[NUMBER_UNSHIFTED + CONST_PROOF_SIZE_LOG_N + 1 ] = quotient_commitment;
411+ scalars[NUMBER_UNSHIFTED + CONST_PROOF_SIZE_LOG_N + 1 ] = tp.shplonkZ; // evaluation challenge
408412
409413 Honk.G1Point memory P_0_agg = batchMul (commitments, scalars);
410414 Honk.G1Point memory P_1_agg = negateInplace (quotient_commitment);
@@ -426,10 +430,10 @@ abstract contract BaseHonkVerifier is IVerifier {
426430 }
427431
428432 function batchMul (
429- Honk.G1Point[NUMBER_OF_ENTITIES + CONST_PROOF_SIZE_LOG_N + 2 ] memory base ,
430- Fr[NUMBER_OF_ENTITIES + CONST_PROOF_SIZE_LOG_N + 2 ] memory scalars
433+ Honk.G1Point[NUMBER_UNSHIFTED + CONST_PROOF_SIZE_LOG_N + 2 ] memory base ,
434+ Fr[NUMBER_UNSHIFTED + CONST_PROOF_SIZE_LOG_N + 2 ] memory scalars
431435 ) internal view returns (Honk.G1Point memory result ) {
432- uint256 limit = NUMBER_OF_ENTITIES + CONST_PROOF_SIZE_LOG_N + 2 ;
436+ uint256 limit = NUMBER_UNSHIFTED + CONST_PROOF_SIZE_LOG_N + 2 ;
433437
434438 // Validate all points are on the curve
435439 for (uint256 i = 0 ; i < limit; ++ i) {
0 commit comments