Skip to content

Commit

Permalink
fix verifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
Arvolear committed Oct 4, 2024
1 parent 7e9137b commit 506e7f1
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,43 @@ contract PUKRECDSABrainpool256Verifier2 {
uint256 constant gammay2 =
8495653923123431417604973247489272438418190587263600148770280649306958101930;
uint256 constant deltax1 =
17648214234331957568330960957431498544435101565910880115570722598320265006571;
3547477126449857139633983009620137460077554114237445026314115360610043979285;
uint256 constant deltax2 =
1377972305104844376387599205844979928840838786046793361825321730630934362959;
10928568844374400863804629708475431407023075271945564227434729637878072403442;
uint256 constant deltay1 =
2077816914261812197050368998616279328991484916205907994635778419662553645477;
6080597990532056495189362405786162840655216728633201784347465362060146785147;
uint256 constant deltay2 =
2206289321184310538510887385465087836163090981404797579272381439458278590108;
4470100564077453791046567972062974757478646606817982473103558560020476829479;

uint256 constant IC0x =
18620266600276641562820981570212476034197495789902029506640735641849992291769;
10250235582079194827836991969627586349381170409876348846599756079093427988497;
uint256 constant IC0y =
19180656759806716198038875169019531739979112910755771923690114773726221215288;
15021764662541658579603701689108175389487330366093878113369205744700213460589;

uint256 constant IC1x =
272955953602785972907203424364571796460055637613382016500922878551440008739;
8444482028550266727267446371407600277359423226788825172923546302631757426303;
uint256 constant IC1y =
5276638731998402720315200280007489042508900143842986105052170133990433041996;
20567122366412833514064038388656763224136645108636454252273751989834794488680;

uint256 constant IC2x =
19523878693630562681534219732646856453490628958195981653494410919086629964675;
uint256 constant IC2y =
7730898387503924487832366441827237748045223447795996584667813415617107202964;

uint256 constant IC3x =
3028300552888553431116928444027305617355323551625467033079227968847299852223;
uint256 constant IC3y =
4250638535098742158512408607318096897991046787212599889959156830476662724582;

uint256 constant IC4x =
21417058039462991694371445700567389442057771542456275334068536076335021821064;
uint256 constant IC4y =
12285131923302442434091610043581925373748375712262200709071460912066048110233;

uint256 constant IC5x =
15184214753614260431513409366509190696008185285895794433237639770781441189853;
uint256 constant IC5y =
21265173286952119853849320938728787811885073521266012829526366850297501599277;

// Memory data
uint16 constant pVk = 0;
Expand All @@ -78,7 +98,7 @@ contract PUKRECDSABrainpool256Verifier2 {
uint[2] calldata _pA,
uint[2][2] calldata _pB,
uint[2] calldata _pC,
uint[1] calldata _pubSignals
uint[5] calldata _pubSignals
) public view returns (bool) {
assembly {
function checkField(v) {
Expand Down Expand Up @@ -125,6 +145,14 @@ contract PUKRECDSABrainpool256Verifier2 {

g1_mulAccC(_pVk, IC1x, IC1y, calldataload(add(pubSignals, 0)))

g1_mulAccC(_pVk, IC2x, IC2y, calldataload(add(pubSignals, 32)))

g1_mulAccC(_pVk, IC3x, IC3y, calldataload(add(pubSignals, 64)))

g1_mulAccC(_pVk, IC4x, IC4y, calldataload(add(pubSignals, 96)))

g1_mulAccC(_pVk, IC5x, IC5y, calldataload(add(pubSignals, 128)))

// -A
mstore(_pPairing, calldataload(pA))
mstore(add(_pPairing, 32), mod(sub(q, calldataload(add(pA, 32))), q))
Expand Down Expand Up @@ -179,6 +207,14 @@ contract PUKRECDSABrainpool256Verifier2 {

checkField(calldataload(add(_pubSignals, 32)))

checkField(calldataload(add(_pubSignals, 64)))

checkField(calldataload(add(_pubSignals, 96)))

checkField(calldataload(add(_pubSignals, 128)))

checkField(calldataload(add(_pubSignals, 160)))

// Validate all evaluations
let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ contract PUniversal2048V3Verifier2 {
uint256 constant gammay2 =
8495653923123431417604973247489272438418190587263600148770280649306958101930;
uint256 constant deltax1 =
9972707892756301992628027167100508635235743168894163807910432640003585670629;
21818559822095531460277741956009236371690941928804783562934258002820233242209;
uint256 constant deltax2 =
9749496022321274900984616736448293748140758292374440315949719817944605689753;
4205244828637642913379637926365471090424230129569287067880549976328521826437;
uint256 constant deltay1 =
7772157013299609022678719283393952295722213676852534163551823291113120946228;
7270374609396363334923017213699704738455304908952034008346196376087632726341;
uint256 constant deltay2 =
26272521512268138931993210565971109758901587741324471023734102574650437587;
2026075313606086515381406605768777826453548736078627762702012235718770915919;

uint256 constant IC0x =
3464583722225543371880851919955508593389116045816737133541148879661253237975;
Expand All @@ -83,6 +83,11 @@ contract PUniversal2048V3Verifier2 {
uint256 constant IC4y =
15444056503358316610565611012661912704454712484500203458593334820917539080308;

uint256 constant IC5x =
385717035648767674946342312840112992282559354693396557430191176802463765476;
uint256 constant IC5y =
5078610744451341480156901316544353839730031367348173770134657662497683445816;

// Memory data
uint16 constant pVk = 0;
uint16 constant pPairing = 128;
Expand All @@ -93,7 +98,7 @@ contract PUniversal2048V3Verifier2 {
uint[2] calldata _pA,
uint[2][2] calldata _pB,
uint[2] calldata _pC,
uint[4] calldata _pubSignals
uint[5] calldata _pubSignals
) public view returns (bool) {
assembly {
function checkField(v) {
Expand Down Expand Up @@ -146,6 +151,8 @@ contract PUniversal2048V3Verifier2 {

g1_mulAccC(_pVk, IC4x, IC4y, calldataload(add(pubSignals, 96)))

g1_mulAccC(_pVk, IC5x, IC5y, calldataload(add(pubSignals, 128)))

// -A
mstore(_pPairing, calldataload(pA))
mstore(add(_pPairing, 32), mod(sub(q, calldataload(add(pA, 32))), q))
Expand Down Expand Up @@ -206,6 +213,8 @@ contract PUniversal2048V3Verifier2 {

checkField(calldataload(add(_pubSignals, 128)))

checkField(calldataload(add(_pubSignals, 160)))

// Validate all evaluations
let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem)

Expand Down
76 changes: 45 additions & 31 deletions deploy/2_registration.migration.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,60 @@
import { ethers } from "hardhat";

import { Deployer, Reporter } from "@solarity/hardhat-migrate";

import {
deployProxy,
deployPVerifiers,
deployCRSADispatcher,
deployCRSAPSSDispatcher,
deployPNOAADispatcher,
deployPRSASHA2688Dispatcher,
deployPECDSASHA12704Dispatcher,
} from "./helpers";
PUKRECDSABrainpool256Verifier2__factory,
PUniversal2048V3Verifier2__factory,
Registration2Mock__factory,
} from "@ethers-v6";

import { Registration2Mock__factory, StateKeeperMock__factory } from "@ethers-v6";
import {
C_RSA_SHA1_2048,
C_RSA_SHA2_2048,
C_RSA_SHA1_4096,
C_RSA_SHA2_4096,
C_RSAPSS_SHA2_2048,
C_RSAPSS_SHA2_4096,
C_RSAPSS_SHA512_2048,
C_RSAPSS_SHA512_4096,
P_ECDSA_SHA1_2704,
P_NO_AA,
P_RSA_SHA1_2688,
P_RSA_SHA1_2688_3,
P_RSA_SHA2_2688,
P_RSA_SHA2_2688_3,
Z_UNIVERSAL_2048,
Z_UNIVERSAL_2048_V2,
Z_UNIVERSAL_2048_V3,
Z_UNIVERSAL_4096,
Z_UNIVERSAL_PSS_2048_S32_E2,
Z_UNIVERSAL_PSS_2048_S32_E17,
Z_UNIVERSAL_PSS_2048_S64_E17,
Z_UKR_ECDSA_BRAINPOOL_256,
Z_INTERNAL,
Z_INTERNAL_OPT,
Z_MNE_OPT,
Z_MNE_OPT_2,
} from "@/scripts/utils/types";

import { getConfig } from "./config/config";

export = async (deployer: Deployer) => {
const config = (await getConfig())!;
const stateKeeper = await deployer.deployed(StateKeeperMock__factory, "StateKeeper Proxy");

const registration = await deployProxy(deployer, Registration2Mock__factory, "Registration2");
await registration.__Registration_init(config.tssSigner, config.chainName, await stateKeeper.getAddress());

await deployPVerifiers(deployer);
const registration = await deployer.deployed(
Registration2Mock__factory,
"0x1b0F076c8800c457CE734BA85aC8569284DD640A",
);

await deployCRSADispatcher(deployer, "SHA1", "65537", "512", "0x0282020100");
await deployCRSADispatcher(deployer, "SHA1", "65537", "256", "0x0282010100");
await deployCRSADispatcher(deployer, "SHA2", "65537", "512", "0x0282020100");
await deployCRSADispatcher(deployer, "SHA2", "65537", "256", "0x0282010100");
const v1 = await deployer.deploy(PUniversal2048V3Verifier2__factory);
const v2 = await deployer.deploy(PUKRECDSABrainpool256Verifier2__factory);

await deployCRSAPSSDispatcher(deployer, "SHA2", "65537", "256", "0x0282010100");
await deployCRSAPSSDispatcher(deployer, "SHA2", "65537", "512", "0x0282020100");
await deployCRSAPSSDispatcher(deployer, "SHA512", "65537", "256", "0x0282010100");
await deployCRSAPSSDispatcher(deployer, "SHA512", "65537", "512", "0x0282020100");
const coder = ethers.AbiCoder.defaultAbiCoder();

await deployPRSASHA2688Dispatcher(deployer, "65537", "SHA1");
await deployPRSASHA2688Dispatcher(deployer, "3", "SHA1");
let data = coder.encode(["bytes32", "address"], [Z_UNIVERSAL_2048_V3, await v1.getAddress()]);

await deployPRSASHA2688Dispatcher(deployer, "65537", "SHA2");
await deployPRSASHA2688Dispatcher(deployer, "3", "SHA2");
await registration.updateDependency(5, data, "0x");

await deployPNOAADispatcher(deployer);
await deployPECDSASHA12704Dispatcher(deployer);
data = coder.encode(["bytes32", "address"], [Z_UKR_ECDSA_BRAINPOOL_256, await v2.getAddress()]);

Reporter.reportContracts(["Registration2", `${await registration.getAddress()}`]);
await registration.updateDependency(5, data, "0x");
};

0 comments on commit 506e7f1

Please sign in to comment.