@aztec/simulator 0.86.0 → 0.87.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/dest/common/errors.d.ts +3 -6
- package/dest/common/errors.d.ts.map +1 -1
- package/dest/common/errors.js +50 -31
- package/dest/private/acvm/acvm.d.ts +0 -2
- package/dest/private/acvm/acvm.d.ts.map +1 -1
- package/dest/private/acvm/acvm.js +2 -2
- package/dest/private/acvm/deserialize.d.ts +0 -2
- package/dest/private/acvm/deserialize.d.ts.map +1 -1
- package/dest/private/acvm/oracle/oracle.d.ts +2 -2
- package/dest/private/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/private/acvm/oracle/oracle.js +30 -33
- package/dest/private/acvm/oracle/typed_oracle.d.ts +1 -3
- package/dest/private/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/private/acvm/serialize.d.ts +8 -2
- package/dest/private/acvm/serialize.d.ts.map +1 -1
- package/dest/private/acvm/serialize.js +26 -0
- package/dest/private/index.d.ts +3 -0
- package/dest/private/index.d.ts.map +1 -1
- package/dest/private/index.js +3 -0
- package/dest/private/private_execution.d.ts.map +1 -1
- package/dest/private/private_execution.js +7 -1
- package/dest/private/providers/acvm_native.d.ts +0 -2
- package/dest/private/providers/acvm_native.d.ts.map +1 -1
- package/dest/private/providers/acvm_native.js +1 -1
- package/dest/private/providers/circuit_recording/circuit_recorder.d.ts +0 -2
- package/dest/private/providers/circuit_recording/circuit_recorder.d.ts.map +1 -1
- package/dest/private/providers/simulation_provider.d.ts.map +1 -1
- package/dest/private/providers/simulation_provider.js +14 -16
- package/dest/private/simulator.d.ts.map +1 -1
- package/dest/private/utility_execution_oracle.d.ts +0 -2
- package/dest/private/utility_execution_oracle.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.js +2 -2
- package/dest/public/avm/avm_execution_environment.d.ts +2 -1
- package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/public/avm/avm_execution_environment.js +4 -2
- package/dest/public/avm/avm_gas.d.ts +0 -15
- package/dest/public/avm/avm_gas.d.ts.map +1 -1
- package/dest/public/avm/avm_gas.js +0 -18
- package/dest/public/avm/avm_memory_types.d.ts +84 -86
- package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.d.ts +1 -3
- package/dest/public/avm/avm_simulator.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.js +3 -3
- package/dest/public/avm/avm_simulator_interface.d.ts +0 -2
- package/dest/public/avm/avm_simulator_interface.d.ts.map +1 -1
- package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
- package/dest/public/avm/fixtures/initializers.js +1 -1
- package/dest/public/avm/fixtures/utils.d.ts +0 -10
- package/dest/public/avm/fixtures/utils.d.ts.map +1 -1
- package/dest/public/avm/fixtures/utils.js +0 -42
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/accrued_substate.js +7 -7
- package/dest/public/avm/opcodes/addressing_mode.d.ts +7 -6
- package/dest/public/avm/opcodes/addressing_mode.d.ts.map +1 -1
- package/dest/public/avm/opcodes/addressing_mode.js +18 -15
- package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/public/avm/opcodes/arithmetic.js +1 -1
- package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/public/avm/opcodes/bitwise.js +2 -2
- package/dest/public/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/public/avm/opcodes/comparators.js +1 -1
- package/dest/public/avm/opcodes/contract.d.ts +1 -2
- package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/public/avm/opcodes/contract.js +8 -9
- package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -1
- package/dest/public/avm/opcodes/control_flow.js +1 -1
- package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/public/avm/opcodes/conversion.js +1 -1
- package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/public/avm/opcodes/ec_add.js +1 -1
- package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/public/avm/opcodes/environment_getters.js +1 -1
- package/dest/public/avm/opcodes/external_calls.d.ts +6 -6
- package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/public/avm/opcodes/external_calls.js +22 -22
- package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/public/avm/opcodes/hashing.js +3 -3
- package/dest/public/avm/opcodes/instruction.d.ts +0 -2
- package/dest/public/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.d.ts +4 -4
- package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.js +16 -16
- package/dest/public/avm/opcodes/misc.d.ts.map +1 -1
- package/dest/public/avm/opcodes/misc.js +18 -11
- package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/public/avm/opcodes/storage.js +2 -2
- package/dest/public/avm/serialization/buffer_cursor.d.ts +0 -2
- package/dest/public/avm/serialization/buffer_cursor.d.ts.map +1 -1
- package/dest/public/avm/serialization/bytecode_serialization.d.ts +0 -2
- package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/instruction_serialization.d.ts +0 -2
- package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/public/executor_metrics.d.ts +3 -3
- package/dest/public/executor_metrics.d.ts.map +1 -1
- package/dest/public/executor_metrics.js +6 -6
- package/dest/public/executor_metrics_interface.d.ts +1 -1
- package/dest/public/executor_metrics_interface.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +3 -3
- package/dest/public/fixtures/utils.d.ts.map +1 -1
- package/dest/public/fixtures/utils.js +19 -26
- package/dest/public/hinting_db_sources.d.ts +0 -2
- package/dest/public/hinting_db_sources.d.ts.map +1 -1
- package/dest/public/hinting_db_sources.js +9 -2
- package/dest/public/public_processor/public_processor.d.ts +5 -7
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +10 -7
- package/dest/public/public_tx_simulator/apps_tests/amm_test.js +5 -5
- package/dest/public/public_tx_simulator/apps_tests/token_test.js +6 -6
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +1 -1
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +3 -3
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +37 -34
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +2 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +15 -4
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +1 -1
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +2 -2
- package/dest/public/side_effect_trace.d.ts +2 -39
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +8 -32
- package/dest/public/side_effect_trace_interface.d.ts +0 -4
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/dest/public/state_manager/nullifiers.d.ts.map +1 -1
- package/dest/public/state_manager/public_storage.d.ts.map +1 -1
- package/dest/public/state_manager/state_manager.d.ts +6 -4
- package/dest/public/state_manager/state_manager.d.ts.map +1 -1
- package/dest/public/state_manager/state_manager.js +6 -3
- package/dest/public/test_executor_metrics.d.ts +5 -4
- package/dest/public/test_executor_metrics.d.ts.map +1 -1
- package/dest/public/test_executor_metrics.js +47 -11
- package/dest/public/unique_class_ids.d.ts.map +1 -1
- package/dest/test/utils.d.ts.map +1 -1
- package/package.json +18 -17
- package/src/common/errors.ts +77 -41
- package/src/private/acvm/acvm.ts +2 -2
- package/src/private/acvm/oracle/oracle.ts +38 -31
- package/src/private/acvm/oracle/typed_oracle.ts +1 -1
- package/src/private/acvm/serialize.ts +35 -0
- package/src/private/index.ts +3 -0
- package/src/private/pick_notes.ts +4 -4
- package/src/private/private_execution.ts +8 -0
- package/src/private/providers/acvm_native.ts +6 -2
- package/src/private/providers/simulation_provider.ts +14 -16
- package/src/private/simulator.ts +4 -1
- package/src/public/avm/avm_contract_call_result.ts +2 -2
- package/src/public/avm/avm_execution_environment.ts +7 -1
- package/src/public/avm/avm_gas.ts +0 -20
- package/src/public/avm/avm_simulator.ts +3 -1
- package/src/public/avm/fixtures/initializers.ts +1 -0
- package/src/public/avm/fixtures/utils.ts +0 -66
- package/src/public/avm/opcodes/accrued_substate.ts +31 -11
- package/src/public/avm/opcodes/addressing_mode.ts +23 -20
- package/src/public/avm/opcodes/arithmetic.ts +2 -1
- package/src/public/avm/opcodes/bitwise.ts +9 -3
- package/src/public/avm/opcodes/comparators.ts +2 -1
- package/src/public/avm/opcodes/contract.ts +7 -6
- package/src/public/avm/opcodes/control_flow.ts +7 -2
- package/src/public/avm/opcodes/conversion.ts +2 -1
- package/src/public/avm/opcodes/ec_add.ts +2 -1
- package/src/public/avm/opcodes/environment_getters.ts +7 -2
- package/src/public/avm/opcodes/external_calls.ts +26 -14
- package/src/public/avm/opcodes/hashing.ts +17 -5
- package/src/public/avm/opcodes/memory.ts +33 -15
- package/src/public/avm/opcodes/misc.ts +23 -15
- package/src/public/avm/opcodes/storage.ts +9 -3
- package/src/public/avm/serialization/buffer_cursor.ts +4 -1
- package/src/public/executor_metrics.ts +11 -6
- package/src/public/executor_metrics_interface.ts +1 -1
- package/src/public/fixtures/public_tx_simulation_tester.ts +3 -2
- package/src/public/fixtures/utils.ts +21 -28
- package/src/public/hinting_db_sources.ts +17 -4
- package/src/public/public_processor/public_processor.ts +11 -5
- package/src/public/public_tx_simulator/apps_tests/amm_test.ts +5 -5
- package/src/public/public_tx_simulator/apps_tests/token_test.ts +6 -6
- package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +3 -2
- package/src/public/public_tx_simulator/public_tx_context.ts +96 -81
- package/src/public/public_tx_simulator/public_tx_simulator.ts +14 -3
- package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +10 -1
- package/src/public/side_effect_trace.ts +7 -111
- package/src/public/side_effect_trace_interface.ts +0 -4
- package/src/public/state_manager/state_manager.ts +13 -5
- package/src/public/test_executor_metrics.ts +60 -13
- package/src/public/avm/opcodes/.eslintrc.cjs +0 -8
package/src/common/errors.ts
CHANGED
|
@@ -2,7 +2,14 @@ import type { Fr } from '@aztec/foundation/fields';
|
|
|
2
2
|
import { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
3
3
|
import type { RawAssertionPayload } from '@aztec/noir-acvm_js';
|
|
4
4
|
import { abiDecodeError } from '@aztec/noir-noirc_abi';
|
|
5
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
BrilligFunctionId,
|
|
7
|
+
DebugFileMap,
|
|
8
|
+
DebugInfo,
|
|
9
|
+
FunctionAbi,
|
|
10
|
+
LocationNodeDebugInfo,
|
|
11
|
+
OpcodeLocation,
|
|
12
|
+
} from '@aztec/stdlib/abi';
|
|
6
13
|
import {
|
|
7
14
|
type FailingFunction,
|
|
8
15
|
type NoirCallStack,
|
|
@@ -76,38 +83,42 @@ export function createSimulationError(error: Error, revertData?: Fr[]): Simulati
|
|
|
76
83
|
}
|
|
77
84
|
|
|
78
85
|
/**
|
|
79
|
-
*
|
|
80
|
-
* @param opcodeLocation - The opcode location to extract from. It should be in the format `acirLocation.brilligLocation` or `acirLocation`.
|
|
81
|
-
* @returns The brillig location if the opcode location contains one.
|
|
82
|
-
*/
|
|
83
|
-
function extractBrilligLocation(opcodeLocation: string): string | undefined {
|
|
84
|
-
const splitted = opcodeLocation.split('.');
|
|
85
|
-
if (splitted.length === 2) {
|
|
86
|
-
return splitted[1];
|
|
87
|
-
}
|
|
88
|
-
return undefined;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Extracts the call stack from the location of a failing opcode and the debug metadata.
|
|
93
|
-
* One opcode can point to multiple calls due to inlining.
|
|
86
|
+
* Resolves the source code locations from an array of opcode locations
|
|
94
87
|
*/
|
|
95
|
-
function
|
|
96
|
-
|
|
97
|
-
debug:
|
|
88
|
+
export function resolveOpcodeLocations(
|
|
89
|
+
opcodeLocations: OpcodeLocation[],
|
|
90
|
+
debug: DebugInfo,
|
|
91
|
+
files: DebugFileMap,
|
|
98
92
|
brilligFunctionId?: BrilligFunctionId,
|
|
99
93
|
): SourceCodeLocation[] {
|
|
100
|
-
|
|
94
|
+
let locations = opcodeLocations.flatMap(opcodeLocation =>
|
|
95
|
+
getSourceCodeLocationsFromOpcodeLocation(opcodeLocation, debug, files, brilligFunctionId),
|
|
96
|
+
);
|
|
101
97
|
|
|
102
|
-
|
|
103
|
-
if (
|
|
104
|
-
const
|
|
105
|
-
if (
|
|
106
|
-
|
|
98
|
+
// Adds the acir call stack if the last location is a brillig opcode
|
|
99
|
+
if (locations.length > 0) {
|
|
100
|
+
const decomposedOpcodeLocation = opcodeLocations[opcodeLocations.length - 1].split('.');
|
|
101
|
+
if (decomposedOpcodeLocation.length === 2) {
|
|
102
|
+
const acirCallstackId = debug.acir_locations[decomposedOpcodeLocation[0]];
|
|
103
|
+
if (acirCallstackId !== undefined) {
|
|
104
|
+
const callStack = debug.location_tree.locations[acirCallstackId];
|
|
105
|
+
const acirCallstack = getCallStackFromLocationNode(callStack, debug.location_tree.locations, files);
|
|
106
|
+
locations = acirCallstack.concat(locations);
|
|
107
|
+
}
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
|
-
return
|
|
110
|
-
|
|
110
|
+
return locations;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function getCallStackFromLocationNode(
|
|
114
|
+
callStack: LocationNodeDebugInfo,
|
|
115
|
+
locationTree: LocationNodeDebugInfo[],
|
|
116
|
+
files: DebugFileMap,
|
|
117
|
+
): SourceCodeLocation[] {
|
|
118
|
+
const result: SourceCodeLocation[] = [];
|
|
119
|
+
|
|
120
|
+
while (callStack.parent !== null) {
|
|
121
|
+
const { file: fileId, span } = callStack.value;
|
|
111
122
|
|
|
112
123
|
const { path, source } = files[fileId];
|
|
113
124
|
|
|
@@ -118,30 +129,55 @@ function getSourceCodeLocationsFromOpcodeLocation(
|
|
|
118
129
|
const line = previousLines.length;
|
|
119
130
|
const column = previousLines[previousLines.length - 1].length + 1;
|
|
120
131
|
|
|
121
|
-
|
|
132
|
+
// Unshift since we are exploring child nodes first
|
|
133
|
+
result.unshift({
|
|
122
134
|
filePath: path,
|
|
123
135
|
line,
|
|
124
136
|
column,
|
|
125
137
|
fileSource: source,
|
|
126
138
|
locationText,
|
|
127
|
-
};
|
|
128
|
-
});
|
|
129
|
-
}
|
|
139
|
+
});
|
|
130
140
|
|
|
141
|
+
callStack = locationTree[callStack.parent];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
131
146
|
/**
|
|
132
|
-
* Extracts the
|
|
133
|
-
*
|
|
134
|
-
* @param debug - The debug metadata of the function.
|
|
135
|
-
* @returns The source code locations.
|
|
147
|
+
* Extracts the call stack from the location of a failing opcode and the debug metadata.
|
|
148
|
+
* One opcode can point to multiple calls due to inlining.
|
|
136
149
|
*/
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
debug:
|
|
150
|
+
function getSourceCodeLocationsFromOpcodeLocation(
|
|
151
|
+
opcodeLocation: string,
|
|
152
|
+
debug: DebugInfo,
|
|
153
|
+
files: DebugFileMap,
|
|
140
154
|
brilligFunctionId?: BrilligFunctionId,
|
|
141
155
|
): SourceCodeLocation[] {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
)
|
|
156
|
+
let callStackID = debug.acir_locations[opcodeLocation];
|
|
157
|
+
const brilligLocation = extractBrilligLocation(opcodeLocation);
|
|
158
|
+
if (brilligFunctionId !== undefined && brilligLocation !== undefined) {
|
|
159
|
+
callStackID = debug.brillig_locations[brilligFunctionId][brilligLocation];
|
|
160
|
+
if (callStackID === undefined) {
|
|
161
|
+
return [];
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (callStackID === undefined) {
|
|
166
|
+
return [];
|
|
167
|
+
}
|
|
168
|
+
const callStack = debug.location_tree.locations[callStackID];
|
|
169
|
+
return getCallStackFromLocationNode(callStack, debug.location_tree.locations, files);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Extracts a brillig location from an opcode location.
|
|
174
|
+
*/
|
|
175
|
+
function extractBrilligLocation(opcodeLocation: string): string | undefined {
|
|
176
|
+
const splitted = opcodeLocation.split('.');
|
|
177
|
+
if (splitted.length === 2) {
|
|
178
|
+
return splitted[1];
|
|
179
|
+
}
|
|
180
|
+
return undefined;
|
|
145
181
|
}
|
|
146
182
|
|
|
147
183
|
export function resolveAssertionMessage(errorPayload: RawAssertionPayload, abi: FunctionAbi): string | undefined {
|
package/src/private/acvm/acvm.ts
CHANGED
|
@@ -103,8 +103,8 @@ export function extractCallStack(
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
try {
|
|
106
|
-
return resolveOpcodeLocations(callStack, debug, brilligFunctionId);
|
|
107
|
-
} catch
|
|
106
|
+
return resolveOpcodeLocations(callStack, debug.debugSymbols, debug.files, brilligFunctionId);
|
|
107
|
+
} catch {
|
|
108
108
|
return callStack;
|
|
109
109
|
}
|
|
110
110
|
}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { Fr, Point } from '@aztec/foundation/fields';
|
|
2
2
|
import { EventSelector, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
3
3
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
-
import { ContractClassLog, LogWithTxData } from '@aztec/stdlib/logs';
|
|
4
|
+
import { ContractClassLog, ContractClassLogFields, LogWithTxData } from '@aztec/stdlib/logs';
|
|
5
5
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
6
6
|
import { TxHash } from '@aztec/stdlib/tx';
|
|
7
7
|
|
|
8
8
|
import type { ACVMField } from '../acvm_types.js';
|
|
9
9
|
import { fromBoundedVec, fromUintArray, fromUintBoundedVec } from '../deserialize.js';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
arrayOfArraysToBoundedVecOfArrays,
|
|
12
|
+
bufferToBoundedVec,
|
|
13
|
+
toACVMField,
|
|
14
|
+
toACVMFieldSingleOrArray,
|
|
15
|
+
} from '../serialize.js';
|
|
11
16
|
import type { TypedOracle } from './typed_oracle.js';
|
|
12
17
|
|
|
13
18
|
/**
|
|
@@ -169,8 +174,9 @@ export class Oracle {
|
|
|
169
174
|
[limit]: ACVMField[],
|
|
170
175
|
[offset]: ACVMField[],
|
|
171
176
|
[status]: ACVMField[],
|
|
172
|
-
[
|
|
173
|
-
|
|
177
|
+
[maxNotes]: ACVMField[],
|
|
178
|
+
[packedRetrievedNoteLength]: ACVMField[],
|
|
179
|
+
): Promise<(ACVMField | ACVMField[])[]> {
|
|
174
180
|
const noteDatas = await this.typedOracle.getNotes(
|
|
175
181
|
Fr.fromString(storageSlot),
|
|
176
182
|
+numSelects,
|
|
@@ -188,32 +194,30 @@ export class Oracle {
|
|
|
188
194
|
+status,
|
|
189
195
|
);
|
|
190
196
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
197
|
+
if (noteDatas.length > 0) {
|
|
198
|
+
const noteLength = noteDatas[0].note.items.length;
|
|
199
|
+
if (!noteDatas.every(({ note }) => noteLength === note.items.length)) {
|
|
200
|
+
throw new Error('Notes should all be the same length.');
|
|
201
|
+
}
|
|
194
202
|
}
|
|
195
203
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
// Values indicates whether the note is settled or transient.
|
|
199
|
-
const noteTypes = {
|
|
200
|
-
isSettled: new Fr(0),
|
|
201
|
-
isTransient: new Fr(1),
|
|
202
|
-
};
|
|
203
|
-
const flattenData = noteDatas.flatMap(({ nonce, note, index }) => [
|
|
204
|
-
nonce,
|
|
205
|
-
index === undefined ? noteTypes.isTransient : noteTypes.isSettled,
|
|
206
|
-
...note.items,
|
|
207
|
-
]);
|
|
208
|
-
|
|
209
|
-
const returnFieldSize = +returnSize;
|
|
210
|
-
const returnData = [noteDatas.length, contractAddress, ...flattenData].map(v => toACVMField(v));
|
|
211
|
-
if (returnData.length > returnFieldSize) {
|
|
212
|
-
throw new Error(`Return data size too big. Maximum ${returnFieldSize} fields. Got ${flattenData.length}.`);
|
|
213
|
-
}
|
|
204
|
+
// The expected return type is a BoundedVec<[Field; packedRetrievedNoteLength], maxNotes> where each
|
|
205
|
+
// array is structured as [contract_address, nonce, nonzero_note_hash_counter, ...packed_note].
|
|
214
206
|
|
|
215
|
-
const
|
|
216
|
-
|
|
207
|
+
const returnDataAsArrayOfArrays = noteDatas.map(({ contractAddress, nonce, index, note }) => {
|
|
208
|
+
// If index is undefined, the note is transient which implies that the nonzero_note_hash_counter has to be true
|
|
209
|
+
const noteIsTransient = index === undefined;
|
|
210
|
+
const nonzeroNoteHashCounter = noteIsTransient ? true : false;
|
|
211
|
+
// If you change the array on the next line you have to change the `unpack_retrieved_note` function in
|
|
212
|
+
// `aztec/src/note/retrieved_note.nr`
|
|
213
|
+
return [contractAddress, nonce, nonzeroNoteHashCounter, ...note.items];
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// Now we convert each sub-array to an array of ACVMField
|
|
217
|
+
const returnDataAsArrayOfACVMFieldArrays = returnDataAsArrayOfArrays.map(subArray => subArray.map(toACVMField));
|
|
218
|
+
|
|
219
|
+
// At last we convert the array of arrays to a bounded vec of arrays
|
|
220
|
+
return arrayOfArraysToBoundedVecOfArrays(returnDataAsArrayOfACVMFieldArrays, +maxNotes, +packedRetrievedNoteLength);
|
|
217
221
|
}
|
|
218
222
|
|
|
219
223
|
notifyCreatedNote(
|
|
@@ -288,10 +292,11 @@ export class Oracle {
|
|
|
288
292
|
notifyCreatedContractClassLog(
|
|
289
293
|
[contractAddress]: ACVMField[],
|
|
290
294
|
message: ACVMField[],
|
|
295
|
+
[length]: ACVMField[],
|
|
291
296
|
[counter]: ACVMField[],
|
|
292
297
|
): Promise<ACVMField[]> {
|
|
293
|
-
const
|
|
294
|
-
const log = new ContractClassLog(new AztecAddress(Fr.fromString(contractAddress)),
|
|
298
|
+
const logFields = new ContractClassLogFields(message.map(Fr.fromString));
|
|
299
|
+
const log = new ContractClassLog(new AztecAddress(Fr.fromString(contractAddress)), logFields, +length);
|
|
295
300
|
|
|
296
301
|
this.typedOracle.notifyCreatedContractClassLog(log, +counter);
|
|
297
302
|
return Promise.resolve([]);
|
|
@@ -351,8 +356,10 @@ export class Oracle {
|
|
|
351
356
|
return [];
|
|
352
357
|
}
|
|
353
358
|
|
|
354
|
-
notifySetMinRevertibleSideEffectCounter([minRevertibleSideEffectCounter]: ACVMField[]): Promise<ACVMField[]> {
|
|
355
|
-
this.typedOracle.notifySetMinRevertibleSideEffectCounter(
|
|
359
|
+
async notifySetMinRevertibleSideEffectCounter([minRevertibleSideEffectCounter]: ACVMField[]): Promise<ACVMField[]> {
|
|
360
|
+
await this.typedOracle.notifySetMinRevertibleSideEffectCounter(
|
|
361
|
+
Fr.fromString(minRevertibleSideEffectCounter).toNumber(),
|
|
362
|
+
);
|
|
356
363
|
return Promise.resolve([]);
|
|
357
364
|
}
|
|
358
365
|
|
|
@@ -198,7 +198,7 @@ export abstract class TypedOracle {
|
|
|
198
198
|
return Promise.reject(new OracleMethodNotAvailableError('notifySetPublicTeardownFunctionCall'));
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
-
notifySetMinRevertibleSideEffectCounter(_minRevertibleSideEffectCounter: number): void {
|
|
201
|
+
notifySetMinRevertibleSideEffectCounter(_minRevertibleSideEffectCounter: number): Promise<void> {
|
|
202
202
|
throw new OracleMethodNotAvailableError('notifySetMinRevertibleSideEffectCounter');
|
|
203
203
|
}
|
|
204
204
|
|
|
@@ -86,3 +86,38 @@ export function arrayToBoundedVec(bVecStorage: ACVMField[], maxLen: number): [AC
|
|
|
86
86
|
const len = toACVMField(BigInt(bVecStorage.length));
|
|
87
87
|
return [storage, len];
|
|
88
88
|
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Converts an array of arrays representing Noir BoundedVec of nested arrays into its Noir serialized form.
|
|
92
|
+
* @param bVecStorage - The array underlying the BoundedVec.
|
|
93
|
+
* @param maxLen - The max length of the BoundedVec (max num of the nested arrays in the BoundedVec).
|
|
94
|
+
* @param nestedArrayLength - The length of the nested arrays (each nested array has to have the same length).
|
|
95
|
+
* @returns Serialized BoundedVec following Noir intrinsic serialization.
|
|
96
|
+
*/
|
|
97
|
+
export function arrayOfArraysToBoundedVecOfArrays(
|
|
98
|
+
bVecStorage: ACVMField[][],
|
|
99
|
+
maxLen: number,
|
|
100
|
+
nestedArrayLength: number,
|
|
101
|
+
): [ACVMField[], ACVMField] {
|
|
102
|
+
if (bVecStorage.length > maxLen) {
|
|
103
|
+
throw new Error(`Array of length ${bVecStorage.length} larger than maxLen ${maxLen}`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Check that all nested arrays have length nestedArrayLength
|
|
107
|
+
if (!bVecStorage.every(nestedArray => nestedArray.length === nestedArrayLength)) {
|
|
108
|
+
throw new Error(
|
|
109
|
+
`Nested array length passed in from Noir does not correspond to the length obtained in TS: ${nestedArrayLength} !== ${bVecStorage[0].length}`,
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Flatten the array of arrays
|
|
114
|
+
const flattenedStorage = bVecStorage.flat();
|
|
115
|
+
|
|
116
|
+
// Calculate and add padding
|
|
117
|
+
const numFieldsToPad = maxLen * nestedArrayLength - flattenedStorage.length;
|
|
118
|
+
const flattenedStorageWithPadding = flattenedStorage.concat(Array(numFieldsToPad).fill(toACVMField(BigInt(0))));
|
|
119
|
+
|
|
120
|
+
// Return flattened array with padding and length
|
|
121
|
+
const len = toACVMField(BigInt(bVecStorage.length));
|
|
122
|
+
return [flattenedStorageWithPadding, len];
|
|
123
|
+
}
|
package/src/private/index.ts
CHANGED
|
@@ -9,6 +9,9 @@ export { ExecutionNoteCache } from './execution_note_cache.js';
|
|
|
9
9
|
export { extractPrivateCircuitPublicInputs, readCurrentClassId } from './private_execution.js';
|
|
10
10
|
export { witnessMapToFields } from './acvm/deserialize.js';
|
|
11
11
|
export { toACVMWitness } from './acvm/serialize.js';
|
|
12
|
+
export { executePrivateFunction } from './private_execution.js';
|
|
13
|
+
export { PrivateExecutionOracle } from './private_execution_oracle.js';
|
|
14
|
+
export { UtilityExecutionOracle } from './utility_execution_oracle.js';
|
|
12
15
|
export { extractCallStack } from './acvm/acvm.js';
|
|
13
16
|
export { type NoteData, TypedOracle } from './acvm/oracle/typed_oracle.js';
|
|
14
17
|
export { Oracle } from './acvm/oracle/oracle.js';
|
|
@@ -113,19 +113,19 @@ const sortNotes = (a: Fr[], b: Fr[], sorts: Sort[], level = 0): number => {
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
const { selector, order } = sorts[level];
|
|
116
|
-
if (order === 0) {
|
|
116
|
+
if (order === (0 as SortOrder)) {
|
|
117
117
|
return 0;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
const aValue = selectPropertyFromPackedNoteContent(a, selector);
|
|
121
121
|
const bValue = selectPropertyFromPackedNoteContent(b, selector);
|
|
122
122
|
|
|
123
|
-
const dir = order === 1 ? [-1, 1] : [1, -1];
|
|
123
|
+
const dir = order === (1 as SortOrder) ? [-1, 1] : [1, -1];
|
|
124
124
|
return aValue.toBigInt() === bValue.toBigInt()
|
|
125
125
|
? sortNotes(a, b, sorts, level + 1)
|
|
126
126
|
: aValue.toBigInt() > bValue.toBigInt()
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
? dir[0]
|
|
128
|
+
: dir[1];
|
|
129
129
|
};
|
|
130
130
|
|
|
131
131
|
/**
|
|
@@ -91,6 +91,14 @@ export async function executePrivateFunction(
|
|
|
91
91
|
rawReturnValues,
|
|
92
92
|
nestedExecutions,
|
|
93
93
|
contractClassLogs,
|
|
94
|
+
{
|
|
95
|
+
timings: {
|
|
96
|
+
witgen:
|
|
97
|
+
// Due to the recursive nature of execution, we have to subtract the time taken by the first level of
|
|
98
|
+
// child executions
|
|
99
|
+
duration - nestedExecutions.reduce((acc, nested) => acc + (nested.profileResult?.timings.witgen ?? 0), 0),
|
|
100
|
+
},
|
|
101
|
+
},
|
|
94
102
|
);
|
|
95
103
|
}
|
|
96
104
|
|
|
@@ -78,7 +78,7 @@ export async function executeNativeCircuit(
|
|
|
78
78
|
try {
|
|
79
79
|
// Check that the directory exists
|
|
80
80
|
await fs.access(workingDirectory);
|
|
81
|
-
} catch
|
|
81
|
+
} catch {
|
|
82
82
|
return { status: ACVM_RESULT.FAILURE, reason: `Working directory ${workingDirectory} does not exist` };
|
|
83
83
|
}
|
|
84
84
|
|
|
@@ -138,7 +138,11 @@ export async function executeNativeCircuit(
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
export class NativeACVMSimulator implements SimulationProvider {
|
|
141
|
-
constructor(
|
|
141
|
+
constructor(
|
|
142
|
+
private workingDirectory: string,
|
|
143
|
+
private pathToAcvm: string,
|
|
144
|
+
private witnessFilename?: string,
|
|
145
|
+
) {}
|
|
142
146
|
|
|
143
147
|
async executeProtocolCircuit(
|
|
144
148
|
input: ACVMWitness,
|
|
@@ -46,25 +46,23 @@ export type DecodedError = ExecutionError & { decodedAssertionPayload?: any; noi
|
|
|
46
46
|
// Payload parsing taken from noir/noir-repo/tooling/noir_js/src/witness_generation.ts.
|
|
47
47
|
// TODO: import this in isolation without having to import noir_js in its entirety.
|
|
48
48
|
export function enrichNoirError(artifact: NoirCompiledCircuit, originalError: ExecutionError): DecodedError {
|
|
49
|
-
const payload = originalError.rawAssertionPayload;
|
|
50
|
-
if (!payload) {
|
|
51
|
-
return originalError;
|
|
52
|
-
}
|
|
53
49
|
const enrichedError = originalError as DecodedError;
|
|
54
50
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
if (originalError.rawAssertionPayload) {
|
|
52
|
+
try {
|
|
53
|
+
// Decode the payload
|
|
54
|
+
const decodedPayload = abiDecodeError(artifact.abi, originalError.rawAssertionPayload);
|
|
58
55
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
56
|
+
if (typeof decodedPayload === 'string') {
|
|
57
|
+
// If it's a string, just add it to the error message
|
|
58
|
+
enrichedError.message = `Circuit execution failed: ${decodedPayload}`;
|
|
59
|
+
} else {
|
|
60
|
+
// If not, attach the payload to the original error
|
|
61
|
+
enrichedError.decodedAssertionPayload = decodedPayload;
|
|
62
|
+
}
|
|
63
|
+
} catch {
|
|
64
|
+
// Ignore errors decoding the payload
|
|
65
65
|
}
|
|
66
|
-
} catch (_errorDecoding) {
|
|
67
|
-
// Ignore errors decoding the payload
|
|
68
66
|
}
|
|
69
67
|
|
|
70
68
|
try {
|
|
@@ -84,7 +82,7 @@ export function enrichNoirError(artifact: NoirCompiledCircuit, originalError: Ex
|
|
|
84
82
|
return `at ${errorLocation.locationText} (${errorLocation.filePath}:${errorLocation.line}:${errorLocation.column})`;
|
|
85
83
|
}
|
|
86
84
|
});
|
|
87
|
-
} catch
|
|
85
|
+
} catch {
|
|
88
86
|
// Ignore errors resolving the callstack
|
|
89
87
|
}
|
|
90
88
|
|
package/src/private/simulator.ts
CHANGED
|
@@ -22,7 +22,10 @@ import { UtilityExecutionOracle } from './utility_execution_oracle.js';
|
|
|
22
22
|
export class AcirSimulator {
|
|
23
23
|
private log: Logger;
|
|
24
24
|
|
|
25
|
-
constructor(
|
|
25
|
+
constructor(
|
|
26
|
+
private executionDataProvider: ExecutionDataProvider,
|
|
27
|
+
private simulationProvider: SimulationProvider,
|
|
28
|
+
) {
|
|
26
29
|
this.log = createLogger('simulator');
|
|
27
30
|
}
|
|
28
31
|
|
|
@@ -25,7 +25,7 @@ export class AvmContractCallResult {
|
|
|
25
25
|
this.gasLeft,
|
|
26
26
|
)}, totalInstructions: ${this.totalInstructions}`;
|
|
27
27
|
if (this.revertReason) {
|
|
28
|
-
resultsStr += `, revertReason: ${this.revertReason}`;
|
|
28
|
+
resultsStr += `, revertReason: ${this.revertReason.message}`;
|
|
29
29
|
}
|
|
30
30
|
return resultsStr;
|
|
31
31
|
}
|
|
@@ -60,7 +60,7 @@ export class AvmFinalizedCallResult {
|
|
|
60
60
|
this.gasLeft,
|
|
61
61
|
)}, totalInstructions: ${this.totalInstructions}`;
|
|
62
62
|
if (this.revertReason) {
|
|
63
|
-
resultsStr += `, revertReason: ${this.revertReason}`;
|
|
63
|
+
resultsStr += `, revertReason: ${this.revertReason.message}`;
|
|
64
64
|
}
|
|
65
65
|
return resultsStr;
|
|
66
66
|
}
|
|
@@ -15,9 +15,14 @@ export class AvmExecutionEnvironment {
|
|
|
15
15
|
public readonly globals: GlobalVariables,
|
|
16
16
|
public readonly isStaticCall: boolean,
|
|
17
17
|
public readonly calldata: Fr[],
|
|
18
|
+
public readonly clientInitiatedSimulation: boolean = false,
|
|
18
19
|
) {}
|
|
19
20
|
|
|
20
|
-
private deriveEnvironmentForNestedCallInternal(
|
|
21
|
+
private deriveEnvironmentForNestedCallInternal(
|
|
22
|
+
targetAddress: AztecAddress,
|
|
23
|
+
calldata: Fr[],
|
|
24
|
+
isStaticCall: boolean,
|
|
25
|
+
): AvmExecutionEnvironment {
|
|
21
26
|
return new AvmExecutionEnvironment(
|
|
22
27
|
/*address=*/ targetAddress,
|
|
23
28
|
/*sender=*/ this.address,
|
|
@@ -26,6 +31,7 @@ export class AvmExecutionEnvironment {
|
|
|
26
31
|
this.globals,
|
|
27
32
|
isStaticCall,
|
|
28
33
|
calldata,
|
|
34
|
+
/*clientInitiatedSimulation=*/ this.clientInitiatedSimulation,
|
|
29
35
|
);
|
|
30
36
|
}
|
|
31
37
|
|
|
@@ -2,7 +2,6 @@ import * as c from '@aztec/constants';
|
|
|
2
2
|
|
|
3
3
|
import { TypeTag } from './avm_memory_types.js';
|
|
4
4
|
import { InstructionExecutionError } from './errors.js';
|
|
5
|
-
import { Addressing, AddressingMode } from './opcodes/addressing_mode.js';
|
|
6
5
|
import { Opcode } from './serialization/instruction_serialization.js';
|
|
7
6
|
|
|
8
7
|
/** Gas counters in L1, L2, and DA. */
|
|
@@ -136,7 +135,6 @@ const DYNAMIC_GAS_COSTS = new Map<Opcode, Gas>([
|
|
|
136
135
|
[Opcode.RETURN, makeCost(c.AVM_RETURN_DYN_L2_GAS, 0)],
|
|
137
136
|
[Opcode.REVERT_8, makeCost(c.AVM_REVERT_DYN_L2_GAS, 0)],
|
|
138
137
|
[Opcode.REVERT_16, makeCost(c.AVM_REVERT_DYN_L2_GAS, 0)],
|
|
139
|
-
[Opcode.DEBUGLOG, makeCost(c.AVM_DEBUGLOG_DYN_L2_GAS, 0)],
|
|
140
138
|
[Opcode.TORADIXBE, makeCost(c.AVM_TORADIXBE_DYN_L2_GAS, 0)],
|
|
141
139
|
]);
|
|
142
140
|
|
|
@@ -149,24 +147,6 @@ export function getDynamicGasCost(opcode: Opcode): Gas {
|
|
|
149
147
|
return DYNAMIC_GAS_COSTS.has(opcode) ? DYNAMIC_GAS_COSTS.get(opcode)! : makeCost(0, 0);
|
|
150
148
|
}
|
|
151
149
|
|
|
152
|
-
/** Returns the gas cost associated with the memory operations performed. */
|
|
153
|
-
export function getMemoryGasCost(args: { reads?: number; writes?: number; indirect?: number }) {
|
|
154
|
-
const { reads, writes, indirect } = args;
|
|
155
|
-
const indirectCount = Addressing.fromWire(indirect ?? 0).count(AddressingMode.INDIRECT);
|
|
156
|
-
const l2MemoryGasCost =
|
|
157
|
-
(reads ?? 0) * GAS_COST_CONSTANTS.MEMORY_READ +
|
|
158
|
-
(writes ?? 0) * GAS_COST_CONSTANTS.MEMORY_WRITE +
|
|
159
|
-
indirectCount * GAS_COST_CONSTANTS.MEMORY_INDIRECT_READ_PENALTY;
|
|
160
|
-
return makeGas({ l2Gas: l2MemoryGasCost });
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/** Constants used in base cost calculations. */
|
|
164
|
-
export const GAS_COST_CONSTANTS = {
|
|
165
|
-
MEMORY_READ: 10,
|
|
166
|
-
MEMORY_INDIRECT_READ_PENALTY: 10,
|
|
167
|
-
MEMORY_WRITE: 100,
|
|
168
|
-
};
|
|
169
|
-
|
|
170
150
|
/** Returns gas cost for an operation on a given type tag based on the base cost per byte. */
|
|
171
151
|
export function getGasCostForTypeTag(tag: TypeTag, baseCost: Gas) {
|
|
172
152
|
return mulGas(baseCost, getGasCostMultiplierFromTypeTag(tag));
|
|
@@ -79,6 +79,7 @@ export class AvmSimulator implements AvmSimulatorInterface {
|
|
|
79
79
|
isStaticCall: boolean,
|
|
80
80
|
calldata: Fr[],
|
|
81
81
|
allocatedGas: Gas,
|
|
82
|
+
clientInitiatedSimulation: boolean = false,
|
|
82
83
|
) {
|
|
83
84
|
const avmExecutionEnv = new AvmExecutionEnvironment(
|
|
84
85
|
address,
|
|
@@ -88,6 +89,7 @@ export class AvmSimulator implements AvmSimulatorInterface {
|
|
|
88
89
|
globals,
|
|
89
90
|
isStaticCall,
|
|
90
91
|
calldata,
|
|
92
|
+
clientInitiatedSimulation,
|
|
91
93
|
);
|
|
92
94
|
|
|
93
95
|
const avmMachineState = new AvmMachineState(allocatedGas);
|
|
@@ -108,7 +110,7 @@ export class AvmSimulator implements AvmSimulatorInterface {
|
|
|
108
110
|
throw err;
|
|
109
111
|
}
|
|
110
112
|
return await this.handleFailureToRetrieveBytecode(
|
|
111
|
-
`Bytecode retrieval for contract '${this.context.environment.address}' failed with ${err}. Reverting...`,
|
|
113
|
+
`Bytecode retrieval for contract '${this.context.environment.address}' failed with ${err.message}. Reverting...`,
|
|
112
114
|
);
|
|
113
115
|
}
|
|
114
116
|
|
|
@@ -71,6 +71,7 @@ export function initExecutionEnvironment(overrides?: Partial<AvmExecutionEnviron
|
|
|
71
71
|
overrides?.globals ?? GlobalVariables.empty(),
|
|
72
72
|
overrides?.isStaticCall ?? false,
|
|
73
73
|
overrides?.calldata ?? [],
|
|
74
|
+
overrides?.clientInitiatedSimulation ?? true, // default to true for testing even though internal default is false
|
|
74
75
|
);
|
|
75
76
|
}
|
|
76
77
|
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { DEPLOYER_CONTRACT_ADDRESS } from '@aztec/constants';
|
|
2
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
-
import { AvmGadgetsTestContract } from '@aztec/noir-contracts.js/AvmGadgetsTest';
|
|
4
|
-
import { AvmTestContract } from '@aztec/noir-contracts.js/AvmTest';
|
|
5
3
|
import {
|
|
6
4
|
type ContractArtifact,
|
|
7
5
|
type FunctionAbi,
|
|
@@ -98,70 +96,6 @@ export function resolveContractAssertionMessage(
|
|
|
98
96
|
return resolveAssertionMessageFromRevertData(output, functionArtifact);
|
|
99
97
|
}
|
|
100
98
|
|
|
101
|
-
export function getAvmTestContractFunctionSelector(functionName: string): Promise<FunctionSelector> {
|
|
102
|
-
return getFunctionSelector(functionName, AvmTestContract.artifactForPublic);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function getAvmGadgetsTestContractFunctionSelector(functionName: string): Promise<FunctionSelector> {
|
|
106
|
-
const artifact = getAllFunctionAbis(AvmGadgetsTestContract.artifactForPublic).find(f => f.name === functionName)!;
|
|
107
|
-
assert(!!artifact, `Function ${functionName} not found in AvmGadgetsTestContractArtifact`);
|
|
108
|
-
const params = artifact.parameters;
|
|
109
|
-
return FunctionSelector.fromNameAndParameters(artifact.name, params);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export function getAvmTestContractArtifact(functionName: string): FunctionArtifact {
|
|
113
|
-
const artifact = getContractFunctionArtifact(functionName, AvmTestContract.artifactForPublic) as FunctionArtifact;
|
|
114
|
-
assert(
|
|
115
|
-
!!artifact?.bytecode,
|
|
116
|
-
`No bytecode found for function ${functionName}. Try re-running bootstrap.sh on the repository root.`,
|
|
117
|
-
);
|
|
118
|
-
return artifact;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export function getAvmGadgetsTestContractArtifact(functionName: string): FunctionArtifact {
|
|
122
|
-
const artifact = AvmGadgetsTestContract.artifactForPublic.functions.find(f => f.name === functionName)!;
|
|
123
|
-
assert(
|
|
124
|
-
!!artifact?.bytecode,
|
|
125
|
-
`No bytecode found for function ${functionName}. Try re-running bootstrap.sh on the repository root.`,
|
|
126
|
-
);
|
|
127
|
-
return artifact;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export function getAvmTestContractBytecode(functionName: string): Buffer {
|
|
131
|
-
const artifact = getAvmTestContractArtifact(functionName);
|
|
132
|
-
return artifact.bytecode;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export function getAvmGadgetsTestContractBytecode(functionName: string): Buffer {
|
|
136
|
-
const artifact = getAvmGadgetsTestContractArtifact(functionName);
|
|
137
|
-
return artifact.bytecode;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export function resolveAvmTestContractAssertionMessage(
|
|
141
|
-
functionName: string,
|
|
142
|
-
revertReason: AvmRevertReason,
|
|
143
|
-
output: Fr[],
|
|
144
|
-
): string | undefined {
|
|
145
|
-
return resolveContractAssertionMessage(functionName, revertReason, output, AvmTestContract.artifactForPublic);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export function resolveAvmGadgetsTestContractAssertionMessage(
|
|
149
|
-
functionName: string,
|
|
150
|
-
revertReason: AvmRevertReason,
|
|
151
|
-
output: Fr[],
|
|
152
|
-
): string | undefined {
|
|
153
|
-
traverseCauseChain(revertReason, cause => {
|
|
154
|
-
revertReason = cause as AvmRevertReason;
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
const functionArtifact = AvmGadgetsTestContract.artifactForPublic.functions.find(f => f.name === functionName);
|
|
158
|
-
if (!functionArtifact || !revertReason.noirCallStack || !isNoirCallStackUnresolved(revertReason.noirCallStack)) {
|
|
159
|
-
return undefined;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return resolveAssertionMessageFromRevertData(output, functionArtifact);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
99
|
/**
|
|
166
100
|
* Create a contract class and instance given constructor args, artifact, etc.
|
|
167
101
|
* NOTE: This is useful for testing real-ish contract class registration and instance deployment TXs (via logs)
|