From 331bc56e8fadad6b07de44e7eedcff9dec6f119e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Uhl=C3=AD=C5=99?= Date: Tue, 30 Jan 2024 06:36:27 +0100 Subject: [PATCH] feat: zkey hash in marketplace config (#81) --- contracts/Configuration.sol | 1 + contracts/FuzzMarketplace.sol | 5 ++++- deploy/marketplace.js | 5 ++++- test/Proofs.test.js | 2 +- test/examples.js | 1 + .../networks/hardhat/example-proof/proof.json | 16 ++++++++-------- .../networks/hardhat/example-proof/public.json | 2 +- .../proof_main_verification_key.json | 8 ++++---- verifier/networks/hardhat/zkey_hash.json | 1 + verifier/verifier.js | 11 +++++++++-- 10 files changed, 34 insertions(+), 18 deletions(-) rename verifier/networks/hardhat/{verification-key => }/proof_main_verification_key.json (89%) create mode 100644 verifier/networks/hardhat/zkey_hash.json diff --git a/contracts/Configuration.sol b/contracts/Configuration.sol index 0a4b922..c1ad61c 100644 --- a/contracts/Configuration.sol +++ b/contracts/Configuration.sol @@ -23,4 +23,5 @@ struct ProofConfig { uint256 period; // proofs requirements are calculated per period (in seconds) uint256 timeout; // mark proofs as missing before the timeout (in seconds) uint8 downtime; // ignore this much recent blocks for proof requirements + string zkeyHash; // hash of the zkey file which is linked to the verifier } diff --git a/contracts/FuzzMarketplace.sol b/contracts/FuzzMarketplace.sol index 71673a2..fce4d9c 100644 --- a/contracts/FuzzMarketplace.sol +++ b/contracts/FuzzMarketplace.sol @@ -8,7 +8,10 @@ import "./TestVerifier.sol"; contract FuzzMarketplace is Marketplace { constructor() Marketplace( - MarketplaceConfig(CollateralConfig(10, 5, 3, 10), ProofConfig(10, 5, 64)), + MarketplaceConfig( + CollateralConfig(10, 5, 3, 10), + ProofConfig(10, 5, 64, "") + ), new TestToken(), new TestVerifier() ) diff --git a/deploy/marketplace.js b/deploy/marketplace.js index 59dc1f8..eb8c7a8 100644 --- a/deploy/marketplace.js +++ b/deploy/marketplace.js @@ -1,6 +1,8 @@ +const { loadZkeyHash } = require ("../verifier/verifier.js") + const MARKETPLACE_HARDCODED_ADDRESS = "0x59b670e9fA9D0A427751Af201D676719a970857b" -async function deployMarketplace({ deployments, getNamedAccounts }) { +async function deployMarketplace({ deployments, getNamedAccounts, network }) { const token = await deployments.get("TestToken") const verifier = await deployments.get("Groth16Verifier") const configuration = { @@ -14,6 +16,7 @@ async function deployMarketplace({ deployments, getNamedAccounts }) { period: 10, timeout: 5, downtime: 64, + zkeyHash: loadZkeyHash(network.name), }, } const args = [configuration, token.address, verifier.address] diff --git a/test/Proofs.test.js b/test/Proofs.test.js index c239d86..6b0c69a 100644 --- a/test/Proofs.test.js +++ b/test/Proofs.test.js @@ -33,7 +33,7 @@ describe("Proofs", function () { await deployments.fixture(["Groth16Verifier"]) const verifier = await deployments.get("Groth16Verifier") proofs = await Proofs.deploy( - { period, timeout, downtime }, + { period, timeout, downtime, zkeyHash: "" }, verifier.address ) }) diff --git a/test/examples.js b/test/examples.js index 16a2cf3..61b2976 100644 --- a/test/examples.js +++ b/test/examples.js @@ -14,6 +14,7 @@ const exampleConfiguration = () => ({ period: 10, timeout: 5, downtime: 64, + zkeyHash: "", }, }) diff --git a/verifier/networks/hardhat/example-proof/proof.json b/verifier/networks/hardhat/example-proof/proof.json index 5de5ebe..559d792 100644 --- a/verifier/networks/hardhat/example-proof/proof.json +++ b/verifier/networks/hardhat/example-proof/proof.json @@ -1,17 +1,17 @@ { "pi_a": [ - "5354152410986528740889949811485085083352383496724906496620004560773766258873", - "18134846030714314375408574013835366655850239581285468242834655581868166406486", + "7660723414354960115525441084999694570984078535773668898653309300593084455533", + "13530035710725348149248647938083875391713661082920395232005195032418705681044", "1" ], "pi_b": [ [ - "4789242673778392422990537486305482696481357883414443488947138222420834201517", - "2027024107056245515978112401631176046626549081189495220144757031281248965782" + "2901049701023582640714756481602042737261909502555520071221132529600598809861", + "16912924802763251099243304625254406414459294932221399417825327530544648619341" ], [ - "14074051812573855135840075486089320372866984532507488654928193739831517782936", - "7485586556662798915982244873929621022563116002979775814431258294905458788251" + "1466763974310418266645354657059454821840794309805321553635263869263906930810", + "7919549687544999068783867201010060068898464272548283100322334851170181843674" ], [ "1", @@ -19,8 +19,8 @@ ] ], "pi_c": [ - "13387824467635444633441399613298811843935004737405384070996599011859892267608", - "18364006371113837324322071862501578716151167725869146988611466294121991858941", + "16466626257875743363595172691363309940341494894360337991073652025213400816020", + "726868384379000975195472980386786614662718074766231997317916406216503344910", "1" ], "protocol": "groth16", diff --git a/verifier/networks/hardhat/example-proof/public.json b/verifier/networks/hardhat/example-proof/public.json index a984225..d94a687 100644 --- a/verifier/networks/hardhat/example-proof/public.json +++ b/verifier/networks/hardhat/example-proof/public.json @@ -1,5 +1,5 @@ [ - "7538754537", + "7613683355", "16074246370508166450132968585287196391860062495017081813239200574579640171677", "3" ] \ No newline at end of file diff --git a/verifier/networks/hardhat/verification-key/proof_main_verification_key.json b/verifier/networks/hardhat/proof_main_verification_key.json similarity index 89% rename from verifier/networks/hardhat/verification-key/proof_main_verification_key.json rename to verifier/networks/hardhat/proof_main_verification_key.json index 02d01ce..50d2be6 100644 --- a/verifier/networks/hardhat/verification-key/proof_main_verification_key.json +++ b/verifier/networks/hardhat/proof_main_verification_key.json @@ -37,12 +37,12 @@ ], "vk_delta_2": [ [ - "9526465944650138768726332063321262597514193803543146241262920033512923206833", - "16947967852917776612242666765339055140004530219040719566241973405926209896589" + "7266368133833883232696069721567436218373292960862868097298822586114813920314", + "20179748680988515246787231619783022280905346903974148635767068251171792499335" ], [ - "19350668523204772149977938696677933779621485674406066708436704188235339847628", - "8391255886665123549932056926338579244742743577262957977406729945277596579696" + "11281139796322341653654563690864590481498751340552223660930514795611905053341", + "18865664978433701919673993490064453553613307046760943003771776295179590961997" ], [ "1", diff --git a/verifier/networks/hardhat/zkey_hash.json b/verifier/networks/hardhat/zkey_hash.json new file mode 100644 index 0000000..a468319 --- /dev/null +++ b/verifier/networks/hardhat/zkey_hash.json @@ -0,0 +1 @@ +"74fe889808fa3024e008ca603841e2afeda36044b70a06173e38ab82e632cea0" diff --git a/verifier/verifier.js b/verifier/verifier.js index 0e2d77c..fe207b9 100644 --- a/verifier/verifier.js +++ b/verifier/verifier.js @@ -3,8 +3,9 @@ const fs = require("fs") const BASE_PATH = __dirname + "/networks" const PROOF_FILE_NAME = "example-proof/proof.json" const PUBLIC_INPUT_FILE_NAME = "example-proof/public.json" +const ZKEY_HASH_FILE_NAME = "zkey_hash.json" const VERIFICATION_KEY_FILE_NAME = - "verification-key/proof_main_verification_key.json" + "proof_main_verification_key.json" function G1ToStruct(point) { return { @@ -36,6 +37,12 @@ function loadPublicInput(name) { return input } +function loadZkeyHash(name) { + const path = `${BASE_PATH}/${name}/${ZKEY_HASH_FILE_NAME}` + const input = JSON.parse(fs.readFileSync(path)) + return input +} + function loadVerificationKey(name) { const path = `${BASE_PATH}/${name}/${VERIFICATION_KEY_FILE_NAME}` const key = JSON.parse(fs.readFileSync(path)) @@ -48,4 +55,4 @@ function loadVerificationKey(name) { } } -module.exports = { loadProof, loadPublicInput, loadVerificationKey } +module.exports = { loadProof, loadPublicInput, loadVerificationKey, loadZkeyHash }