Return false when public inputs are invalid

This commit is contained in:
Mark Spanbroek 2024-01-30 15:02:47 +01:00 committed by markspanbroek
parent d38e0f5954
commit 576254423e
1 changed files with 6 additions and 4 deletions

View File

@ -139,13 +139,15 @@ contract Groth16Verifier {
uint[] memory input
) public view returns (bool success) {
require(input.length + 1 == _verifyingKey.ic.length, "verifier-bad-input");
// Check that inputs are field elements
for (uint i = 0; i < input.length; i++) {
if (input[i] >= _Q) {
return false;
}
}
// Compute the linear combination vkX
G1Point memory vkX = G1Point(0, 0);
for (uint i = 0; i < input.length; i++) {
require(
input[i] < _Q,
"verifier-gte-snark-scalar-field"
);
G1Point memory product;
(success, product) = _multiply(_verifyingKey.ic[i + 1], input[i]);
if (!success) {