@succinctlabs/sp1-wasm-verifier 5.0.4 → 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,39 +1,33 @@
1
1
  {
2
- "name": "@succinctlabs/sp1-wasm-verifier",
3
- "version": "5.0.4",
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
- "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",
13
- "repository": {
14
- "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"
19
- },
20
- "homepage": "https://github.com/succinctlabs/example-sp1-wasm-verifier#readme",
21
- "readme": "README.md",
22
- "keywords": [
23
- "zero-knowledge",
24
- "cryptography",
25
- "zkSNARK",
26
- "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.js",
36
- "sp1_wasm_verifier_bg.wasm",
37
- "sp1_wasm_verifier.d.ts"
38
- ]
2
+ "name": "@succinctlabs/sp1-wasm-verifier",
3
+ "type": "module",
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",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/succinctlabs/example-sp1-wasm-verifier"
13
+ },
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
+ ],
26
+ "keywords": [
27
+ "zero-knowledge",
28
+ "cryptography",
29
+ "zkSNARK",
30
+ "SNARK",
31
+ "gnark"
32
+ ]
39
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";
@@ -1,16 +1,11 @@
1
1
  let wasm;
2
- let wasmModule;
3
- export function __wbg_set_wasm(exports, module) {
4
- wasm = exports;
5
- wasmModule = module;
2
+ export function __wbg_set_wasm(val) {
3
+ wasm = val;
6
4
  }
7
5
 
8
- function getStringFromWasm0(ptr, len) {
9
- ptr = ptr >>> 0;
10
- return decodeText(ptr, len);
11
- }
12
6
 
13
7
  let cachedUint8ArrayMemory0 = null;
8
+
14
9
  function getUint8ArrayMemory0() {
15
10
  if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
16
11
  cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
@@ -18,6 +13,31 @@ function getUint8ArrayMemory0() {
18
13
  return cachedUint8ArrayMemory0;
19
14
  }
20
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
+
21
41
  function passArray8ToWasm0(arg, malloc) {
22
42
  const ptr = malloc(arg.length * 1, 1) >>> 0;
23
43
  getUint8ArrayMemory0().set(arg, ptr / 1);
@@ -25,7 +45,25 @@ function passArray8ToWasm0(arg, malloc) {
25
45
  return ptr;
26
46
  }
27
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
+
28
65
  function passStringToWasm0(arg, malloc, realloc) {
66
+
29
67
  if (realloc === undefined) {
30
68
  const buf = cachedTextEncoder.encode(arg);
31
69
  const ptr = malloc(buf.length, 1) >>> 0;
@@ -46,13 +84,14 @@ function passStringToWasm0(arg, malloc, realloc) {
46
84
  if (code > 0x7F) break;
47
85
  mem[ptr + offset] = code;
48
86
  }
87
+
49
88
  if (offset !== len) {
50
89
  if (offset !== 0) {
51
90
  arg = arg.slice(offset);
52
91
  }
53
92
  ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
54
93
  const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
55
- const ret = cachedTextEncoder.encodeInto(arg, view);
94
+ const ret = encodeString(arg, view);
56
95
 
57
96
  offset += ret.written;
58
97
  ptr = realloc(ptr, len, offset, 1) >>> 0;
@@ -61,102 +100,82 @@ function passStringToWasm0(arg, malloc, realloc) {
61
100
  WASM_VECTOR_LEN = offset;
62
101
  return ptr;
63
102
  }
64
-
65
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
66
- cachedTextDecoder.decode();
67
- function decodeText(ptr, len) {
68
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
69
- }
70
-
71
- const cachedTextEncoder = new TextEncoder();
72
-
73
- if (!('encodeInto' in cachedTextEncoder)) {
74
- cachedTextEncoder.encodeInto = function (arg, view) {
75
- const buf = cachedTextEncoder.encode(arg);
76
- view.set(buf);
77
- return {
78
- read: arg.length,
79
- written: buf.length
80
- };
81
- }
82
- }
83
-
84
- let WASM_VECTOR_LEN = 0;
85
-
86
103
  /**
87
- * Wrapper around [`sp1_verifier::CompressedVerifier::verify_sp1_proof`].
104
+ * Wrapper around [`sp1_verifier::Groth16Verifier::verify`].
88
105
  *
89
- * We hardcode the Plonk VK bytes to only verify SP1 proofs.
106
+ * We hardcode the Groth16 VK bytes to only verify SP1 proofs.
90
107
  * @param {Uint8Array} proof
91
108
  * @param {Uint8Array} public_inputs
92
- * @param {Uint8Array} sp1_vk_hash
109
+ * @param {string} sp1_vk_hash
93
110
  * @returns {boolean}
94
111
  */
95
- export function verify_compressed(proof, public_inputs, sp1_vk_hash) {
112
+ export function verify_groth16(proof, public_inputs, sp1_vk_hash) {
96
113
  const ptr0 = passArray8ToWasm0(proof, wasm.__wbindgen_malloc);
97
114
  const len0 = WASM_VECTOR_LEN;
98
115
  const ptr1 = passArray8ToWasm0(public_inputs, wasm.__wbindgen_malloc);
99
116
  const len1 = WASM_VECTOR_LEN;
100
- const ptr2 = passArray8ToWasm0(sp1_vk_hash, wasm.__wbindgen_malloc);
117
+ const ptr2 = passStringToWasm0(sp1_vk_hash, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
101
118
  const len2 = WASM_VECTOR_LEN;
102
- const ret = wasm.verify_compressed(ptr0, len0, ptr1, len1, ptr2, len2);
119
+ const ret = wasm.verify_groth16(ptr0, len0, ptr1, len1, ptr2, len2);
103
120
  return ret !== 0;
104
121
  }
105
122
 
106
123
  /**
107
- * Wrapper around [`sp1_verifier::Groth16Verifier::verify`].
124
+ * Wrapper around [`sp1_verifier::PlonkVerifier::verify`].
108
125
  *
109
- * We hardcode the Groth16 VK bytes to only verify SP1 proofs.
126
+ * We hardcode the Plonk VK bytes to only verify SP1 proofs.
110
127
  * @param {Uint8Array} proof
111
128
  * @param {Uint8Array} public_inputs
112
129
  * @param {string} sp1_vk_hash
113
130
  * @returns {boolean}
114
131
  */
115
- export function verify_groth16(proof, public_inputs, sp1_vk_hash) {
132
+ export function verify_plonk(proof, public_inputs, sp1_vk_hash) {
116
133
  const ptr0 = passArray8ToWasm0(proof, wasm.__wbindgen_malloc);
117
134
  const len0 = WASM_VECTOR_LEN;
118
135
  const ptr1 = passArray8ToWasm0(public_inputs, wasm.__wbindgen_malloc);
119
136
  const len1 = WASM_VECTOR_LEN;
120
137
  const ptr2 = passStringToWasm0(sp1_vk_hash, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
121
138
  const len2 = WASM_VECTOR_LEN;
122
- const ret = wasm.verify_groth16(ptr0, len0, ptr1, len1, ptr2, len2);
139
+ const ret = wasm.verify_plonk(ptr0, len0, ptr1, len1, ptr2, len2);
123
140
  return ret !== 0;
124
141
  }
125
142
 
126
143
  /**
127
- * Wrapper around [`sp1_verifier::PlonkVerifier::verify`].
144
+ * Wrapper around [`sp1_verifier::CompressedVerifier::verify_sp1_proof`].
128
145
  *
129
146
  * We hardcode the Plonk VK bytes to only verify SP1 proofs.
130
147
  * @param {Uint8Array} proof
131
148
  * @param {Uint8Array} public_inputs
132
- * @param {string} sp1_vk_hash
149
+ * @param {Uint8Array} sp1_vk_hash
133
150
  * @returns {boolean}
134
151
  */
135
- export function verify_plonk(proof, public_inputs, sp1_vk_hash) {
152
+ export function verify_compressed(proof, public_inputs, sp1_vk_hash) {
136
153
  const ptr0 = passArray8ToWasm0(proof, wasm.__wbindgen_malloc);
137
154
  const len0 = WASM_VECTOR_LEN;
138
155
  const ptr1 = passArray8ToWasm0(public_inputs, wasm.__wbindgen_malloc);
139
156
  const len1 = WASM_VECTOR_LEN;
140
- const ptr2 = passStringToWasm0(sp1_vk_hash, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
157
+ const ptr2 = passArray8ToWasm0(sp1_vk_hash, wasm.__wbindgen_malloc);
141
158
  const len2 = WASM_VECTOR_LEN;
142
- const ret = wasm.verify_plonk(ptr0, len0, ptr1, len1, ptr2, len2);
159
+ const ret = wasm.verify_compressed(ptr0, len0, ptr1, len1, ptr2, len2);
143
160
  return ret !== 0;
144
161
  }
145
162
 
146
- export function __wbg___wbindgen_throw_dd24417ed36fc46e(arg0, arg1) {
147
- throw new Error(getStringFromWasm0(arg0, arg1));
148
- };
149
-
150
- export function __wbg_error_2e0b9dae3eefa9fd(arg0, arg1) {
163
+ export function __wbg_error_4375b917961b0e7a(arg0, arg1) {
151
164
  console.error(getStringFromWasm0(arg0, arg1));
152
165
  };
153
166
 
154
167
  export function __wbindgen_init_externref_table() {
155
- const table = wasm.__wbindgen_externrefs;
168
+ const table = wasm.__wbindgen_export_0;
156
169
  const offset = table.grow(4);
157
170
  table.set(0, undefined);
158
171
  table.set(offset + 0, undefined);
159
172
  table.set(offset + 1, null);
160
173
  table.set(offset + 2, true);
161
174
  table.set(offset + 3, false);
175
+ ;
162
176
  };
177
+
178
+ export function __wbindgen_throw(arg0, arg1) {
179
+ throw new Error(getStringFromWasm0(arg0, arg1));
180
+ };
181
+
Binary file