@aztec/bb.js 0.0.1-commit.fce3e4f → 0.0.1-commit.fffb133c
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/build/amd64-linux/bb +0 -0
- package/build/amd64-linux/nodejs_module.node +0 -0
- package/build/amd64-macos/bb +0 -0
- package/build/amd64-macos/nodejs_module.node +0 -0
- package/build/arm64-linux/bb +0 -0
- package/build/arm64-linux/nodejs_module.node +0 -0
- package/build/arm64-macos/bb +0 -0
- package/build/arm64-macos/nodejs_module.node +0 -0
- package/dest/browser/barretenberg/backend.d.ts +49 -17
- package/dest/browser/barretenberg/backend.d.ts.map +1 -1
- package/dest/browser/barretenberg/backend.js +111 -11
- package/dest/browser/barretenberg/index.d.ts +2 -2
- package/dest/browser/barretenberg/index.d.ts.map +1 -1
- package/dest/browser/barretenberg/index.js +2 -2
- package/dest/browser/barretenberg_wasm/barretenberg_wasm_main/index.js +1 -1
- package/dest/browser/barretenberg_wasm/fetch_code/browser/barretenberg-threads.js +1 -1
- package/dest/browser/barretenberg_wasm/fetch_code/browser/barretenberg.js +1 -1
- package/dest/browser/bb_backends/index.d.ts +3 -1
- package/dest/browser/bb_backends/index.d.ts.map +1 -1
- package/dest/browser/cbind/generate.d.ts +5 -2
- package/dest/browser/cbind/generate.d.ts.map +1 -1
- package/dest/browser/cbind/generate.js +47 -25
- package/dest/browser/cbind/generated/api_types.d.ts +766 -1687
- package/dest/browser/cbind/generated/api_types.d.ts.map +1 -1
- package/dest/browser/cbind/generated/api_types.js +1465 -1555
- package/dest/browser/cbind/generated/async.d.ts +3 -5
- package/dest/browser/cbind/generated/async.d.ts.map +1 -1
- package/dest/browser/cbind/generated/async.js +13 -33
- package/dest/browser/cbind/generated/sync.d.ts +3 -5
- package/dest/browser/cbind/generated/sync.d.ts.map +1 -1
- package/dest/browser/cbind/generated/sync.js +13 -31
- package/dest/browser/cbind/naming.d.ts +16 -0
- package/dest/browser/cbind/naming.d.ts.map +1 -0
- package/dest/browser/cbind/naming.js +24 -0
- package/dest/browser/cbind/rust_codegen.d.ts +26 -0
- package/dest/browser/cbind/rust_codegen.d.ts.map +1 -0
- package/dest/browser/cbind/rust_codegen.js +461 -0
- package/dest/browser/cbind/schema_visitor.d.ts +47 -0
- package/dest/browser/cbind/schema_visitor.d.ts.map +1 -0
- package/dest/browser/cbind/schema_visitor.js +158 -0
- package/dest/browser/cbind/typescript_codegen.d.ts +30 -0
- package/dest/browser/cbind/typescript_codegen.d.ts.map +1 -0
- package/dest/browser/cbind/typescript_codegen.js +365 -0
- package/dest/browser/index.d.ts +2 -2
- package/dest/browser/index.d.ts.map +1 -1
- package/dest/browser/index.js +2 -2
- package/dest/node/barretenberg/backend.d.ts +49 -17
- package/dest/node/barretenberg/backend.d.ts.map +1 -1
- package/dest/node/barretenberg/backend.js +111 -11
- package/dest/node/barretenberg/backend.test.d.ts +2 -0
- package/dest/node/barretenberg/backend.test.d.ts.map +1 -0
- package/dest/node/barretenberg/backend.test.js +103 -0
- package/dest/node/barretenberg/index.d.ts +2 -2
- package/dest/node/barretenberg/index.d.ts.map +1 -1
- package/dest/node/barretenberg/index.js +2 -2
- package/dest/node/barretenberg_wasm/barretenberg-threads.wasm.gz +0 -0
- package/dest/node/barretenberg_wasm/barretenberg_wasm_main/index.js +1 -1
- package/dest/node/bb_backends/index.d.ts +3 -1
- package/dest/node/bb_backends/index.d.ts.map +1 -1
- package/dest/node/bb_backends/node/index.d.ts +1 -1
- package/dest/node/bb_backends/node/index.d.ts.map +1 -1
- package/dest/node/bb_backends/node/index.js +5 -5
- package/dest/node/bb_backends/node/native_shm.d.ts +3 -2
- package/dest/node/bb_backends/node/native_shm.d.ts.map +1 -1
- package/dest/node/bb_backends/node/native_shm.js +40 -21
- package/dest/node/bb_backends/node/native_shm_async.d.ts +2 -2
- package/dest/node/bb_backends/node/native_shm_async.d.ts.map +1 -1
- package/dest/node/bb_backends/node/native_shm_async.js +17 -21
- package/dest/node/bb_backends/node/native_socket.d.ts +1 -1
- package/dest/node/bb_backends/node/native_socket.d.ts.map +1 -1
- package/dest/node/bb_backends/node/native_socket.js +7 -5
- package/dest/node/bb_backends/node/platform.d.ts +1 -1
- package/dest/node/bb_backends/node/platform.d.ts.map +1 -1
- package/dest/node/bb_backends/node/platform.js +7 -2
- package/dest/node/cbind/generate.d.ts +5 -2
- package/dest/node/cbind/generate.d.ts.map +1 -1
- package/dest/node/cbind/generate.js +47 -25
- package/dest/node/cbind/generated/api_types.d.ts +766 -1687
- package/dest/node/cbind/generated/api_types.d.ts.map +1 -1
- package/dest/node/cbind/generated/api_types.js +1465 -1555
- package/dest/node/cbind/generated/async.d.ts +3 -5
- package/dest/node/cbind/generated/async.d.ts.map +1 -1
- package/dest/node/cbind/generated/async.js +13 -33
- package/dest/node/cbind/generated/sync.d.ts +3 -5
- package/dest/node/cbind/generated/sync.d.ts.map +1 -1
- package/dest/node/cbind/generated/sync.js +13 -31
- package/dest/node/cbind/naming.d.ts +16 -0
- package/dest/node/cbind/naming.d.ts.map +1 -0
- package/dest/node/cbind/naming.js +24 -0
- package/dest/node/cbind/rust_codegen.d.ts +26 -0
- package/dest/node/cbind/rust_codegen.d.ts.map +1 -0
- package/dest/node/cbind/rust_codegen.js +461 -0
- package/dest/node/cbind/schema_visitor.d.ts +47 -0
- package/dest/node/cbind/schema_visitor.d.ts.map +1 -0
- package/dest/node/cbind/schema_visitor.js +158 -0
- package/dest/node/cbind/typescript_codegen.d.ts +30 -0
- package/dest/node/cbind/typescript_codegen.d.ts.map +1 -0
- package/dest/node/cbind/typescript_codegen.js +365 -0
- package/dest/node/index.d.ts +2 -2
- package/dest/node/index.d.ts.map +1 -1
- package/dest/node/index.js +2 -2
- package/dest/node-cjs/barretenberg/backend.d.ts +49 -17
- package/dest/node-cjs/barretenberg/backend.d.ts.map +1 -1
- package/dest/node-cjs/barretenberg/backend.js +113 -11
- package/dest/node-cjs/barretenberg/backend.test.d.ts +2 -0
- package/dest/node-cjs/barretenberg/backend.test.d.ts.map +1 -0
- package/dest/node-cjs/barretenberg/backend.test.js +105 -0
- package/dest/node-cjs/barretenberg/index.d.ts +2 -2
- package/dest/node-cjs/barretenberg/index.d.ts.map +1 -1
- package/dest/node-cjs/barretenberg/index.js +4 -2
- package/dest/node-cjs/barretenberg_wasm/barretenberg-threads.wasm.gz +0 -0
- package/dest/node-cjs/barretenberg_wasm/barretenberg_wasm_main/index.js +1 -1
- package/dest/node-cjs/bb_backends/index.d.ts +3 -1
- package/dest/node-cjs/bb_backends/index.d.ts.map +1 -1
- package/dest/node-cjs/bb_backends/node/index.d.ts +1 -1
- package/dest/node-cjs/bb_backends/node/index.d.ts.map +1 -1
- package/dest/node-cjs/bb_backends/node/index.js +5 -5
- package/dest/node-cjs/bb_backends/node/native_shm.d.ts +3 -2
- package/dest/node-cjs/bb_backends/node/native_shm.d.ts.map +1 -1
- package/dest/node-cjs/bb_backends/node/native_shm.js +39 -20
- package/dest/node-cjs/bb_backends/node/native_shm_async.d.ts +2 -2
- package/dest/node-cjs/bb_backends/node/native_shm_async.d.ts.map +1 -1
- package/dest/node-cjs/bb_backends/node/native_shm_async.js +17 -21
- package/dest/node-cjs/bb_backends/node/native_socket.d.ts +1 -1
- package/dest/node-cjs/bb_backends/node/native_socket.d.ts.map +1 -1
- package/dest/node-cjs/bb_backends/node/native_socket.js +7 -5
- package/dest/node-cjs/bb_backends/node/platform.d.ts +1 -1
- package/dest/node-cjs/bb_backends/node/platform.d.ts.map +1 -1
- package/dest/node-cjs/bb_backends/node/platform.js +7 -2
- package/dest/node-cjs/cbind/generate.d.ts +5 -2
- package/dest/node-cjs/cbind/generate.d.ts.map +1 -1
- package/dest/node-cjs/cbind/generate.js +47 -25
- package/dest/node-cjs/cbind/generated/api_types.d.ts +766 -1687
- package/dest/node-cjs/cbind/generated/api_types.d.ts.map +1 -1
- package/dest/node-cjs/cbind/generated/api_types.js +1671 -1771
- package/dest/node-cjs/cbind/generated/async.d.ts +3 -5
- package/dest/node-cjs/cbind/generated/async.d.ts.map +1 -1
- package/dest/node-cjs/cbind/generated/async.js +12 -32
- package/dest/node-cjs/cbind/generated/sync.d.ts +3 -5
- package/dest/node-cjs/cbind/generated/sync.d.ts.map +1 -1
- package/dest/node-cjs/cbind/generated/sync.js +12 -30
- package/dest/node-cjs/cbind/naming.d.ts +16 -0
- package/dest/node-cjs/cbind/naming.d.ts.map +1 -0
- package/dest/node-cjs/cbind/naming.js +28 -0
- package/dest/node-cjs/cbind/rust_codegen.d.ts +26 -0
- package/dest/node-cjs/cbind/rust_codegen.d.ts.map +1 -0
- package/dest/node-cjs/cbind/rust_codegen.js +465 -0
- package/dest/node-cjs/cbind/schema_visitor.d.ts +47 -0
- package/dest/node-cjs/cbind/schema_visitor.d.ts.map +1 -0
- package/dest/node-cjs/cbind/schema_visitor.js +162 -0
- package/dest/node-cjs/cbind/typescript_codegen.d.ts +30 -0
- package/dest/node-cjs/cbind/typescript_codegen.d.ts.map +1 -0
- package/dest/node-cjs/cbind/typescript_codegen.js +369 -0
- package/dest/node-cjs/index.d.ts +2 -2
- package/dest/node-cjs/index.d.ts.map +1 -1
- package/dest/node-cjs/index.js +4 -2
- package/package.json +1 -1
- package/src/barretenberg/backend.test.ts +122 -0
- package/src/barretenberg/backend.ts +151 -25
- package/src/barretenberg/index.ts +9 -1
- package/src/barretenberg_wasm/barretenberg_wasm_main/index.ts +1 -1
- package/src/bb_backends/index.ts +3 -0
- package/src/bb_backends/node/index.ts +9 -4
- package/src/bb_backends/node/native_shm.ts +38 -19
- package/src/bb_backends/node/native_shm_async.ts +15 -19
- package/src/bb_backends/node/native_socket.ts +7 -5
- package/src/bb_backends/node/platform.ts +6 -1
- package/src/cbind/generate.ts +51 -32
- package/src/cbind/naming.ts +27 -0
- package/src/cbind/rust_codegen.ts +504 -0
- package/src/cbind/schema_visitor.ts +219 -0
- package/src/cbind/typescript_codegen.ts +419 -0
- package/src/index.ts +4 -0
- package/dest/browser/cbind/schema_compiler.d.ts +0 -68
- package/dest/browser/cbind/schema_compiler.d.ts.map +0 -1
- package/dest/browser/cbind/schema_compiler.js +0 -600
- package/dest/node/cbind/schema_compiler.d.ts +0 -68
- package/dest/node/cbind/schema_compiler.d.ts.map +0 -1
- package/dest/node/cbind/schema_compiler.js +0 -600
- package/dest/node-cjs/cbind/schema_compiler.d.ts +0 -68
- package/dest/node-cjs/cbind/schema_compiler.d.ts.map +0 -1
- package/dest/node-cjs/cbind/schema_compiler.js +0 -607
- package/src/cbind/schema_compiler.ts +0 -745
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/bb.js",
|
|
3
3
|
"packageManager": "yarn@4.5.2",
|
|
4
|
-
"version": "0.0.1-commit.
|
|
4
|
+
"version": "0.0.1-commit.fffb133c",
|
|
5
5
|
"homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/barretenberg/ts",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { fieldToString, fieldsToStrings } from './backend.js';
|
|
2
|
+
|
|
3
|
+
describe('field helper functions', () => {
|
|
4
|
+
describe('fieldToString', () => {
|
|
5
|
+
it('converts zero field to "0"', () => {
|
|
6
|
+
const zeroField = new Uint8Array(32).fill(0);
|
|
7
|
+
expect(fieldToString(zeroField)).toBe('0');
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it('converts field with value 1 to "1"', () => {
|
|
11
|
+
const oneField = new Uint8Array(32).fill(0);
|
|
12
|
+
oneField[31] = 1;
|
|
13
|
+
expect(fieldToString(oneField)).toBe('1');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('converts field with value 256 to "256"', () => {
|
|
17
|
+
const field = new Uint8Array(32).fill(0);
|
|
18
|
+
field[30] = 1;
|
|
19
|
+
field[31] = 0;
|
|
20
|
+
expect(fieldToString(field)).toBe('256');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('converts field with max uint8 in last byte to "255"', () => {
|
|
24
|
+
const field = new Uint8Array(32).fill(0);
|
|
25
|
+
field[31] = 255;
|
|
26
|
+
expect(fieldToString(field)).toBe('255');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('converts larger values correctly', () => {
|
|
30
|
+
// 0x0100 = 256 in decimal
|
|
31
|
+
const field = new Uint8Array(32).fill(0);
|
|
32
|
+
field[30] = 0x01;
|
|
33
|
+
field[31] = 0x00;
|
|
34
|
+
expect(fieldToString(field)).toBe('256');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('handles multi-byte values', () => {
|
|
38
|
+
// 0x010203 = 66051 in decimal
|
|
39
|
+
const field = new Uint8Array(32).fill(0);
|
|
40
|
+
field[29] = 0x01;
|
|
41
|
+
field[30] = 0x02;
|
|
42
|
+
field[31] = 0x03;
|
|
43
|
+
expect(fieldToString(field)).toBe('66051');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('handles large field values', () => {
|
|
47
|
+
// A known value: all bytes set to 1
|
|
48
|
+
const field = new Uint8Array(32).fill(1);
|
|
49
|
+
const result = fieldToString(field);
|
|
50
|
+
// Verify it's a valid decimal string
|
|
51
|
+
expect(result).toMatch(/^\d+$/);
|
|
52
|
+
// Verify the length is reasonable for a 256-bit number
|
|
53
|
+
expect(result.length).toBeGreaterThan(70);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('converts to hex with radix 16', () => {
|
|
57
|
+
const field = new Uint8Array(32).fill(0);
|
|
58
|
+
field[31] = 255;
|
|
59
|
+
expect(fieldToString(field, 16)).toBe('ff');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('converts to hex for multi-byte values', () => {
|
|
63
|
+
// 0x010203
|
|
64
|
+
const field = new Uint8Array(32).fill(0);
|
|
65
|
+
field[29] = 0x01;
|
|
66
|
+
field[30] = 0x02;
|
|
67
|
+
field[31] = 0x03;
|
|
68
|
+
expect(fieldToString(field, 16)).toBe('10203');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('converts to binary with radix 2', () => {
|
|
72
|
+
const field = new Uint8Array(32).fill(0);
|
|
73
|
+
field[31] = 5;
|
|
74
|
+
expect(fieldToString(field, 2)).toBe('101');
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('fieldsToStrings', () => {
|
|
79
|
+
it('converts empty array to empty array', () => {
|
|
80
|
+
expect(fieldsToStrings([])).toEqual([]);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('converts single field', () => {
|
|
84
|
+
const oneField = new Uint8Array(32).fill(0);
|
|
85
|
+
oneField[31] = 42;
|
|
86
|
+
expect(fieldsToStrings([oneField])).toEqual(['42']);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('converts multiple fields', () => {
|
|
90
|
+
const field1 = new Uint8Array(32).fill(0);
|
|
91
|
+
field1[31] = 1;
|
|
92
|
+
|
|
93
|
+
const field2 = new Uint8Array(32).fill(0);
|
|
94
|
+
field2[31] = 2;
|
|
95
|
+
|
|
96
|
+
const field3 = new Uint8Array(32).fill(0);
|
|
97
|
+
field3[31] = 3;
|
|
98
|
+
|
|
99
|
+
expect(fieldsToStrings([field1, field2, field3])).toEqual(['1', '2', '3']);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('preserves order of fields', () => {
|
|
103
|
+
const fields = [10, 20, 30, 40, 50].map(v => {
|
|
104
|
+
const field = new Uint8Array(32).fill(0);
|
|
105
|
+
field[31] = v;
|
|
106
|
+
return field;
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
expect(fieldsToStrings(fields)).toEqual(['10', '20', '30', '40', '50']);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('converts to hex with radix 16', () => {
|
|
113
|
+
const fields = [15, 16, 255].map(v => {
|
|
114
|
+
const field = new Uint8Array(32).fill(0);
|
|
115
|
+
field[31] = v;
|
|
116
|
+
return field;
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
expect(fieldsToStrings(fields, 16)).toEqual(['f', '10', 'ff']);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Barretenberg } from './index.js';
|
|
2
2
|
import { ProofData, uint8ArrayToHex, hexToUint8Array } from '../proof/index.js';
|
|
3
|
-
import { fromChonkProof, toChonkProof } from '../cbind/generated/api_types.js';
|
|
3
|
+
import { fromChonkProof, toChonkProof, ChonkProof } from '../cbind/generated/api_types.js';
|
|
4
4
|
import { ungzip } from 'pako';
|
|
5
5
|
import { Decoder, Encoder } from 'msgpackr';
|
|
6
6
|
|
|
@@ -10,29 +10,46 @@ export class AztecClientBackendError extends Error {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Target verification environment for proof generation.
|
|
15
|
+
* This determines the hash function used and whether zero-knowledge is enabled.
|
|
16
|
+
*/
|
|
17
|
+
export type VerifierTarget =
|
|
18
|
+
| 'evm' // Ethereum/Solidity verification (keccak, ZK enabled)
|
|
19
|
+
| 'evm-no-zk' // Ethereum/Solidity without zero-knowledge
|
|
20
|
+
| 'noir-recursive' // Recursive verification in Noir circuits (poseidon2, ZK enabled)
|
|
21
|
+
| 'noir-recursive-no-zk' // Recursive verification without ZK
|
|
22
|
+
| 'noir-rollup' // Rollup circuits with IPA accumulation (poseidon2, ZK enabled)
|
|
23
|
+
| 'noir-rollup-no-zk' // Rollup circuits without ZK
|
|
24
|
+
| 'starknet' // Starknet verification via Garaga (ZK enabled)
|
|
25
|
+
| 'starknet-no-zk'; // Starknet without zero-knowledge
|
|
26
|
+
|
|
13
27
|
/**
|
|
14
28
|
* Options for the UltraHonkBackend.
|
|
15
29
|
*/
|
|
16
30
|
export type UltraHonkBackendOptions = {
|
|
17
|
-
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
31
|
+
/**
|
|
32
|
+
* Target verification environment. Determines hash function and ZK settings.
|
|
33
|
+
* This is the recommended way to configure proof generation.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* // For EVM/Solidity verification
|
|
37
|
+
* backend.generateProof(witness, { verifierTarget: 'evm' });
|
|
38
|
+
*
|
|
39
|
+
* // For recursive verification in Noir
|
|
40
|
+
* backend.generateProof(witness, { verifierTarget: 'noir-recursive' });
|
|
20
41
|
*/
|
|
42
|
+
verifierTarget?: VerifierTarget;
|
|
43
|
+
|
|
44
|
+
// Legacy options - prefer using verifierTarget instead
|
|
45
|
+
|
|
46
|
+
/** @deprecated Use verifierTarget: 'evm-no-zk' instead */
|
|
21
47
|
keccak?: boolean;
|
|
22
|
-
/**
|
|
23
|
-
* when generating challenges in the proof.
|
|
24
|
-
* Use this when you want to verify the created proof on an EVM chain.
|
|
25
|
-
*/
|
|
48
|
+
/** @deprecated Use verifierTarget: 'evm' instead */
|
|
26
49
|
keccakZK?: boolean;
|
|
27
|
-
/**
|
|
28
|
-
* when generating challenges in the proof.
|
|
29
|
-
* Use this when you want to verify the created proof on an Starknet chain with Garaga.
|
|
30
|
-
*/
|
|
50
|
+
/** @deprecated Use verifierTarget: 'starknet-no-zk' instead */
|
|
31
51
|
starknet?: boolean;
|
|
32
|
-
/**
|
|
33
|
-
* when generating challenges in the proof.
|
|
34
|
-
* Use this when you want to verify the created proof on an Starknet chain with Garaga.
|
|
35
|
-
*/
|
|
52
|
+
/** @deprecated Use verifierTarget: 'starknet' instead */
|
|
36
53
|
starknetZK?: boolean;
|
|
37
54
|
};
|
|
38
55
|
|
|
@@ -42,6 +59,67 @@ function getProofSettingsFromOptions(options?: UltraHonkBackendOptions): {
|
|
|
42
59
|
disableZk: boolean;
|
|
43
60
|
optimizedSolidityVerifier: boolean;
|
|
44
61
|
} {
|
|
62
|
+
// Check for conflicting options - verifierTarget should not be combined with legacy options
|
|
63
|
+
if (options?.verifierTarget) {
|
|
64
|
+
const legacyOptions = [options.keccak, options.keccakZK, options.starknet, options.starknetZK].filter(Boolean);
|
|
65
|
+
if (legacyOptions.length > 0) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
'Cannot use verifierTarget with legacy options (keccak, keccakZK, starknet, starknetZK). ' +
|
|
68
|
+
'Use verifierTarget alone.',
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
switch (options.verifierTarget) {
|
|
73
|
+
case 'evm':
|
|
74
|
+
return { ipaAccumulation: false, oracleHashType: 'keccak', disableZk: false, optimizedSolidityVerifier: false };
|
|
75
|
+
case 'evm-no-zk':
|
|
76
|
+
return { ipaAccumulation: false, oracleHashType: 'keccak', disableZk: true, optimizedSolidityVerifier: false };
|
|
77
|
+
case 'noir-recursive':
|
|
78
|
+
return {
|
|
79
|
+
ipaAccumulation: false,
|
|
80
|
+
oracleHashType: 'poseidon2',
|
|
81
|
+
disableZk: false,
|
|
82
|
+
optimizedSolidityVerifier: false,
|
|
83
|
+
};
|
|
84
|
+
case 'noir-recursive-no-zk':
|
|
85
|
+
return {
|
|
86
|
+
ipaAccumulation: false,
|
|
87
|
+
oracleHashType: 'poseidon2',
|
|
88
|
+
disableZk: true,
|
|
89
|
+
optimizedSolidityVerifier: false,
|
|
90
|
+
};
|
|
91
|
+
case 'noir-rollup':
|
|
92
|
+
return {
|
|
93
|
+
ipaAccumulation: true,
|
|
94
|
+
oracleHashType: 'poseidon2',
|
|
95
|
+
disableZk: false,
|
|
96
|
+
optimizedSolidityVerifier: false,
|
|
97
|
+
};
|
|
98
|
+
case 'noir-rollup-no-zk':
|
|
99
|
+
return {
|
|
100
|
+
ipaAccumulation: true,
|
|
101
|
+
oracleHashType: 'poseidon2',
|
|
102
|
+
disableZk: true,
|
|
103
|
+
optimizedSolidityVerifier: false,
|
|
104
|
+
};
|
|
105
|
+
case 'starknet':
|
|
106
|
+
return {
|
|
107
|
+
ipaAccumulation: false,
|
|
108
|
+
oracleHashType: 'starknet',
|
|
109
|
+
disableZk: false,
|
|
110
|
+
optimizedSolidityVerifier: false,
|
|
111
|
+
};
|
|
112
|
+
case 'starknet-no-zk':
|
|
113
|
+
return {
|
|
114
|
+
ipaAccumulation: false,
|
|
115
|
+
oracleHashType: 'starknet',
|
|
116
|
+
disableZk: true,
|
|
117
|
+
optimizedSolidityVerifier: false,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Legacy options support (deprecated)
|
|
45
123
|
return {
|
|
46
124
|
ipaAccumulation: false,
|
|
47
125
|
oracleHashType:
|
|
@@ -50,7 +128,6 @@ function getProofSettingsFromOptions(options?: UltraHonkBackendOptions): {
|
|
|
50
128
|
: options?.starknet || options?.starknetZK
|
|
51
129
|
? 'starknet'
|
|
52
130
|
: 'poseidon2',
|
|
53
|
-
// TODO no current way to target non-zk poseidon2 hash
|
|
54
131
|
disableZk: options?.keccak || options?.starknet ? true : false,
|
|
55
132
|
optimizedSolidityVerifier: false,
|
|
56
133
|
};
|
|
@@ -162,6 +239,7 @@ export class UltraHonkBackend {
|
|
|
162
239
|
_proof: Uint8Array,
|
|
163
240
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
164
241
|
_numOfPublicInputs: number,
|
|
242
|
+
options?: UltraHonkBackendOptions,
|
|
165
243
|
): Promise<{ proofAsFields: string[]; vkAsFields: string[]; vkHash: string }> {
|
|
166
244
|
// TODO(https://github.com/noir-lang/noir/issues/5661): This needs to be updated to handle recursive aggregation.
|
|
167
245
|
// There is still a proofAsFields method but we could consider getting rid of it as the proof itself
|
|
@@ -171,14 +249,12 @@ export class UltraHonkBackend {
|
|
|
171
249
|
// const proof = reconstructProofWithPublicInputs(proofData);
|
|
172
250
|
// const proofAsFields = (await this.api.acirProofAsFieldsUltraHonk(proof)).slice(numOfPublicInputs);
|
|
173
251
|
|
|
174
|
-
// TODO: perhaps we should put this in the init function. Need to benchmark
|
|
175
|
-
// TODO how long it takes.
|
|
176
252
|
const vkResult = await this.api.circuitComputeVk({
|
|
177
253
|
circuit: {
|
|
178
254
|
name: 'circuit',
|
|
179
255
|
bytecode: this.acirUncompressedBytecode,
|
|
180
256
|
},
|
|
181
|
-
settings: getProofSettingsFromOptions(
|
|
257
|
+
settings: getProofSettingsFromOptions(options),
|
|
182
258
|
});
|
|
183
259
|
|
|
184
260
|
// Convert VK bytes to field elements (32-byte chunks)
|
|
@@ -250,7 +326,7 @@ export class AztecClientBackend {
|
|
|
250
326
|
// The API currently expects a msgpack-encoded API.
|
|
251
327
|
const proof = new Encoder({ useRecords: false }).encode(fromChonkProof(proveResult.proof));
|
|
252
328
|
// Generate the VK
|
|
253
|
-
const vkResult = await this.api.
|
|
329
|
+
const vkResult = await this.api.chonkComputeVk({
|
|
254
330
|
circuit: {
|
|
255
331
|
name: 'hiding',
|
|
256
332
|
bytecode: this.acirBuf[this.acirBuf.length - 1],
|
|
@@ -260,13 +336,13 @@ export class AztecClientBackend {
|
|
|
260
336
|
const proofFields = [
|
|
261
337
|
proveResult.proof.megaProof,
|
|
262
338
|
proveResult.proof.goblinProof.mergeProof,
|
|
263
|
-
proveResult.proof.goblinProof.eccvmProof
|
|
264
|
-
proveResult.proof.goblinProof.
|
|
339
|
+
proveResult.proof.goblinProof.eccvmProof,
|
|
340
|
+
proveResult.proof.goblinProof.ipaProof,
|
|
265
341
|
proveResult.proof.goblinProof.translatorProof,
|
|
266
342
|
].flat();
|
|
267
343
|
|
|
268
|
-
//
|
|
269
|
-
if (!(await this.
|
|
344
|
+
// Verify using native proof directly to avoid redundant encode/decode cycle
|
|
345
|
+
if (!(await this.verifyNative(proveResult.proof, vkResult.bytes))) {
|
|
270
346
|
throw new AztecClientBackendError('Failed to verify the private (Chonk) transaction proof!');
|
|
271
347
|
}
|
|
272
348
|
return [proofFields, proof, vkResult.bytes];
|
|
@@ -280,6 +356,18 @@ export class AztecClientBackend {
|
|
|
280
356
|
return result.valid;
|
|
281
357
|
}
|
|
282
358
|
|
|
359
|
+
/**
|
|
360
|
+
* Internal verification using native ChonkProof type.
|
|
361
|
+
* Avoids encode/decode cycle when called from prove().
|
|
362
|
+
*/
|
|
363
|
+
private async verifyNative(proof: ChonkProof, vk: Uint8Array): Promise<boolean> {
|
|
364
|
+
const result = await this.api.chonkVerify({
|
|
365
|
+
proof,
|
|
366
|
+
vk,
|
|
367
|
+
});
|
|
368
|
+
return result.valid;
|
|
369
|
+
}
|
|
370
|
+
|
|
283
371
|
async gates(): Promise<number[]> {
|
|
284
372
|
const circuitSizes: number[] = [];
|
|
285
373
|
for (const buf of this.acirBuf) {
|
|
@@ -310,3 +398,41 @@ function base64Decode(input: string): Uint8Array {
|
|
|
310
398
|
throw new Error('atob is not available. Node.js 18+ or browser required.');
|
|
311
399
|
}
|
|
312
400
|
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Convert a field element (32-byte Uint8Array) to a string.
|
|
404
|
+
*
|
|
405
|
+
* @param field - A 32-byte field element
|
|
406
|
+
* @param radix - The radix for string conversion (2-36), defaults to 10 (decimal)
|
|
407
|
+
* @returns The field value as a string in the specified radix
|
|
408
|
+
*
|
|
409
|
+
* @example
|
|
410
|
+
* const decimal = fieldToString(field); // "12345678"
|
|
411
|
+
* const hex = fieldToString(field, 16); // "bc614e"
|
|
412
|
+
*/
|
|
413
|
+
export function fieldToString(field: Uint8Array, radix: number = 10): string {
|
|
414
|
+
let result = 0n;
|
|
415
|
+
for (const byte of field) {
|
|
416
|
+
result <<= 8n;
|
|
417
|
+
result += BigInt(byte);
|
|
418
|
+
}
|
|
419
|
+
return result.toString(radix);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Convert an array of field elements to an array of strings.
|
|
424
|
+
* Useful for passing VK fields to Noir circuits.
|
|
425
|
+
*
|
|
426
|
+
* @param fields - Array of 32-byte field elements
|
|
427
|
+
* @param radix - The radix for string conversion (2-36), defaults to 10 (decimal)
|
|
428
|
+
* @returns Array of strings in the specified radix
|
|
429
|
+
*
|
|
430
|
+
* @example
|
|
431
|
+
* const vkAsFields = await barretenbergAPI.vkAsFields({ verificationKey: vk });
|
|
432
|
+
* const vkDecimalStrings = fieldsToStrings(vkAsFields.fields); // ["12345678", "87654321", ...]
|
|
433
|
+
* const vkHexStrings = fieldsToStrings(vkAsFields.fields, 16); // ["bc614e", "5397fb1", ...]
|
|
434
|
+
*/
|
|
435
|
+
export function fieldsToStrings(fields: Uint8Array[], radix: number = 10): string[] {
|
|
436
|
+
return fields.map(field => fieldToString(field, radix));
|
|
437
|
+
}
|
|
438
|
+
|
|
@@ -5,7 +5,15 @@ import { IMsgpackBackendSync, IMsgpackBackendAsync } from '../bb_backends/interf
|
|
|
5
5
|
import { BackendOptions, BackendType } from '../bb_backends/index.js';
|
|
6
6
|
import { createAsyncBackend, createSyncBackend } from '../bb_backends/node/index.js';
|
|
7
7
|
|
|
8
|
-
export {
|
|
8
|
+
export {
|
|
9
|
+
UltraHonkBackend,
|
|
10
|
+
UltraHonkVerifierBackend,
|
|
11
|
+
AztecClientBackend,
|
|
12
|
+
fieldToString,
|
|
13
|
+
fieldsToStrings,
|
|
14
|
+
type UltraHonkBackendOptions,
|
|
15
|
+
type VerifierTarget,
|
|
16
|
+
} from './backend.js';
|
|
9
17
|
export * from '../bb_backends/index.js';
|
|
10
18
|
|
|
11
19
|
export type CircuitOptions = {
|
|
@@ -35,7 +35,7 @@ export class BarretenbergWasmMain extends BarretenbergWasmBase {
|
|
|
35
35
|
module: WebAssembly.Module,
|
|
36
36
|
threads = Math.min(getNumCpu(), BarretenbergWasmMain.MAX_THREADS),
|
|
37
37
|
logger?: (msg: string) => void,
|
|
38
|
-
initial =
|
|
38
|
+
initial = 35,
|
|
39
39
|
maximum = this.getDefaultMaximumMemoryPages(),
|
|
40
40
|
) {
|
|
41
41
|
// Track whether a custom logger was provided so workers know whether to postMessage logs
|
package/src/bb_backends/index.ts
CHANGED
|
@@ -28,6 +28,9 @@ export type BackendOptions = {
|
|
|
28
28
|
/** @description Custom path to bb binary for native backend (overrides automatic detection) */
|
|
29
29
|
bbPath?: string;
|
|
30
30
|
|
|
31
|
+
/** @description Custom path to bb NAPI module for native backend (overrides automatic detection) */
|
|
32
|
+
napiPath?: string;
|
|
33
|
+
|
|
31
34
|
/**
|
|
32
35
|
* @description Logging function
|
|
33
36
|
* Warning: Attaching a logger can prevent nodejs from exiting without explicitly destroying the backend.
|
|
@@ -35,12 +35,17 @@ export async function createAsyncBackend(
|
|
|
35
35
|
if (!bbPath) {
|
|
36
36
|
throw new Error('Native backend requires bb binary.');
|
|
37
37
|
}
|
|
38
|
-
const napiPath = findNapiBinary();
|
|
38
|
+
const napiPath = findNapiBinary(options.napiPath);
|
|
39
39
|
if (!napiPath) {
|
|
40
40
|
throw new Error('Native async backend requires napi client stub.');
|
|
41
41
|
}
|
|
42
42
|
logger(`Using native shared memory async backend: ${bbPath}`);
|
|
43
|
-
const asyncBackend = await BarretenbergNativeShmAsyncBackend.new(
|
|
43
|
+
const asyncBackend = await BarretenbergNativeShmAsyncBackend.new(
|
|
44
|
+
bbPath,
|
|
45
|
+
napiPath,
|
|
46
|
+
options.threads,
|
|
47
|
+
options.logger,
|
|
48
|
+
);
|
|
44
49
|
return new Barretenberg(asyncBackend, options);
|
|
45
50
|
}
|
|
46
51
|
|
|
@@ -82,12 +87,12 @@ export async function createSyncBackend(
|
|
|
82
87
|
if (!bbPath) {
|
|
83
88
|
throw new Error('Native backend requires bb binary.');
|
|
84
89
|
}
|
|
85
|
-
const napiPath = findNapiBinary();
|
|
90
|
+
const napiPath = findNapiBinary(options.napiPath);
|
|
86
91
|
if (!napiPath) {
|
|
87
92
|
throw new Error('Native sync backend requires napi client stub.');
|
|
88
93
|
}
|
|
89
94
|
logger(`Using native shared memory backend: ${bbPath}`);
|
|
90
|
-
const shm = await BarretenbergNativeShmSyncBackend.new(bbPath, options.threads, options.logger);
|
|
95
|
+
const shm = await BarretenbergNativeShmSyncBackend.new(bbPath, napiPath, options.threads, options.logger);
|
|
91
96
|
return new BarretenbergSync(shm);
|
|
92
97
|
}
|
|
93
98
|
|
|
@@ -1,23 +1,9 @@
|
|
|
1
1
|
import { createRequire } from 'module';
|
|
2
2
|
import { spawn, ChildProcess } from 'child_process';
|
|
3
|
-
import { openSync, closeSync } from 'fs';
|
|
3
|
+
import { openSync, closeSync, unlinkSync } from 'fs';
|
|
4
4
|
import { IMsgpackBackendSync } from '../interface.js';
|
|
5
5
|
import { findNapiBinary, findPackageRoot } from './platform.js';
|
|
6
|
-
|
|
7
|
-
// Import the NAPI module
|
|
8
|
-
// The addon is built to the nodejs_module directory
|
|
9
|
-
const addonPath = findNapiBinary();
|
|
10
|
-
// Try loading, but don't throw if it doesn't exist (will be caught in constructor)
|
|
11
|
-
let addon: any = null;
|
|
12
|
-
try {
|
|
13
|
-
if (addonPath) {
|
|
14
|
-
const require = createRequire(findPackageRoot()!);
|
|
15
|
-
addon = require(addonPath);
|
|
16
|
-
}
|
|
17
|
-
} catch (err) {
|
|
18
|
-
// Addon not built yet or not available
|
|
19
|
-
addon = null;
|
|
20
|
-
}
|
|
6
|
+
import { threadId } from 'worker_threads';
|
|
21
7
|
|
|
22
8
|
let instanceCounter = 0;
|
|
23
9
|
|
|
@@ -46,19 +32,30 @@ export class BarretenbergNativeShmSyncBackend implements IMsgpackBackendSync {
|
|
|
46
32
|
/**
|
|
47
33
|
* Create and initialize a shared memory backend.
|
|
48
34
|
* @param bbBinaryPath Path to bb binary
|
|
35
|
+
* @param napiPath Path to NAPI binary
|
|
49
36
|
* @param threads Optional number of threads
|
|
50
37
|
*/
|
|
51
38
|
static async new(
|
|
52
39
|
bbBinaryPath: string,
|
|
40
|
+
napiPath: string,
|
|
53
41
|
threads?: number,
|
|
54
42
|
logger?: (msg: string) => void,
|
|
55
43
|
): Promise<BarretenbergNativeShmSyncBackend> {
|
|
56
|
-
|
|
57
|
-
|
|
44
|
+
// Import the NAPI module
|
|
45
|
+
// The addon is built to the nodejs_module directory
|
|
46
|
+
const addonPath = findNapiBinary(napiPath);
|
|
47
|
+
// Try loading
|
|
48
|
+
let addon: any = null;
|
|
49
|
+
try {
|
|
50
|
+
const require = createRequire(findPackageRoot()!);
|
|
51
|
+
addon = require(addonPath!);
|
|
52
|
+
} catch (err) {
|
|
53
|
+
// Addon not built yet or not available
|
|
54
|
+
throw new Error('Shared memory sync NAPI not available.');
|
|
58
55
|
}
|
|
59
56
|
|
|
60
57
|
// Create a unique shared memory name
|
|
61
|
-
const shmName = `bb-sync-${process.pid}-${instanceCounter++}`;
|
|
58
|
+
const shmName = `bb-sync-${process.pid}-${threadId}-${instanceCounter++}`;
|
|
62
59
|
|
|
63
60
|
// If threads not set use 1 thread. We're not expected to do long lived work on sync backends.
|
|
64
61
|
const hwc = threads ? threads.toString() : '1';
|
|
@@ -74,6 +71,28 @@ export class BarretenbergNativeShmSyncBackend implements IMsgpackBackendSync {
|
|
|
74
71
|
logger(`BB process logs redirected to: ${logPath}`);
|
|
75
72
|
}
|
|
76
73
|
|
|
74
|
+
// Clean up any stale shared memory files from previous runs
|
|
75
|
+
// This handles the case where a previous process crashed without cleanup
|
|
76
|
+
const shmRequestPath = `/dev/shm/${shmName}_request`;
|
|
77
|
+
const shmResponsePath = `/dev/shm/${shmName}_response`;
|
|
78
|
+
try {
|
|
79
|
+
unlinkSync(shmRequestPath);
|
|
80
|
+
} catch (err) {
|
|
81
|
+
const isNotFound = err && typeof err === 'object' && 'code' in err && err.code === 'ENOENT';
|
|
82
|
+
if (!isNotFound) {
|
|
83
|
+
throw new Error(`Failed to clean up stale shared memory file ${shmRequestPath}: ${err}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
unlinkSync(shmResponsePath);
|
|
89
|
+
} catch (err) {
|
|
90
|
+
const isNotFound = err && typeof err === 'object' && 'code' in err && err.code === 'ENOENT';
|
|
91
|
+
if (!isNotFound) {
|
|
92
|
+
throw new Error(`Failed to clean up stale shared memory file ${shmResponsePath}: ${err}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
77
96
|
// Spawn bb process with shared memory mode (SPSC-only, no max-clients needed)
|
|
78
97
|
const args = ['msgpack', 'run', '--input', `${shmName}.shm`, '--request-ring-size', `${1024 * 1024 * 4}`];
|
|
79
98
|
const bbProcess = spawn(bbBinaryPath, args, {
|
|
@@ -3,21 +3,7 @@ import { spawn, ChildProcess } from 'child_process';
|
|
|
3
3
|
import { openSync, closeSync } from 'fs';
|
|
4
4
|
import { IMsgpackBackendAsync } from '../interface.js';
|
|
5
5
|
import { findNapiBinary, findPackageRoot } from './platform.js';
|
|
6
|
-
|
|
7
|
-
// Import the NAPI module
|
|
8
|
-
// The addon is built to the nodejs_module directory
|
|
9
|
-
const addonPath = findNapiBinary();
|
|
10
|
-
// Try loading, but don't throw if it doesn't exist (will be caught in constructor)
|
|
11
|
-
let addon: any = null;
|
|
12
|
-
try {
|
|
13
|
-
if (addonPath) {
|
|
14
|
-
const require = createRequire(findPackageRoot()!);
|
|
15
|
-
addon = require(addonPath);
|
|
16
|
-
}
|
|
17
|
-
} catch (err) {
|
|
18
|
-
// Addon not built yet or not available
|
|
19
|
-
addon = null;
|
|
20
|
-
}
|
|
6
|
+
import { threadId } from 'worker_threads';
|
|
21
7
|
|
|
22
8
|
let instanceCounter = 0;
|
|
23
9
|
|
|
@@ -86,18 +72,28 @@ export class BarretenbergNativeShmAsyncBackend implements IMsgpackBackendAsync {
|
|
|
86
72
|
*/
|
|
87
73
|
static async new(
|
|
88
74
|
bbBinaryPath: string,
|
|
75
|
+
napiPath: string,
|
|
89
76
|
threads?: number,
|
|
90
77
|
logger?: (msg: string) => void,
|
|
91
78
|
): Promise<BarretenbergNativeShmAsyncBackend> {
|
|
92
|
-
|
|
79
|
+
// Import the NAPI module
|
|
80
|
+
// The addon is built to the nodejs_module directory
|
|
81
|
+
const addonPath = findNapiBinary(napiPath);
|
|
82
|
+
// Try loading
|
|
83
|
+
let addon: any = null;
|
|
84
|
+
try {
|
|
85
|
+
const require = createRequire(findPackageRoot()!);
|
|
86
|
+
addon = require(addonPath!);
|
|
87
|
+
} catch (err) {
|
|
88
|
+
// Addon not built yet or not available
|
|
93
89
|
throw new Error('Shared memory async NAPI not available.');
|
|
94
90
|
}
|
|
95
91
|
|
|
96
92
|
// Create a unique shared memory name
|
|
97
|
-
const shmName = `bb-async-${process.pid}-${instanceCounter++}`;
|
|
93
|
+
const shmName = `bb-async-${process.pid}-${threadId}-${instanceCounter++}`;
|
|
98
94
|
|
|
99
|
-
// If threads not set use num cpu cores, max
|
|
100
|
-
const hwc = threads ? threads.toString() : '
|
|
95
|
+
// If threads not set use num cpu cores, max 16 (same as socket backend)
|
|
96
|
+
const hwc = threads ? threads.toString() : '16';
|
|
101
97
|
const env = { ...process.env, HARDWARE_CONCURRENCY: hwc };
|
|
102
98
|
|
|
103
99
|
// Set up file logging if logger is provided
|
|
@@ -4,8 +4,10 @@ import * as fs from 'fs';
|
|
|
4
4
|
import * as os from 'os';
|
|
5
5
|
import * as path from 'path';
|
|
6
6
|
import { IMsgpackBackendAsync } from '../interface.js';
|
|
7
|
-
import { findPackageRoot } from './platform.js';
|
|
8
7
|
import readline from 'readline';
|
|
8
|
+
import { threadId } from 'worker_threads';
|
|
9
|
+
|
|
10
|
+
let instanceCounter = 0;
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* Asynchronous native backend that communicates with bb binary via Unix Domain Socket.
|
|
@@ -43,7 +45,7 @@ export class BarretenbergNativeSocketAsyncBackend implements IMsgpackBackendAsyn
|
|
|
43
45
|
|
|
44
46
|
constructor(bbBinaryPath: string, threads?: number, logger?: (msg: string) => void) {
|
|
45
47
|
// Create a unique socket path in temp directory
|
|
46
|
-
this.socketPath = path.join(os.tmpdir(), `bb-${process.pid}-${
|
|
48
|
+
this.socketPath = path.join(os.tmpdir(), `bb-${process.pid}-${threadId}-${instanceCounter++}.sock`);
|
|
47
49
|
|
|
48
50
|
// Ensure socket path doesn't already exist (cleanup from previous crashes)
|
|
49
51
|
if (fs.existsSync(this.socketPath)) {
|
|
@@ -58,9 +60,9 @@ export class BarretenbergNativeSocketAsyncBackend implements IMsgpackBackendAsyn
|
|
|
58
60
|
connectionReject = reject;
|
|
59
61
|
});
|
|
60
62
|
|
|
61
|
-
// If threads not set use num cpu cores, max
|
|
62
|
-
const hwc = threads ? threads.toString() : Math.min(
|
|
63
|
-
const env = { ...process.env, HARDWARE_CONCURRENCY:
|
|
63
|
+
// If threads not set use num cpu cores, max 16.
|
|
64
|
+
const hwc = threads ? threads.toString() : Math.min(16, os.cpus().length).toString();
|
|
65
|
+
const env = { ...process.env, HARDWARE_CONCURRENCY: hwc };
|
|
64
66
|
|
|
65
67
|
// Spawn bb process - it will create the socket server
|
|
66
68
|
const args = ['msgpack', 'run', '--input', this.socketPath];
|
|
@@ -24,7 +24,12 @@ export function findPackageRoot(): string | null {
|
|
|
24
24
|
while (currentDir !== root) {
|
|
25
25
|
const packageJsonPath = path.join(currentDir, 'package.json');
|
|
26
26
|
if (fs.existsSync(packageJsonPath)) {
|
|
27
|
-
|
|
27
|
+
// Check if this is the actual package root by verifying it has a 'build' directory
|
|
28
|
+
// This ensures we skip intermediate package.json files (e.g., in dest/node-cjs/)
|
|
29
|
+
const buildDir = path.join(currentDir, 'build');
|
|
30
|
+
if (fs.existsSync(buildDir)) {
|
|
31
|
+
return currentDir;
|
|
32
|
+
}
|
|
28
33
|
}
|
|
29
34
|
currentDir = path.dirname(currentDir);
|
|
30
35
|
}
|