mirror of
https://github.com/codex-storage/codex-contracts-eth.git
synced 2025-02-10 18:37:14 +00:00
Refactor verifier contract: verification key as parameter
This commit is contained in:
parent
f2869ff94f
commit
39a2d56a63
@ -159,15 +159,14 @@ contract Verifier {
|
||||
Pairing.G2Point B;
|
||||
Pairing.G1Point C;
|
||||
}
|
||||
constructor() {
|
||||
verifyingKey.alpha1 = Pairing.G1Point(20491192805390485299153009773594534940189261866228447918068658471970481763042, 9383485363053290200918347156157836566562967994039712273449902621266178545958);
|
||||
verifyingKey.beta2 = Pairing.G2Point([4252822878758300859123897981450591353533073413197771768651442665752259397132,6375614351688725206403948262868962793625744043794305715222011528459656738731], [21847035105528745403288232691147584728191162732299865338377159692350059136679,10505242626370262277552901082094356697409835680220590971873171140371331206856]);
|
||||
verifyingKey.gamma2 = Pairing.G2Point([11559732032986387107991004021392285783925812861821192530917403151452391805634,10857046999023057135944570762232829481370756359578518086990519993285655852781], [4082367875863433681332203403145435568316851327593401208105741076214120093531,8495653923123431417604973247489272438418190587263600148770280649306958101930]);
|
||||
verifyingKey.delta2 = Pairing.G2Point([16947967852917776612242666765339055140004530219040719566241973405926209896589,9526465944650138768726332063321262597514193803543146241262920033512923206833], [8391255886665123549932056926338579244742743577262957977406729945277596579696,19350668523204772149977938696677933779621485674406066708436704188235339847628]);
|
||||
verifyingKey.IC.push(Pairing.G1Point(2685717341061384289974985759706305556965509240536260442727245444252129889599, 21827535600902499280458695057256182457185285685995970634461174274051979800815));
|
||||
verifyingKey.IC.push(Pairing.G1Point(13158415194355348546090070151711085027834066488127676886518524272551654481129, 18831701962118195025265682681702066674741422770850028135520336928884612556978));
|
||||
verifyingKey.IC.push(Pairing.G1Point(20882269691461568155321689204947751047717828445545223718893788782534717197527, 11996193054822748526485644723594571195813487505803351159052936325857690315211));
|
||||
verifyingKey.IC.push(Pairing.G1Point(18155166643053044822201627105588517913195535693446564472247126736722594445000, 13816319482622393060406816684195314200198627617641073470088058848129378231754));
|
||||
constructor(VerifyingKey memory key) {
|
||||
verifyingKey.alpha1 = key.alpha1;
|
||||
verifyingKey.beta2 = key.beta2;
|
||||
verifyingKey.gamma2 = key.gamma2;
|
||||
verifyingKey.delta2 = key.delta2;
|
||||
for (uint i=0; i<key.IC.length; i++) {
|
||||
verifyingKey.IC.push(key.IC[i]);
|
||||
}
|
||||
}
|
||||
function verify(uint[] memory input, Proof memory proof) internal view returns (uint) {
|
||||
require(input.length + 1 == verifyingKey.IC.length,"verifier-bad-input");
|
||||
|
@ -11,7 +11,7 @@ const {
|
||||
advanceTimeToForNextBlock,
|
||||
} = require("./evm")
|
||||
const { periodic } = require("./time")
|
||||
const { loadProof, loadPublicInput } = require("./proof")
|
||||
const { loadProof, loadPublicInput, loadVerificationKey } = require("./proof")
|
||||
const { SlotState } = require("./requests")
|
||||
const binomialTest = require("@stdlib/stats-binomial-test")
|
||||
const { exampleProof } = require("./examples")
|
||||
@ -33,7 +33,7 @@ describe("Proofs", function () {
|
||||
const Verifier = await ethers.getContractFactory(
|
||||
"contracts/verifiers/local/verifier_groth.sol:Verifier"
|
||||
)
|
||||
const verifier = await Verifier.deploy()
|
||||
const verifier = await Verifier.deploy(loadVerificationKey("local"))
|
||||
proofs = await Proofs.deploy(
|
||||
{ period, timeout, downtime },
|
||||
verifier.address
|
||||
@ -213,8 +213,7 @@ describe("Proofs", function () {
|
||||
|
||||
it("fails proof submission when public input is incorrect", async function () {
|
||||
let invalid = [1, 2, 3]
|
||||
await expect(proofs.proofReceived(slotId, proof, invalid)).to.be
|
||||
.reverted
|
||||
await expect(proofs.proofReceived(slotId, proof, invalid)).to.be.reverted
|
||||
})
|
||||
|
||||
it("emits an event when proof was submitted", async function () {
|
||||
|
@ -5,6 +5,8 @@ const { BigNumber } = ethers
|
||||
const BASE_PATH = __dirname + "/../verifier/networks"
|
||||
const PROOF_FILE_NAME = "example-proof/proof.json"
|
||||
const PUBLIC_INPUT_FILE_NAME = "example-proof/public.json"
|
||||
const VERIFICATION_KEY_FILE_NAME =
|
||||
"verification-key/proof_main_verification_key.json"
|
||||
|
||||
function G1ToStruct(point) {
|
||||
return {
|
||||
@ -38,4 +40,17 @@ function loadPublicInput(name) {
|
||||
return input
|
||||
}
|
||||
|
||||
module.exports = { loadProof, loadPublicInput }
|
||||
function loadVerificationKey(name) {
|
||||
const key = JSON.parse(
|
||||
fs.readFileSync(`${BASE_PATH}/${name}/${VERIFICATION_KEY_FILE_NAME}`)
|
||||
)
|
||||
return {
|
||||
alpha1: G1ToStruct(key["vk_alpha_1"]),
|
||||
beta2: G2ToStruct(key["vk_beta_2"]),
|
||||
gamma2: G2ToStruct(key["vk_gamma_2"]),
|
||||
delta2: G2ToStruct(key["vk_delta_2"]),
|
||||
IC: key["IC"].map(G1ToStruct),
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { loadProof, loadPublicInput, loadVerificationKey }
|
||||
|
@ -159,12 +159,14 @@ contract Verifier {
|
||||
Pairing.G2Point B;
|
||||
Pairing.G1Point C;
|
||||
}
|
||||
constructor() {
|
||||
verifyingKey.alpha1 = Pairing.G1Point(<%vk_alpha1%>);
|
||||
verifyingKey.beta2 = Pairing.G2Point(<%vk_beta2%>);
|
||||
verifyingKey.gamma2 = Pairing.G2Point(<%vk_gamma2%>);
|
||||
verifyingKey.delta2 = Pairing.G2Point(<%vk_delta2%>);
|
||||
<%vk_ic_pts%>
|
||||
constructor(VerifyingKey memory key) {
|
||||
verifyingKey.alpha1 = key.alpha1;
|
||||
verifyingKey.beta2 = key.beta2;
|
||||
verifyingKey.gamma2 = key.gamma2;
|
||||
verifyingKey.delta2 = key.delta2;
|
||||
for (uint i=0; i<key.IC.length; i++) {
|
||||
verifyingKey.IC.push(key.IC[i]);
|
||||
}
|
||||
}
|
||||
function verify(uint[] memory input, Proof memory proof) internal view returns (uint) {
|
||||
require(input.length + 1 == verifyingKey.IC.length,"verifier-bad-input");
|
||||
|
Loading…
x
Reference in New Issue
Block a user