restored abi-encoded proof code from poma

This commit is contained in:
Koh Wei Jie 2020-02-06 18:17:45 +08:00
parent 21bd15db9d
commit 8d0cb865c1

@ -175,16 +175,16 @@ contract Verifier {
* above and the public inputs * above and the public inputs
*/ */
function verifyProof( function verifyProof(
uint256[2] memory a, bytes memory proof,
uint256[2][2] memory b,
uint256[2] memory c,
uint256[<%vk_input_length%>] memory input uint256[<%vk_input_length%>] memory input
) public view returns (bool r) { ) public view returns (bool r) {
Proof memory proof; uint256[8] memory p = abi.decode(proof, (uint256[8]));
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 memory _proof;
proof.C = Pairing.G1Point(c[0], c[1]); _proof.A = Pairing.G1Point(p[0], p[1]);
_proof.B = Pairing.G2Point([p[2], p[3]], [p[4], p[5]]);
_proof.C = Pairing.G1Point(p[6], p[7]);
VerifyingKey memory vk = verifyingKey(); VerifyingKey memory vk = verifyingKey();
@ -194,17 +194,17 @@ contract Verifier {
Pairing.G1Point memory vk_x = Pairing.G1Point(0, 0); Pairing.G1Point memory vk_x = Pairing.G1Point(0, 0);
// Make sure that proof.A, B, and C are each less than the prime q // Make sure that proof.A, B, and C are each less than the prime q
require(proof.A.X < PRIME_Q, "verifier-aX-gte-prime-q"); require(_proof.A.X < PRIME_Q, "verifier-aX-gte-prime-q");
require(proof.A.Y < PRIME_Q, "verifier-aY-gte-prime-q"); require(_proof.A.Y < PRIME_Q, "verifier-aY-gte-prime-q");
require(proof.B.X[0] < PRIME_Q, "verifier-cX0-gte-prime-q"); require(_proof.B.X[0] < PRIME_Q, "verifier-cX0-gte-prime-q");
require(proof.B.Y[0] < PRIME_Q, "verifier-cY0-gte-prime-q"); require(_proof.B.Y[0] < PRIME_Q, "verifier-cY0-gte-prime-q");
require(proof.B.X[1] < PRIME_Q, "verifier-cX1-gte-prime-q"); require(_proof.B.X[1] < PRIME_Q, "verifier-cX1-gte-prime-q");
require(proof.B.Y[1] < PRIME_Q, "verifier-cY1-gte-prime-q"); require(_proof.B.Y[1] < PRIME_Q, "verifier-cY1-gte-prime-q");
require(proof.C.X < PRIME_Q, "verifier-cX-gte-prime-q"); require(_proof.C.X < PRIME_Q, "verifier-cX-gte-prime-q");
require(proof.C.Y < PRIME_Q, "verifier-cY-gte-prime-q"); require(_proof.C.Y < PRIME_Q, "verifier-cY-gte-prime-q");
// Make sure that every input is less than the snark scalar field // Make sure that every input is less than the snark scalar field
for (uint256 i = 0; i < input.length; i++) { for (uint256 i = 0; i < input.length; i++) {
@ -215,13 +215,13 @@ contract Verifier {
vk_x = Pairing.plus(vk_x, vk.IC[0]); vk_x = Pairing.plus(vk_x, vk.IC[0]);
return Pairing.pairing( return Pairing.pairing(
Pairing.negate(proof.A), Pairing.negate(_proof.A),
proof.B, _proof.B,
vk.alfa1, vk.alfa1,
vk.beta2, vk.beta2,
vk_x, vk_x,
vk.gamma2, vk.gamma2,
proof.C, _proof.C,
vk.delta2 vk.delta2
); );
} }