Skip to content

Commit 70de101

Browse files
authored
docs(sol): add docs and tests with notes on invalid inputs (#734)
# Rationale for this change This improves documentation and test coverage.
2 parents 33f573b + 37706fe commit 70de101

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

solidity/src/hyperkzg/HyperKZGHelpers.pre.sol

+1
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ library HyperKZGHelpers {
270270
/// \\[ g_L := \left(d^2 + d + 1\right)\cdot \left(\mathbf{C} + \sum_{i=0}^{m-1} q^{i+1}\cdot \mathbf{com}_i\right)+
271271
/// r\cdot\mathbf{w}_0 - dr \cdot\mathbf{w}_1 + (dr)^2\cdot\mathbf{w}_2 + b\cdot (-\mathbf{G}) \\]
272272
/// @dev The computation is performed using EC operations via precompiles in a specific order to optimize gas usage
273+
/// @dev NOTE: this function's will revert if any of the EC inputs are invalid.
273274
/// @param __com Array of commitment points
274275
/// @param __w Array of witness points
275276
/// @param __commitment The commitment point C

solidity/src/hyperkzg/HyperKZGVerifier.pre.sol

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ library HyperKZGVerifier {
9999
/// * `commitment_ptr` - the memory pointer to the commitment point
100100
/// * `x` - the memory pointer to the array of x coordinates
101101
/// * `y` - the y value being verified
102+
/// @dev NOTE: the method will always revert if `x` is empty, or if the proof is invalid.
102103
/// @dev This function verifies a HyperKZG proof by:*
103104
/// 1. Running a Fiat-Shamir transcript to generate challenges r, q, d
104105
/// WARNING: The public inputs (x, y, the commitments, digest of the KZG SRS, degree bound, etc) are

solidity/test/base/ECPrecompiles.t.pre.sol

+6
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ contract ECPrecompilesTest is Test {
119119
assert(argsPtr[2] == e);
120120
}
121121

122+
function testFuzz01IsInvalidECPoint(uint256 e) public {
123+
uint256[3] memory argsPtr = [uint256(0), 1, e];
124+
vm.expectRevert(Errors.InvalidECMulInputs.selector);
125+
ECPrecompilesTestWrapper.ecMul(argsPtr);
126+
}
127+
122128
function testRevertWhenECMulInvalidInput() public {
123129
uint256[3] memory argsPtr = [uint256(2), 3, 4];
124130
vm.expectRevert(Errors.InvalidECMulInputs.selector);

solidity/test/hyperkzg/HyperKZGHelpers.t.pre.sol

+39
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,45 @@ contract HyperKZGHelpersTest is Test {
274274
assert(scratch[1] == 0);
275275
}
276276

277+
function testComputeGLMSMWithLenOneRevertsWhenAnInputIsAnInvalidECPoint() public {
278+
uint256[2][] memory com = new uint256[2][](1);
279+
com[0] = [G1_NEG_GEN_X, G1_NEG_GEN_Y];
280+
uint256[2][3] memory w;
281+
w[0] = [uint256(0), 1];
282+
w[1] = [uint256(0), 2];
283+
w[2] = [uint256(0), 3];
284+
uint256[2] memory commitment = [uint256(0), 0];
285+
uint256[4] memory rqdb = [uint256(1), 1, 1, 1];
286+
uint256[5] memory scratch;
287+
vm.expectRevert(Errors.InvalidECMulInputs.selector);
288+
scratch = HyperKZGHelpers.__computeGLMSM({
289+
__com: com,
290+
__w: w,
291+
__commitment: commitment,
292+
__rqdb: rqdb,
293+
__scratch: scratch
294+
});
295+
}
296+
297+
function testComputeGLMSMWithLenOneDoesNotRevertWithValidInputs() public view {
298+
uint256[2][] memory com = new uint256[2][](1);
299+
com[0] = [G1_NEG_GEN_X, G1_NEG_GEN_Y];
300+
uint256[2][3] memory w;
301+
w[0] = [uint256(1), 2];
302+
w[1] = [uint256(0), 0];
303+
w[2] = [uint256(G1_GEN_X), G1_GEN_Y];
304+
uint256[2] memory commitment = [uint256(0), 0];
305+
uint256[4] memory rqdb = [uint256(1), 1, 1, 1];
306+
uint256[5] memory scratch;
307+
scratch = HyperKZGHelpers.__computeGLMSM({
308+
__com: com,
309+
__w: w,
310+
__commitment: commitment,
311+
__rqdb: rqdb,
312+
__scratch: scratch
313+
});
314+
}
315+
277316
function testComputeGLMSMWithSimpleValues() public view {
278317
uint256[2][] memory com = new uint256[2][](2);
279318
(uint256 comx, uint256 comy) = ECPrecompilesTestHelper.ecBasePower(2);

0 commit comments

Comments
 (0)