diff --git a/dist/cjs/helper/util.d.ts b/dist/cjs/helper/util.d.ts index 71cd68ac..8ef320a5 100644 --- a/dist/cjs/helper/util.d.ts +++ b/dist/cjs/helper/util.d.ts @@ -1,5 +1,5 @@ import BN from "bn.js"; -import { AddImageParams, ProvingParams, DeployParams, ResetImageParams, ModifyImageParams, VerifyProofParams, LogQuery, ContextHexString } from "../interface/interface.js"; +import { AddImageParams, ProvingParams, DeployParams, ResetImageParams, ModifyImageParams, VerifyProofParams, LogQuery, ContextHexString, VerifyBatchProofParams } from "../interface/interface.js"; import { Contract, Signer } from "ethers"; import { DelphinusWalletConnector, DelphinusBrowserConnector } from "web3subscriber/src/provider.js"; export declare class ZkWasmUtil { @@ -29,6 +29,43 @@ export declare class ZkWasmUtil { constant: boolean; })[]; }; + static batch_verifier_contract: { + contract_name: string; + abi: ({ + type: string; + inputs: { + internalType: string; + name: string; + type: string; + }[]; + name?: undefined; + outputs?: undefined; + stateMutability?: undefined; + anonymous?: undefined; + } | { + type: string; + name: string; + inputs: { + internalType: string; + name: string; + type: string; + }[]; + outputs: never[]; + stateMutability: string; + anonymous?: undefined; + } | { + type: string; + name: string; + inputs: { + name: string; + type: string; + indexed: boolean; + }[]; + anonymous: boolean; + outputs?: undefined; + stateMutability?: undefined; + })[]; + }; static hexToBNs(hexString: string): Array; static validateBytesInput(value: string): boolean; static validateI64HexInput(value: string): boolean; @@ -53,6 +90,8 @@ export declare class ZkWasmUtil { static bytesToBigIntArray(data: Uint8Array, chunksize?: number): BigInt[]; static composeVerifyContract(signer: DelphinusBrowserConnector | DelphinusWalletConnector, verifier_addr: string): import("web3subscriber/src/client.js").DelphinusContract | Promise; static verifyProof(verify_contract: Contract, params: VerifyProofParams): Promise; + static composeBatchVerifierContract(signer: DelphinusBrowserConnector | DelphinusWalletConnector, verifier_addr: string): import("web3subscriber/src/client.js").DelphinusContract | Promise; + static verifyBatchedProof(batch_verifier_contract: Contract, params: VerifyBatchProofParams): Promise; static signMessage(message: string, priv_key: string): Promise; static ERC20Contract(contractAddress: string, signer: Signer): Contract; static bytesToJSONString(data: Uint8Array): string; diff --git a/dist/cjs/helper/util.js b/dist/cjs/helper/util.js index 6e3f6831..d6010eff 100644 --- a/dist/cjs/helper/util.js +++ b/dist/cjs/helper/util.js @@ -247,20 +247,39 @@ class ZkWasmUtil { params.instances.forEach((instance) => { instances.push(this.bytesToBigIntArray(instance)); }); - // let instances = this.bytesToBigIntArray(params.instances); - // let args = ZkWasmUtil.parseArgs(params.instances).map((x) => - // x.toString(10) - // ); - // console.log("args are:", args); - // if (args.length == 0) { - // args = ["0x0"]; - // } - // // convert to BigInt array - // let bigIntArgs = args.map((x) => BigInt(x)); let result = yield verify_contract.verify.send(aggregate_proof, shadow_instances, aux, instances); return result; }); } + static composeBatchVerifierContract(signer, verifier_addr) { + return signer.getContractWithSigner(verifier_addr, this.batch_verifier_contract.abi); + } + static verifyBatchedProof(batch_verifier_contract, params) { + return __awaiter(this, void 0, void 0, function* () { + let membership_proof_index = params.membership_proof_index; + let verify_instance = this.bytesToBigIntArray(params.verify_instance); + let sibling_instances = []; + params.sibling_instances.forEach((instance) => { + // + sibling_instances.push(this.bytesToBigIntArray(instance)[0]); + }); + let target_instances = []; + params.target_instances.forEach((instance) => { + target_instances.push(this.bytesToBigIntArray(instance)); + }); + let round_1_shadow_instance = this.bytesToBigIntArray(params.round_1_shadow_instance); + // Add the round 1 shadow instance to the flattened sibling instances as this is the expected input format + // for the contract. (12 round 1 target instances + 1 round 1 shadow instance) + sibling_instances.push(round_1_shadow_instance[0]); + console.log("Verify Batch Proof Inputs"); + console.log("membership_proof_index: ", membership_proof_index); + console.log("verify_instance: ", verify_instance); + console.log("sibling_instances: ", [sibling_instances]); + console.log("target_instances: ", target_instances); + let result = yield batch_verifier_contract.check_verified_proof.send(membership_proof_index, verify_instance, [sibling_instances], target_instances); + return result; + }); + } static signMessage(message, priv_key) { return __awaiter(this, void 0, void 0, function* () { let wallet = new ethers_1.Wallet(priv_key, null); @@ -388,4 +407,80 @@ ZkWasmUtil.contract_abi = { }, ], }; +ZkWasmUtil.batch_verifier_contract = { + contract_name: "ProofTracker", + abi: [ + { + type: "constructor", + inputs: [ + { + internalType: "address", + name: "verifier_address", + type: "address", + }, + ], + }, + { + type: "function", + name: "check_verified_proof", + inputs: [ + { + internalType: "uint256[]", + name: "membership_proof_index", + type: "uint256[]", + }, + { + internalType: "uint256[]", + name: "verify_instance", + type: "uint256[]", + }, + { + internalType: "uint256[][]", + name: "sibling_instances", + type: "uint256[][]", + }, + { + internalType: "uint256[][]", + name: "target_instances", + type: "uint256[][]", + }, + ], + outputs: [], + stateMutability: "view", + }, + { + type: "function", + name: "register_proofs", + inputs: [ + { internalType: "uint256[]", name: "proof", type: "uint256[]" }, + { + internalType: "uint256[]", + name: "verify_instance", + type: "uint256[]", + }, + { internalType: "uint256[]", name: "aux", type: "uint256[]" }, + { + internalType: "uint256[][]", + name: "instances", + type: "uint256[][]", + }, + ], + outputs: [], + stateMutability: "nonpayable", + }, + { + type: "function", + name: "set_verifier", + inputs: [{ internalType: "address", name: "vaddr", type: "address" }], + outputs: [], + stateMutability: "nonpayable", + }, + { + type: "event", + name: "ProofAck", + inputs: [{ name: "hash", type: "uint256", indexed: false }], + anonymous: false, + }, + ], +}; ZkWasmUtil.MAX_CONTEXT_SIZE = 4096; diff --git a/dist/cjs/index.d.ts b/dist/cjs/index.d.ts index 3ca3808d..692b9afd 100644 --- a/dist/cjs/index.d.ts +++ b/dist/cjs/index.d.ts @@ -1,6 +1,6 @@ -import { Task, ProvingParams, DeployParams, QueryParams, VerifyProofParams, VerifyData, StatusState, DeploymentInfo, Image, Statistics, AddImageParams, WithSignature, User, UserQueryParams, PaymentParams, SubscriptionParams, Subscription, SubscriptionType, SubscriptionRequest, TxHistoryQueryParams, TransactionInfo, TaskStatus, TaskType, AppConfig, PaginationResult, ResetImageParams, LogQuery, ModifyImageParams, ChainDetails, InputContextType, ContextHexString, WithCustomInputContextType, WithInitialContext, WithNonCustomInputContextType, WithResetContext, WithoutInitialContext, WithoutInputContextType, WithoutResetContext, ImageMetadataKeys, ImageMetadataValsProvePaymentSrc, TaskMetadataKeys, TaskMetadataValsProofSubmitMode, Round1BatchProof, Round2BatchProof, FinalBatchProof, Round1BatchProofStatus, Round2BatchProofStatus, Round1BatchProofQuery, Round2BatchProofQuery, FinalBatchProofQuery, PaginatedQuery, PaginationQuery, AutoSubmitStatus, TaskMetadata } from "./interface/interface.js"; +import { Task, ProvingParams, DeployParams, QueryParams, VerifyProofParams, VerifyData, StatusState, DeploymentInfo, Image, Statistics, AddImageParams, WithSignature, User, UserQueryParams, PaymentParams, SubscriptionParams, Subscription, SubscriptionType, SubscriptionRequest, TxHistoryQueryParams, TransactionInfo, TaskStatus, TaskType, AppConfig, PaginationResult, ResetImageParams, LogQuery, ModifyImageParams, ChainDetails, InputContextType, ContextHexString, WithCustomInputContextType, WithInitialContext, WithNonCustomInputContextType, WithResetContext, WithoutInitialContext, WithoutInputContextType, WithoutResetContext, ImageMetadataKeys, ImageMetadataValsProvePaymentSrc, TaskMetadataKeys, TaskMetadataValsProofSubmitMode, Round1BatchProof, Round2BatchProof, FinalBatchProof, Round1BatchProofStatus, Round2BatchProofStatus, Round1BatchProofQuery, Round2BatchProofQuery, FinalBatchProofQuery, PaginatedQuery, PaginationQuery, AutoSubmitStatus, TaskMetadata, VerifyBatchProofParams, FinalProofStatus } from "./interface/interface.js"; import { ZkWasmUtil } from "./helper/util.js"; import { ZkWasmServiceEndpoint } from "./helper/endpoint.js"; import { ZkWasmServiceHelper } from "./helper/task.js"; -export { ZkWasmServiceEndpoint, ZkWasmServiceHelper, ZkWasmUtil, InputContextType, ImageMetadataKeys, ImageMetadataValsProvePaymentSrc, TaskMetadataKeys, TaskMetadataValsProofSubmitMode, AutoSubmitStatus, }; -export type { Task, ProvingParams, DeployParams, QueryParams, VerifyProofParams, VerifyData, StatusState, DeploymentInfo, Image, Statistics, AddImageParams, TaskStatus, TaskType, WithSignature, User, UserQueryParams, Subscription, SubscriptionType, PaymentParams, SubscriptionParams, SubscriptionRequest, TxHistoryQueryParams, TransactionInfo, ResetImageParams, AppConfig, PaginationResult, LogQuery, ModifyImageParams, ChainDetails, ContextHexString, WithCustomInputContextType, WithInitialContext, WithNonCustomInputContextType, WithResetContext, WithoutInitialContext, WithoutInputContextType, WithoutResetContext, Round1BatchProof, Round2BatchProof, FinalBatchProof, Round1BatchProofStatus, Round2BatchProofStatus, Round1BatchProofQuery, Round2BatchProofQuery, FinalBatchProofQuery, PaginatedQuery, PaginationQuery, TaskMetadata, }; +export { ZkWasmServiceEndpoint, ZkWasmServiceHelper, ZkWasmUtil, InputContextType, ImageMetadataKeys, ImageMetadataValsProvePaymentSrc, TaskMetadataKeys, TaskMetadataValsProofSubmitMode, AutoSubmitStatus, Round1BatchProofStatus, Round2BatchProofStatus, FinalProofStatus, }; +export type { Task, ProvingParams, DeployParams, QueryParams, VerifyProofParams, VerifyData, StatusState, DeploymentInfo, Image, Statistics, AddImageParams, TaskStatus, TaskType, WithSignature, User, UserQueryParams, Subscription, SubscriptionType, PaymentParams, SubscriptionParams, SubscriptionRequest, TxHistoryQueryParams, TransactionInfo, ResetImageParams, AppConfig, PaginationResult, LogQuery, ModifyImageParams, ChainDetails, ContextHexString, WithCustomInputContextType, WithInitialContext, WithNonCustomInputContextType, WithResetContext, WithoutInitialContext, WithoutInputContextType, WithoutResetContext, Round1BatchProof, Round2BatchProof, FinalBatchProof, Round1BatchProofQuery, Round2BatchProofQuery, FinalBatchProofQuery, PaginatedQuery, PaginationQuery, TaskMetadata, VerifyBatchProofParams, }; diff --git a/dist/cjs/index.js b/dist/cjs/index.js index 3eaf1033..8c464880 100644 --- a/dist/cjs/index.js +++ b/dist/cjs/index.js @@ -1,13 +1,16 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.AutoSubmitStatus = exports.TaskMetadataValsProofSubmitMode = exports.TaskMetadataKeys = exports.ImageMetadataValsProvePaymentSrc = exports.ImageMetadataKeys = exports.InputContextType = exports.ZkWasmUtil = exports.ZkWasmServiceHelper = exports.ZkWasmServiceEndpoint = void 0; +exports.FinalProofStatus = exports.Round2BatchProofStatus = exports.Round1BatchProofStatus = exports.AutoSubmitStatus = exports.TaskMetadataValsProofSubmitMode = exports.TaskMetadataKeys = exports.ImageMetadataValsProvePaymentSrc = exports.ImageMetadataKeys = exports.InputContextType = exports.ZkWasmUtil = exports.ZkWasmServiceHelper = exports.ZkWasmServiceEndpoint = void 0; const interface_js_1 = require("./interface/interface.js"); Object.defineProperty(exports, "InputContextType", { enumerable: true, get: function () { return interface_js_1.InputContextType; } }); Object.defineProperty(exports, "ImageMetadataKeys", { enumerable: true, get: function () { return interface_js_1.ImageMetadataKeys; } }); Object.defineProperty(exports, "ImageMetadataValsProvePaymentSrc", { enumerable: true, get: function () { return interface_js_1.ImageMetadataValsProvePaymentSrc; } }); Object.defineProperty(exports, "TaskMetadataKeys", { enumerable: true, get: function () { return interface_js_1.TaskMetadataKeys; } }); Object.defineProperty(exports, "TaskMetadataValsProofSubmitMode", { enumerable: true, get: function () { return interface_js_1.TaskMetadataValsProofSubmitMode; } }); +Object.defineProperty(exports, "Round1BatchProofStatus", { enumerable: true, get: function () { return interface_js_1.Round1BatchProofStatus; } }); +Object.defineProperty(exports, "Round2BatchProofStatus", { enumerable: true, get: function () { return interface_js_1.Round2BatchProofStatus; } }); Object.defineProperty(exports, "AutoSubmitStatus", { enumerable: true, get: function () { return interface_js_1.AutoSubmitStatus; } }); +Object.defineProperty(exports, "FinalProofStatus", { enumerable: true, get: function () { return interface_js_1.FinalProofStatus; } }); const util_js_1 = require("./helper/util.js"); Object.defineProperty(exports, "ZkWasmUtil", { enumerable: true, get: function () { return util_js_1.ZkWasmUtil; } }); const endpoint_js_1 = require("./helper/endpoint.js"); diff --git a/dist/cjs/interface/interface.d.ts b/dist/cjs/interface/interface.d.ts index e86f5f52..7766ed85 100644 --- a/dist/cjs/interface/interface.d.ts +++ b/dist/cjs/interface/interface.d.ts @@ -95,6 +95,11 @@ export interface FinalBatchProof { internal_message?: string; static_files_verification_data: StaticFileVerificationData; verifier_contracts: VerifierContracts[]; + status: FinalProofStatus; +} +export declare enum FinalProofStatus { + ProofNotRegistered = "ProofNotRegistered", + ProofRegistered = "ProofRegistered" } export type PaginatedQuery = T & PaginationQuery; export interface Round1BatchProofQuery { @@ -113,6 +118,7 @@ export interface FinalBatchProofQuery { id?: string; round_2_id?: string; task_id?: string; + status?: FinalProofStatus; } export interface PaginationQuery { total?: number; @@ -125,6 +131,7 @@ export interface TaskVerificationData { export interface VerifierContracts { chain_id: number; aggregator_verifier: string; + batch_verifier: string; circuit_size: number; } export type TaskType = "Setup" | "Prove" | "Reset"; @@ -139,7 +146,8 @@ export type TaskStatus = "Pending" | "Processing" | "DryRunFailed" | "Done" | "F export declare enum AutoSubmitStatus { Round1 = "Round1", Round2 = "Round2", - Done = "Done", + Batched = "Batched", + RegisteredProof = "RegisteredProof", Failed = "Failed" } export type TaskMetadata = { @@ -178,8 +186,8 @@ export interface WithoutInitialContext { export type AddImageParams = BaseAddImageParams & (WithInitialContext | WithoutInitialContext); export declare enum TaskMetadataKeys { ProofSubmitMode = "ProofSubmitMode", - Round1BatchProofId = "Round1BatchProofTaskId", - Round2BatchProofId = "Round2BatchProofTaskId", + Round1BatchProofId = "Round1BatchProofId", + Round2BatchProofId = "Round2BatchProofId", FinalBatchProofId = "FinalBatchProofId" } export declare enum TaskMetadataValsProofSubmitMode { @@ -263,6 +271,13 @@ export interface VerifyProofParams { aux: Uint8Array; instances: Array; } +export interface VerifyBatchProofParams { + membership_proof_index: Array; + verify_instance: Uint8Array; + sibling_instances: Array; + round_1_shadow_instance: Uint8Array; + target_instances: Array; +} export interface LogQuery { id: string; user_address: string; @@ -294,6 +309,7 @@ export interface ContractDeployments { aggregator_config_address: string; aggregator_verifier_steps: string[]; aggregator_verifier: string; + batch_verifier: string; static_file_checksum: Uint8Array; } export interface ChainInfo { diff --git a/dist/cjs/interface/interface.js b/dist/cjs/interface/interface.js index 95e35cc5..fc2ec3e2 100644 --- a/dist/cjs/interface/interface.js +++ b/dist/cjs/interface/interface.js @@ -1,6 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.TaskMetadataValsProofSubmitMode = exports.TaskMetadataKeys = exports.ImageMetadataValsProvePaymentSrc = exports.ImageMetadataKeys = exports.AutoSubmitStatus = exports.Round2BatchProofStatus = exports.Round1BatchProofStatus = exports.InputContextType = void 0; +exports.TaskMetadataValsProofSubmitMode = exports.TaskMetadataKeys = exports.ImageMetadataValsProvePaymentSrc = exports.ImageMetadataKeys = exports.AutoSubmitStatus = exports.FinalProofStatus = exports.Round2BatchProofStatus = exports.Round1BatchProofStatus = exports.InputContextType = void 0; var InputContextType; (function (InputContextType) { InputContextType["Custom"] = "Custom"; @@ -19,11 +19,17 @@ var Round2BatchProofStatus; Round2BatchProofStatus["Batched"] = "Batched"; Round2BatchProofStatus["Failed"] = "Failed"; })(Round2BatchProofStatus = exports.Round2BatchProofStatus || (exports.Round2BatchProofStatus = {})); +var FinalProofStatus; +(function (FinalProofStatus) { + FinalProofStatus["ProofNotRegistered"] = "ProofNotRegistered"; + FinalProofStatus["ProofRegistered"] = "ProofRegistered"; +})(FinalProofStatus = exports.FinalProofStatus || (exports.FinalProofStatus = {})); var AutoSubmitStatus; (function (AutoSubmitStatus) { AutoSubmitStatus["Round1"] = "Round1"; AutoSubmitStatus["Round2"] = "Round2"; - AutoSubmitStatus["Done"] = "Done"; + AutoSubmitStatus["Batched"] = "Batched"; + AutoSubmitStatus["RegisteredProof"] = "RegisteredProof"; AutoSubmitStatus["Failed"] = "Failed"; })(AutoSubmitStatus = exports.AutoSubmitStatus || (exports.AutoSubmitStatus = {})); var ImageMetadataKeys; @@ -38,8 +44,8 @@ var ImageMetadataValsProvePaymentSrc; var TaskMetadataKeys; (function (TaskMetadataKeys) { TaskMetadataKeys["ProofSubmitMode"] = "ProofSubmitMode"; - TaskMetadataKeys["Round1BatchProofId"] = "Round1BatchProofTaskId"; - TaskMetadataKeys["Round2BatchProofId"] = "Round2BatchProofTaskId"; + TaskMetadataKeys["Round1BatchProofId"] = "Round1BatchProofId"; + TaskMetadataKeys["Round2BatchProofId"] = "Round2BatchProofId"; TaskMetadataKeys["FinalBatchProofId"] = "FinalBatchProofId"; })(TaskMetadataKeys = exports.TaskMetadataKeys || (exports.TaskMetadataKeys = {})); var TaskMetadataValsProofSubmitMode; diff --git a/dist/mjs/helper/util.d.ts b/dist/mjs/helper/util.d.ts index 71cd68ac..8ef320a5 100644 --- a/dist/mjs/helper/util.d.ts +++ b/dist/mjs/helper/util.d.ts @@ -1,5 +1,5 @@ import BN from "bn.js"; -import { AddImageParams, ProvingParams, DeployParams, ResetImageParams, ModifyImageParams, VerifyProofParams, LogQuery, ContextHexString } from "../interface/interface.js"; +import { AddImageParams, ProvingParams, DeployParams, ResetImageParams, ModifyImageParams, VerifyProofParams, LogQuery, ContextHexString, VerifyBatchProofParams } from "../interface/interface.js"; import { Contract, Signer } from "ethers"; import { DelphinusWalletConnector, DelphinusBrowserConnector } from "web3subscriber/src/provider.js"; export declare class ZkWasmUtil { @@ -29,6 +29,43 @@ export declare class ZkWasmUtil { constant: boolean; })[]; }; + static batch_verifier_contract: { + contract_name: string; + abi: ({ + type: string; + inputs: { + internalType: string; + name: string; + type: string; + }[]; + name?: undefined; + outputs?: undefined; + stateMutability?: undefined; + anonymous?: undefined; + } | { + type: string; + name: string; + inputs: { + internalType: string; + name: string; + type: string; + }[]; + outputs: never[]; + stateMutability: string; + anonymous?: undefined; + } | { + type: string; + name: string; + inputs: { + name: string; + type: string; + indexed: boolean; + }[]; + anonymous: boolean; + outputs?: undefined; + stateMutability?: undefined; + })[]; + }; static hexToBNs(hexString: string): Array; static validateBytesInput(value: string): boolean; static validateI64HexInput(value: string): boolean; @@ -53,6 +90,8 @@ export declare class ZkWasmUtil { static bytesToBigIntArray(data: Uint8Array, chunksize?: number): BigInt[]; static composeVerifyContract(signer: DelphinusBrowserConnector | DelphinusWalletConnector, verifier_addr: string): import("web3subscriber/src/client.js").DelphinusContract | Promise; static verifyProof(verify_contract: Contract, params: VerifyProofParams): Promise; + static composeBatchVerifierContract(signer: DelphinusBrowserConnector | DelphinusWalletConnector, verifier_addr: string): import("web3subscriber/src/client.js").DelphinusContract | Promise; + static verifyBatchedProof(batch_verifier_contract: Contract, params: VerifyBatchProofParams): Promise; static signMessage(message: string, priv_key: string): Promise; static ERC20Contract(contractAddress: string, signer: Signer): Contract; static bytesToJSONString(data: Uint8Array): string; diff --git a/dist/mjs/helper/util.js b/dist/mjs/helper/util.js index 8eee8c1d..9e88c463 100644 --- a/dist/mjs/helper/util.js +++ b/dist/mjs/helper/util.js @@ -49,6 +49,82 @@ export class ZkWasmUtil { }, ], }; + static batch_verifier_contract = { + contract_name: "ProofTracker", + abi: [ + { + type: "constructor", + inputs: [ + { + internalType: "address", + name: "verifier_address", + type: "address", + }, + ], + }, + { + type: "function", + name: "check_verified_proof", + inputs: [ + { + internalType: "uint256[]", + name: "membership_proof_index", + type: "uint256[]", + }, + { + internalType: "uint256[]", + name: "verify_instance", + type: "uint256[]", + }, + { + internalType: "uint256[][]", + name: "sibling_instances", + type: "uint256[][]", + }, + { + internalType: "uint256[][]", + name: "target_instances", + type: "uint256[][]", + }, + ], + outputs: [], + stateMutability: "view", + }, + { + type: "function", + name: "register_proofs", + inputs: [ + { internalType: "uint256[]", name: "proof", type: "uint256[]" }, + { + internalType: "uint256[]", + name: "verify_instance", + type: "uint256[]", + }, + { internalType: "uint256[]", name: "aux", type: "uint256[]" }, + { + internalType: "uint256[][]", + name: "instances", + type: "uint256[][]", + }, + ], + outputs: [], + stateMutability: "nonpayable", + }, + { + type: "function", + name: "set_verifier", + inputs: [{ internalType: "address", name: "vaddr", type: "address" }], + outputs: [], + stateMutability: "nonpayable", + }, + { + type: "event", + name: "ProofAck", + inputs: [{ name: "hash", type: "uint256", indexed: false }], + anonymous: false, + }, + ], + }; static hexToBNs(hexString) { let bytes = new Array(Math.ceil(hexString.length / 16)); for (var i = 0; i < hexString.length; i += 16) { @@ -276,19 +352,36 @@ export class ZkWasmUtil { params.instances.forEach((instance) => { instances.push(this.bytesToBigIntArray(instance)); }); - // let instances = this.bytesToBigIntArray(params.instances); - // let args = ZkWasmUtil.parseArgs(params.instances).map((x) => - // x.toString(10) - // ); - // console.log("args are:", args); - // if (args.length == 0) { - // args = ["0x0"]; - // } - // // convert to BigInt array - // let bigIntArgs = args.map((x) => BigInt(x)); let result = await verify_contract.verify.send(aggregate_proof, shadow_instances, aux, instances); return result; } + static composeBatchVerifierContract(signer, verifier_addr) { + return signer.getContractWithSigner(verifier_addr, this.batch_verifier_contract.abi); + } + static async verifyBatchedProof(batch_verifier_contract, params) { + let membership_proof_index = params.membership_proof_index; + let verify_instance = this.bytesToBigIntArray(params.verify_instance); + let sibling_instances = []; + params.sibling_instances.forEach((instance) => { + // + sibling_instances.push(this.bytesToBigIntArray(instance)[0]); + }); + let target_instances = []; + params.target_instances.forEach((instance) => { + target_instances.push(this.bytesToBigIntArray(instance)); + }); + let round_1_shadow_instance = this.bytesToBigIntArray(params.round_1_shadow_instance); + // Add the round 1 shadow instance to the flattened sibling instances as this is the expected input format + // for the contract. (12 round 1 target instances + 1 round 1 shadow instance) + sibling_instances.push(round_1_shadow_instance[0]); + console.log("Verify Batch Proof Inputs"); + console.log("membership_proof_index: ", membership_proof_index); + console.log("verify_instance: ", verify_instance); + console.log("sibling_instances: ", [sibling_instances]); + console.log("target_instances: ", target_instances); + let result = await batch_verifier_contract.check_verified_proof.send(membership_proof_index, verify_instance, [sibling_instances], target_instances); + return result; + } static async signMessage(message, priv_key) { let wallet = new Wallet(priv_key, null); let signature = await wallet.signMessage(message); diff --git a/dist/mjs/index.d.ts b/dist/mjs/index.d.ts index 3ca3808d..692b9afd 100644 --- a/dist/mjs/index.d.ts +++ b/dist/mjs/index.d.ts @@ -1,6 +1,6 @@ -import { Task, ProvingParams, DeployParams, QueryParams, VerifyProofParams, VerifyData, StatusState, DeploymentInfo, Image, Statistics, AddImageParams, WithSignature, User, UserQueryParams, PaymentParams, SubscriptionParams, Subscription, SubscriptionType, SubscriptionRequest, TxHistoryQueryParams, TransactionInfo, TaskStatus, TaskType, AppConfig, PaginationResult, ResetImageParams, LogQuery, ModifyImageParams, ChainDetails, InputContextType, ContextHexString, WithCustomInputContextType, WithInitialContext, WithNonCustomInputContextType, WithResetContext, WithoutInitialContext, WithoutInputContextType, WithoutResetContext, ImageMetadataKeys, ImageMetadataValsProvePaymentSrc, TaskMetadataKeys, TaskMetadataValsProofSubmitMode, Round1BatchProof, Round2BatchProof, FinalBatchProof, Round1BatchProofStatus, Round2BatchProofStatus, Round1BatchProofQuery, Round2BatchProofQuery, FinalBatchProofQuery, PaginatedQuery, PaginationQuery, AutoSubmitStatus, TaskMetadata } from "./interface/interface.js"; +import { Task, ProvingParams, DeployParams, QueryParams, VerifyProofParams, VerifyData, StatusState, DeploymentInfo, Image, Statistics, AddImageParams, WithSignature, User, UserQueryParams, PaymentParams, SubscriptionParams, Subscription, SubscriptionType, SubscriptionRequest, TxHistoryQueryParams, TransactionInfo, TaskStatus, TaskType, AppConfig, PaginationResult, ResetImageParams, LogQuery, ModifyImageParams, ChainDetails, InputContextType, ContextHexString, WithCustomInputContextType, WithInitialContext, WithNonCustomInputContextType, WithResetContext, WithoutInitialContext, WithoutInputContextType, WithoutResetContext, ImageMetadataKeys, ImageMetadataValsProvePaymentSrc, TaskMetadataKeys, TaskMetadataValsProofSubmitMode, Round1BatchProof, Round2BatchProof, FinalBatchProof, Round1BatchProofStatus, Round2BatchProofStatus, Round1BatchProofQuery, Round2BatchProofQuery, FinalBatchProofQuery, PaginatedQuery, PaginationQuery, AutoSubmitStatus, TaskMetadata, VerifyBatchProofParams, FinalProofStatus } from "./interface/interface.js"; import { ZkWasmUtil } from "./helper/util.js"; import { ZkWasmServiceEndpoint } from "./helper/endpoint.js"; import { ZkWasmServiceHelper } from "./helper/task.js"; -export { ZkWasmServiceEndpoint, ZkWasmServiceHelper, ZkWasmUtil, InputContextType, ImageMetadataKeys, ImageMetadataValsProvePaymentSrc, TaskMetadataKeys, TaskMetadataValsProofSubmitMode, AutoSubmitStatus, }; -export type { Task, ProvingParams, DeployParams, QueryParams, VerifyProofParams, VerifyData, StatusState, DeploymentInfo, Image, Statistics, AddImageParams, TaskStatus, TaskType, WithSignature, User, UserQueryParams, Subscription, SubscriptionType, PaymentParams, SubscriptionParams, SubscriptionRequest, TxHistoryQueryParams, TransactionInfo, ResetImageParams, AppConfig, PaginationResult, LogQuery, ModifyImageParams, ChainDetails, ContextHexString, WithCustomInputContextType, WithInitialContext, WithNonCustomInputContextType, WithResetContext, WithoutInitialContext, WithoutInputContextType, WithoutResetContext, Round1BatchProof, Round2BatchProof, FinalBatchProof, Round1BatchProofStatus, Round2BatchProofStatus, Round1BatchProofQuery, Round2BatchProofQuery, FinalBatchProofQuery, PaginatedQuery, PaginationQuery, TaskMetadata, }; +export { ZkWasmServiceEndpoint, ZkWasmServiceHelper, ZkWasmUtil, InputContextType, ImageMetadataKeys, ImageMetadataValsProvePaymentSrc, TaskMetadataKeys, TaskMetadataValsProofSubmitMode, AutoSubmitStatus, Round1BatchProofStatus, Round2BatchProofStatus, FinalProofStatus, }; +export type { Task, ProvingParams, DeployParams, QueryParams, VerifyProofParams, VerifyData, StatusState, DeploymentInfo, Image, Statistics, AddImageParams, TaskStatus, TaskType, WithSignature, User, UserQueryParams, Subscription, SubscriptionType, PaymentParams, SubscriptionParams, SubscriptionRequest, TxHistoryQueryParams, TransactionInfo, ResetImageParams, AppConfig, PaginationResult, LogQuery, ModifyImageParams, ChainDetails, ContextHexString, WithCustomInputContextType, WithInitialContext, WithNonCustomInputContextType, WithResetContext, WithoutInitialContext, WithoutInputContextType, WithoutResetContext, Round1BatchProof, Round2BatchProof, FinalBatchProof, Round1BatchProofQuery, Round2BatchProofQuery, FinalBatchProofQuery, PaginatedQuery, PaginationQuery, TaskMetadata, VerifyBatchProofParams, }; diff --git a/dist/mjs/index.js b/dist/mjs/index.js index d0cbeb9d..afccec0e 100644 --- a/dist/mjs/index.js +++ b/dist/mjs/index.js @@ -1,5 +1,5 @@ -import { InputContextType, ImageMetadataKeys, ImageMetadataValsProvePaymentSrc, TaskMetadataKeys, TaskMetadataValsProofSubmitMode, AutoSubmitStatus, } from "./interface/interface.js"; +import { InputContextType, ImageMetadataKeys, ImageMetadataValsProvePaymentSrc, TaskMetadataKeys, TaskMetadataValsProofSubmitMode, Round1BatchProofStatus, Round2BatchProofStatus, AutoSubmitStatus, FinalProofStatus, } from "./interface/interface.js"; import { ZkWasmUtil } from "./helper/util.js"; import { ZkWasmServiceEndpoint } from "./helper/endpoint.js"; import { ZkWasmServiceHelper } from "./helper/task.js"; -export { ZkWasmServiceEndpoint, ZkWasmServiceHelper, ZkWasmUtil, InputContextType, ImageMetadataKeys, ImageMetadataValsProvePaymentSrc, TaskMetadataKeys, TaskMetadataValsProofSubmitMode, AutoSubmitStatus, }; +export { ZkWasmServiceEndpoint, ZkWasmServiceHelper, ZkWasmUtil, InputContextType, ImageMetadataKeys, ImageMetadataValsProvePaymentSrc, TaskMetadataKeys, TaskMetadataValsProofSubmitMode, AutoSubmitStatus, Round1BatchProofStatus, Round2BatchProofStatus, FinalProofStatus, }; diff --git a/dist/mjs/interface/interface.d.ts b/dist/mjs/interface/interface.d.ts index e86f5f52..7766ed85 100644 --- a/dist/mjs/interface/interface.d.ts +++ b/dist/mjs/interface/interface.d.ts @@ -95,6 +95,11 @@ export interface FinalBatchProof { internal_message?: string; static_files_verification_data: StaticFileVerificationData; verifier_contracts: VerifierContracts[]; + status: FinalProofStatus; +} +export declare enum FinalProofStatus { + ProofNotRegistered = "ProofNotRegistered", + ProofRegistered = "ProofRegistered" } export type PaginatedQuery = T & PaginationQuery; export interface Round1BatchProofQuery { @@ -113,6 +118,7 @@ export interface FinalBatchProofQuery { id?: string; round_2_id?: string; task_id?: string; + status?: FinalProofStatus; } export interface PaginationQuery { total?: number; @@ -125,6 +131,7 @@ export interface TaskVerificationData { export interface VerifierContracts { chain_id: number; aggregator_verifier: string; + batch_verifier: string; circuit_size: number; } export type TaskType = "Setup" | "Prove" | "Reset"; @@ -139,7 +146,8 @@ export type TaskStatus = "Pending" | "Processing" | "DryRunFailed" | "Done" | "F export declare enum AutoSubmitStatus { Round1 = "Round1", Round2 = "Round2", - Done = "Done", + Batched = "Batched", + RegisteredProof = "RegisteredProof", Failed = "Failed" } export type TaskMetadata = { @@ -178,8 +186,8 @@ export interface WithoutInitialContext { export type AddImageParams = BaseAddImageParams & (WithInitialContext | WithoutInitialContext); export declare enum TaskMetadataKeys { ProofSubmitMode = "ProofSubmitMode", - Round1BatchProofId = "Round1BatchProofTaskId", - Round2BatchProofId = "Round2BatchProofTaskId", + Round1BatchProofId = "Round1BatchProofId", + Round2BatchProofId = "Round2BatchProofId", FinalBatchProofId = "FinalBatchProofId" } export declare enum TaskMetadataValsProofSubmitMode { @@ -263,6 +271,13 @@ export interface VerifyProofParams { aux: Uint8Array; instances: Array; } +export interface VerifyBatchProofParams { + membership_proof_index: Array; + verify_instance: Uint8Array; + sibling_instances: Array; + round_1_shadow_instance: Uint8Array; + target_instances: Array; +} export interface LogQuery { id: string; user_address: string; @@ -294,6 +309,7 @@ export interface ContractDeployments { aggregator_config_address: string; aggregator_verifier_steps: string[]; aggregator_verifier: string; + batch_verifier: string; static_file_checksum: Uint8Array; } export interface ChainInfo { diff --git a/dist/mjs/interface/interface.js b/dist/mjs/interface/interface.js index d1d2dc3f..f981a028 100644 --- a/dist/mjs/interface/interface.js +++ b/dist/mjs/interface/interface.js @@ -16,11 +16,17 @@ export var Round2BatchProofStatus; Round2BatchProofStatus["Batched"] = "Batched"; Round2BatchProofStatus["Failed"] = "Failed"; })(Round2BatchProofStatus || (Round2BatchProofStatus = {})); +export var FinalProofStatus; +(function (FinalProofStatus) { + FinalProofStatus["ProofNotRegistered"] = "ProofNotRegistered"; + FinalProofStatus["ProofRegistered"] = "ProofRegistered"; +})(FinalProofStatus || (FinalProofStatus = {})); export var AutoSubmitStatus; (function (AutoSubmitStatus) { AutoSubmitStatus["Round1"] = "Round1"; AutoSubmitStatus["Round2"] = "Round2"; - AutoSubmitStatus["Done"] = "Done"; + AutoSubmitStatus["Batched"] = "Batched"; + AutoSubmitStatus["RegisteredProof"] = "RegisteredProof"; AutoSubmitStatus["Failed"] = "Failed"; })(AutoSubmitStatus || (AutoSubmitStatus = {})); export var ImageMetadataKeys; @@ -35,8 +41,8 @@ export var ImageMetadataValsProvePaymentSrc; export var TaskMetadataKeys; (function (TaskMetadataKeys) { TaskMetadataKeys["ProofSubmitMode"] = "ProofSubmitMode"; - TaskMetadataKeys["Round1BatchProofId"] = "Round1BatchProofTaskId"; - TaskMetadataKeys["Round2BatchProofId"] = "Round2BatchProofTaskId"; + TaskMetadataKeys["Round1BatchProofId"] = "Round1BatchProofId"; + TaskMetadataKeys["Round2BatchProofId"] = "Round2BatchProofId"; TaskMetadataKeys["FinalBatchProofId"] = "FinalBatchProofId"; })(TaskMetadataKeys || (TaskMetadataKeys = {})); export var TaskMetadataValsProofSubmitMode; diff --git a/src/helper/util.ts b/src/helper/util.ts index e7383833..b5d3bc6c 100644 --- a/src/helper/util.ts +++ b/src/helper/util.ts @@ -10,6 +10,7 @@ import { LogQuery, ContextHexString, InputContextType, + VerifyBatchProofParams, } from "../interface/interface.js"; import { Contract, formatUnits, Signer, Wallet } from "ethers"; import { @@ -65,6 +66,83 @@ export class ZkWasmUtil { ], }; + static batch_verifier_contract = { + contract_name: "ProofTracker", + abi: [ + { + type: "constructor", + inputs: [ + { + internalType: "address", + name: "verifier_address", + type: "address", + }, + ], + }, + { + type: "function", + name: "check_verified_proof", + inputs: [ + { + internalType: "uint256[]", + name: "membership_proof_index", + type: "uint256[]", + }, + { + internalType: "uint256[]", + name: "verify_instance", + type: "uint256[]", + }, + { + internalType: "uint256[][]", + name: "sibling_instances", + type: "uint256[][]", + }, + { + internalType: "uint256[][]", + name: "target_instances", + type: "uint256[][]", + }, + ], + outputs: [], + stateMutability: "view", + }, + { + type: "function", + name: "register_proofs", + inputs: [ + { internalType: "uint256[]", name: "proof", type: "uint256[]" }, + { + internalType: "uint256[]", + name: "verify_instance", + type: "uint256[]", + }, + { internalType: "uint256[]", name: "aux", type: "uint256[]" }, + { + internalType: "uint256[][]", + name: "instances", + type: "uint256[][]", + }, + ], + outputs: [], + stateMutability: "nonpayable", + }, + { + type: "function", + name: "set_verifier", + inputs: [{ internalType: "address", name: "vaddr", type: "address" }], + outputs: [], + stateMutability: "nonpayable", + }, + { + type: "event", + name: "ProofAck", + inputs: [{ name: "hash", type: "uint256", indexed: false }], + anonymous: false, + }, + ], + }; + static hexToBNs(hexString: string): Array { let bytes = new Array(Math.ceil(hexString.length / 16)); for (var i = 0; i < hexString.length; i += 16) { @@ -344,16 +422,6 @@ export class ZkWasmUtil { params.instances.forEach((instance) => { instances.push(this.bytesToBigIntArray(instance)); }); - // let instances = this.bytesToBigIntArray(params.instances); - // let args = ZkWasmUtil.parseArgs(params.instances).map((x) => - // x.toString(10) - // ); - // console.log("args are:", args); - // if (args.length == 0) { - // args = ["0x0"]; - // } - // // convert to BigInt array - // let bigIntArgs = args.map((x) => BigInt(x)); let result = await verify_contract.verify.send( aggregate_proof, @@ -364,6 +432,58 @@ export class ZkWasmUtil { return result; } + static composeBatchVerifierContract( + signer: DelphinusBrowserConnector | DelphinusWalletConnector, + verifier_addr: string + ) { + return signer.getContractWithSigner( + verifier_addr, + this.batch_verifier_contract.abi + ); + } + + static async verifyBatchedProof( + batch_verifier_contract: Contract, + params: VerifyBatchProofParams + ) { + let membership_proof_index = params.membership_proof_index; + let verify_instance = this.bytesToBigIntArray(params.verify_instance); + + let sibling_instances: Array = []; + + params.sibling_instances.forEach((instance) => { + // + sibling_instances.push(this.bytesToBigIntArray(instance)[0]); + }); + + let target_instances: Array = []; + params.target_instances.forEach((instance) => { + target_instances.push(this.bytesToBigIntArray(instance)); + }); + + let round_1_shadow_instance = this.bytesToBigIntArray( + params.round_1_shadow_instance + ); + + // Add the round 1 shadow instance to the flattened sibling instances as this is the expected input format + // for the contract. (12 round 1 target instances + 1 round 1 shadow instance) + sibling_instances.push(round_1_shadow_instance[0]); + + console.log("Verify Batch Proof Inputs"); + console.log("membership_proof_index: ", membership_proof_index); + console.log("verify_instance: ", verify_instance); + console.log("sibling_instances: ", [sibling_instances]); + console.log("target_instances: ", target_instances); + + let result = await batch_verifier_contract.check_verified_proof.send( + membership_proof_index, + verify_instance, + [sibling_instances], + target_instances + ); + return result; + } + static async signMessage(message: string, priv_key: string) { let wallet = new Wallet(priv_key, null); let signature = await wallet.signMessage(message); diff --git a/src/index.ts b/src/index.ts index 0cff0d02..5513e6e4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -54,6 +54,8 @@ import { PaginationQuery, AutoSubmitStatus, TaskMetadata, + VerifyBatchProofParams, + FinalProofStatus, } from "./interface/interface.js"; import { ZkWasmUtil } from "./helper/util.js"; @@ -70,6 +72,9 @@ export { TaskMetadataKeys, TaskMetadataValsProofSubmitMode, AutoSubmitStatus, + Round1BatchProofStatus, + Round2BatchProofStatus, + FinalProofStatus, }; export type { @@ -113,12 +118,11 @@ export type { Round1BatchProof, Round2BatchProof, FinalBatchProof, - Round1BatchProofStatus, - Round2BatchProofStatus, Round1BatchProofQuery, Round2BatchProofQuery, FinalBatchProofQuery, PaginatedQuery, PaginationQuery, TaskMetadata, + VerifyBatchProofParams, }; diff --git a/src/interface/interface.ts b/src/interface/interface.ts index 1ac545d0..39e44832 100644 --- a/src/interface/interface.ts +++ b/src/interface/interface.ts @@ -121,6 +121,12 @@ export interface FinalBatchProof { internal_message?: string; static_files_verification_data: StaticFileVerificationData; verifier_contracts: VerifierContracts[]; + status: FinalProofStatus; +} + +export enum FinalProofStatus { + ProofNotRegistered = "ProofNotRegistered", + ProofRegistered = "ProofRegistered", } export type PaginatedQuery = T & PaginationQuery; @@ -143,6 +149,7 @@ export interface FinalBatchProofQuery { id?: string; round_2_id?: string; task_id?: string; + status?: FinalProofStatus; } export interface PaginationQuery { @@ -158,6 +165,7 @@ export interface TaskVerificationData { export interface VerifierContracts { chain_id: number; aggregator_verifier: string; + batch_verifier: string; circuit_size: number; } @@ -182,7 +190,8 @@ export type TaskStatus = export enum AutoSubmitStatus { Round1 = "Round1", Round2 = "Round2", - Done = "Done", + Batched = "Batched", + RegisteredProof = "RegisteredProof", Failed = "Failed", } @@ -231,8 +240,8 @@ export type AddImageParams = BaseAddImageParams & export enum TaskMetadataKeys { ProofSubmitMode = "ProofSubmitMode", - Round1BatchProofId = "Round1BatchProofTaskId", - Round2BatchProofId = "Round2BatchProofTaskId", + Round1BatchProofId = "Round1BatchProofId", + Round2BatchProofId = "Round2BatchProofId", FinalBatchProofId = "FinalBatchProofId", } @@ -331,11 +340,22 @@ export interface QueryParams { export interface VerifyProofParams { aggregate_proof: Uint8Array; shadow_instances: Uint8Array; - aux: Uint8Array; instances: Array; } +export interface VerifyBatchProofParams { + // Should be of length 1 + membership_proof_index: Array; + // Shadow instance of the aggregate proof + verify_instance: Uint8Array; + // Array of length 12, where the entries are (round 1 target instances) + sibling_instances: Array; + round_1_shadow_instance: Uint8Array; + // Single proof instance (base wasm image proof) + target_instances: Array; +} + export interface LogQuery { id: string; user_address: string; @@ -370,6 +390,7 @@ export interface ContractDeployments { aggregator_config_address: string; aggregator_verifier_steps: string[]; aggregator_verifier: string; + batch_verifier: string; static_file_checksum: Uint8Array; } // returned from zkwasm service server