-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1901186
commit 8365d4a
Showing
6 changed files
with
224 additions
and
17 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
contracts/lib/groth16-verifiers/Groth16VerifierLinkedMultiQuery10Wrapper.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// Copyright 2017 Christian Reitwiessner | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
// | ||
// 2019 OKIMS | ||
// ported to solidity 0.6 | ||
// fixed linter warnings | ||
// added requiere error messages | ||
// | ||
// | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity ^0.8.10; | ||
|
||
import {IGroth16Verifier} from "../../interfaces/IGroth16Verifier.sol"; | ||
import {Groth16VerifierLinkedMultiQuery10} from "./Groth16VerifierLinkedMultiQuery10.sol"; | ||
|
||
contract Groth16VerifierLinkedMultiQuery10Wrapper is | ||
Groth16VerifierLinkedMultiQuery10, | ||
IGroth16Verifier | ||
{ | ||
/** | ||
* @dev Number of public signals for atomic mtp circuit | ||
*/ | ||
uint constant PUBSIGNALS_LENGTH = 22; | ||
|
||
/** | ||
* @dev Verify the circuit with the groth16 proof π=([πa]1,[πb]2,[πc]1). | ||
* @param a πa element of the groth16 proof. | ||
* @param b πb element of the groth16 proof. | ||
* @param c πc element of the groth16 proof. | ||
* @param input Public inputs of the circuit. | ||
* @return r true if the proof is valid. | ||
*/ | ||
function verify( | ||
uint256[2] calldata a, | ||
uint256[2][2] calldata b, | ||
uint256[2] calldata c, | ||
uint256[] calldata input | ||
) public view returns (bool r) { | ||
uint[PUBSIGNALS_LENGTH] memory pubSignals; | ||
|
||
require(input.length == PUBSIGNALS_LENGTH, "expected array length is 22"); | ||
|
||
for (uint256 i = 0; i < PUBSIGNALS_LENGTH; i++) { | ||
pubSignals[i] = input[i]; | ||
} | ||
|
||
return this.verifyProof(a, b, c, pubSignals); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules"; | ||
import { contractsInfo } from "../../helpers/constants"; | ||
|
||
export const LinkedMultiQueryProxyModule = buildModule("LinkedMultiQueryModule", (m) => { | ||
const proxyAdminOwner = m.getAccount(0); | ||
|
||
// This contract is supposed to be deployed to the same address across many networks, | ||
// so the first implementation address is a dummy contract that does nothing but accepts any calldata. | ||
// Therefore, it is a mechanism to deploy TransparentUpgradeableProxy contract | ||
// with constant constructor arguments, so predictable init bytecode and predictable CREATE2 address. | ||
// Subsequent upgrades are supposed to switch this proxy to the real implementation. | ||
|
||
const proxy = m.contract("TransparentUpgradeableProxy", [ | ||
contractsInfo.CREATE2_ADDRESS_ANCHOR.unifiedAddress, | ||
proxyAdminOwner, | ||
contractsInfo.VALIDATOR_LINKED_MULTI_QUERY.create2Calldata, | ||
]); | ||
|
||
const proxyAdminAddress = m.readEventArgument(proxy, "AdminChanged", "newAdmin"); | ||
const proxyAdmin = m.contractAt("ProxyAdmin", proxyAdminAddress); | ||
return { proxyAdmin, proxy }; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// An integration test with a MultiRequest | ||
// The multiRequest has a single group with two requests inside | ||
// One request is based on V3 validator | ||
// Another one is based on LinkedMultiQuery validator | ||
|
||
import { ethers } from "hardhat"; | ||
import { DeployHelper } from "../../helpers/DeployHelper"; | ||
import { loadFixture } from "@nomicfoundation/hardhat-toolbox/network-helpers"; | ||
|
||
describe("Verifier Integration test", function () { | ||
let verifier, verifierLib, v3Validator, lmkValidator; | ||
|
||
async function deployContractsFixture() { | ||
const verifierLib = await ethers.deployContract("VerifierLib"); | ||
const verifier = await ethers.deployContract("VerifierTestWrapper", [], { | ||
libraries: { VerifierLib: await verifierLib.getAddress() }, | ||
}); | ||
|
||
const deployHelper = await DeployHelper.initialize(null, true); | ||
const { state } = await deployHelper.deployStateWithLibraries([]); | ||
await verifier.initialize(await state.getAddress()); | ||
|
||
const authValidator = await ethers.deployContract("AuthV2Validator_forAuth"); | ||
|
||
const authType = { | ||
authType: "authV2", | ||
validator: await authValidator.getAddress(), | ||
params: "0x", | ||
}; | ||
await verifier.setAuthType(authType); | ||
|
||
const { validator: v3Validator } = await deployHelper.deployValidatorContractsWithVerifiers( | ||
"v3", | ||
await state.getAddress(), | ||
); | ||
const { validator: lmkValidator } = await deployHelper.deployValidatorContractsWithVerifiers( | ||
"lmk", | ||
await state.getAddress(), | ||
); | ||
|
||
return { verifier, verifierLib, v3Validator, lmkValidator }; | ||
} | ||
|
||
beforeEach(async () => { | ||
({ verifier, verifierLib, v3Validator, lmkValidator } = | ||
await loadFixture(deployContractsFixture)); | ||
}); | ||
|
||
it("Should verify", async function () { | ||
console.log("Verifier address: ", await verifier.getAddress()); | ||
console.log("VerifierLib address: ", await verifierLib.getAddress()); | ||
console.log("V3Validator address: ", await v3Validator.getAddress()); | ||
console.log("LinkedMultiQueryValidator address: ", await lmkValidator.getAddress()); | ||
}); | ||
}); |