mirror of
https://github.com/status-im/codex-contracts-eth.git
synced 2025-02-26 07:05:32 +00:00
Refactor verifier contract: public input as dynamic array
This commit is contained in:
parent
39a2d56a63
commit
c0ca508a6b
contracts
verifier/template
@ -186,9 +186,11 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
|
|||||||
) public requestIsKnown(_slots[id].requestId) {
|
) public requestIsKnown(_slots[id].requestId) {
|
||||||
Slot storage slot = _slots[id];
|
Slot storage slot = _slots[id];
|
||||||
Request storage request = _requests[slot.requestId];
|
Request storage request = _requests[slot.requestId];
|
||||||
uint256 challenge = _challengeToFieldElement(getChallenge(id));
|
uint256[] memory pubSignals = new uint256[](3);
|
||||||
uint256 merkleRoot = _merkleRootToFieldElement(request.content.merkleRoot);
|
pubSignals[0] = _challengeToFieldElement(getChallenge(id));
|
||||||
_proofReceived(id, proof, [challenge, merkleRoot, slot.slotIndex]);
|
pubSignals[1] = _merkleRootToFieldElement(request.content.merkleRoot);
|
||||||
|
pubSignals[2] = slot.slotIndex;
|
||||||
|
_proofReceived(id, proof, pubSignals);
|
||||||
}
|
}
|
||||||
|
|
||||||
function markProofAsMissing(SlotId slotId, Period period) public {
|
function markProofAsMissing(SlotId slotId, Period period) public {
|
||||||
|
@ -112,7 +112,7 @@ abstract contract Proofs is Periods {
|
|||||||
function _proofReceived(
|
function _proofReceived(
|
||||||
SlotId id,
|
SlotId id,
|
||||||
Groth16Proof calldata proof,
|
Groth16Proof calldata proof,
|
||||||
uint[3] memory pubSignals
|
uint[] memory pubSignals
|
||||||
) internal {
|
) internal {
|
||||||
require(!_received[id][_blockPeriod()], "Proof already submitted");
|
require(!_received[id][_blockPeriod()], "Proof already submitted");
|
||||||
require(
|
require(
|
||||||
|
@ -27,7 +27,7 @@ contract TestProofs is Proofs {
|
|||||||
function proofReceived(
|
function proofReceived(
|
||||||
SlotId id,
|
SlotId id,
|
||||||
Groth16Proof calldata proof,
|
Groth16Proof calldata proof,
|
||||||
uint[3] memory pubSignals
|
uint[] memory pubSignals
|
||||||
) public {
|
) public {
|
||||||
_proofReceived(id, proof, pubSignals);
|
_proofReceived(id, proof, pubSignals);
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ contract TestVerifier is IVerifier {
|
|||||||
uint[2] calldata,
|
uint[2] calldata,
|
||||||
uint[2][2] calldata,
|
uint[2][2] calldata,
|
||||||
uint[2] calldata,
|
uint[2] calldata,
|
||||||
uint[3] calldata
|
uint[] calldata
|
||||||
) external view returns (bool) {
|
) external view returns (bool) {
|
||||||
return _proofsAreValid;
|
return _proofsAreValid;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,6 @@ interface IVerifier {
|
|||||||
uint[2] calldata pA,
|
uint[2] calldata pA,
|
||||||
uint[2][2] calldata pB,
|
uint[2][2] calldata pB,
|
||||||
uint[2] calldata pC,
|
uint[2] calldata pC,
|
||||||
uint[3] calldata pubSignals
|
uint[] calldata pubSignals
|
||||||
) external view returns (bool);
|
) external view returns (bool);
|
||||||
}
|
}
|
||||||
|
@ -189,17 +189,13 @@ contract Verifier {
|
|||||||
uint[2] memory a,
|
uint[2] memory a,
|
||||||
uint[2][2] memory b,
|
uint[2][2] memory b,
|
||||||
uint[2] memory c,
|
uint[2] memory c,
|
||||||
uint[3] memory input
|
uint[] memory input
|
||||||
) public view returns (bool r) {
|
) public view returns (bool r) {
|
||||||
Proof memory proof;
|
Proof memory proof;
|
||||||
proof.A = Pairing.G1Point(a[0], a[1]);
|
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.B = Pairing.G2Point([b[0][0], b[0][1]], [b[1][0], b[1][1]]);
|
||||||
proof.C = Pairing.G1Point(c[0], c[1]);
|
proof.C = Pairing.G1Point(c[0], c[1]);
|
||||||
uint[] memory inputValues = new uint[](input.length);
|
if (verify(input, proof) == 0) {
|
||||||
for(uint i = 0; i < input.length; i++){
|
|
||||||
inputValues[i] = input[i];
|
|
||||||
}
|
|
||||||
if (verify(inputValues, proof) == 0) {
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -189,17 +189,13 @@ contract Verifier {
|
|||||||
uint[2] memory a,
|
uint[2] memory a,
|
||||||
uint[2][2] memory b,
|
uint[2][2] memory b,
|
||||||
uint[2] memory c,
|
uint[2] memory c,
|
||||||
uint[<%vk_input_length%>] memory input
|
uint[] memory input
|
||||||
) public view returns (bool r) {
|
) public view returns (bool r) {
|
||||||
Proof memory proof;
|
Proof memory proof;
|
||||||
proof.A = Pairing.G1Point(a[0], a[1]);
|
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.B = Pairing.G2Point([b[0][0], b[0][1]], [b[1][0], b[1][1]]);
|
||||||
proof.C = Pairing.G1Point(c[0], c[1]);
|
proof.C = Pairing.G1Point(c[0], c[1]);
|
||||||
uint[] memory inputValues = new uint[](input.length);
|
if (verify(input, proof) == 0) {
|
||||||
for(uint i = 0; i < input.length; i++){
|
|
||||||
inputValues[i] = input[i];
|
|
||||||
}
|
|
||||||
if (verify(inputValues, proof) == 0) {
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user