@succinctlabs/sp1-wasm-verifier 5.0.3 → 5.0.5

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 ADDED
@@ -0,0 +1,19 @@
1
+ # SP1 Wasm verification
2
+
3
+ This repo wraps the [`sp1-verifier`](https://github.com/succinctlabs/sp1) crate in Wasm bindings, and invoke it from JavaScript (Node.js).
4
+
5
+ ## Usage
6
+
7
+ Install the node module with the following command:
8
+
9
+ ```bash
10
+ npm install sp1-wasm-verifier
11
+ ```
12
+
13
+ `sp1-wasm-verifier` declare the following functions:
14
+
15
+ ```js
16
+ function verify_groth16(proof: Uint8Array, public_inputs: Uint8Array, sp1_vk_hash: string): boolean;
17
+ function verify_plonk(proof: Uint8Array, public_inputs: Uint8Array, sp1_vk_hash: string): boolean
18
+ function verify_compressed(proof: Uint8Array, public_inputs: Uint8Array, sp1_vk_hash: Uint8Array): boolean;
19
+ ```
package/package.json CHANGED
@@ -1,38 +1,33 @@
1
1
  {
2
2
  "name": "@succinctlabs/sp1-wasm-verifier",
3
- "version": "5.0.3",
4
- "description": "A rust verifier for BN254 curve",
5
- "main": "./sp1_wasm_verifier.js",
6
- "module": "./sp1_wasm_verifier.js",
7
- "types": "./sp1_wasm_verifier.d.ts",
8
3
  "type": "module",
9
- "react-native": "./sp1_wasm_verifier.rn.js",
10
- "sideEffects": false,
11
- "author": "Bhargav Annem, Yuwen Zhang",
12
- "license": "MIT OR Apache-2.0",
4
+ "collaborators": [
5
+ "Bhargav Annem, Yuwen Zhang"
6
+ ],
7
+ "description": "A rust verifier for BN254 curve",
8
+ "version": "5.0.5",
9
+ "license": "MIT/Apache-2.0",
13
10
  "repository": {
14
11
  "type": "git",
15
- "url": "git+https://github.com/succinctlabs/example-sp1-wasm-verifier"
16
- },
17
- "bugs": {
18
- "url": "https://github.com/succinctlabs/example-sp1-wasm-verifier/issues"
12
+ "url": "https://github.com/succinctlabs/example-sp1-wasm-verifier"
19
13
  },
20
- "homepage": "https://github.com/succinctlabs/example-sp1-wasm-verifier#readme",
21
- "readme": "README.md",
14
+ "files": [
15
+ "sp1_wasm_verifier_bg.wasm",
16
+ "sp1_wasm_verifier.js",
17
+ "sp1_wasm_verifier_bg.js",
18
+ "sp1_wasm_verifier.d.ts"
19
+ ],
20
+ "main": "sp1_wasm_verifier.js",
21
+ "types": "sp1_wasm_verifier.d.ts",
22
+ "sideEffects": [
23
+ "./sp1_wasm_verifier.js",
24
+ "./snippets/*"
25
+ ],
22
26
  "keywords": [
23
27
  "zero-knowledge",
24
28
  "cryptography",
25
29
  "zkSNARK",
26
30
  "SNARK",
27
- "gnark",
28
- "bn254",
29
- "verifier",
30
- "wasm"
31
- ],
32
- "files": [
33
- "sp1_wasm_verifier.js",
34
- "sp1_wasm_verifier.rn.js",
35
- "sp1_wasm_verifier_bg.wasm",
36
- "sp1_wasm_verifier.d.ts"
31
+ "gnark"
37
32
  ]
38
33
  }
@@ -1,23 +1,20 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
-
4
- /**
5
- * Wrapper around [`sp1_verifier::CompressedVerifier::verify_sp1_proof`].
6
- *
7
- * We hardcode the Plonk VK bytes to only verify SP1 proofs.
8
- */
9
- export function verify_compressed(proof: Uint8Array, public_inputs: Uint8Array, sp1_vk_hash: Uint8Array): boolean;
10
-
11
3
  /**
12
4
  * Wrapper around [`sp1_verifier::Groth16Verifier::verify`].
13
5
  *
14
6
  * We hardcode the Groth16 VK bytes to only verify SP1 proofs.
15
7
  */
16
8
  export function verify_groth16(proof: Uint8Array, public_inputs: Uint8Array, sp1_vk_hash: string): boolean;
17
-
18
9
  /**
19
10
  * Wrapper around [`sp1_verifier::PlonkVerifier::verify`].
20
11
  *
21
12
  * We hardcode the Plonk VK bytes to only verify SP1 proofs.
22
13
  */
23
14
  export function verify_plonk(proof: Uint8Array, public_inputs: Uint8Array, sp1_vk_hash: string): boolean;
15
+ /**
16
+ * Wrapper around [`sp1_verifier::CompressedVerifier::verify_sp1_proof`].
17
+ *
18
+ * We hardcode the Plonk VK bytes to only verify SP1 proofs.
19
+ */
20
+ export function verify_compressed(proof: Uint8Array, public_inputs: Uint8Array, sp1_vk_hash: Uint8Array): boolean;
@@ -1,16 +1,5 @@
1
-
2
- let imports = {};
3
- import * as import0 from './sp1_wasm_verifier_bg.js';
4
- imports['./sp1_wasm_verifier_bg.js'] = import0;
5
-
6
- import { readFileSync } from 'node:fs';
7
-
8
- const wasmUrl = new URL('sp1_wasm_verifier_bg.wasm', import.meta.url);
9
- const wasmBytes = readFileSync(wasmUrl);
10
- const wasmModule = new WebAssembly.Module(wasmBytes);
11
- const wasm = new WebAssembly.Instance(wasmModule, imports).exports;
12
- export { wasm as __wasm };
13
- imports["./sp1_wasm_verifier_bg.js"].__wbg_set_wasm(wasm, wasmModule);
1
+ import * as wasm from "./sp1_wasm_verifier_bg.wasm";
2
+ export * from "./sp1_wasm_verifier_bg.js";
3
+ import { __wbg_set_wasm } from "./sp1_wasm_verifier_bg.js";
4
+ __wbg_set_wasm(wasm);
14
5
  wasm.__wbindgen_start();
15
-
16
- export * from "./sp1_wasm_verifier_bg.js";
@@ -0,0 +1,181 @@
1
+ let wasm;
2
+ export function __wbg_set_wasm(val) {
3
+ wasm = val;
4
+ }
5
+
6
+
7
+ let cachedUint8ArrayMemory0 = null;
8
+
9
+ function getUint8ArrayMemory0() {
10
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
11
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
12
+ }
13
+ return cachedUint8ArrayMemory0;
14
+ }
15
+
16
+ const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
17
+
18
+ let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
19
+
20
+ cachedTextDecoder.decode();
21
+
22
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
23
+ let numBytesDecoded = 0;
24
+ function decodeText(ptr, len) {
25
+ numBytesDecoded += len;
26
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
27
+ cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
28
+ cachedTextDecoder.decode();
29
+ numBytesDecoded = len;
30
+ }
31
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
32
+ }
33
+
34
+ function getStringFromWasm0(ptr, len) {
35
+ ptr = ptr >>> 0;
36
+ return decodeText(ptr, len);
37
+ }
38
+
39
+ let WASM_VECTOR_LEN = 0;
40
+
41
+ function passArray8ToWasm0(arg, malloc) {
42
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
43
+ getUint8ArrayMemory0().set(arg, ptr / 1);
44
+ WASM_VECTOR_LEN = arg.length;
45
+ return ptr;
46
+ }
47
+
48
+ const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;
49
+
50
+ const cachedTextEncoder = new lTextEncoder('utf-8');
51
+
52
+ const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
53
+ ? function (arg, view) {
54
+ return cachedTextEncoder.encodeInto(arg, view);
55
+ }
56
+ : function (arg, view) {
57
+ const buf = cachedTextEncoder.encode(arg);
58
+ view.set(buf);
59
+ return {
60
+ read: arg.length,
61
+ written: buf.length
62
+ };
63
+ });
64
+
65
+ function passStringToWasm0(arg, malloc, realloc) {
66
+
67
+ if (realloc === undefined) {
68
+ const buf = cachedTextEncoder.encode(arg);
69
+ const ptr = malloc(buf.length, 1) >>> 0;
70
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
71
+ WASM_VECTOR_LEN = buf.length;
72
+ return ptr;
73
+ }
74
+
75
+ let len = arg.length;
76
+ let ptr = malloc(len, 1) >>> 0;
77
+
78
+ const mem = getUint8ArrayMemory0();
79
+
80
+ let offset = 0;
81
+
82
+ for (; offset < len; offset++) {
83
+ const code = arg.charCodeAt(offset);
84
+ if (code > 0x7F) break;
85
+ mem[ptr + offset] = code;
86
+ }
87
+
88
+ if (offset !== len) {
89
+ if (offset !== 0) {
90
+ arg = arg.slice(offset);
91
+ }
92
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
93
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
94
+ const ret = encodeString(arg, view);
95
+
96
+ offset += ret.written;
97
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
98
+ }
99
+
100
+ WASM_VECTOR_LEN = offset;
101
+ return ptr;
102
+ }
103
+ /**
104
+ * Wrapper around [`sp1_verifier::Groth16Verifier::verify`].
105
+ *
106
+ * We hardcode the Groth16 VK bytes to only verify SP1 proofs.
107
+ * @param {Uint8Array} proof
108
+ * @param {Uint8Array} public_inputs
109
+ * @param {string} sp1_vk_hash
110
+ * @returns {boolean}
111
+ */
112
+ export function verify_groth16(proof, public_inputs, sp1_vk_hash) {
113
+ const ptr0 = passArray8ToWasm0(proof, wasm.__wbindgen_malloc);
114
+ const len0 = WASM_VECTOR_LEN;
115
+ const ptr1 = passArray8ToWasm0(public_inputs, wasm.__wbindgen_malloc);
116
+ const len1 = WASM_VECTOR_LEN;
117
+ const ptr2 = passStringToWasm0(sp1_vk_hash, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
118
+ const len2 = WASM_VECTOR_LEN;
119
+ const ret = wasm.verify_groth16(ptr0, len0, ptr1, len1, ptr2, len2);
120
+ return ret !== 0;
121
+ }
122
+
123
+ /**
124
+ * Wrapper around [`sp1_verifier::PlonkVerifier::verify`].
125
+ *
126
+ * We hardcode the Plonk VK bytes to only verify SP1 proofs.
127
+ * @param {Uint8Array} proof
128
+ * @param {Uint8Array} public_inputs
129
+ * @param {string} sp1_vk_hash
130
+ * @returns {boolean}
131
+ */
132
+ export function verify_plonk(proof, public_inputs, sp1_vk_hash) {
133
+ const ptr0 = passArray8ToWasm0(proof, wasm.__wbindgen_malloc);
134
+ const len0 = WASM_VECTOR_LEN;
135
+ const ptr1 = passArray8ToWasm0(public_inputs, wasm.__wbindgen_malloc);
136
+ const len1 = WASM_VECTOR_LEN;
137
+ const ptr2 = passStringToWasm0(sp1_vk_hash, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
138
+ const len2 = WASM_VECTOR_LEN;
139
+ const ret = wasm.verify_plonk(ptr0, len0, ptr1, len1, ptr2, len2);
140
+ return ret !== 0;
141
+ }
142
+
143
+ /**
144
+ * Wrapper around [`sp1_verifier::CompressedVerifier::verify_sp1_proof`].
145
+ *
146
+ * We hardcode the Plonk VK bytes to only verify SP1 proofs.
147
+ * @param {Uint8Array} proof
148
+ * @param {Uint8Array} public_inputs
149
+ * @param {Uint8Array} sp1_vk_hash
150
+ * @returns {boolean}
151
+ */
152
+ export function verify_compressed(proof, public_inputs, sp1_vk_hash) {
153
+ const ptr0 = passArray8ToWasm0(proof, wasm.__wbindgen_malloc);
154
+ const len0 = WASM_VECTOR_LEN;
155
+ const ptr1 = passArray8ToWasm0(public_inputs, wasm.__wbindgen_malloc);
156
+ const len1 = WASM_VECTOR_LEN;
157
+ const ptr2 = passArray8ToWasm0(sp1_vk_hash, wasm.__wbindgen_malloc);
158
+ const len2 = WASM_VECTOR_LEN;
159
+ const ret = wasm.verify_compressed(ptr0, len0, ptr1, len1, ptr2, len2);
160
+ return ret !== 0;
161
+ }
162
+
163
+ export function __wbg_error_4375b917961b0e7a(arg0, arg1) {
164
+ console.error(getStringFromWasm0(arg0, arg1));
165
+ };
166
+
167
+ export function __wbindgen_init_externref_table() {
168
+ const table = wasm.__wbindgen_export_0;
169
+ const offset = table.grow(4);
170
+ table.set(0, undefined);
171
+ table.set(offset + 0, undefined);
172
+ table.set(offset + 1, null);
173
+ table.set(offset + 2, true);
174
+ table.set(offset + 3, false);
175
+ ;
176
+ };
177
+
178
+ export function __wbindgen_throw(arg0, arg1) {
179
+ throw new Error(getStringFromWasm0(arg0, arg1));
180
+ };
181
+
Binary file