Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion dist/cjs/helper/util.d.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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<BN>;
static validateBytesInput(value: string): boolean;
static validateI64HexInput(value: string): boolean;
Expand All @@ -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<import("web3subscriber/src/client.js").DelphinusContract>;
static verifyProof(verify_contract: Contract, params: VerifyProofParams): Promise<import("ethers").ContractTransactionResponse>;
static composeBatchVerifierContract(signer: DelphinusBrowserConnector | DelphinusWalletConnector, verifier_addr: string): import("web3subscriber/src/client.js").DelphinusContract | Promise<import("web3subscriber/src/client.js").DelphinusContract>;
static verifyBatchedProof(batch_verifier_contract: Contract, params: VerifyBatchProofParams): Promise<import("ethers").ContractTransactionResponse>;
static signMessage(message: string, priv_key: string): Promise<string>;
static ERC20Contract(contractAddress: string, signer: Signer): Contract;
static bytesToJSONString(data: Uint8Array): string;
Expand Down
115 changes: 105 additions & 10 deletions dist/cjs/helper/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
6 changes: 3 additions & 3 deletions dist/cjs/index.d.ts
Original file line number Diff line number Diff line change
@@ -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, };
5 changes: 4 additions & 1 deletion dist/cjs/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 19 additions & 3 deletions dist/cjs/interface/interface.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> = T & PaginationQuery;
export interface Round1BatchProofQuery {
Expand All @@ -113,6 +118,7 @@ export interface FinalBatchProofQuery {
id?: string;
round_2_id?: string;
task_id?: string;
status?: FinalProofStatus;
}
export interface PaginationQuery {
total?: number;
Expand All @@ -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";
Expand All @@ -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 = {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -263,6 +271,13 @@ export interface VerifyProofParams {
aux: Uint8Array;
instances: Array<Uint8Array>;
}
export interface VerifyBatchProofParams {
membership_proof_index: Array<BigInt>;
verify_instance: Uint8Array;
sibling_instances: Array<Uint8Array>;
round_1_shadow_instance: Uint8Array;
target_instances: Array<Uint8Array>;
}
export interface LogQuery {
id: string;
user_address: string;
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 10 additions & 4 deletions dist/cjs/interface/interface.js
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Loading