Skip to content

Commit

Permalink
Test works
Browse files Browse the repository at this point in the history
  • Loading branch information
puma314 committed Oct 13, 2023
1 parent c50cbf5 commit 1f82c01
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
36 changes: 31 additions & 5 deletions contracts/test/verifiers/TestVerifier.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ import {PlonkVerifier} from "./VerifierPlonk.sol";
import {PlonkVerifier as PlonkRangeCheckVerifier} from "./VerifierPlonkRangeCheck.sol";
import {VmSafe} from "forge-std/Vm.sol";
import {stdJson} from "forge-std/StdJson.sol";
import {FunctionVerifier} from "./FunctionVerifier.sol";

contract VerifierTest is Test {
function testVerifierGroth16() public {
Groth16Verifier verifier = new Groth16Verifier();

string memory groth16Json = vm.readFile("test/verifiers/groth16_proof_data.json");
string memory groth16Json = vm.readFile(
"test/verifiers/groth16_proof_data.json"
);
uint256[] memory proof = stdJson.readUintArray(groth16Json, "$.proof");
uint256[] memory input = stdJson.readUintArray(groth16Json, "$.inputs");

Expand All @@ -33,16 +36,23 @@ contract VerifierTest is Test {
uint256 endGas = gasleft();
console.log("gas used: %d", startGas - endGas);

uint256[4] memory compressedProof = verifier.compressProof(proofConverted);
uint256[4] memory compressedProof = verifier.compressProof(
proofConverted
);
startGas = gasleft();
verifier.verifyCompressedProof(compressedProof, inputConverted);
endGas = gasleft();
console.log("gas used for verifying compressed proof: %d", startGas - endGas);
console.log(
"gas used for verifying compressed proof: %d",
startGas - endGas
);
}

function testVerifierPlonk() public {
PlonkVerifier verifier = new PlonkVerifier();
string memory proofJson = vm.readFile("test/verifiers/plonk_proof_data.json");
string memory proofJson = vm.readFile(
"test/verifiers/plonk_proof_data.json"
);
bytes memory proof = stdJson.readBytes(proofJson, "$.proof");
uint256[] memory input = stdJson.readUintArray(proofJson, "$.inputs");
uint256 startGas = gasleft();
Expand All @@ -53,12 +63,28 @@ contract VerifierTest is Test {

function testVerifierPlonkRangeCheck() public {
PlonkRangeCheckVerifier verifier = new PlonkRangeCheckVerifier();
string memory proofJson = vm.readFile("test/verifiers/plonk_proof_data_range_check.json");
string memory proofJson = vm.readFile(
"test/verifiers/plonk_proof_data_range_check.json"
);
bytes memory proof = stdJson.readBytes(proofJson, "$.proof");
uint256[] memory input = stdJson.readUintArray(proofJson, "$.inputs");
uint256 startGas = gasleft();
verifier.Verify(proof, input);
uint256 endGas = gasleft();
console.log("gas used: %d", startGas - endGas);
}

function testVerifierFunction() public {
FunctionVerifier verifier = new FunctionVerifier();
string memory proofJson = vm.readFile(
"test/verifiers/function_proof_data.json"
);
bytes memory proof = stdJson.readBytes(proofJson, "$.proof");
bytes32 inputHash = stdJson.readBytes32(proofJson, "$.input_hash");
bytes32 outputHash = stdJson.readBytes32(proofJson, "$.output_hash");
uint256 startGas = gasleft();
verifier.verify(inputHash, outputHash, proof);
uint256 endGas = gasleft();
console.log("gas used: %d", startGas - endGas);
}
}
6 changes: 6 additions & 0 deletions contracts/test/verifiers/function_proof_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"input_hash": "0x0b2871da34670fde248604e0f18fd3e4f7e1e6dfddb85875ce4813a6612953bb",
"output_hash": "0x07cf46a078fed4fafd0b5e3aff144802b853f8ae459a4f0c14add3314b7cc3a6",
"verifier_digest": "0x1c08790b2727738d6d86858ce7b584cb2a9f24b1911aac93ed5f66d9c01f0fda",
"proof": "0x1c727bc35e3aada620810beae257c96f394e05964373291b786577f7a7158b722f059d091a946faceacfaefb21d78bb81f0fe1b9c5008719f313a7713809cddf25416ab356a985fbe896c36a7e69fd63ad1a60113c3705e9cbcc6cd457327351257bd62c85bf00f2f8ad8e99b8e627d6215e3e1fec348dec503e3e18963ea1ed13979ba111e754644fb56e3614af63e67bfa6942398496730ee72ea6505471ff21a962d11da39d981818a66937041e693b0078111a2dda5e3c7737dea268aca121cbbdae287128441527ebbf9aba84d5b4c1d6e6129f9e2975801c731cc066e5268769235ebcfe288795333b0f53293d3ae6f4c9f52471907c3a8ba24340e2fb134e326a6669a7f7f695433a75e18e80040b1b824da3a390c96a77f5b05db44d0dfbbde8a82b47e71d250fba7453744375ed8c182e5d967eed949272b84581a7111bd233f42e658b1d8eba2fea19c9f82969176fba0b40c8013abea54cd29b830fc8c7ea3ee6e24697a0b984a64ff78468d5bda5a42ae1f83e7f083721197d3e14e43e8e3feb36d22b58158464817c8a3ccf840b588b340edf48fb2d060a37aa0126a0a2b6b1d5cdc7820a5f0afab9b705898bbc441795edae7d3a468fc572ec074013598d3b92d7b2def1d38cade7cdc5c7172c417cfe09f0dc541f04b1c36d0dfec80f151107ffe21509756b378e7c1a51da170ed2e6bc409683f105c9ac6c0542c601e99d9b36b166c30faffe770746811f3e23f2c4b27cec61a1f704352114eb6db0395cff9f74beafa5ff7c7ecd8fef0fbf43da5cbfd78ecd166f68d23b2e5bb9494557be40f12ff9e5711a9baee4def6abdcfe5f62e86b4b6ad479a7e61d04a446d1a215b4eb0997979afb09e16c3c42e84ad29113c327837ebfde3b7d1c8423e43363d877bba75c3bf1f93ced9bc5b42d00f071a74be43f577ff9d0251de1dc14d637db44b1cc01bb5a83bcd8de6d3b063bbf9f61c6731fc83455c098277c2fe9d0fd2ffc425539a3d36128258442610b6ddf96e736edce7917c198b60c39b86940fb56eeaffc5d0d24a4a219fa8abb5d87cea4b1f3d94d1f2eef64a2283a54d02e0b0360c4a055feabac4a79b85f0c15796a0a0c43cc802510ef7e371a6dc9a71f78c6e93f8ec15fb50bb40f92748411fda41ff0398a72e6d6c4949b185ce63c827e43c4542de512b12b84e66546d5a9c47576982ef95e50842e889b21d1e4407df939ce389bb4bdb686e42424e5e912906bb27f5d6ae1a9237fa38f27a47b3be6d655ba5a87fb3921e58324ceeec99d63ceee69bd0a15511ada78bb"
}

0 comments on commit 1f82c01

Please sign in to comment.