Skip to content

Commit

Permalink
Step 4
Browse files Browse the repository at this point in the history
  • Loading branch information
storojs72 committed Jul 24, 2023
1 parent 5a1f751 commit f41757d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/NovaVerifierContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "src/blocks/PolyEvalInstance.sol";
import "src/verifier/Step1.sol";
import "src/verifier/Step2.sol";
import "src/verifier/Step3.sol";
import "src/verifier/Step4.sol";
import "src/NovaVerifierAbstractions.sol";

contract NovaVerifierContract {
Expand Down Expand Up @@ -94,6 +95,12 @@ contract NovaVerifierContract {
return false;
}

// check the required multiset relationship
if (!Step4Lib.verify(proof)) {
console.log("[Step4] false");
return false;
}

return true;
}

Expand Down
36 changes: 36 additions & 0 deletions src/verifier/Step4.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import "@std/Test.sol";
import "src/blocks/pasta/Pallas.sol";
import "src/blocks/pasta/Vesta.sol";
import "src/NovaVerifierAbstractions.sol";

library Step4Lib {
function verify(Abstractions.CompressedSnark calldata proof) public view returns (bool) {
if (!verifyInner(proof.r_W_snark_primary, Vesta.P_MOD)) {
return false;
} else if (!verifyInner(proof.f_W_snark_secondary, Pallas.P_MOD)) {
return false;
}
return true;
}

function verifyInner(Abstractions.RelaxedR1CSSNARK calldata proof, uint256 modulus) private view returns (bool) {
// row
uint256 left = mulmod(proof.claims_product_arr[0], proof.claims_product_arr[2], modulus);
uint256 right = mulmod(proof.claims_product_arr[1], proof.claims_product_arr[3], modulus);
if (left != right) {
return false;
}

// col
left = mulmod(proof.claims_product_arr[4], proof.claims_product_arr[6], modulus);
right = mulmod(proof.claims_product_arr[5], proof.claims_product_arr[7], modulus);
if (left != right) {
return false;
}

return true;
}
}

0 comments on commit f41757d

Please sign in to comment.