Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolezhniuk committed Oct 30, 2024
1 parent c5f2e5b commit 38a9d50
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract Groth16VerifierAuthV2Wrapper is Groth16VerifierAuthV2, IVerifier {
) public view returns (bool r) {
uint[PUBSIGNALS_LENGTH] memory pubSignals;

require(input.length == PUBSIGNALS_LENGTH, "expected array length is 11");
require(input.length == PUBSIGNALS_LENGTH, "expected array length is 3");

for (uint256 i = 0; i < PUBSIGNALS_LENGTH; i++) {
pubSignals[i] = input[i];
Expand Down
65 changes: 15 additions & 50 deletions contracts/validators/AuthV2Validator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,34 +76,20 @@ contract AuthV2Validator is CredentialAtomicQueryValidatorBase {
* @return Array of key to public input index as result.
*/
function verify(
// solhint-disable-next-line no-unused-vars
uint256[] memory inputs,
// solhint-disable-next-line no-unused-vars
uint256[2] memory a,
// solhint-disable-next-line no-unused-vars
uint256[2][2] memory b,
// solhint-disable-next-line no-unused-vars
uint256[2] memory c,
// solhint-disable-next-line no-unused-vars
bytes calldata data,
// solhint-disable-next-line no-unused-vars
address sender
) public view override returns (ICircuitValidator.KeyToInputIndex[] memory) {
ICircuitValidator.KeyToInputIndex[]
memory keyToInputIndex = new ICircuitValidator.KeyToInputIndex[](1);
if (inputs.length == 0) {
uint256 userId = GenesisUtils.calcIdFromEthAddress(
_getState().getDefaultIdType(),
sender
);

keyToInputIndex[0] = ICircuitValidator.KeyToInputIndex({
key: "userID",
inputIndex: userId
});
return keyToInputIndex;
}

_verifyMain(inputs, a, b, c, data, sender, IState(getStateAddress()));
keyToInputIndex[0] = ICircuitValidator.KeyToInputIndex({
key: "userID",
inputIndex: inputs[0]
});
return keyToInputIndex;
revert("fuction not supported in this contract");
}

/**
Expand All @@ -116,28 +102,25 @@ contract AuthV2Validator is CredentialAtomicQueryValidatorBase {
*/
function verifyV2(
bytes calldata zkProof,
// solhint-disable-next-line no-unused-vars
bytes calldata data,
address sender,
IState stateContract
) public view override returns (ICircuitValidator.Signal[] memory) {
if (zkProof.length == 0) {
uint256 userId = GenesisUtils.calcIdFromEthAddress(
_getState().getDefaultIdType(),
sender
);
ICircuitValidator.Signal[] memory signals = new ICircuitValidator.Signal[](1);
signals[0] = ICircuitValidator.Signal({name: "userID", value: userId});
return signals;
}

(
uint256[] memory inputs,
uint256[2] memory a,
uint256[2][2] memory b,
uint256[2] memory c
) = abi.decode(zkProof, (uint256[], uint256[2], uint256[2][2], uint256[2]));

return _verifyMain(inputs, a, b, c, data, sender, stateContract);
PubSignals memory pubSignals = parsePubSignals(inputs);
_checkGistRoot(pubSignals.userID, pubSignals.gistRoot, stateContract);
_checkChallenge(pubSignals.challenge, sender);
_verifyZKP(inputs, a, b, c);
ICircuitValidator.Signal[] memory signals = new ICircuitValidator.Signal[](1);
signals[0] = ICircuitValidator.Signal({name: "userID", value: pubSignals.userID});
return signals;
}

function _verifyZKP(
Expand All @@ -152,22 +135,4 @@ contract AuthV2Validator is CredentialAtomicQueryValidatorBase {
// verify that zkp is valid
require(verifier.verify(a, b, c, inputs), "Proof is not valid");
}

function _verifyMain(
uint256[] memory inputs,
uint256[2] memory a,
uint256[2][2] memory b,
uint256[2] memory c,
bytes calldata data,
address sender,
IState state
) internal view returns (ICircuitValidator.Signal[] memory) {
PubSignals memory pubSignals = parsePubSignals(inputs);
_checkGistRoot(pubSignals.userID, pubSignals.gistRoot, state);
_checkChallenge(pubSignals.challenge, sender);
_verifyZKP(inputs, a, b, c);
ICircuitValidator.Signal[] memory signals = new ICircuitValidator.Signal[](1);
signals[0] = ICircuitValidator.Signal({name: "userID", value: pubSignals.userID});
return signals;
}
}
26 changes: 14 additions & 12 deletions helpers/DeployHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
UniversalVerifierProxyModule,
Groth16VerifierStateTransitionModule,
AuthV2ValidatorProxyModule,
Groth16VerifierAuthV2Module,
Groth16VerifierAuthV2WrapperModule,
} from "../ignition";
import { chainIdInfoMap, contractsInfo } from "./constants";
import {
Expand All @@ -30,6 +30,8 @@ import { MCPaymentProxyModule } from "../ignition/modules/mcPayment";

const SMT_MAX_DEPTH = 64;

export type VerifierType = "mtpV2" | "sigV2" | "v3" | "authV2";

export class DeployHelper {
constructor(
private signers: SignerWithAddress[],
Expand Down Expand Up @@ -565,26 +567,26 @@ export class DeployHelper {
return g16Verifier;
}

getGroth16VerifierWrapperName(verifierType: "mtpV2" | "sigV2" | "v3" | "authV2"): string {
getGroth16VerifierWrapperName(verifierType: VerifierType): string {
let g16VerifierContractWrapperName;
switch (verifierType) {
case "mtpV2":
g16VerifierContractWrapperName = "Groth16VerifierMTPWrapper";
g16VerifierContractWrapperName = contractsInfo.GROTH16_VERIFIER_MTP.name;
break;
case "sigV2":
g16VerifierContractWrapperName = "Groth16VerifierSigWrapper";
g16VerifierContractWrapperName = contractsInfo.GROTH16_VERIFIER_SIG.name;
break;
case "v3":
g16VerifierContractWrapperName = "Groth16VerifierV3Wrapper";
g16VerifierContractWrapperName = contractsInfo.GROTH16_VERIFIER_V3.name;
break;
case "authV2":
g16VerifierContractWrapperName = "Groth16VerifierAuthV2Wrapper";
g16VerifierContractWrapperName = contractsInfo.GROTH16_VERIFIER_AUTH_V2.name;
break;
}
return g16VerifierContractWrapperName;
}

getGroth16VerifierWrapperVerification(verifierType: "mtpV2" | "sigV2" | "v3" | "authV2"): {
getGroth16VerifierWrapperVerification(verifierType: VerifierType): {
contract: string;
constructorArgsImplementation: any[];
constructorArgsProxy?: any[];
Expand All @@ -608,7 +610,7 @@ export class DeployHelper {
return verification;
}

getValidatorVerification(verifierType: "mtpV2" | "sigV2" | "v3" | "authV2"): {
getValidatorVerification(verifierType: VerifierType): {
contract: string;
constructorArgsImplementation: any[];
constructorArgsProxy?: any[];
Expand All @@ -633,7 +635,7 @@ export class DeployHelper {
}

async deployGroth16VerifierWrapper(
verifierType: "mtpV2" | "sigV2" | "v3" | "authV2",
verifierType: VerifierType,
deployStrategy: "basic" | "create2" = "basic",
): Promise<Contract> {
const g16VerifierContractWrapperName = this.getGroth16VerifierWrapperName(verifierType);
Expand All @@ -653,7 +655,7 @@ export class DeployHelper {
case "v3":
g16VerifierWrapperModule = Groth16VerifierV3WrapperModule;
case "authV2":
g16VerifierWrapperModule = Groth16VerifierAuthV2Module;
g16VerifierWrapperModule = Groth16VerifierAuthV2WrapperModule;
break;
}

Expand Down Expand Up @@ -685,7 +687,7 @@ export class DeployHelper {
}

async deployValidatorContractsWithVerifiers(
validatorType: "mtpV2" | "sigV2" | "v3" | "authV2",
validatorType: VerifierType,
stateAddress: string,
deployStrategy: "basic" | "create2" = "basic",
): Promise<{
Expand Down Expand Up @@ -713,7 +715,7 @@ export class DeployHelper {
}

async deployValidatorContracts(
validatorType: "mtpV2" | "sigV2" | "v3" | "authV2",
validatorType: VerifierType,
stateAddress: string,
groth16VerifierWrapperAddress: string,
deployStrategy: "basic" | "create2" = "basic",
Expand Down
1 change: 1 addition & 0 deletions helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export const contractsInfo = Object.freeze({
},
VALIDATOR_AUTH_V2: {
name: "AuthV2Validator",
version: "1.0.0",
unifiedAddress: "0x6B847C4b53368a290bdce4aE4e46343Ee8946bE0",
create2Calldata: ethers.hexlify(ethers.toUtf8Bytes("iden3.create2.AuthV2Validator")),
verificationOpts: {
Expand Down
11 changes: 7 additions & 4 deletions ignition/modules/groth16Verifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export const Groth16VerifierStateTransitionModule = buildModule(
},
);

export const Groth16VerifierAuthV2Module = buildModule("Groth16VerifierAuthV2Module", (m) => {
const verifier = m.contract(contractsInfo.GROTH16_VERIFIER_AUTH_V2.name);
return { verifier };
});
export const Groth16VerifierAuthV2WrapperModule = buildModule(
"Groth16VerifierAuthV2WrapperModule",
(m) => {
const wrapper = m.contract(contractsInfo.GROTH16_VERIFIER_AUTH_V2.name);
return { wrapper };
},
);

0 comments on commit 38a9d50

Please sign in to comment.