@aztec/simulator 0.82.2 → 0.82.3-nightly.20250403
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dest/private/acvm/oracle/oracle.d.ts +3 -2
- package/dest/private/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/private/acvm/oracle/oracle.js +9 -6
- package/dest/private/acvm/oracle/typed_oracle.d.ts +4 -3
- package/dest/private/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/private/acvm/oracle/typed_oracle.js +4 -1
- package/dest/private/execution_data_provider.d.ts +20 -16
- package/dest/private/execution_data_provider.d.ts.map +1 -1
- package/dest/private/private_execution_oracle.d.ts +1 -1
- package/dest/private/private_execution_oracle.d.ts.map +1 -1
- package/dest/private/private_execution_oracle.js +2 -6
- package/dest/private/unconstrained_execution_oracle.d.ts +4 -2
- package/dest/private/unconstrained_execution_oracle.d.ts.map +1 -1
- package/dest/private/unconstrained_execution_oracle.js +5 -6
- package/dest/public/avm/avm_context.d.ts +3 -3
- package/dest/public/avm/avm_context.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.d.ts +4 -2
- package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
- package/dest/public/avm/avm_contract_call_result.js +9 -5
- package/dest/public/avm/avm_machine_state.d.ts +2 -0
- package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/public/avm/avm_machine_state.js +2 -0
- package/dest/public/avm/avm_simulator.d.ts +2 -2
- package/dest/public/avm/avm_simulator.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.js +5 -6
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +2 -2
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.js +3 -4
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +1 -2
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.js +0 -5
- package/dest/public/avm/fixtures/index.d.ts +6 -5
- package/dest/public/avm/fixtures/index.d.ts.map +1 -1
- package/dest/public/avm/fixtures/index.js +3 -3
- package/dest/public/avm/fixtures/simple_contract_data_source.d.ts +3 -2
- package/dest/public/avm/fixtures/simple_contract_data_source.d.ts.map +1 -1
- package/dest/public/avm/fixtures/simple_contract_data_source.js +30 -6
- package/dest/public/avm/index.d.ts +0 -1
- package/dest/public/avm/index.d.ts.map +1 -1
- package/dest/public/avm/index.js +0 -1
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/accrued_substate.js +1 -1
- package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/public/avm/opcodes/external_calls.js +2 -0
- package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.js +8 -10
- package/dest/public/avm/serialization/instruction_serialization.d.ts +5 -2
- package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/instruction_serialization.js +25 -7
- package/dest/public/avm/test_utils.d.ts +1 -1
- package/dest/public/avm/test_utils.d.ts.map +1 -1
- package/dest/public/executor_metrics.d.ts +11 -3
- package/dest/public/executor_metrics.d.ts.map +1 -1
- package/dest/public/executor_metrics.js +40 -6
- package/dest/public/executor_metrics_interface.d.ts +10 -0
- package/dest/public/executor_metrics_interface.d.ts.map +1 -0
- package/dest/public/executor_metrics_interface.js +1 -0
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts +12 -6
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +39 -19
- package/dest/public/hinting_db_sources.d.ts +26 -3
- package/dest/public/hinting_db_sources.d.ts.map +1 -1
- package/dest/public/hinting_db_sources.js +134 -1
- package/dest/public/index.d.ts +1 -1
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +1 -1
- package/dest/public/public_db_sources.d.ts +2 -3
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +26 -16
- package/dest/public/public_processor/public_processor.d.ts +4 -4
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +7 -28
- package/dest/public/public_tx_simulator/apps_tests/amm_test.d.ts +9 -0
- package/dest/public/public_tx_simulator/apps_tests/amm_test.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/apps_tests/amm_test.js +237 -0
- package/dest/public/public_tx_simulator/apps_tests/token_test.d.ts +7 -0
- package/dest/public/public_tx_simulator/apps_tests/token_test.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/apps_tests/token_test.js +109 -0
- package/dest/public/public_tx_simulator/index.d.ts +3 -0
- package/dest/public/public_tx_simulator/index.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/index.js +2 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +23 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +58 -0
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +5 -5
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +10 -8
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +16 -16
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +25 -65
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +19 -0
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +39 -0
- package/dest/public/state_manager/index.d.ts +2 -0
- package/dest/public/state_manager/index.d.ts.map +1 -0
- package/dest/public/state_manager/index.js +1 -0
- package/dest/public/{avm/journal → state_manager}/nullifiers.d.ts +1 -1
- package/dest/public/state_manager/nullifiers.d.ts.map +1 -0
- package/dest/public/{avm/journal → state_manager}/public_storage.d.ts +1 -1
- package/dest/public/state_manager/public_storage.d.ts.map +1 -0
- package/dest/public/{avm/journal/journal.d.ts → state_manager/state_manager.d.ts} +10 -10
- package/dest/public/state_manager/state_manager.d.ts.map +1 -0
- package/dest/public/{avm/journal/journal.js → state_manager/state_manager.js} +5 -5
- package/dest/public/test_executor_metrics.d.ts +43 -0
- package/dest/public/test_executor_metrics.d.ts.map +1 -0
- package/dest/public/test_executor_metrics.js +158 -0
- package/package.json +14 -14
- package/src/private/acvm/oracle/oracle.ts +26 -5
- package/src/private/acvm/oracle/typed_oracle.ts +14 -3
- package/src/private/execution_data_provider.ts +34 -18
- package/src/private/private_execution_oracle.ts +2 -13
- package/src/private/unconstrained_execution_oracle.ts +22 -15
- package/src/public/avm/avm_context.ts +2 -2
- package/src/public/avm/avm_contract_call_result.ts +15 -3
- package/src/public/avm/avm_machine_state.ts +5 -0
- package/src/public/avm/avm_simulator.ts +20 -9
- package/src/public/avm/fixtures/avm_simulation_tester.ts +4 -4
- package/src/public/avm/fixtures/base_avm_simulation_tester.ts +1 -7
- package/src/public/avm/fixtures/index.ts +7 -7
- package/src/public/avm/fixtures/simple_contract_data_source.ts +33 -6
- package/src/public/avm/index.ts +0 -1
- package/src/public/avm/opcodes/accrued_substate.ts +1 -1
- package/src/public/avm/opcodes/external_calls.ts +3 -0
- package/src/public/avm/opcodes/memory.ts +8 -10
- package/src/public/avm/serialization/instruction_serialization.ts +24 -9
- package/src/public/avm/test_utils.ts +1 -1
- package/src/public/executor_metrics.ts +54 -6
- package/src/public/executor_metrics_interface.ts +15 -0
- package/src/public/fixtures/public_tx_simulation_tester.ts +74 -18
- package/src/public/hinting_db_sources.ts +228 -3
- package/src/public/index.ts +1 -1
- package/src/public/public_db_sources.ts +36 -23
- package/src/public/public_processor/public_processor.ts +8 -28
- package/src/public/public_tx_simulator/apps_tests/amm_test.ts +316 -0
- package/src/public/public_tx_simulator/apps_tests/token_test.ts +138 -0
- package/src/public/public_tx_simulator/index.ts +2 -0
- package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +111 -0
- package/src/public/public_tx_simulator/public_tx_context.ts +13 -17
- package/src/public/public_tx_simulator/public_tx_simulator.ts +35 -79
- package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +62 -0
- package/src/public/state_manager/index.ts +1 -0
- package/src/public/{avm/journal → state_manager}/nullifiers.ts +1 -1
- package/src/public/{avm/journal → state_manager}/public_storage.ts +1 -1
- package/src/public/{avm/journal/journal.ts → state_manager/state_manager.ts} +20 -13
- package/src/public/test_executor_metrics.ts +222 -0
- package/dest/public/avm/journal/index.d.ts +0 -2
- package/dest/public/avm/journal/index.d.ts.map +0 -1
- package/dest/public/avm/journal/index.js +0 -1
- package/dest/public/avm/journal/journal.d.ts.map +0 -1
- package/dest/public/avm/journal/nullifiers.d.ts.map +0 -1
- package/dest/public/avm/journal/public_storage.d.ts.map +0 -1
- package/src/public/avm/journal/index.ts +0 -1
- /package/dest/public/{avm/journal → state_manager}/nullifiers.js +0 -0
- /package/dest/public/{avm/journal → state_manager}/public_storage.js +0 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { sum } from '@aztec/foundation/collection';
|
|
2
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
4
|
+
import { strict as assert } from 'assert';
|
|
5
|
+
const NUM_SPACES = 4;
|
|
6
|
+
const H1 = '# ';
|
|
7
|
+
const H2 = '\n## ';
|
|
8
|
+
const INDENT = ' '.repeat(NUM_SPACES);
|
|
9
|
+
const INDENT0 = '- ';
|
|
10
|
+
const INDENT1 = INDENT + '- ';
|
|
11
|
+
const INDENT2 = INDENT + INDENT + '- ';
|
|
12
|
+
const H_LINE = '\n---------------------------------------------------------------------';
|
|
13
|
+
export var PublicTxMetricsFilter = /*#__PURE__*/ function(PublicTxMetricsFilter) {
|
|
14
|
+
PublicTxMetricsFilter[PublicTxMetricsFilter["ALL"] = 0] = "ALL";
|
|
15
|
+
PublicTxMetricsFilter[PublicTxMetricsFilter["TOTALS"] = 1] = "TOTALS";
|
|
16
|
+
PublicTxMetricsFilter[PublicTxMetricsFilter["DURATIONS"] = 2] = "DURATIONS";
|
|
17
|
+
PublicTxMetricsFilter[PublicTxMetricsFilter["INSTRUCTIONS"] = 3] = "INSTRUCTIONS";
|
|
18
|
+
return PublicTxMetricsFilter;
|
|
19
|
+
}({});
|
|
20
|
+
export class TestExecutorMetrics {
|
|
21
|
+
logger;
|
|
22
|
+
// tx label -> tx metrics
|
|
23
|
+
txMetrics = new Map();
|
|
24
|
+
currentTxLabel;
|
|
25
|
+
txTimer;
|
|
26
|
+
constructor(){
|
|
27
|
+
this.logger = createLogger(`simulator:test_executor_metrics`);
|
|
28
|
+
}
|
|
29
|
+
startRecordingTxSimulation(txLabel) {
|
|
30
|
+
assert(!this.currentTxLabel, 'Cannot start recording tx simulation when another is live');
|
|
31
|
+
assert(!this.txMetrics.has(txLabel), 'Cannot start recording metrics for tx with duplicate label');
|
|
32
|
+
this.txMetrics.set(txLabel, {
|
|
33
|
+
totalDurationMs: 0,
|
|
34
|
+
manaUsed: 0,
|
|
35
|
+
totalInstructions: 0,
|
|
36
|
+
txHashMs: undefined,
|
|
37
|
+
nonRevertiblePrivateInsertionsUs: undefined,
|
|
38
|
+
revertiblePrivateInsertionsUs: undefined,
|
|
39
|
+
enqueuedCalls: [],
|
|
40
|
+
revertedCode: undefined
|
|
41
|
+
});
|
|
42
|
+
this.currentTxLabel = txLabel;
|
|
43
|
+
this.txTimer = new Timer();
|
|
44
|
+
}
|
|
45
|
+
stopRecordingTxSimulation(txLabel, revertedCode) {
|
|
46
|
+
assert(this.currentTxLabel === txLabel, 'Cannot stop recording metrics for tx when another is live');
|
|
47
|
+
const txMetrics = this.txMetrics.get(txLabel);
|
|
48
|
+
// total duration of tx
|
|
49
|
+
txMetrics.totalDurationMs = this.txTimer.ms();
|
|
50
|
+
this.logger.debug(`Public TX simulation of ${txLabel} took ${txMetrics.totalDurationMs}ms`);
|
|
51
|
+
// add manaUsed across all enqueued calls
|
|
52
|
+
txMetrics.manaUsed = sum(txMetrics.enqueuedCalls.map((call)=>call.manaUsed));
|
|
53
|
+
// add totalInstructions across all enqueued calls
|
|
54
|
+
txMetrics.totalInstructions = sum(txMetrics.enqueuedCalls.map((call)=>call.totalInstructions));
|
|
55
|
+
txMetrics.revertedCode = revertedCode;
|
|
56
|
+
this.currentTxLabel = undefined;
|
|
57
|
+
}
|
|
58
|
+
recordEnqueuedCallSimulation(fnName, durationMs, manaUsed, totalInstructions) {
|
|
59
|
+
this.#recordEnqueuedCallSimulation(fnName, durationMs, manaUsed, totalInstructions, false);
|
|
60
|
+
}
|
|
61
|
+
recordEnqueuedCallSimulationFailure(fnName, durationMs, manaUsed, totalInstructions) {
|
|
62
|
+
this.#recordEnqueuedCallSimulation(fnName, durationMs, manaUsed, totalInstructions, true);
|
|
63
|
+
}
|
|
64
|
+
#recordEnqueuedCallSimulation(fnName, durationMs, manaUsed, totalInstructions, reverted) {
|
|
65
|
+
assert(this.currentTxLabel, 'Cannot record enqueued call simulation when no tx is live');
|
|
66
|
+
const txMetrics = this.txMetrics.get(this.currentTxLabel);
|
|
67
|
+
txMetrics.enqueuedCalls.push({
|
|
68
|
+
fnName,
|
|
69
|
+
durationMs,
|
|
70
|
+
manaUsed,
|
|
71
|
+
totalInstructions,
|
|
72
|
+
reverted
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
recordTxHashComputation(durationMs) {
|
|
76
|
+
assert(this.currentTxLabel, 'Cannot record tx hash computation time when no tx is live');
|
|
77
|
+
const txMetrics = this.txMetrics.get(this.currentTxLabel);
|
|
78
|
+
assert(txMetrics.txHashMs === undefined, 'Cannot RE-record tx hash computation time');
|
|
79
|
+
txMetrics.txHashMs = durationMs;
|
|
80
|
+
}
|
|
81
|
+
recordPrivateEffectsInsertion(durationUs, type) {
|
|
82
|
+
assert(this.currentTxLabel, 'Cannot record private effects insertion when no tx is live');
|
|
83
|
+
const txMetrics = this.txMetrics.get(this.currentTxLabel);
|
|
84
|
+
if (type === 'revertible') {
|
|
85
|
+
assert(txMetrics.revertiblePrivateInsertionsUs === undefined, 'Cannot RE-record revertible insertions of private effects');
|
|
86
|
+
txMetrics.revertiblePrivateInsertionsUs = durationUs;
|
|
87
|
+
} else {
|
|
88
|
+
assert(txMetrics.nonRevertiblePrivateInsertionsUs === undefined, 'Cannot RE-record non-revertible insertions of private effects');
|
|
89
|
+
txMetrics.nonRevertiblePrivateInsertionsUs = durationUs;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
prettyPrint(filter = 0) {
|
|
93
|
+
this.logger.info(this.toPrettyString(filter));
|
|
94
|
+
}
|
|
95
|
+
toPrettyString(filter = 0) {
|
|
96
|
+
let pretty = '';
|
|
97
|
+
//pretty += H_LINE + '\n';
|
|
98
|
+
pretty += `${H1}Public TX Simulation Metrics (${PublicTxMetricsFilter[filter]})\n`;
|
|
99
|
+
for (const [txLabel, txMetrics] of this.txMetrics.entries()){
|
|
100
|
+
//pretty += H_LINE + '\n';
|
|
101
|
+
pretty += `${H2}TX Label: ${txLabel}\n`;
|
|
102
|
+
if (filter == 2 || filter === 1 || filter === 0) {
|
|
103
|
+
pretty += `${INDENT0}Total duration: ${fmtNum(txMetrics.totalDurationMs, 'ms')}\n`;
|
|
104
|
+
}
|
|
105
|
+
if (filter === 1 || filter === 0) {
|
|
106
|
+
pretty += `${INDENT0}Total mana used: ${fmtNum(txMetrics.manaUsed)}\n`;
|
|
107
|
+
const manaPerSecond = Math.round(txMetrics.manaUsed * 1000 / txMetrics.totalDurationMs);
|
|
108
|
+
pretty += `${INDENT0}Mana per second: ${fmtNum(manaPerSecond)}\n`;
|
|
109
|
+
}
|
|
110
|
+
if (filter === 3 || filter === 1 || filter === 0) {
|
|
111
|
+
pretty += `${INDENT0}Total instructions executed: ${fmtNum(txMetrics.totalInstructions)}\n`;
|
|
112
|
+
}
|
|
113
|
+
if (filter === 2 || filter === 0) {
|
|
114
|
+
pretty += `${INDENT0}Tx hash computation: ${fmtNum(txMetrics.txHashMs, 'ms')}\n`;
|
|
115
|
+
pretty += `${INDENT0}Private insertions:\n`;
|
|
116
|
+
pretty += `${INDENT1}Non-revertible: ${fmtNum(txMetrics.nonRevertiblePrivateInsertionsUs / 1_000, 'ms')}\n`;
|
|
117
|
+
pretty += `${INDENT1}Revertible: ${fmtNum(txMetrics.revertiblePrivateInsertionsUs / 1_000, 'ms')}\n`;
|
|
118
|
+
}
|
|
119
|
+
if (filter !== 1) {
|
|
120
|
+
// totals exclude enqueued calls
|
|
121
|
+
pretty += this.#enqueuedCallsToPrettyString(txMetrics, filter);
|
|
122
|
+
}
|
|
123
|
+
if (txMetrics.revertedCode !== undefined && !txMetrics.revertedCode.isOK()) {
|
|
124
|
+
pretty += `${INDENT0}Reverted code: ${txMetrics.revertedCode?.getDescription()}\n`;
|
|
125
|
+
}
|
|
126
|
+
pretty += H_LINE + '\n';
|
|
127
|
+
}
|
|
128
|
+
return pretty;
|
|
129
|
+
}
|
|
130
|
+
#enqueuedCallsToPrettyString(txMetrics, filter) {
|
|
131
|
+
let pretty = '';
|
|
132
|
+
pretty += `${INDENT0}Enqueued public calls:\n`;
|
|
133
|
+
for (const enqueuedCall of txMetrics.enqueuedCalls){
|
|
134
|
+
pretty += `${INDENT1}**Fn: ${enqueuedCall.fnName}**\n`;
|
|
135
|
+
if (filter === 2 || filter === 0) {
|
|
136
|
+
pretty += `${INDENT2}Duration: ${fmtNum(enqueuedCall.durationMs, 'ms')}\n`;
|
|
137
|
+
}
|
|
138
|
+
if (filter === 0) {
|
|
139
|
+
pretty += `${INDENT2}Mana used: ${fmtNum(enqueuedCall.manaUsed)}\n`;
|
|
140
|
+
const manaPerSecond = Math.round(enqueuedCall.manaUsed * 1000 / enqueuedCall.durationMs);
|
|
141
|
+
pretty += `${INDENT2}Mana per second: ${fmtNum(manaPerSecond)}\n`;
|
|
142
|
+
}
|
|
143
|
+
if (filter === 3 || filter === 0) {
|
|
144
|
+
pretty += `${INDENT2}Instructions executed: ${fmtNum(enqueuedCall.totalInstructions)}\n`;
|
|
145
|
+
}
|
|
146
|
+
if (enqueuedCall.reverted) {
|
|
147
|
+
pretty += `${INDENT2}Reverted!\n`;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return pretty;
|
|
151
|
+
}
|
|
152
|
+
toJSON(indent = 2) {
|
|
153
|
+
return JSON.stringify(Object.fromEntries(this.txMetrics.entries()), null, indent);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function fmtNum(num, unit) {
|
|
157
|
+
return `\`${num.toLocaleString()}${unit ? ` ${unit}` : ''}\``;
|
|
158
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/simulator",
|
|
3
|
-
"version": "0.82.
|
|
3
|
+
"version": "0.82.3-nightly.20250403",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./server": "./dest/server.js",
|
|
@@ -60,16 +60,16 @@
|
|
|
60
60
|
]
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@aztec/constants": "0.82.
|
|
64
|
-
"@aztec/foundation": "0.82.
|
|
65
|
-
"@aztec/noir-acvm_js": "0.82.
|
|
66
|
-
"@aztec/noir-noirc_abi": "0.82.
|
|
67
|
-
"@aztec/noir-protocol-circuits-types": "0.82.
|
|
68
|
-
"@aztec/noir-types": "0.82.
|
|
69
|
-
"@aztec/protocol-contracts": "0.82.
|
|
70
|
-
"@aztec/stdlib": "0.82.
|
|
71
|
-
"@aztec/telemetry-client": "0.82.
|
|
72
|
-
"@aztec/world-state": "0.82.
|
|
63
|
+
"@aztec/constants": "0.82.3-nightly.20250403",
|
|
64
|
+
"@aztec/foundation": "0.82.3-nightly.20250403",
|
|
65
|
+
"@aztec/noir-acvm_js": "0.82.3-nightly.20250403",
|
|
66
|
+
"@aztec/noir-noirc_abi": "0.82.3-nightly.20250403",
|
|
67
|
+
"@aztec/noir-protocol-circuits-types": "0.82.3-nightly.20250403",
|
|
68
|
+
"@aztec/noir-types": "0.82.3-nightly.20250403",
|
|
69
|
+
"@aztec/protocol-contracts": "0.82.3-nightly.20250403",
|
|
70
|
+
"@aztec/stdlib": "0.82.3-nightly.20250403",
|
|
71
|
+
"@aztec/telemetry-client": "0.82.3-nightly.20250403",
|
|
72
|
+
"@aztec/world-state": "0.82.3-nightly.20250403",
|
|
73
73
|
"levelup": "^5.1.1",
|
|
74
74
|
"lodash.clonedeep": "^4.5.0",
|
|
75
75
|
"lodash.merge": "^4.6.2",
|
|
@@ -77,9 +77,9 @@
|
|
|
77
77
|
"tslib": "^2.4.0"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
|
-
"@aztec/kv-store": "0.82.
|
|
81
|
-
"@aztec/merkle-tree": "0.82.
|
|
82
|
-
"@aztec/noir-contracts.js": "0.82.
|
|
80
|
+
"@aztec/kv-store": "0.82.3-nightly.20250403",
|
|
81
|
+
"@aztec/merkle-tree": "0.82.3-nightly.20250403",
|
|
82
|
+
"@aztec/noir-contracts.js": "0.82.3-nightly.20250403",
|
|
83
83
|
"@jest/globals": "^29.5.0",
|
|
84
84
|
"@types/jest": "^29.5.0",
|
|
85
85
|
"@types/levelup": "^5.1.3",
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Fr, Point } from '@aztec/foundation/fields';
|
|
2
|
-
import { FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
2
|
+
import { EventSelector, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
3
3
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
4
|
import { ContractClassLog, LogWithTxData } from '@aztec/stdlib/logs';
|
|
5
5
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
6
|
+
import { TxHash } from '@aztec/stdlib/tx';
|
|
6
7
|
|
|
7
8
|
import type { ACVMField } from '../acvm_types.js';
|
|
8
9
|
import { fromBoundedVec, fromUintArray, fromUintBoundedVec } from '../deserialize.js';
|
|
@@ -355,12 +356,12 @@ export class Oracle {
|
|
|
355
356
|
return Promise.resolve([]);
|
|
356
357
|
}
|
|
357
358
|
|
|
358
|
-
async getIndexedTaggingSecretAsSender([sender]: ACVMField[], [recipient]: ACVMField[]): Promise<ACVMField[]
|
|
359
|
+
async getIndexedTaggingSecretAsSender([sender]: ACVMField[], [recipient]: ACVMField[]): Promise<ACVMField[]> {
|
|
359
360
|
const taggingSecret = await this.typedOracle.getIndexedTaggingSecretAsSender(
|
|
360
361
|
AztecAddress.fromString(sender),
|
|
361
362
|
AztecAddress.fromString(recipient),
|
|
362
363
|
);
|
|
363
|
-
return
|
|
364
|
+
return taggingSecret.toFields().map(toACVMField);
|
|
364
365
|
}
|
|
365
366
|
|
|
366
367
|
async incrementAppTaggingSecretIndexAsSender([sender]: ACVMField[], [recipient]: ACVMField[]): Promise<ACVMField[]> {
|
|
@@ -371,8 +372,8 @@ export class Oracle {
|
|
|
371
372
|
return [];
|
|
372
373
|
}
|
|
373
374
|
|
|
374
|
-
async syncNotes(): Promise<ACVMField[]> {
|
|
375
|
-
await this.typedOracle.syncNotes();
|
|
375
|
+
async syncNotes([pendingTaggedLogArrayBaseSlot]: ACVMField[]): Promise<ACVMField[]> {
|
|
376
|
+
await this.typedOracle.syncNotes(Fr.fromString(pendingTaggedLogArrayBaseSlot));
|
|
376
377
|
return [];
|
|
377
378
|
}
|
|
378
379
|
|
|
@@ -490,4 +491,24 @@ export class Oracle {
|
|
|
490
491
|
);
|
|
491
492
|
return secret.toFields().map(toACVMField);
|
|
492
493
|
}
|
|
494
|
+
|
|
495
|
+
async storePrivateEventLog(
|
|
496
|
+
[contractAddress]: ACVMField[],
|
|
497
|
+
[recipient]: ACVMField[],
|
|
498
|
+
[eventSelector]: ACVMField[],
|
|
499
|
+
logContentBVecStorage: ACVMField[],
|
|
500
|
+
[logContentLength]: ACVMField[],
|
|
501
|
+
[txHash]: ACVMField[],
|
|
502
|
+
[logIndexInTx]: ACVMField[],
|
|
503
|
+
) {
|
|
504
|
+
await this.typedOracle.storePrivateEventLog(
|
|
505
|
+
AztecAddress.fromField(Fr.fromString(contractAddress)),
|
|
506
|
+
AztecAddress.fromField(Fr.fromString(recipient)),
|
|
507
|
+
EventSelector.fromField(Fr.fromString(eventSelector)),
|
|
508
|
+
fromBoundedVec(logContentBVecStorage, logContentLength),
|
|
509
|
+
new TxHash(Fr.fromString(txHash)),
|
|
510
|
+
Fr.fromString(logIndexInTx).toNumber(),
|
|
511
|
+
);
|
|
512
|
+
return [];
|
|
513
|
+
}
|
|
493
514
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/constants';
|
|
2
2
|
import { Fr, Point } from '@aztec/foundation/fields';
|
|
3
|
-
import type { FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
3
|
+
import type { EventSelector, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
4
4
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
5
|
import type { CompleteAddress, ContractInstance } from '@aztec/stdlib/contract';
|
|
6
6
|
import type { KeyValidationRequest } from '@aztec/stdlib/kernel';
|
|
7
7
|
import type { ContractClassLog, IndexedTaggingSecret, LogWithTxData } from '@aztec/stdlib/logs';
|
|
8
8
|
import type { Note, NoteStatus } from '@aztec/stdlib/note';
|
|
9
9
|
import { type MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
10
|
-
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
10
|
+
import type { BlockHeader, TxHash } from '@aztec/stdlib/tx';
|
|
11
11
|
|
|
12
12
|
import type { MessageLoadOracleInputs } from '../../../common/message_load_oracle_inputs.js';
|
|
13
13
|
|
|
@@ -214,7 +214,7 @@ export abstract class TypedOracle {
|
|
|
214
214
|
return Promise.reject(new OracleMethodNotAvailableError('incrementAppTaggingSecretIndexAsSender'));
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
-
syncNotes(): Promise<void> {
|
|
217
|
+
syncNotes(_pendingTaggedLogArrayBaseSlot: Fr): Promise<void> {
|
|
218
218
|
return Promise.reject(new OracleMethodNotAvailableError('syncNotes'));
|
|
219
219
|
}
|
|
220
220
|
|
|
@@ -258,4 +258,15 @@ export abstract class TypedOracle {
|
|
|
258
258
|
getSharedSecret(_address: AztecAddress, _ephPk: Point): Promise<Point> {
|
|
259
259
|
return Promise.reject(new OracleMethodNotAvailableError('getSharedSecret'));
|
|
260
260
|
}
|
|
261
|
+
|
|
262
|
+
storePrivateEventLog(
|
|
263
|
+
_contractAddress: AztecAddress,
|
|
264
|
+
_recipient: AztecAddress,
|
|
265
|
+
_eventSelector: EventSelector,
|
|
266
|
+
_logContent: Fr[],
|
|
267
|
+
_txHash: TxHash,
|
|
268
|
+
_logIndexInTx: number,
|
|
269
|
+
): Promise<void> {
|
|
270
|
+
return Promise.reject(new OracleMethodNotAvailableError('storePrivateEventLog'));
|
|
271
|
+
}
|
|
261
272
|
}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import type { Fr, Point } from '@aztec/foundation/fields';
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
EventSelector,
|
|
4
|
+
FunctionArtifact,
|
|
5
|
+
FunctionArtifactWithContractName,
|
|
6
|
+
FunctionSelector,
|
|
7
|
+
} from '@aztec/stdlib/abi';
|
|
3
8
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
9
|
import type { L2Block } from '@aztec/stdlib/block';
|
|
5
10
|
import type { CompleteAddress, ContractInstance } from '@aztec/stdlib/contract';
|
|
6
11
|
import type { KeyValidationRequest } from '@aztec/stdlib/kernel';
|
|
7
|
-
import { IndexedTaggingSecret, LogWithTxData
|
|
12
|
+
import { IndexedTaggingSecret, LogWithTxData } from '@aztec/stdlib/logs';
|
|
8
13
|
import type { NoteStatus } from '@aztec/stdlib/note';
|
|
9
14
|
import { type MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
10
|
-
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
15
|
+
import type { BlockHeader, TxHash } from '@aztec/stdlib/tx';
|
|
11
16
|
|
|
12
17
|
import type { CommitmentsDBInterface } from '../common/db_interfaces.js';
|
|
13
18
|
import type { NoteData } from './acvm/index.js';
|
|
@@ -221,25 +226,18 @@ export interface ExecutionDataProvider extends CommitmentsDBInterface {
|
|
|
221
226
|
): Promise<void>;
|
|
222
227
|
|
|
223
228
|
/**
|
|
224
|
-
* Synchronizes the logs tagged with
|
|
225
|
-
*
|
|
226
|
-
* @param contractAddress - The address of the contract that the logs are tagged for
|
|
227
|
-
* @param
|
|
228
|
-
* @
|
|
229
|
+
* Synchronizes the logs tagged with scoped addresses and all the senders in the address book. Stores the found logs
|
|
230
|
+
* in CapsuleArray ready for a later retrieval in Aztec.nr.
|
|
231
|
+
* @param contractAddress - The address of the contract that the logs are tagged for.
|
|
232
|
+
* @param pendingTaggedLogArrayBaseSlot - The base slot of the pending tagged log capsule array in which found logs will be stored.
|
|
233
|
+
* @param scopes - The scoped addresses to sync logs for. If not provided, all accounts in the address book will be
|
|
234
|
+
* synced.
|
|
229
235
|
*/
|
|
230
236
|
syncTaggedLogs(
|
|
231
237
|
contractAddress: AztecAddress,
|
|
232
|
-
|
|
238
|
+
pendingTaggedLogArrayBaseSlot: Fr,
|
|
233
239
|
scopes?: AztecAddress[],
|
|
234
|
-
): Promise<
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Processes the tagged logs returned by syncTaggedLogs by decrypting them and storing them in the database.
|
|
238
|
-
* @param contractAddress - The address of the contract that emitted the logs.
|
|
239
|
-
* @param logs - The logs to process.
|
|
240
|
-
* @param recipient - The recipient of the logs.
|
|
241
|
-
*/
|
|
242
|
-
processTaggedLogs(contractAddress: AztecAddress, logs: TxScopedL2Log[], recipient: AztecAddress): Promise<void>;
|
|
240
|
+
): Promise<void>;
|
|
243
241
|
|
|
244
242
|
/**
|
|
245
243
|
* Delivers the preimage and metadata of a committed note so that it can be later requested via the `getNotes`
|
|
@@ -325,4 +323,22 @@ export interface ExecutionDataProvider extends CommitmentsDBInterface {
|
|
|
325
323
|
* @returns The secret for the given address.
|
|
326
324
|
*/
|
|
327
325
|
getSharedSecret(address: AztecAddress, ephPk: Point): Promise<Point>;
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Stores an event log in the database.
|
|
329
|
+
* @param contractAddress - The address of the contract that emitted the log.
|
|
330
|
+
* @param recipient - The address of the recipient.
|
|
331
|
+
* @param eventSelector - The event selector of the event.
|
|
332
|
+
* @param logContent - The content of the private event log.
|
|
333
|
+
* @param txHash - The hash of the transaction that emitted the log.
|
|
334
|
+
* @param logIndexInTx - The index of the log within the transaction.
|
|
335
|
+
*/
|
|
336
|
+
storePrivateEventLog(
|
|
337
|
+
contractAddress: AztecAddress,
|
|
338
|
+
recipient: AztecAddress,
|
|
339
|
+
eventSelector: EventSelector,
|
|
340
|
+
logContent: Fr[],
|
|
341
|
+
txHash: TxHash,
|
|
342
|
+
logIndexInTx: number,
|
|
343
|
+
): Promise<void>;
|
|
328
344
|
}
|
|
@@ -500,19 +500,8 @@ export class PrivateExecutionOracle extends UnconstrainedExecutionOracle {
|
|
|
500
500
|
await this.executionDataProvider.incrementAppTaggingSecretIndexAsSender(this.contractAddress, sender, recipient);
|
|
501
501
|
}
|
|
502
502
|
|
|
503
|
-
public override async syncNotes() {
|
|
504
|
-
|
|
505
|
-
this.contractAddress,
|
|
506
|
-
this.historicalHeader.globalVariables.blockNumber.toNumber(),
|
|
507
|
-
this.scopes,
|
|
508
|
-
);
|
|
509
|
-
for (const [recipient, taggedLogs] of taggedLogsByRecipient.entries()) {
|
|
510
|
-
await this.executionDataProvider.processTaggedLogs(
|
|
511
|
-
this.contractAddress,
|
|
512
|
-
taggedLogs,
|
|
513
|
-
AztecAddress.fromString(recipient),
|
|
514
|
-
);
|
|
515
|
-
}
|
|
503
|
+
public override async syncNotes(pendingTaggedLogArrayBaseSlot: Fr) {
|
|
504
|
+
await this.executionDataProvider.syncTaggedLogs(this.contractAddress, pendingTaggedLogArrayBaseSlot, this.scopes);
|
|
516
505
|
|
|
517
506
|
await this.executionDataProvider.removeNullifiedNotes(this.contractAddress);
|
|
518
507
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Aes128 } from '@aztec/foundation/crypto';
|
|
2
2
|
import { Fr, Point } from '@aztec/foundation/fields';
|
|
3
3
|
import { applyStringFormatting, createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import type { EventSelector } from '@aztec/stdlib/abi';
|
|
4
5
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
5
6
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
7
|
import type { CompleteAddress, ContractInstance } from '@aztec/stdlib/contract';
|
|
@@ -9,7 +10,7 @@ import type { KeyValidationRequest } from '@aztec/stdlib/kernel';
|
|
|
9
10
|
import { IndexedTaggingSecret, LogWithTxData } from '@aztec/stdlib/logs';
|
|
10
11
|
import type { NoteStatus } from '@aztec/stdlib/note';
|
|
11
12
|
import { type MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
12
|
-
import type { BlockHeader, Capsule } from '@aztec/stdlib/tx';
|
|
13
|
+
import type { BlockHeader, Capsule, TxHash } from '@aztec/stdlib/tx';
|
|
13
14
|
|
|
14
15
|
import { type NoteData, TypedOracle } from './acvm/index.js';
|
|
15
16
|
import type { ExecutionDataProvider } from './execution_data_provider.js';
|
|
@@ -277,20 +278,8 @@ export class UnconstrainedExecutionOracle extends TypedOracle {
|
|
|
277
278
|
return await this.executionDataProvider.getIndexedTaggingSecretAsSender(this.contractAddress, sender, recipient);
|
|
278
279
|
}
|
|
279
280
|
|
|
280
|
-
public override async syncNotes() {
|
|
281
|
-
|
|
282
|
-
this.contractAddress,
|
|
283
|
-
await this.executionDataProvider.getBlockNumber(),
|
|
284
|
-
this.scopes,
|
|
285
|
-
);
|
|
286
|
-
|
|
287
|
-
for (const [recipient, taggedLogs] of taggedLogsByRecipient.entries()) {
|
|
288
|
-
await this.executionDataProvider.processTaggedLogs(
|
|
289
|
-
this.contractAddress,
|
|
290
|
-
taggedLogs,
|
|
291
|
-
AztecAddress.fromString(recipient),
|
|
292
|
-
);
|
|
293
|
-
}
|
|
281
|
+
public override async syncNotes(pendingTaggedLogArrayBaseSlot: Fr) {
|
|
282
|
+
await this.executionDataProvider.syncTaggedLogs(this.contractAddress, pendingTaggedLogArrayBaseSlot, this.scopes);
|
|
294
283
|
|
|
295
284
|
await this.executionDataProvider.removeNullifiedNotes(this.contractAddress);
|
|
296
285
|
}
|
|
@@ -376,4 +365,22 @@ export class UnconstrainedExecutionOracle extends TypedOracle {
|
|
|
376
365
|
public override getSharedSecret(address: AztecAddress, ephPk: Point): Promise<Point> {
|
|
377
366
|
return this.executionDataProvider.getSharedSecret(address, ephPk);
|
|
378
367
|
}
|
|
368
|
+
|
|
369
|
+
public override storePrivateEventLog(
|
|
370
|
+
contractAddress: AztecAddress,
|
|
371
|
+
recipient: AztecAddress,
|
|
372
|
+
eventSelector: EventSelector,
|
|
373
|
+
logContent: Fr[],
|
|
374
|
+
txHash: TxHash,
|
|
375
|
+
logIndexInTx: number,
|
|
376
|
+
): Promise<void> {
|
|
377
|
+
return this.executionDataProvider.storePrivateEventLog(
|
|
378
|
+
contractAddress,
|
|
379
|
+
recipient,
|
|
380
|
+
eventSelector,
|
|
381
|
+
logContent,
|
|
382
|
+
txHash,
|
|
383
|
+
logIndexInTx,
|
|
384
|
+
);
|
|
385
|
+
}
|
|
379
386
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Fr } from '@aztec/foundation/fields';
|
|
2
2
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
3
|
|
|
4
|
+
import type { PublicPersistableStateManager } from '../state_manager/state_manager.js';
|
|
4
5
|
import type { AvmExecutionEnvironment } from './avm_execution_environment.js';
|
|
5
6
|
import { type Gas, gasToGasLeft } from './avm_gas.js';
|
|
6
7
|
import { AvmMachineState } from './avm_machine_state.js';
|
|
7
8
|
import type { AvmSimulator } from './avm_simulator.js';
|
|
8
|
-
import type { AvmPersistableStateManager } from './journal/journal.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* An execution context includes the information necessary to initiate AVM
|
|
@@ -20,7 +20,7 @@ export class AvmContext {
|
|
|
20
20
|
* @returns new AvmContext instance
|
|
21
21
|
*/
|
|
22
22
|
constructor(
|
|
23
|
-
public persistableState:
|
|
23
|
+
public persistableState: PublicPersistableStateManager,
|
|
24
24
|
public environment: AvmExecutionEnvironment,
|
|
25
25
|
public machineState: AvmMachineState,
|
|
26
26
|
) {}
|
|
@@ -17,10 +17,13 @@ export class AvmContractCallResult {
|
|
|
17
17
|
public output: Fr[],
|
|
18
18
|
public gasLeft: AvmGas,
|
|
19
19
|
public revertReason?: AvmRevertReason,
|
|
20
|
+
public totalInstructions: number = 0, // including nested calls
|
|
20
21
|
) {}
|
|
21
22
|
|
|
22
23
|
toString(): string {
|
|
23
|
-
let resultsStr = `reverted: ${this.reverted}, output: ${this.output}, gasLeft: ${inspect(
|
|
24
|
+
let resultsStr = `reverted: ${this.reverted}, output: ${this.output}, gasLeft: ${inspect(
|
|
25
|
+
this.gasLeft,
|
|
26
|
+
)}, totalInstructions: ${this.totalInstructions}`;
|
|
24
27
|
if (this.revertReason) {
|
|
25
28
|
resultsStr += `, revertReason: ${this.revertReason}`;
|
|
26
29
|
}
|
|
@@ -29,7 +32,13 @@ export class AvmContractCallResult {
|
|
|
29
32
|
|
|
30
33
|
finalize(): AvmFinalizedCallResult {
|
|
31
34
|
const revertReason = this.revertReason ? createSimulationError(this.revertReason, this.output) : undefined;
|
|
32
|
-
return new AvmFinalizedCallResult(
|
|
35
|
+
return new AvmFinalizedCallResult(
|
|
36
|
+
this.reverted,
|
|
37
|
+
this.output,
|
|
38
|
+
Gas.from(this.gasLeft),
|
|
39
|
+
revertReason,
|
|
40
|
+
this.totalInstructions,
|
|
41
|
+
);
|
|
33
42
|
}
|
|
34
43
|
}
|
|
35
44
|
|
|
@@ -43,10 +52,13 @@ export class AvmFinalizedCallResult {
|
|
|
43
52
|
public output: Fr[],
|
|
44
53
|
public gasLeft: Gas,
|
|
45
54
|
public revertReason?: SimulationError,
|
|
55
|
+
public totalInstructions: number = 0, // including nested calls
|
|
46
56
|
) {}
|
|
47
57
|
|
|
48
58
|
toString(): string {
|
|
49
|
-
let resultsStr = `reverted: ${this.reverted}, output: ${this.output}, gasLeft: ${inspect(
|
|
59
|
+
let resultsStr = `reverted: ${this.reverted}, output: ${this.output}, gasLeft: ${inspect(
|
|
60
|
+
this.gasLeft,
|
|
61
|
+
)}, totalInstructions: ${this.totalInstructions}`;
|
|
50
62
|
if (this.revertReason) {
|
|
51
63
|
resultsStr += `, revertReason: ${this.revertReason}`;
|
|
52
64
|
}
|
|
@@ -68,6 +68,11 @@ export class AvmMachineState {
|
|
|
68
68
|
/** Output data must NOT be modified once it is set */
|
|
69
69
|
private output: Fr[] = [];
|
|
70
70
|
|
|
71
|
+
// Metrics only - not needed for execution
|
|
72
|
+
/** instruction counter, including nested calls */
|
|
73
|
+
public instrCounter: number = 0;
|
|
74
|
+
// End metrics only
|
|
75
|
+
|
|
71
76
|
constructor(gasLeft: Gas);
|
|
72
77
|
constructor(l2GasLeft: number, daGasLeft: number);
|
|
73
78
|
constructor(gasLeftOrL2GasLeft: Gas | number, daGasLeft?: number) {
|
|
@@ -7,6 +7,7 @@ import type { GlobalVariables } from '@aztec/stdlib/tx';
|
|
|
7
7
|
import { strict as assert } from 'assert';
|
|
8
8
|
|
|
9
9
|
import { SideEffectLimitReachedError } from '../side_effect_errors.js';
|
|
10
|
+
import type { PublicPersistableStateManager } from '../state_manager/state_manager.js';
|
|
10
11
|
import { AvmContext } from './avm_context.js';
|
|
11
12
|
import { AvmContractCallResult } from './avm_contract_call_result.js';
|
|
12
13
|
import { AvmExecutionEnvironment } from './avm_execution_environment.js';
|
|
@@ -19,7 +20,6 @@ import {
|
|
|
19
20
|
revertReasonFromExceptionalHalt,
|
|
20
21
|
revertReasonFromExplicitRevert,
|
|
21
22
|
} from './errors.js';
|
|
22
|
-
import type { AvmPersistableStateManager } from './journal/journal.js';
|
|
23
23
|
import type { Instruction } from './opcodes/instruction.js';
|
|
24
24
|
import {
|
|
25
25
|
INSTRUCTION_SET,
|
|
@@ -75,7 +75,7 @@ export class AvmSimulator {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
public static async create(
|
|
78
|
-
stateManager:
|
|
78
|
+
stateManager: PublicPersistableStateManager,
|
|
79
79
|
address: AztecAddress,
|
|
80
80
|
sender: AztecAddress,
|
|
81
81
|
transactionFee: Fr,
|
|
@@ -147,7 +147,6 @@ export class AvmSimulator {
|
|
|
147
147
|
try {
|
|
148
148
|
// Execute instruction pointed to by the current program counter
|
|
149
149
|
// continuing until the machine state signifies a halt
|
|
150
|
-
let instrCounter = 0;
|
|
151
150
|
while (!machineState.getHalted()) {
|
|
152
151
|
// Get the instruction from cache, or deserialize for the first time
|
|
153
152
|
let cachedInstruction = this.deserializedInstructionsCache.get(machineState.pc);
|
|
@@ -163,13 +162,11 @@ export class AvmSimulator {
|
|
|
163
162
|
if (this.log.isLevelEnabled('trace')) {
|
|
164
163
|
// Skip this entirely to avoid toStringing etc if trace is not enabled
|
|
165
164
|
this.log.trace(
|
|
166
|
-
`[PC:${machineState.pc}] [IC:${instrCounter}] ${instruction.toString()} (gasLeft l2=${
|
|
165
|
+
`[PC:${machineState.pc}] [IC:${machineState.instrCounter}] ${instruction.toString()} (gasLeft l2=${
|
|
167
166
|
machineState.l2GasLeft
|
|
168
167
|
} da=${machineState.daGasLeft})`,
|
|
169
168
|
);
|
|
170
169
|
}
|
|
171
|
-
instrCounter++;
|
|
172
|
-
|
|
173
170
|
machineState.nextPc = machineState.pc + bytesRead;
|
|
174
171
|
|
|
175
172
|
// Execute the instruction.
|
|
@@ -181,6 +178,8 @@ export class AvmSimulator {
|
|
|
181
178
|
machineState.pc += bytesRead;
|
|
182
179
|
}
|
|
183
180
|
|
|
181
|
+
machineState.instrCounter++;
|
|
182
|
+
|
|
184
183
|
// gas used by this instruction - used for profiling/tallying
|
|
185
184
|
const gasUsed: Gas = {
|
|
186
185
|
l2Gas: instrStartGas.l2Gas - machineState.l2GasLeft,
|
|
@@ -197,13 +196,19 @@ export class AvmSimulator {
|
|
|
197
196
|
const output = machineState.getOutput();
|
|
198
197
|
const reverted = machineState.getReverted();
|
|
199
198
|
const revertReason = reverted ? await revertReasonFromExplicitRevert(output, this.context) : undefined;
|
|
200
|
-
const results = new AvmContractCallResult(
|
|
199
|
+
const results = new AvmContractCallResult(
|
|
200
|
+
reverted,
|
|
201
|
+
output,
|
|
202
|
+
machineState.gasLeft,
|
|
203
|
+
revertReason,
|
|
204
|
+
machineState.instrCounter,
|
|
205
|
+
);
|
|
201
206
|
this.log.debug(`Context execution results: ${results.toString()}`);
|
|
202
207
|
const totalGasUsed: Gas = {
|
|
203
208
|
l2Gas: callStartGas.l2Gas - machineState.l2GasLeft,
|
|
204
209
|
daGas: callStartGas.daGas - machineState.daGasLeft,
|
|
205
210
|
};
|
|
206
|
-
this.log.debug(`Executed ${instrCounter} instructions and consumed ${totalGasUsed.l2Gas} L2 Gas`);
|
|
211
|
+
this.log.debug(`Executed ${machineState.instrCounter} instructions and consumed ${totalGasUsed.l2Gas} L2 Gas`);
|
|
207
212
|
|
|
208
213
|
this.tallyPrintFunction();
|
|
209
214
|
|
|
@@ -233,7 +238,13 @@ export class AvmSimulator {
|
|
|
233
238
|
// Exceptional halts consume all allocated gas
|
|
234
239
|
const noGasLeft = { l2Gas: 0, daGas: 0 };
|
|
235
240
|
// Note: "exceptional halts" cannot return data, hence [].
|
|
236
|
-
const results = new AvmContractCallResult(
|
|
241
|
+
const results = new AvmContractCallResult(
|
|
242
|
+
/*reverted=*/ true,
|
|
243
|
+
/*output=*/ [],
|
|
244
|
+
noGasLeft,
|
|
245
|
+
revertReason,
|
|
246
|
+
machineState.instrCounter,
|
|
247
|
+
);
|
|
237
248
|
this.log.debug(`Context execution results: ${results.toString()}`);
|
|
238
249
|
|
|
239
250
|
this.tallyPrintFunction();
|