@noir-lang/noir_js 0.29.0 → 0.30.0
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/lib/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export { ecdsa_secp256r1_verify, ecdsa_secp256k1_verify, keccak256, blake2s256,
|
|
|
5
5
|
export { InputMap } from '@noir-lang/noirc_abi';
|
|
6
6
|
export { WitnessMap, ForeignCallHandler, ForeignCallInput, ForeignCallOutput } from '@noir-lang/acvm_js';
|
|
7
7
|
export { Noir } from './program.js';
|
|
8
|
+
export { ErrorWithPayload } from './witness_generation.js';
|
|
8
9
|
/** @ignore */
|
|
9
10
|
export { acvm, abi };
|
|
10
11
|
export { CompiledCircuit, ProofData };
|
|
@@ -19,15 +19,30 @@ const defaultForeignCallHandler = async (name, args) => {
|
|
|
19
19
|
// If a user needs to print values then they should provide a custom foreign call handler.
|
|
20
20
|
return [];
|
|
21
21
|
}
|
|
22
|
-
else if (name == 'assert_message') {
|
|
23
|
-
// By default we do not do anything for `assert_message` foreign calls due to a need for formatting,
|
|
24
|
-
// however we provide an empty response in order to not halt execution.
|
|
25
|
-
//
|
|
26
|
-
// If a user needs to use dynamic assertion messages then they should provide a custom foreign call handler.
|
|
27
|
-
return [];
|
|
28
|
-
}
|
|
29
22
|
throw Error(`Unexpected oracle during execution: ${name}(${args.join(', ')})`);
|
|
30
23
|
};
|
|
24
|
+
function parseErrorPayload(abi, originalError) {
|
|
25
|
+
const payload = originalError.rawAssertionPayload;
|
|
26
|
+
if (!payload)
|
|
27
|
+
return originalError;
|
|
28
|
+
const enrichedError = originalError;
|
|
29
|
+
try {
|
|
30
|
+
// Decode the payload
|
|
31
|
+
const decodedPayload = (0, noirc_abi_1.abiDecodeError)(abi, payload);
|
|
32
|
+
if (typeof decodedPayload === 'string') {
|
|
33
|
+
// If it's a string, just add it to the error message
|
|
34
|
+
enrichedError.message = `Circuit execution failed: ${decodedPayload}`;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
// If not, attach the payload to the original error
|
|
38
|
+
enrichedError.decodedAssertionPayload = decodedPayload;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch (_errorDecoding) {
|
|
42
|
+
// Ignore errors decoding the payload
|
|
43
|
+
}
|
|
44
|
+
return enrichedError;
|
|
45
|
+
}
|
|
31
46
|
// Generates the witnesses needed to feed into the chosen proving system
|
|
32
47
|
async function generateWitness(compiledProgram, inputs, foreignCallHandler = defaultForeignCallHandler) {
|
|
33
48
|
// Throws on ABI encoding error
|
|
@@ -39,6 +54,10 @@ async function generateWitness(compiledProgram, inputs, foreignCallHandler = def
|
|
|
39
54
|
return solvedWitness;
|
|
40
55
|
}
|
|
41
56
|
catch (err) {
|
|
57
|
+
// Typescript types catched errors as unknown or any, so we need to narrow its type to check if it has raw assertion payload.
|
|
58
|
+
if (typeof err === 'object' && err !== null && 'rawAssertionPayload' in err) {
|
|
59
|
+
throw parseErrorPayload(compiledProgram.abi, err);
|
|
60
|
+
}
|
|
42
61
|
throw new Error(`Circuit execution failed: ${err}`);
|
|
43
62
|
}
|
|
44
63
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { InputMap } from '@noir-lang/noirc_abi';
|
|
2
|
-
import { WitnessStack, ForeignCallHandler } from '@noir-lang/acvm_js';
|
|
2
|
+
import { WitnessStack, ForeignCallHandler, ExecutionError } from '@noir-lang/acvm_js';
|
|
3
3
|
import { CompiledCircuit } from '@noir-lang/types';
|
|
4
|
+
export type ErrorWithPayload = ExecutionError & {
|
|
5
|
+
decodedAssertionPayload?: any;
|
|
6
|
+
};
|
|
4
7
|
export declare function generateWitness(compiledProgram: CompiledCircuit, inputs: InputMap, foreignCallHandler?: ForeignCallHandler): Promise<WitnessStack>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { abiEncode } from '@noir-lang/noirc_abi';
|
|
1
|
+
import { abiDecodeError, abiEncode } from '@noir-lang/noirc_abi';
|
|
2
2
|
import { base64Decode } from "./base64_decode.mjs";
|
|
3
3
|
import { createBlackBoxSolver, executeProgramWithBlackBoxSolver, } from '@noir-lang/acvm_js';
|
|
4
4
|
let solver;
|
|
@@ -16,15 +16,30 @@ const defaultForeignCallHandler = async (name, args) => {
|
|
|
16
16
|
// If a user needs to print values then they should provide a custom foreign call handler.
|
|
17
17
|
return [];
|
|
18
18
|
}
|
|
19
|
-
else if (name == 'assert_message') {
|
|
20
|
-
// By default we do not do anything for `assert_message` foreign calls due to a need for formatting,
|
|
21
|
-
// however we provide an empty response in order to not halt execution.
|
|
22
|
-
//
|
|
23
|
-
// If a user needs to use dynamic assertion messages then they should provide a custom foreign call handler.
|
|
24
|
-
return [];
|
|
25
|
-
}
|
|
26
19
|
throw Error(`Unexpected oracle during execution: ${name}(${args.join(', ')})`);
|
|
27
20
|
};
|
|
21
|
+
function parseErrorPayload(abi, originalError) {
|
|
22
|
+
const payload = originalError.rawAssertionPayload;
|
|
23
|
+
if (!payload)
|
|
24
|
+
return originalError;
|
|
25
|
+
const enrichedError = originalError;
|
|
26
|
+
try {
|
|
27
|
+
// Decode the payload
|
|
28
|
+
const decodedPayload = abiDecodeError(abi, payload);
|
|
29
|
+
if (typeof decodedPayload === 'string') {
|
|
30
|
+
// If it's a string, just add it to the error message
|
|
31
|
+
enrichedError.message = `Circuit execution failed: ${decodedPayload}`;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
// If not, attach the payload to the original error
|
|
35
|
+
enrichedError.decodedAssertionPayload = decodedPayload;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (_errorDecoding) {
|
|
39
|
+
// Ignore errors decoding the payload
|
|
40
|
+
}
|
|
41
|
+
return enrichedError;
|
|
42
|
+
}
|
|
28
43
|
// Generates the witnesses needed to feed into the chosen proving system
|
|
29
44
|
export async function generateWitness(compiledProgram, inputs, foreignCallHandler = defaultForeignCallHandler) {
|
|
30
45
|
// Throws on ABI encoding error
|
|
@@ -36,6 +51,10 @@ export async function generateWitness(compiledProgram, inputs, foreignCallHandle
|
|
|
36
51
|
return solvedWitness;
|
|
37
52
|
}
|
|
38
53
|
catch (err) {
|
|
54
|
+
// Typescript types catched errors as unknown or any, so we need to narrow its type to check if it has raw assertion payload.
|
|
55
|
+
if (typeof err === 'object' && err !== null && 'rawAssertionPayload' in err) {
|
|
56
|
+
throw parseErrorPayload(compiledProgram.abi, err);
|
|
57
|
+
}
|
|
39
58
|
throw new Error(`Circuit execution failed: ${err}`);
|
|
40
59
|
}
|
|
41
60
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"contributors": [
|
|
4
4
|
"The Noir Team <team@noir-lang.org>"
|
|
5
5
|
],
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.30.0",
|
|
7
7
|
"packageManager": "yarn@3.5.1",
|
|
8
8
|
"license": "(MIT OR Apache-2.0)",
|
|
9
9
|
"type": "module",
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"url": "https://github.com/noir-lang/noir/issues"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@noir-lang/acvm_js": "0.
|
|
21
|
-
"@noir-lang/noirc_abi": "0.
|
|
22
|
-
"@noir-lang/types": "0.
|
|
20
|
+
"@noir-lang/acvm_js": "0.46.0",
|
|
21
|
+
"@noir-lang/noirc_abi": "0.30.0",
|
|
22
|
+
"@noir-lang/types": "0.30.0"
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
25
|
"lib",
|