@aztec/simulator 0.62.0 → 0.63.1
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/acvm/acvm.d.ts +2 -16
- package/dest/acvm/acvm.d.ts.map +1 -1
- package/dest/acvm/acvm.js +2 -70
- package/dest/acvm/oracle/oracle.d.ts +4 -4
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +10 -11
- package/dest/acvm/oracle/typed_oracle.d.ts +5 -5
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +8 -8
- package/dest/avm/avm_gas.d.ts.map +1 -1
- package/dest/avm/avm_gas.js +2 -1
- package/dest/avm/avm_machine_state.d.ts +27 -8
- package/dest/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/avm/avm_machine_state.js +6 -10
- package/dest/avm/avm_memory_types.d.ts +8 -0
- package/dest/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/avm/avm_memory_types.js +5 -1
- package/dest/avm/avm_simulator.d.ts +2 -19
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +12 -14
- package/dest/avm/avm_tree.d.ts +249 -0
- package/dest/avm/avm_tree.d.ts.map +1 -0
- package/dest/avm/avm_tree.js +637 -0
- package/dest/avm/errors.d.ts +4 -17
- package/dest/avm/errors.d.ts.map +1 -1
- package/dest/avm/errors.js +21 -50
- package/dest/avm/fixtures/index.d.ts +7 -2
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +12 -12
- package/dest/avm/index.d.ts +1 -0
- package/dest/avm/index.d.ts.map +1 -1
- package/dest/avm/index.js +2 -1
- package/dest/avm/journal/journal.d.ts +43 -24
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +172 -39
- package/dest/avm/journal/nullifiers.d.ts +5 -4
- package/dest/avm/journal/nullifiers.d.ts.map +1 -1
- package/dest/avm/journal/nullifiers.js +2 -3
- package/dest/avm/journal/public_storage.d.ts +6 -5
- package/dest/avm/journal/public_storage.d.ts.map +1 -1
- package/dest/avm/journal/public_storage.js +1 -1
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +4 -10
- package/dest/avm/opcodes/arithmetic.d.ts +4 -1
- package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/avm/opcodes/arithmetic.js +18 -4
- package/dest/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/avm/opcodes/bitwise.js +1 -3
- package/dest/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/avm/opcodes/comparators.js +1 -2
- package/dest/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/avm/opcodes/contract.js +2 -3
- package/dest/avm/opcodes/control_flow.d.ts +4 -0
- package/dest/avm/opcodes/control_flow.d.ts.map +1 -1
- package/dest/avm/opcodes/control_flow.js +21 -6
- package/dest/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/avm/opcodes/conversion.js +1 -2
- package/dest/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/avm/opcodes/ec_add.js +5 -11
- package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/avm/opcodes/environment_getters.js +1 -2
- package/dest/avm/opcodes/external_calls.d.ts +4 -2
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +38 -22
- package/dest/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/avm/opcodes/hashing.js +1 -4
- package/dest/avm/opcodes/instruction.d.ts +4 -0
- package/dest/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction.js +7 -1
- package/dest/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/avm/opcodes/memory.js +1 -7
- package/dest/avm/opcodes/misc.js +3 -3
- package/dest/avm/opcodes/multi_scalar_mul.d.ts.map +1 -1
- package/dest/avm/opcodes/multi_scalar_mul.js +6 -5
- package/dest/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/avm/opcodes/storage.js +2 -4
- package/dest/avm/serialization/bytecode_serialization.d.ts +1 -6
- package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/bytecode_serialization.js +24 -20
- package/dest/client/client_execution_context.d.ts +7 -11
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +18 -20
- package/dest/client/db_oracle.d.ts +17 -10
- package/dest/client/db_oracle.d.ts.map +1 -1
- package/dest/client/db_oracle.js +1 -1
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +5 -4
- package/dest/client/unconstrained_execution.d.ts.map +1 -1
- package/dest/client/unconstrained_execution.js +3 -2
- package/dest/client/view_data_oracle.d.ts +6 -12
- package/dest/client/view_data_oracle.d.ts.map +1 -1
- package/dest/client/view_data_oracle.js +10 -12
- package/dest/common/errors.d.ts +15 -2
- package/dest/common/errors.d.ts.map +1 -1
- package/dest/common/errors.js +85 -4
- package/dest/mocks/fixtures.d.ts +9 -28
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +12 -57
- package/dest/public/dual_side_effect_trace.d.ts +34 -26
- package/dest/public/dual_side_effect_trace.d.ts.map +1 -1
- package/dest/public/dual_side_effect_trace.js +48 -36
- package/dest/public/enqueued_call_side_effect_trace.d.ts +96 -33
- package/dest/public/enqueued_call_side_effect_trace.d.ts.map +1 -1
- package/dest/public/enqueued_call_side_effect_trace.js +212 -138
- package/dest/public/execution.d.ts +50 -17
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +1 -29
- package/dest/public/executor.d.ts +28 -11
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +33 -33
- package/dest/public/index.d.ts +4 -5
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +4 -5
- package/dest/public/public_db_sources.d.ts +1 -0
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +12 -5
- package/dest/public/public_processor.d.ts +7 -11
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +60 -42
- package/dest/public/public_processor_metrics.d.ts +3 -3
- package/dest/public/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_processor_metrics.js +1 -1
- package/dest/public/public_tx_context.d.ts +130 -0
- package/dest/public/public_tx_context.d.ts.map +1 -0
- package/dest/public/public_tx_context.js +293 -0
- package/dest/public/public_tx_simulator.d.ts +36 -0
- package/dest/public/public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator.js +148 -0
- package/dest/public/side_effect_trace.d.ts +30 -15
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +70 -16
- package/dest/public/side_effect_trace_interface.d.ts +43 -12
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/dest/public/transitional_adapters.d.ts +9 -0
- package/dest/public/transitional_adapters.d.ts.map +1 -0
- package/dest/public/transitional_adapters.js +127 -0
- package/dest/public/utils.d.ts +5 -0
- package/dest/public/utils.d.ts.map +1 -0
- package/dest/public/utils.js +30 -0
- package/package.json +12 -9
- package/src/acvm/acvm.ts +3 -94
- package/src/acvm/oracle/oracle.ts +9 -14
- package/src/acvm/oracle/typed_oracle.ts +8 -8
- package/src/avm/avm_gas.ts +1 -0
- package/src/avm/avm_machine_state.ts +28 -12
- package/src/avm/avm_memory_types.ts +5 -0
- package/src/avm/avm_simulator.ts +13 -16
- package/src/avm/avm_tree.ts +785 -0
- package/src/avm/errors.ts +25 -48
- package/src/avm/fixtures/index.ts +16 -12
- package/src/avm/index.ts +1 -0
- package/src/avm/journal/journal.ts +291 -52
- package/src/avm/journal/nullifiers.ts +7 -7
- package/src/avm/journal/public_storage.ts +5 -5
- package/src/avm/opcodes/accrued_substate.ts +3 -9
- package/src/avm/opcodes/arithmetic.ts +26 -4
- package/src/avm/opcodes/bitwise.ts +0 -2
- package/src/avm/opcodes/comparators.ts +0 -1
- package/src/avm/opcodes/contract.ts +1 -2
- package/src/avm/opcodes/control_flow.ts +24 -5
- package/src/avm/opcodes/conversion.ts +0 -1
- package/src/avm/opcodes/ec_add.ts +6 -9
- package/src/avm/opcodes/environment_getters.ts +0 -1
- package/src/avm/opcodes/external_calls.ts +39 -21
- package/src/avm/opcodes/hashing.ts +0 -3
- package/src/avm/opcodes/instruction.ts +7 -0
- package/src/avm/opcodes/memory.ts +0 -6
- package/src/avm/opcodes/misc.ts +2 -2
- package/src/avm/opcodes/multi_scalar_mul.ts +5 -4
- package/src/avm/opcodes/storage.ts +1 -3
- package/src/avm/serialization/bytecode_serialization.ts +31 -22
- package/src/client/client_execution_context.ts +22 -23
- package/src/client/db_oracle.ts +22 -11
- package/src/client/private_execution.ts +5 -4
- package/src/client/unconstrained_execution.ts +2 -1
- package/src/client/view_data_oracle.ts +14 -13
- package/src/common/errors.ts +119 -3
- package/src/mocks/fixtures.ts +15 -106
- package/src/public/dual_side_effect_trace.ts +138 -50
- package/src/public/enqueued_call_side_effect_trace.ts +352 -212
- package/src/public/execution.ts +58 -42
- package/src/public/executor.ts +52 -67
- package/src/public/index.ts +7 -5
- package/src/public/public_db_sources.ts +12 -4
- package/src/public/public_processor.ts +111 -73
- package/src/public/public_processor_metrics.ts +3 -3
- package/src/public/public_tx_context.ts +411 -0
- package/src/public/public_tx_simulator.ts +232 -0
- package/src/public/side_effect_trace.ts +154 -28
- package/src/public/side_effect_trace_interface.ts +92 -14
- package/src/public/transitional_adapters.ts +347 -0
- package/src/public/utils.ts +32 -0
- package/dest/public/enqueued_call_simulator.d.ts +0 -43
- package/dest/public/enqueued_call_simulator.d.ts.map +0 -1
- package/dest/public/enqueued_call_simulator.js +0 -156
- package/dest/public/enqueued_calls_processor.d.ts +0 -43
- package/dest/public/enqueued_calls_processor.d.ts.map +0 -1
- package/dest/public/enqueued_calls_processor.js +0 -209
- package/dest/public/hints_builder.d.ts +0 -29
- package/dest/public/hints_builder.d.ts.map +0 -1
- package/dest/public/hints_builder.js +0 -75
- package/dest/public/public_kernel.d.ts +0 -30
- package/dest/public/public_kernel.d.ts.map +0 -1
- package/dest/public/public_kernel.js +0 -67
- package/dest/public/public_kernel_circuit_simulator.d.ts +0 -25
- package/dest/public/public_kernel_circuit_simulator.d.ts.map +0 -1
- package/dest/public/public_kernel_circuit_simulator.js +0 -2
- package/dest/public/public_kernel_tail_simulator.d.ts +0 -15
- package/dest/public/public_kernel_tail_simulator.d.ts.map +0 -1
- package/dest/public/public_kernel_tail_simulator.js +0 -39
- package/src/public/enqueued_call_simulator.ts +0 -360
- package/src/public/enqueued_calls_processor.ts +0 -372
- package/src/public/hints_builder.ts +0 -168
- package/src/public/public_kernel.ts +0 -100
- package/src/public/public_kernel_circuit_simulator.ts +0 -32
- package/src/public/public_kernel_tail_simulator.ts +0 -97
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/simulator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.63.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -59,17 +59,19 @@
|
|
|
59
59
|
]
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@aztec/circuit-types": "0.
|
|
63
|
-
"@aztec/circuits.js": "0.
|
|
64
|
-
"@aztec/foundation": "0.
|
|
65
|
-
"@aztec/noir-protocol-circuits-types": "0.
|
|
66
|
-
"@aztec/protocol-contracts": "0.
|
|
67
|
-
"@aztec/telemetry-client": "0.
|
|
68
|
-
"@aztec/types": "0.
|
|
69
|
-
"@aztec/world-state": "0.
|
|
62
|
+
"@aztec/circuit-types": "0.63.1",
|
|
63
|
+
"@aztec/circuits.js": "0.63.1",
|
|
64
|
+
"@aztec/foundation": "0.63.1",
|
|
65
|
+
"@aztec/noir-protocol-circuits-types": "0.63.1",
|
|
66
|
+
"@aztec/protocol-contracts": "0.63.1",
|
|
67
|
+
"@aztec/telemetry-client": "0.63.1",
|
|
68
|
+
"@aztec/types": "0.63.1",
|
|
69
|
+
"@aztec/world-state": "0.63.1",
|
|
70
70
|
"@noir-lang/acvm_js": "portal:../../noir/packages/acvm_js",
|
|
71
|
+
"@noir-lang/noirc_abi": "portal:../../noir/packages/noirc_abi",
|
|
71
72
|
"@noir-lang/types": "portal:../../noir/packages/types",
|
|
72
73
|
"levelup": "^5.1.1",
|
|
74
|
+
"lodash.clonedeep": "^4.5.0",
|
|
73
75
|
"memdown": "^6.1.1",
|
|
74
76
|
"tslib": "^2.4.0"
|
|
75
77
|
},
|
|
@@ -80,6 +82,7 @@
|
|
|
80
82
|
"@jest/globals": "^29.5.0",
|
|
81
83
|
"@types/jest": "^29.5.0",
|
|
82
84
|
"@types/levelup": "^5.1.3",
|
|
85
|
+
"@types/lodash.clonedeep": "^4.5.7",
|
|
83
86
|
"@types/lodash.merge": "^4.6.9",
|
|
84
87
|
"@types/memdown": "^3.0.2",
|
|
85
88
|
"@types/node": "^18.7.23",
|
package/src/acvm/acvm.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type NoirCallStack
|
|
2
|
-
import type {
|
|
1
|
+
import { type NoirCallStack } from '@aztec/circuit-types';
|
|
2
|
+
import type { FunctionDebugMetadata } from '@aztec/foundation/abi';
|
|
3
3
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
4
4
|
|
|
5
5
|
import {
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
executeCircuitWithReturnWitness,
|
|
10
10
|
} from '@noir-lang/acvm_js';
|
|
11
11
|
|
|
12
|
-
import { traverseCauseChain } from '../common/errors.js';
|
|
12
|
+
import { resolveOpcodeLocations, traverseCauseChain } from '../common/errors.js';
|
|
13
13
|
import { type ACVMWitness } from './acvm_types.js';
|
|
14
14
|
import { type ORACLE_NAMES } from './oracle/index.js';
|
|
15
15
|
|
|
@@ -34,97 +34,6 @@ export interface ACIRExecutionResult {
|
|
|
34
34
|
returnWitness: ACVMWitness;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
/**
|
|
38
|
-
* Extracts a brillig location from an opcode location.
|
|
39
|
-
* @param opcodeLocation - The opcode location to extract from. It should be in the format `acirLocation.brilligLocation` or `acirLocation`.
|
|
40
|
-
* @returns The brillig location if the opcode location contains one.
|
|
41
|
-
*/
|
|
42
|
-
function extractBrilligLocation(opcodeLocation: string): string | undefined {
|
|
43
|
-
const splitted = opcodeLocation.split('.');
|
|
44
|
-
if (splitted.length === 2) {
|
|
45
|
-
return splitted[1];
|
|
46
|
-
}
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Extracts the call stack from the location of a failing opcode and the debug metadata.
|
|
52
|
-
* One opcode can point to multiple calls due to inlining.
|
|
53
|
-
*/
|
|
54
|
-
function getSourceCodeLocationsFromOpcodeLocation(
|
|
55
|
-
opcodeLocation: string,
|
|
56
|
-
debug: FunctionDebugMetadata,
|
|
57
|
-
brilligFunctionId?: BrilligFunctionId,
|
|
58
|
-
): SourceCodeLocation[] {
|
|
59
|
-
const { debugSymbols, files } = debug;
|
|
60
|
-
|
|
61
|
-
let callStack = debugSymbols.locations[opcodeLocation] || [];
|
|
62
|
-
if (callStack.length === 0) {
|
|
63
|
-
const brilligLocation = extractBrilligLocation(opcodeLocation);
|
|
64
|
-
if (brilligFunctionId !== undefined && brilligLocation !== undefined) {
|
|
65
|
-
callStack = debugSymbols.brillig_locations[brilligFunctionId][brilligLocation] || [];
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return callStack.map(call => {
|
|
69
|
-
const { file: fileId, span } = call;
|
|
70
|
-
|
|
71
|
-
const { path, source } = files[fileId];
|
|
72
|
-
|
|
73
|
-
const locationText = source.substring(span.start, span.end);
|
|
74
|
-
const precedingText = source.substring(0, span.start);
|
|
75
|
-
const previousLines = precedingText.split('\n');
|
|
76
|
-
// Lines and columns in stacks are one indexed.
|
|
77
|
-
const line = previousLines.length;
|
|
78
|
-
const column = previousLines[previousLines.length - 1].length + 1;
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
filePath: path,
|
|
82
|
-
line,
|
|
83
|
-
column,
|
|
84
|
-
fileSource: source,
|
|
85
|
-
locationText,
|
|
86
|
-
};
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Extracts the source code locations for an array of opcode locations
|
|
92
|
-
* @param opcodeLocations - The opcode locations that caused the error.
|
|
93
|
-
* @param debug - The debug metadata of the function.
|
|
94
|
-
* @returns The source code locations.
|
|
95
|
-
*/
|
|
96
|
-
export function resolveOpcodeLocations(
|
|
97
|
-
opcodeLocations: OpcodeLocation[],
|
|
98
|
-
debug: FunctionDebugMetadata,
|
|
99
|
-
brilligFunctionId?: BrilligFunctionId,
|
|
100
|
-
): SourceCodeLocation[] {
|
|
101
|
-
return opcodeLocations.flatMap(opcodeLocation =>
|
|
102
|
-
getSourceCodeLocationsFromOpcodeLocation(opcodeLocation, debug, brilligFunctionId),
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Extracts the source code locations for an array of opcode locations
|
|
108
|
-
* @param opcodeLocations - The opcode locations that caused the error.
|
|
109
|
-
* @param debug - The debug metadata of the function.
|
|
110
|
-
* @returns The source code locations.
|
|
111
|
-
*/
|
|
112
|
-
export function resolveAssertionMessage(
|
|
113
|
-
opcodeLocations: OpcodeLocation[],
|
|
114
|
-
debug: FunctionDebugMetadata,
|
|
115
|
-
): string | undefined {
|
|
116
|
-
if (opcodeLocations.length === 0) {
|
|
117
|
-
return undefined;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const lastLocation = extractBrilligLocation(opcodeLocations[opcodeLocations.length - 1]);
|
|
121
|
-
if (!lastLocation) {
|
|
122
|
-
return undefined;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return debug.assertMessages?.[parseInt(lastLocation, 10)];
|
|
126
|
-
}
|
|
127
|
-
|
|
128
37
|
/**
|
|
129
38
|
* The function call that executes an ACIR.
|
|
130
39
|
*/
|
|
@@ -293,7 +293,7 @@ export class Oracle {
|
|
|
293
293
|
[numberOfElements]: ACVMField[],
|
|
294
294
|
): Promise<ACVMField[]> {
|
|
295
295
|
const values = await this.typedOracle.storageRead(
|
|
296
|
-
fromACVMField(contractAddress),
|
|
296
|
+
new AztecAddress(fromACVMField(contractAddress)),
|
|
297
297
|
fromACVMField(startStorageSlot),
|
|
298
298
|
+blockNumber,
|
|
299
299
|
+numberOfElements,
|
|
@@ -336,15 +336,11 @@ export class Oracle {
|
|
|
336
336
|
return toACVMField(0);
|
|
337
337
|
}
|
|
338
338
|
|
|
339
|
-
|
|
340
|
-
[contractAddress]: ACVMField[],
|
|
341
|
-
message: ACVMField[],
|
|
342
|
-
[counter]: ACVMField[],
|
|
343
|
-
): ACVMField {
|
|
339
|
+
emitContractClassLog([contractAddress]: ACVMField[], message: ACVMField[], [counter]: ACVMField[]): ACVMField {
|
|
344
340
|
const logPayload = Buffer.concat(message.map(fromACVMField).map(f => f.toBuffer()));
|
|
345
341
|
const log = new UnencryptedL2Log(AztecAddress.fromString(contractAddress), logPayload);
|
|
346
342
|
|
|
347
|
-
const logHash = this.typedOracle.
|
|
343
|
+
const logHash = this.typedOracle.emitContractClassLog(log, +counter);
|
|
348
344
|
return toACVMField(logHash);
|
|
349
345
|
}
|
|
350
346
|
|
|
@@ -409,23 +405,22 @@ export class Oracle {
|
|
|
409
405
|
this.typedOracle.notifySetMinRevertibleSideEffectCounter(frToNumber(fromACVMField(minRevertibleSideEffectCounter)));
|
|
410
406
|
}
|
|
411
407
|
|
|
412
|
-
async
|
|
413
|
-
const taggingSecret = await this.typedOracle.
|
|
408
|
+
async getAppTaggingSecretAsSender([sender]: ACVMField[], [recipient]: ACVMField[]): Promise<ACVMField[]> {
|
|
409
|
+
const taggingSecret = await this.typedOracle.getAppTaggingSecretAsSender(
|
|
414
410
|
AztecAddress.fromString(sender),
|
|
415
411
|
AztecAddress.fromString(recipient),
|
|
416
412
|
);
|
|
417
413
|
return taggingSecret.toFields().map(toACVMField);
|
|
418
414
|
}
|
|
419
415
|
|
|
420
|
-
async
|
|
421
|
-
await this.typedOracle.
|
|
416
|
+
async incrementAppTaggingSecretIndexAsSender([sender]: ACVMField[], [recipient]: ACVMField[]) {
|
|
417
|
+
await this.typedOracle.incrementAppTaggingSecretIndexAsSender(
|
|
422
418
|
AztecAddress.fromString(sender),
|
|
423
419
|
AztecAddress.fromString(recipient),
|
|
424
420
|
);
|
|
425
421
|
}
|
|
426
422
|
|
|
427
|
-
async
|
|
428
|
-
|
|
429
|
-
return taggingSecrets.flatMap(taggingSecret => taggingSecret.toFields().map(toACVMField));
|
|
423
|
+
async syncNotes() {
|
|
424
|
+
await this.typedOracle.syncNotes();
|
|
430
425
|
}
|
|
431
426
|
}
|
|
@@ -183,7 +183,7 @@ export abstract class TypedOracle {
|
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
storageRead(
|
|
186
|
-
_contractAddress:
|
|
186
|
+
_contractAddress: AztecAddress,
|
|
187
187
|
_startStorageSlot: Fr,
|
|
188
188
|
_blockNumber: number,
|
|
189
189
|
_numberOfElements: number,
|
|
@@ -212,7 +212,7 @@ export abstract class TypedOracle {
|
|
|
212
212
|
throw new OracleMethodNotAvailableError('emitUnencryptedLog');
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
-
|
|
215
|
+
emitContractClassLog(_log: UnencryptedL2Log, _counter: number): Fr {
|
|
216
216
|
throw new OracleMethodNotAvailableError('emitContractClassUnencryptedLog');
|
|
217
217
|
}
|
|
218
218
|
|
|
@@ -254,15 +254,15 @@ export abstract class TypedOracle {
|
|
|
254
254
|
throw new OracleMethodNotAvailableError('debugLog');
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
-
|
|
258
|
-
throw new OracleMethodNotAvailableError('
|
|
257
|
+
getAppTaggingSecretAsSender(_sender: AztecAddress, _recipient: AztecAddress): Promise<IndexedTaggingSecret> {
|
|
258
|
+
throw new OracleMethodNotAvailableError('getAppTaggingSecretAsSender');
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
-
|
|
262
|
-
throw new OracleMethodNotAvailableError('
|
|
261
|
+
incrementAppTaggingSecretIndexAsSender(_sender: AztecAddress, _recipient: AztecAddress): Promise<void> {
|
|
262
|
+
throw new OracleMethodNotAvailableError('incrementAppTaggingSecretIndexAsSender');
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
-
|
|
266
|
-
throw new OracleMethodNotAvailableError('
|
|
265
|
+
syncNotes(): Promise<void> {
|
|
266
|
+
throw new OracleMethodNotAvailableError('syncNotes');
|
|
267
267
|
}
|
|
268
268
|
}
|
package/src/avm/avm_gas.ts
CHANGED
|
@@ -136,6 +136,7 @@ const DYNAMIC_GAS_COSTS = new Map<Opcode, Gas>([
|
|
|
136
136
|
[Opcode.RETURN, makeCost(c.AVM_RETURN_DYN_L2_GAS, 0)],
|
|
137
137
|
[Opcode.REVERT_8, makeCost(c.AVM_REVERT_DYN_L2_GAS, 0)],
|
|
138
138
|
[Opcode.REVERT_16, makeCost(c.AVM_REVERT_DYN_L2_GAS, 0)],
|
|
139
|
+
[Opcode.DEBUGLOG, makeCost(c.AVM_DEBUGLOG_DYN_L2_GAS, 0)],
|
|
139
140
|
[Opcode.MSM, makeCost(c.AVM_MSM_DYN_L2_GAS, 0)],
|
|
140
141
|
[Opcode.TORADIXBE, makeCost(c.AVM_TORADIXBE_DYN_L2_GAS, 0)],
|
|
141
142
|
]);
|
|
@@ -2,7 +2,7 @@ import { type Fr } from '@aztec/circuits.js';
|
|
|
2
2
|
|
|
3
3
|
import { GAS_DIMENSIONS, type Gas } from './avm_gas.js';
|
|
4
4
|
import { TaggedMemory } from './avm_memory_types.js';
|
|
5
|
-
import { OutOfGasError } from './errors.js';
|
|
5
|
+
import { type AvmRevertReason, OutOfGasError } from './errors.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* A few fields of machine state are initialized from AVM session inputs or call instruction arguments
|
|
@@ -12,6 +12,21 @@ export type InitialAvmMachineState = {
|
|
|
12
12
|
daGasLeft: number;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Used to track the call stack and revert data of nested calls.
|
|
17
|
+
* This is used to provide a more detailed revert reason when a contract call reverts.
|
|
18
|
+
* It is only a heuristic and may not always provide the correct revert reason.
|
|
19
|
+
*/
|
|
20
|
+
type TrackedRevertInfo = {
|
|
21
|
+
revertDataRepresentative: Fr[];
|
|
22
|
+
recursiveRevertReason: AvmRevertReason;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type CallStackEntry = {
|
|
26
|
+
callPc: number;
|
|
27
|
+
returnPc: number;
|
|
28
|
+
};
|
|
29
|
+
|
|
15
30
|
/**
|
|
16
31
|
* Avm state modified on an instruction-per-instruction basis.
|
|
17
32
|
*/
|
|
@@ -19,16 +34,24 @@ export class AvmMachineState {
|
|
|
19
34
|
/** gas remaining of the gas allocated for a contract call */
|
|
20
35
|
public l2GasLeft: number;
|
|
21
36
|
public daGasLeft: number;
|
|
22
|
-
/** program counter */
|
|
37
|
+
/** program counter, byte based */
|
|
23
38
|
public pc: number = 0;
|
|
39
|
+
/** program counter of the next instruction, byte based */
|
|
40
|
+
public nextPc: number = 0;
|
|
24
41
|
/** return/revertdata of the last nested call. */
|
|
25
42
|
public nestedReturndata: Fr[] = [];
|
|
43
|
+
/**
|
|
44
|
+
* Used to track the call stack and revert data of nested calls.
|
|
45
|
+
* This is used to provide a more detailed revert reason when a contract call reverts.
|
|
46
|
+
* It is only a heuristic and may not always provide the correct revert reason.
|
|
47
|
+
*/
|
|
48
|
+
public collectedRevertInfo: TrackedRevertInfo | undefined;
|
|
26
49
|
|
|
27
50
|
/**
|
|
28
|
-
* On INTERNALCALL, internal call stack is pushed to with the current pc
|
|
29
|
-
* On INTERNALRETURN, value is popped from the internal call stack and assigned to the pc.
|
|
51
|
+
* On INTERNALCALL, internal call stack is pushed to with the current pc and the return pc.
|
|
52
|
+
* On INTERNALRETURN, value is popped from the internal call stack and assigned to the return pc.
|
|
30
53
|
*/
|
|
31
|
-
public internalCallStack:
|
|
54
|
+
public internalCallStack: CallStackEntry[] = [];
|
|
32
55
|
|
|
33
56
|
/** Memory accessible to user code */
|
|
34
57
|
public readonly memory: TaggedMemory = new TaggedMemory();
|
|
@@ -91,13 +114,6 @@ export class AvmMachineState {
|
|
|
91
114
|
}
|
|
92
115
|
}
|
|
93
116
|
|
|
94
|
-
/**
|
|
95
|
-
* Most instructions just increment PC before they complete
|
|
96
|
-
*/
|
|
97
|
-
public incrementPc() {
|
|
98
|
-
this.pc++;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
117
|
/**
|
|
102
118
|
* Halt as successful
|
|
103
119
|
* Output data must NOT be modified once it is set
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
MEM_TAG_U64,
|
|
8
8
|
MEM_TAG_U128,
|
|
9
9
|
} from '@aztec/circuits.js';
|
|
10
|
+
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
10
11
|
import { toBufferBE } from '@aztec/foundation/bigint-buffer';
|
|
11
12
|
import { Fr } from '@aztec/foundation/fields';
|
|
12
13
|
import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
@@ -41,6 +42,10 @@ export abstract class MemoryValue {
|
|
|
41
42
|
return new Fr(this.toBigInt());
|
|
42
43
|
}
|
|
43
44
|
|
|
45
|
+
public toAztecAddress(): AztecAddress {
|
|
46
|
+
return new AztecAddress(this.toFr());
|
|
47
|
+
}
|
|
48
|
+
|
|
44
49
|
// To number. Throws if exceeds max safe int.
|
|
45
50
|
public toNumber(): number {
|
|
46
51
|
return this.toFr().toNumber();
|
package/src/avm/avm_simulator.ts
CHANGED
|
@@ -15,8 +15,7 @@ import {
|
|
|
15
15
|
revertReasonFromExceptionalHalt,
|
|
16
16
|
revertReasonFromExplicitRevert,
|
|
17
17
|
} from './errors.js';
|
|
18
|
-
import
|
|
19
|
-
import { decodeFromBytecode } from './serialization/bytecode_serialization.js';
|
|
18
|
+
import { decodeInstructionFromBytecode } from './serialization/bytecode_serialization.js';
|
|
20
19
|
|
|
21
20
|
type OpcodeTally = {
|
|
22
21
|
count: number;
|
|
@@ -31,8 +30,8 @@ type PcTally = {
|
|
|
31
30
|
export class AvmSimulator {
|
|
32
31
|
private log: DebugLogger;
|
|
33
32
|
private bytecode: Buffer | undefined;
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
private opcodeTallies: Map<string, OpcodeTally> = new Map();
|
|
34
|
+
private pcTallies: Map<number, PcTally> = new Map();
|
|
36
35
|
|
|
37
36
|
constructor(private context: AvmContext) {
|
|
38
37
|
assert(
|
|
@@ -70,24 +69,17 @@ export class AvmSimulator {
|
|
|
70
69
|
*/
|
|
71
70
|
public async executeBytecode(bytecode: Buffer): Promise<AvmContractCallResult> {
|
|
72
71
|
assert(isAvmBytecode(bytecode), "AVM simulator can't execute non-AVM bytecode");
|
|
72
|
+
assert(bytecode.length > 0, "AVM simulator can't execute empty bytecode");
|
|
73
73
|
|
|
74
74
|
this.bytecode = bytecode;
|
|
75
|
-
return await this.executeInstructions(decodeFromBytecode(bytecode));
|
|
76
|
-
}
|
|
77
75
|
|
|
78
|
-
/**
|
|
79
|
-
* Executes the provided instructions in the current context.
|
|
80
|
-
* This method is useful for testing and debugging.
|
|
81
|
-
*/
|
|
82
|
-
public async executeInstructions(instructions: Instruction[]): Promise<AvmContractCallResult> {
|
|
83
|
-
assert(instructions.length > 0);
|
|
84
76
|
const { machineState } = this.context;
|
|
85
77
|
try {
|
|
86
78
|
// Execute instruction pointed to by the current program counter
|
|
87
79
|
// continuing until the machine state signifies a halt
|
|
88
80
|
let instrCounter = 0;
|
|
89
81
|
while (!machineState.getHalted()) {
|
|
90
|
-
const instruction =
|
|
82
|
+
const [instruction, bytesRead] = decodeInstructionFromBytecode(bytecode, machineState.pc);
|
|
91
83
|
assert(
|
|
92
84
|
!!instruction,
|
|
93
85
|
'AVM attempted to execute non-existent instruction. This should never happen (invalid bytecode or AVM simulator bug)!',
|
|
@@ -104,7 +96,12 @@ export class AvmSimulator {
|
|
|
104
96
|
// Execute the instruction.
|
|
105
97
|
// Normal returns and reverts will return normally here.
|
|
106
98
|
// "Exceptional halts" will throw.
|
|
99
|
+
machineState.nextPc = machineState.pc + bytesRead;
|
|
107
100
|
await instruction.execute(this.context);
|
|
101
|
+
if (!instruction.handlesPC()) {
|
|
102
|
+
// Increment PC if the instruction doesn't handle it itself
|
|
103
|
+
machineState.pc += bytesRead;
|
|
104
|
+
}
|
|
108
105
|
|
|
109
106
|
// gas used by this instruction - used for profiling/tallying
|
|
110
107
|
const gasUsed: Gas = {
|
|
@@ -113,9 +110,9 @@ export class AvmSimulator {
|
|
|
113
110
|
};
|
|
114
111
|
this.tallyInstruction(instrPc, instruction.constructor.name, gasUsed);
|
|
115
112
|
|
|
116
|
-
if (machineState.pc >=
|
|
113
|
+
if (machineState.pc >= bytecode.length) {
|
|
117
114
|
this.log.warn('Passed end of program');
|
|
118
|
-
throw new InvalidProgramCounterError(machineState.pc, /*max=*/
|
|
115
|
+
throw new InvalidProgramCounterError(machineState.pc, /*max=*/ bytecode.length);
|
|
119
116
|
}
|
|
120
117
|
}
|
|
121
118
|
|
|
@@ -136,7 +133,7 @@ export class AvmSimulator {
|
|
|
136
133
|
}
|
|
137
134
|
|
|
138
135
|
const revertReason = revertReasonFromExceptionalHalt(err, this.context);
|
|
139
|
-
// Note: "exceptional halts" cannot return data, hence []
|
|
136
|
+
// Note: "exceptional halts" cannot return data, hence [].
|
|
140
137
|
const results = new AvmContractCallResult(/*reverted=*/ true, /*output=*/ [], revertReason);
|
|
141
138
|
this.log.debug(`Context execution results: ${results.toString()}`);
|
|
142
139
|
|