Refactor verifier contract: public input as dynamic array

This commit is contained in:
Mark Spanbroek 2024-01-23 12:50:14 +01:00 committed by markspanbroek
parent 39a2d56a63
commit c0ca508a6b
7 changed files with 13 additions and 19 deletions

View File

@ -186,9 +186,11 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
) public requestIsKnown(_slots[id].requestId) {
Slot storage slot = _slots[id];
Request storage request = _requests[slot.requestId];
uint256 challenge = _challengeToFieldElement(getChallenge(id));
uint256 merkleRoot = _merkleRootToFieldElement(request.content.merkleRoot);
_proofReceived(id, proof, [challenge, merkleRoot, slot.slotIndex]);
uint256[] memory pubSignals = new uint256[](3);
pubSignals[0] = _challengeToFieldElement(getChallenge(id));
pubSignals[1] = _merkleRootToFieldElement(request.content.merkleRoot);
pubSignals[2] = slot.slotIndex;
_proofReceived(id, proof, pubSignals);
}
function markProofAsMissing(SlotId slotId, Period period) public {

View File

@ -112,7 +112,7 @@ abstract contract Proofs is Periods {
function _proofReceived(
SlotId id,
Groth16Proof calldata proof,
uint[3] memory pubSignals
uint[] memory pubSignals
) internal {
require(!_received[id][_blockPeriod()], "Proof already submitted");
require(

View File

@ -27,7 +27,7 @@ contract TestProofs is Proofs {
function proofReceived(
SlotId id,
Groth16Proof calldata proof,
uint[3] memory pubSignals
uint[] memory pubSignals
) public {
_proofReceived(id, proof, pubSignals);
}

View File

@ -18,7 +18,7 @@ contract TestVerifier is IVerifier {
uint[2] calldata,
uint[2][2] calldata,
uint[2] calldata,
uint[3] calldata
uint[] calldata
) external view returns (bool) {
return _proofsAreValid;
}

View File

@ -6,6 +6,6 @@ interface IVerifier {
uint[2] calldata pA,
uint[2][2] calldata pB,
uint[2] calldata pC,
uint[3] calldata pubSignals
uint[] calldata pubSignals
) external view returns (bool);
}

View File

@ -189,17 +189,13 @@ contract Verifier {
uint[2] memory a,
uint[2][2] memory b,
uint[2] memory c,
uint[3] memory input
uint[] memory input
) public view returns (bool r) {
Proof memory proof;
proof.A = Pairing.G1Point(a[0], a[1]);
proof.B = Pairing.G2Point([b[0][0], b[0][1]], [b[1][0], b[1][1]]);
proof.C = Pairing.G1Point(c[0], c[1]);
uint[] memory inputValues = new uint[](input.length);
for(uint i = 0; i < input.length; i++){
inputValues[i] = input[i];
}
if (verify(inputValues, proof) == 0) {
if (verify(input, proof) == 0) {
return true;
} else {
return false;

View File

@ -189,17 +189,13 @@ contract Verifier {
uint[2] memory a,
uint[2][2] memory b,
uint[2] memory c,
uint[<%vk_input_length%>] memory input
uint[] memory input
) public view returns (bool r) {
Proof memory proof;
proof.A = Pairing.G1Point(a[0], a[1]);
proof.B = Pairing.G2Point([b[0][0], b[0][1]], [b[1][0], b[1][1]]);
proof.C = Pairing.G1Point(c[0], c[1]);
uint[] memory inputValues = new uint[](input.length);
for(uint i = 0; i < input.length; i++){
inputValues[i] = input[i];
}
if (verify(inputValues, proof) == 0) {
if (verify(input, proof) == 0) {
return true;
} else {
return false;