Skip to content

Commit 42ba572

Browse files
committed
fix: address finding on odd lengths
1 parent a8e21f9 commit 42ba572

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

solidity/src/base/Errors.sol

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ uint32 constant ERR_INVALID_EC_ADD_INPUTS = 0x765bcba0;
88
uint32 constant ERR_INVALID_EC_MUL_INPUTS = 0xe32c7472;
99
/// @dev Error code for when ECPAIRING inputs are invalid.
1010
uint32 constant ERR_INVALID_EC_PAIRING_INPUTS = 0x4385b511;
11+
/// @dev Error code for commitment array having odd length which is impossible
12+
/// since each commitment is 2 elements.
13+
uint32 constant ERR_COMMITMENT_ARRAY_ODD_LENGTH = 0x88acadef;
1114
/// @dev Error code for when the size of a sumcheck proof is incorrect.
1215
uint32 constant ERR_INVALID_SUMCHECK_PROOF_SIZE = 0x3f889a17;
1316
/// @dev Error code for when the evaluation of a round in a sumcheck proof does not match the expected value.
@@ -58,6 +61,9 @@ library Errors {
5861
error InvalidECMulInputs();
5962
/// @notice Error thrown when the inputs to the ECPAIRING precompile are invalid.
6063
error InvalidECPairingInputs();
64+
/// @notice Error code for commitment array having odd length which is impossible
65+
/// since each commitment is 2 elements.
66+
error CommitmentArrayOddLength();
6167
/// @notice Error thrown when the size of a sumcheck proof is incorrect.
6268
error InvalidSumcheckProofSize();
6369
/// @notice Error thrown when the evaluation of a round in a sumcheck proof does not match the expected value.

solidity/src/verifier/Verifier.pre.sol

+4-1
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,10 @@ library Verifier {
519519
verify_result_evaluations(result_ptr, evaluation_point_ptr, evaluations_ptr)
520520
}
521521

522-
mstore(__commitments, div(mload(__commitments), 2))
522+
// Revert if the commitments array has an odd length
523+
let commitments_len := mload(__commitments)
524+
if mod(commitments_len, 2) { err(ERR_COMMITMENT_ARRAY_ODD_LENGTH) }
525+
mstore(__commitments, div(commitments_len, 2))
523526
verify_query(__result.offset, __plan.offset, __proof.offset, __tableLengths, __commitments)
524527
}
525528
}

solidity/test/base/Errors.t.sol

+7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ contract ErrorsTest is Test {
2727
Errors.__err(ERR_INVALID_EC_PAIRING_INPUTS);
2828
}
2929

30+
/// forge-config: default.allow_internal_expect_revert = true
31+
function testErrorCommitmentArrayOddLength() public {
32+
assert(Errors.CommitmentArrayOddLength.selector == bytes4(ERR_COMMITMENT_ARRAY_ODD_LENGTH));
33+
vm.expectRevert(Errors.CommitmentArrayOddLength.selector);
34+
Errors.__err(ERR_COMMITMENT_ARRAY_ODD_LENGTH);
35+
}
36+
3037
/// forge-config: default.allow_internal_expect_revert = true
3138
function testErrorInvalidSumcheckProofSize() public {
3239
assert(Errors.InvalidSumcheckProofSize.selector == bytes4(ERR_INVALID_SUMCHECK_PROOF_SIZE));

solidity/test/verifier/Verifier.t.pre.sol

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pragma solidity ^0.8.28;
44

55
import {Test} from "forge-std/Test.sol";
66
import "../../src/base/Constants.sol";
7+
import {Errors} from "../../src/base/Errors.sol";
78
import {Verifier} from "../../src/verifier/Verifier.pre.sol";
89

910
contract VerifierTest is Test {

0 commit comments

Comments
 (0)