@matterlabs/ethproofs-airbender-verifier 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -6
- package/dist/index.d.ts +19 -10
- package/dist/index.js +28 -13
- package/package.json +1 -1
- package/wasm/pkg/package.json +1 -1
- package/wasm/pkg/proof_verifier_wasm.d.ts +18 -9
- package/wasm/pkg/proof_verifier_wasm.js +70 -32
- package/wasm/pkg/proof_verifier_wasm_bg.wasm +0 -0
- package/wasm/pkg/proof_verifier_wasm_bg.wasm.d.ts +4 -3
package/README.md
CHANGED
|
@@ -14,8 +14,9 @@ yarn add @matterlabs/ethproofs-airbender-verifier
|
|
|
14
14
|
```ts
|
|
15
15
|
import { createVerifier } from "@matterlabs/ethproofs-airbender-verifier";
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
const verifier = await createVerifier({
|
|
18
|
+
verificationKey
|
|
19
|
+
});
|
|
19
20
|
|
|
20
21
|
// Deserialize the submitted proof (without `base64` encoding; e.g. format that is used on EthProofs to store proofs)
|
|
21
22
|
const handle = verifier.deserializeProofBytes(proofBytes);
|
|
@@ -27,9 +28,29 @@ if (!result.success) {
|
|
|
27
28
|
}
|
|
28
29
|
```
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
`createVerifier()` requires explicit verification keys.
|
|
32
|
+
`verifyProof(handle)` requires the proof security level to match the supplied
|
|
33
|
+
verification key. Legacy proof payloads do not carry that metadata, so they are
|
|
34
|
+
verified as 80-bit proofs.
|
|
35
|
+
|
|
36
|
+
## Verification keys
|
|
37
|
+
|
|
38
|
+
Use single-file verification keys for new integrations:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { createVerifier } from "proof-verifier-js";
|
|
42
|
+
|
|
43
|
+
const verifier = await createVerifier({
|
|
44
|
+
verificationKey
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The key must match the proof’s circuit version and security level.
|
|
49
|
+
|
|
50
|
+
## Legacy setup/layout
|
|
31
51
|
|
|
32
|
-
Use this when you need to verify
|
|
52
|
+
Use this only when you need to verify with existing 80-bit split setup/layout
|
|
53
|
+
artifacts.
|
|
33
54
|
|
|
34
55
|
```ts
|
|
35
56
|
import { createVerifier } from "proof-verifier-js";
|
|
@@ -40,8 +61,8 @@ const verifier = await createVerifier({
|
|
|
40
61
|
});
|
|
41
62
|
```
|
|
42
63
|
|
|
43
|
-
`setupBin`
|
|
44
|
-
|
|
64
|
+
The legacy `setupBin` / `layoutBin` pair initializes 80-bit verification only.
|
|
65
|
+
Use the single-file VK format for 100-bit verification.
|
|
45
66
|
|
|
46
67
|
## License
|
|
47
68
|
|
package/dist/index.d.ts
CHANGED
|
@@ -13,18 +13,27 @@ type VerificationResult = {
|
|
|
13
13
|
/** Error details reported by the verifier, or null on success. */
|
|
14
14
|
error: string | null;
|
|
15
15
|
};
|
|
16
|
+
type VerificationKey = Uint8Array;
|
|
17
|
+
type SingleFileVerifierOptions = {
|
|
18
|
+
/** Single-file verification key. Its embedded security level must match verified proofs. */
|
|
19
|
+
verificationKey: VerificationKey;
|
|
20
|
+
setupBin?: never;
|
|
21
|
+
layoutBin?: never;
|
|
22
|
+
};
|
|
23
|
+
type LegacySingleVerifierOptions = {
|
|
24
|
+
/** Legacy 80-bit setup data for existing split-key deployments. */
|
|
25
|
+
setupBin: Uint8Array;
|
|
26
|
+
/** Legacy 80-bit layout data for existing split-key deployments. */
|
|
27
|
+
layoutBin: Uint8Array;
|
|
28
|
+
verificationKey?: never;
|
|
29
|
+
};
|
|
16
30
|
/**
|
|
17
|
-
*
|
|
31
|
+
* Verifier configuration with explicit verification keys.
|
|
18
32
|
*
|
|
19
33
|
* These correspond to the precomputed verifier artifacts used by the
|
|
20
34
|
* Ethereum STF ZK proof system and must match the proof's circuit version.
|
|
21
35
|
*/
|
|
22
|
-
type VerifierOptions =
|
|
23
|
-
/** Binary setup data that defines the verifier's cryptographic setup. */
|
|
24
|
-
setupBin: Uint8Array;
|
|
25
|
-
/** Binary layout data that defines circuit layout metadata. */
|
|
26
|
-
layoutBin: Uint8Array;
|
|
27
|
-
};
|
|
36
|
+
type VerifierOptions = SingleFileVerifierOptions | LegacySingleVerifierOptions;
|
|
28
37
|
/**
|
|
29
38
|
* Verifier API for Ethereum STF ZK proofs submitted to EthProofs.
|
|
30
39
|
*/
|
|
@@ -47,9 +56,9 @@ type Verifier = {
|
|
|
47
56
|
/**
|
|
48
57
|
* Initializes the WASM dependency and creates a Verifier instance.
|
|
49
58
|
*
|
|
50
|
-
* @param options
|
|
59
|
+
* @param options Verifier configuration with an explicit key or legacy artifacts.
|
|
51
60
|
* @returns A Promise that resolves to a Verifier instance.
|
|
52
61
|
*/
|
|
53
|
-
declare function createVerifier(options
|
|
62
|
+
declare function createVerifier(options: VerifierOptions): Promise<Verifier>;
|
|
54
63
|
|
|
55
|
-
export { type ProofHandle, type VerificationResult, type Verifier, type VerifierOptions, createVerifier };
|
|
64
|
+
export { type ProofHandle, type VerificationKey, type VerificationResult, type Verifier, type VerifierOptions, createVerifier };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import init, {
|
|
3
3
|
deserialize_proof_bytes,
|
|
4
|
-
|
|
5
|
-
init_with,
|
|
6
|
-
verify_proof
|
|
4
|
+
WasmVerifier
|
|
7
5
|
} from "../wasm/pkg/proof_verifier_wasm";
|
|
8
6
|
var initPromise = null;
|
|
9
7
|
function ensureInit() {
|
|
@@ -12,26 +10,43 @@ function ensureInit() {
|
|
|
12
10
|
}
|
|
13
11
|
return initPromise;
|
|
14
12
|
}
|
|
13
|
+
function resultFromWasm(result) {
|
|
14
|
+
const typed = result;
|
|
15
|
+
return {
|
|
16
|
+
success: typed.success,
|
|
17
|
+
error: typed.error()
|
|
18
|
+
};
|
|
19
|
+
}
|
|
15
20
|
var VerifierImpl = class {
|
|
21
|
+
constructor(inner) {
|
|
22
|
+
this.inner = inner;
|
|
23
|
+
}
|
|
16
24
|
deserializeProofBytes(proofBytes) {
|
|
17
25
|
return deserialize_proof_bytes(proofBytes);
|
|
18
26
|
}
|
|
19
27
|
verifyProof(handle) {
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
success: result.success,
|
|
23
|
-
error: result.error()
|
|
24
|
-
};
|
|
28
|
+
return resultFromWasm(this.inner.verifyProof(handle));
|
|
25
29
|
}
|
|
26
30
|
};
|
|
31
|
+
function createWasmVerifier(options) {
|
|
32
|
+
if (options.verificationKey) {
|
|
33
|
+
return WasmVerifier.fromKey(options.verificationKey);
|
|
34
|
+
}
|
|
35
|
+
if (options.setupBin && options.layoutBin) {
|
|
36
|
+
return WasmVerifier.fromLegacyKey(options.setupBin, options.layoutBin);
|
|
37
|
+
}
|
|
38
|
+
throw new Error(
|
|
39
|
+
"verifier options must include a verification key or legacy setup/layout artifacts"
|
|
40
|
+
);
|
|
41
|
+
}
|
|
27
42
|
async function createVerifier(options) {
|
|
28
43
|
await ensureInit();
|
|
29
|
-
if (options) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
44
|
+
if (!options) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
"verifier options must include a verification key or legacy setup/layout artifacts"
|
|
47
|
+
);
|
|
33
48
|
}
|
|
34
|
-
return new VerifierImpl();
|
|
49
|
+
return new VerifierImpl(createWasmVerifier(options));
|
|
35
50
|
}
|
|
36
51
|
export {
|
|
37
52
|
createVerifier
|
package/package.json
CHANGED
package/wasm/pkg/package.json
CHANGED
|
@@ -7,6 +7,11 @@ export class ProofHandle {
|
|
|
7
7
|
[Symbol.dispose](): void;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
export enum SecurityLevel {
|
|
11
|
+
Security80 = 0,
|
|
12
|
+
Security100 = 1,
|
|
13
|
+
}
|
|
14
|
+
|
|
10
15
|
export class VerifyResult {
|
|
11
16
|
private constructor();
|
|
12
17
|
free(): void;
|
|
@@ -15,13 +20,16 @@ export class VerifyResult {
|
|
|
15
20
|
readonly success: boolean;
|
|
16
21
|
}
|
|
17
22
|
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
export class WasmVerifier {
|
|
24
|
+
private constructor();
|
|
25
|
+
free(): void;
|
|
26
|
+
[Symbol.dispose](): void;
|
|
27
|
+
static fromKey(vk_bin: Uint8Array): WasmVerifier;
|
|
28
|
+
static fromLegacyKey(setup_bin: Uint8Array, layout_bin: Uint8Array): WasmVerifier;
|
|
29
|
+
verifyProof(handle: ProofHandle): VerifyResult;
|
|
30
|
+
}
|
|
23
31
|
|
|
24
|
-
export function
|
|
32
|
+
export function deserialize_proof_bytes(proof_bytes: Uint8Array): ProofHandle;
|
|
25
33
|
|
|
26
34
|
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
27
35
|
|
|
@@ -29,12 +37,13 @@ export interface InitOutput {
|
|
|
29
37
|
readonly memory: WebAssembly.Memory;
|
|
30
38
|
readonly __wbg_proofhandle_free: (a: number, b: number) => void;
|
|
31
39
|
readonly __wbg_verifyresult_free: (a: number, b: number) => void;
|
|
40
|
+
readonly __wbg_wasmverifier_free: (a: number, b: number) => void;
|
|
32
41
|
readonly deserialize_proof_bytes: (a: number, b: number) => [number, number, number];
|
|
33
|
-
readonly init_defaults: () => [number, number];
|
|
34
|
-
readonly init_with: (a: number, b: number, c: number, d: number) => [number, number];
|
|
35
|
-
readonly verify_proof: (a: number) => number;
|
|
36
42
|
readonly verifyresult_error: (a: number) => any;
|
|
37
43
|
readonly verifyresult_success: (a: number) => number;
|
|
44
|
+
readonly wasmverifier_fromKey: (a: number, b: number) => [number, number, number];
|
|
45
|
+
readonly wasmverifier_fromLegacyKey: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
46
|
+
readonly wasmverifier_verifyProof: (a: number, b: number) => number;
|
|
38
47
|
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
39
48
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
40
49
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
@@ -21,6 +21,14 @@ export class ProofHandle {
|
|
|
21
21
|
}
|
|
22
22
|
if (Symbol.dispose) ProofHandle.prototype[Symbol.dispose] = ProofHandle.prototype.free;
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* @enum {0 | 1}
|
|
26
|
+
*/
|
|
27
|
+
export const SecurityLevel = Object.freeze({
|
|
28
|
+
Security80: 0, "0": "Security80",
|
|
29
|
+
Security100: 1, "1": "Security100",
|
|
30
|
+
});
|
|
31
|
+
|
|
24
32
|
export class VerifyResult {
|
|
25
33
|
static __wrap(ptr) {
|
|
26
34
|
ptr = ptr >>> 0;
|
|
@@ -56,6 +64,65 @@ export class VerifyResult {
|
|
|
56
64
|
}
|
|
57
65
|
if (Symbol.dispose) VerifyResult.prototype[Symbol.dispose] = VerifyResult.prototype.free;
|
|
58
66
|
|
|
67
|
+
export class WasmVerifier {
|
|
68
|
+
static __wrap(ptr) {
|
|
69
|
+
ptr = ptr >>> 0;
|
|
70
|
+
const obj = Object.create(WasmVerifier.prototype);
|
|
71
|
+
obj.__wbg_ptr = ptr;
|
|
72
|
+
WasmVerifierFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
73
|
+
return obj;
|
|
74
|
+
}
|
|
75
|
+
__destroy_into_raw() {
|
|
76
|
+
const ptr = this.__wbg_ptr;
|
|
77
|
+
this.__wbg_ptr = 0;
|
|
78
|
+
WasmVerifierFinalization.unregister(this);
|
|
79
|
+
return ptr;
|
|
80
|
+
}
|
|
81
|
+
free() {
|
|
82
|
+
const ptr = this.__destroy_into_raw();
|
|
83
|
+
wasm.__wbg_wasmverifier_free(ptr, 0);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* @param {Uint8Array} vk_bin
|
|
87
|
+
* @returns {WasmVerifier}
|
|
88
|
+
*/
|
|
89
|
+
static fromKey(vk_bin) {
|
|
90
|
+
const ptr0 = passArray8ToWasm0(vk_bin, wasm.__wbindgen_malloc);
|
|
91
|
+
const len0 = WASM_VECTOR_LEN;
|
|
92
|
+
const ret = wasm.wasmverifier_fromKey(ptr0, len0);
|
|
93
|
+
if (ret[2]) {
|
|
94
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
95
|
+
}
|
|
96
|
+
return WasmVerifier.__wrap(ret[0]);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* @param {Uint8Array} setup_bin
|
|
100
|
+
* @param {Uint8Array} layout_bin
|
|
101
|
+
* @returns {WasmVerifier}
|
|
102
|
+
*/
|
|
103
|
+
static fromLegacyKey(setup_bin, layout_bin) {
|
|
104
|
+
const ptr0 = passArray8ToWasm0(setup_bin, wasm.__wbindgen_malloc);
|
|
105
|
+
const len0 = WASM_VECTOR_LEN;
|
|
106
|
+
const ptr1 = passArray8ToWasm0(layout_bin, wasm.__wbindgen_malloc);
|
|
107
|
+
const len1 = WASM_VECTOR_LEN;
|
|
108
|
+
const ret = wasm.wasmverifier_fromLegacyKey(ptr0, len0, ptr1, len1);
|
|
109
|
+
if (ret[2]) {
|
|
110
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
111
|
+
}
|
|
112
|
+
return WasmVerifier.__wrap(ret[0]);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* @param {ProofHandle} handle
|
|
116
|
+
* @returns {VerifyResult}
|
|
117
|
+
*/
|
|
118
|
+
verifyProof(handle) {
|
|
119
|
+
_assertClass(handle, ProofHandle);
|
|
120
|
+
const ret = wasm.wasmverifier_verifyProof(this.__wbg_ptr, handle.__wbg_ptr);
|
|
121
|
+
return VerifyResult.__wrap(ret);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (Symbol.dispose) WasmVerifier.prototype[Symbol.dispose] = WasmVerifier.prototype.free;
|
|
125
|
+
|
|
59
126
|
/**
|
|
60
127
|
* @param {Uint8Array} proof_bytes
|
|
61
128
|
* @returns {ProofHandle}
|
|
@@ -70,38 +137,6 @@ export function deserialize_proof_bytes(proof_bytes) {
|
|
|
70
137
|
return ProofHandle.__wrap(ret[0]);
|
|
71
138
|
}
|
|
72
139
|
|
|
73
|
-
export function init_defaults() {
|
|
74
|
-
const ret = wasm.init_defaults();
|
|
75
|
-
if (ret[1]) {
|
|
76
|
-
throw takeFromExternrefTable0(ret[0]);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* @param {Uint8Array} setup_bin
|
|
82
|
-
* @param {Uint8Array} layout_bin
|
|
83
|
-
*/
|
|
84
|
-
export function init_with(setup_bin, layout_bin) {
|
|
85
|
-
const ptr0 = passArray8ToWasm0(setup_bin, wasm.__wbindgen_malloc);
|
|
86
|
-
const len0 = WASM_VECTOR_LEN;
|
|
87
|
-
const ptr1 = passArray8ToWasm0(layout_bin, wasm.__wbindgen_malloc);
|
|
88
|
-
const len1 = WASM_VECTOR_LEN;
|
|
89
|
-
const ret = wasm.init_with(ptr0, len0, ptr1, len1);
|
|
90
|
-
if (ret[1]) {
|
|
91
|
-
throw takeFromExternrefTable0(ret[0]);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* @param {ProofHandle} handle
|
|
97
|
-
* @returns {VerifyResult}
|
|
98
|
-
*/
|
|
99
|
-
export function verify_proof(handle) {
|
|
100
|
-
_assertClass(handle, ProofHandle);
|
|
101
|
-
const ret = wasm.verify_proof(handle.__wbg_ptr);
|
|
102
|
-
return VerifyResult.__wrap(ret);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
140
|
function __wbg_get_imports() {
|
|
106
141
|
const import0 = {
|
|
107
142
|
__proto__: null,
|
|
@@ -157,6 +192,9 @@ const ProofHandleFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
|
157
192
|
const VerifyResultFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
158
193
|
? { register: () => {}, unregister: () => {} }
|
|
159
194
|
: new FinalizationRegistry(ptr => wasm.__wbg_verifyresult_free(ptr >>> 0, 1));
|
|
195
|
+
const WasmVerifierFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
196
|
+
? { register: () => {}, unregister: () => {} }
|
|
197
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmverifier_free(ptr >>> 0, 1));
|
|
160
198
|
|
|
161
199
|
function _assertClass(instance, klass) {
|
|
162
200
|
if (!(instance instanceof klass)) {
|
|
Binary file
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
4
|
export const __wbg_proofhandle_free: (a: number, b: number) => void;
|
|
5
5
|
export const __wbg_verifyresult_free: (a: number, b: number) => void;
|
|
6
|
+
export const __wbg_wasmverifier_free: (a: number, b: number) => void;
|
|
6
7
|
export const deserialize_proof_bytes: (a: number, b: number) => [number, number, number];
|
|
7
|
-
export const init_defaults: () => [number, number];
|
|
8
|
-
export const init_with: (a: number, b: number, c: number, d: number) => [number, number];
|
|
9
|
-
export const verify_proof: (a: number) => number;
|
|
10
8
|
export const verifyresult_error: (a: number) => any;
|
|
11
9
|
export const verifyresult_success: (a: number) => number;
|
|
10
|
+
export const wasmverifier_fromKey: (a: number, b: number) => [number, number, number];
|
|
11
|
+
export const wasmverifier_fromLegacyKey: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
12
|
+
export const wasmverifier_verifyProof: (a: number, b: number) => number;
|
|
12
13
|
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
13
14
|
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
14
15
|
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|