@aztec/simulator 0.37.0 → 0.38.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/acvm/acvm.d.ts +1 -1
- package/dest/acvm/acvm.d.ts.map +1 -1
- package/dest/acvm/acvm.js +2 -2
- package/dest/acvm/oracle/oracle.d.ts +5 -4
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +19 -8
- package/dest/acvm/oracle/typed_oracle.d.ts +3 -2
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +6 -3
- package/dest/avm/avm_gas.d.ts.map +1 -1
- package/dest/avm/avm_gas.js +2 -1
- package/dest/avm/avm_memory_types.d.ts +1 -1
- package/dest/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +3 -1
- package/dest/avm/journal/journal.d.ts +20 -1
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +69 -9
- package/dest/avm/journal/nullifiers.d.ts +3 -1
- package/dest/avm/journal/nullifiers.d.ts.map +1 -1
- package/dest/avm/journal/nullifiers.js +14 -6
- package/dest/avm/journal/public_storage.d.ts +10 -1
- package/dest/avm/journal/public_storage.d.ts.map +1 -1
- package/dest/avm/journal/public_storage.js +17 -2
- package/dest/avm/journal/trace.d.ts +1 -4
- package/dest/avm/journal/trace.d.ts.map +1 -1
- package/dest/avm/journal/trace.js +4 -5
- package/dest/avm/journal/trace_types.d.ts +1 -0
- package/dest/avm/journal/trace_types.d.ts.map +1 -1
- package/dest/avm/journal/trace_types.js +1 -1
- package/dest/avm/opcodes/bitwise.d.ts +4 -1
- package/dest/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/avm/opcodes/bitwise.js +14 -2
- package/dest/avm/opcodes/environment_getters.d.ts +5 -0
- package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/avm/opcodes/environment_getters.js +8 -1
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +14 -13
- package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/bytecode_serialization.js +3 -2
- package/dest/avm/serialization/instruction_serialization.d.ts +39 -38
- package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/instruction_serialization.js +40 -39
- package/dest/client/client_execution_context.d.ts +31 -18
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +48 -31
- package/dest/client/db_oracle.d.ts +3 -3
- package/dest/client/db_oracle.d.ts.map +1 -1
- package/dest/client/execution_result.d.ts +19 -15
- package/dest/client/execution_result.d.ts.map +1 -1
- package/dest/client/execution_result.js +45 -12
- package/dest/client/logs_cache.d.ts +33 -0
- package/dest/client/logs_cache.d.ts.map +1 -0
- package/dest/client/logs_cache.js +59 -0
- package/dest/client/private_execution.d.ts +2 -2
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +3 -7
- package/dest/client/simulator.d.ts +3 -3
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +3 -2
- package/dest/client/unconstrained_execution.d.ts +2 -2
- package/dest/client/unconstrained_execution.d.ts.map +1 -1
- package/dest/client/unconstrained_execution.js +1 -1
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +3 -1
- package/dest/public/abstract_phase_manager.d.ts +2 -0
- package/dest/public/abstract_phase_manager.d.ts.map +1 -1
- package/dest/public/abstract_phase_manager.js +13 -6
- package/dest/public/execution.d.ts +9 -0
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +1 -1
- package/dest/public/executor.d.ts +2 -2
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +34 -14
- package/dest/public/public_execution_context.d.ts +10 -4
- package/dest/public/public_execution_context.d.ts.map +1 -1
- package/dest/public/public_execution_context.js +19 -6
- package/dest/public/tail_phase_manager.d.ts +0 -1
- package/dest/public/tail_phase_manager.d.ts.map +1 -1
- package/dest/public/tail_phase_manager.js +3 -26
- package/dest/public/transitional_adaptors.d.ts +4 -17
- package/dest/public/transitional_adaptors.d.ts.map +1 -1
- package/dest/public/transitional_adaptors.js +27 -119
- package/package.json +8 -8
- package/src/acvm/acvm.ts +2 -2
- package/src/acvm/oracle/oracle.ts +39 -9
- package/src/acvm/oracle/typed_oracle.ts +7 -2
- package/src/avm/avm_gas.ts +1 -0
- package/src/avm/avm_memory_types.ts +1 -1
- package/src/avm/avm_simulator.ts +2 -0
- package/src/avm/journal/journal.ts +133 -9
- package/src/avm/journal/nullifiers.ts +19 -8
- package/src/avm/journal/public_storage.ts +23 -2
- package/src/avm/journal/trace.ts +3 -4
- package/src/avm/journal/trace_types.ts +1 -0
- package/src/avm/opcodes/bitwise.ts +18 -7
- package/src/avm/opcodes/environment_getters.ts +9 -0
- package/src/avm/opcodes/external_calls.ts +21 -16
- package/src/avm/serialization/bytecode_serialization.ts +2 -0
- package/src/avm/serialization/instruction_serialization.ts +1 -0
- package/src/client/client_execution_context.ts +55 -31
- package/src/client/db_oracle.ts +3 -9
- package/src/client/execution_result.ts +55 -24
- package/src/client/logs_cache.ts +65 -0
- package/src/client/private_execution.ts +4 -10
- package/src/client/simulator.ts +6 -4
- package/src/client/unconstrained_execution.ts +2 -2
- package/src/mocks/fixtures.ts +2 -0
- package/src/public/abstract_phase_manager.ts +13 -5
- package/src/public/execution.ts +9 -0
- package/src/public/executor.ts +47 -10
- package/src/public/public_execution_context.ts +18 -4
- package/src/public/tail_phase_manager.ts +2 -34
- package/src/public/transitional_adaptors.ts +39 -178
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
// All code in this file needs to die once the public executor is phased out in favor of the AVM.
|
|
2
|
-
import { UnencryptedFunctionL2Logs
|
|
3
|
-
import { CallContext,
|
|
2
|
+
import { UnencryptedFunctionL2Logs } from '@aztec/circuit-types';
|
|
3
|
+
import { CallContext, FunctionData, } from '@aztec/circuits.js';
|
|
4
4
|
import { Fr } from '@aztec/foundation/fields';
|
|
5
5
|
import { AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
|
|
6
|
-
import { AvmContractCallResults } from '../avm/avm_message_call_result.js';
|
|
7
6
|
import { Mov } from '../avm/opcodes/memory.js';
|
|
8
7
|
import { createSimulationError } from '../common/errors.js';
|
|
9
|
-
import { PackedValuesCache, SideEffectCounter } from '../index.js';
|
|
10
|
-
import { PublicExecutionContext } from './public_execution_context.js';
|
|
11
8
|
/**
|
|
12
9
|
* Convert a PublicExecution(Environment) object to an AvmExecutionEnvironment
|
|
13
10
|
*
|
|
@@ -19,131 +16,42 @@ export function createAvmExecutionEnvironment(current, header, globalVariables,
|
|
|
19
16
|
return new AvmExecutionEnvironment(current.contractAddress, current.callContext.storageContractAddress, current.callContext.msgSender, globalVariables.gasFees.feePerL2Gas, globalVariables.gasFees.feePerDaGas,
|
|
20
17
|
/*contractCallDepth=*/ Fr.zero(), header, globalVariables, current.callContext.isStaticCall, current.callContext.isDelegateCall, current.args, gasSettings, transactionFee, current.functionData.selector);
|
|
21
18
|
}
|
|
22
|
-
export function
|
|
23
|
-
const sideEffectCounter = avmContext.persistableState.trace.accessCounter;
|
|
19
|
+
export function createPublicExecution(startSideEffectCounter, avmEnvironment, calldata) {
|
|
24
20
|
const callContext = CallContext.from({
|
|
25
|
-
msgSender:
|
|
26
|
-
storageContractAddress:
|
|
27
|
-
functionSelector:
|
|
28
|
-
isDelegateCall:
|
|
29
|
-
isStaticCall:
|
|
30
|
-
sideEffectCounter:
|
|
21
|
+
msgSender: avmEnvironment.sender,
|
|
22
|
+
storageContractAddress: avmEnvironment.storageAddress,
|
|
23
|
+
functionSelector: avmEnvironment.temporaryFunctionSelector,
|
|
24
|
+
isDelegateCall: avmEnvironment.isDelegateCall,
|
|
25
|
+
isStaticCall: avmEnvironment.isStaticCall,
|
|
26
|
+
sideEffectCounter: startSideEffectCounter,
|
|
31
27
|
});
|
|
32
|
-
const functionData = new FunctionData(
|
|
28
|
+
const functionData = new FunctionData(avmEnvironment.temporaryFunctionSelector, /*isPrivate=*/ false);
|
|
33
29
|
const execution = {
|
|
34
|
-
contractAddress:
|
|
30
|
+
contractAddress: avmEnvironment.address,
|
|
35
31
|
callContext,
|
|
36
32
|
args: calldata,
|
|
37
33
|
functionData,
|
|
38
34
|
};
|
|
39
|
-
|
|
40
|
-
const context = new PublicExecutionContext(execution, avmContext.environment.header, avmContext.environment.globals, packedArgs, new SideEffectCounter(sideEffectCounter), avmContext.persistableState.hostStorage.publicStateDb, avmContext.persistableState.hostStorage.contractsDb, avmContext.persistableState.hostStorage.commitmentsDb, Gas.from(avmContext.machineState.gasLeft), avmContext.environment.transactionFee, avmContext.environment.gasSettings);
|
|
41
|
-
return context;
|
|
35
|
+
return execution;
|
|
42
36
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
* @param execution
|
|
47
|
-
* @param newWorldState
|
|
48
|
-
* @param result
|
|
49
|
-
* @returns
|
|
50
|
-
*/
|
|
51
|
-
export async function convertAvmResults(executionContext, newWorldState, result, endMachineState) {
|
|
52
|
-
const execution = executionContext.execution;
|
|
53
|
-
const contractStorageReads = newWorldState.storageReads.map(read => new ContractStorageRead(read.slot, read.value, read.counter.toNumber(), read.storageAddress));
|
|
54
|
-
const contractStorageUpdateRequests = newWorldState.storageWrites.map(write => new ContractStorageUpdateRequest(write.slot, write.value, write.counter.toNumber(), write.storageAddress));
|
|
55
|
-
// We need to write the storage updates to the DB, because that's what the ACVM expects.
|
|
56
|
-
// Assumes the updates are in the right order.
|
|
57
|
-
for (const write of newWorldState.storageWrites) {
|
|
58
|
-
await executionContext.stateDb.storageWrite(write.storageAddress, write.slot, write.value);
|
|
59
|
-
}
|
|
60
|
-
const newNoteHashes = newWorldState.newNoteHashes.map(noteHash => new NoteHash(noteHash.noteHash, noteHash.counter.toNumber()));
|
|
61
|
-
const nullifierReadRequests = newWorldState.nullifierChecks
|
|
62
|
-
.filter(nullifierCheck => nullifierCheck.exists)
|
|
63
|
-
.map(nullifierCheck => new ReadRequest(nullifierCheck.nullifier, nullifierCheck.counter.toNumber()));
|
|
64
|
-
const nullifierNonExistentReadRequests = newWorldState.nullifierChecks
|
|
65
|
-
.filter(nullifierCheck => !nullifierCheck.exists)
|
|
66
|
-
.map(nullifierCheck => new ReadRequest(nullifierCheck.nullifier, nullifierCheck.counter.toNumber()));
|
|
67
|
-
const newNullifiers = newWorldState.newNullifiers.map(tracedNullifier => new Nullifier(
|
|
68
|
-
/*value=*/ tracedNullifier.nullifier, tracedNullifier.counter.toNumber(),
|
|
69
|
-
/*noteHash=*/ Fr.ZERO));
|
|
70
|
-
const unencryptedLogs = new UnencryptedFunctionL2Logs(newWorldState.newLogs.map(log => new UnencryptedL2Log(log.contractAddress, log.selector, log.data)));
|
|
71
|
-
const unencryptedLogsHashes = newWorldState.newLogsHashes.map(logHash => new SideEffect(logHash.logHash, logHash.counter));
|
|
72
|
-
const newL2ToL1Messages = newWorldState.newL1Messages.map(m => new L2ToL1Message(m.recipient, m.content));
|
|
73
|
-
const returnValues = result.output;
|
|
74
|
-
// TODO: Support nested executions.
|
|
75
|
-
const nestedExecutions = [];
|
|
76
|
-
// TODO keep track of side effect counters
|
|
77
|
-
const startSideEffectCounter = Fr.ZERO;
|
|
78
|
-
const endSideEffectCounter = Fr.ZERO;
|
|
37
|
+
export function convertAvmResultsToPxResult(avmResult, startSideEffectCounter, fromPx, startGas, endAvmContext) {
|
|
38
|
+
const endPersistableState = endAvmContext.persistableState;
|
|
39
|
+
const endMachineState = endAvmContext.machineState;
|
|
79
40
|
return {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
returnValues,
|
|
91
|
-
nestedExecutions,
|
|
92
|
-
unencryptedLogsHashes,
|
|
93
|
-
unencryptedLogs,
|
|
94
|
-
reverted: result.reverted,
|
|
95
|
-
revertReason: result.revertReason ? createSimulationError(result.revertReason) : undefined,
|
|
96
|
-
startGasLeft: executionContext.availableGas,
|
|
41
|
+
...endPersistableState.transitionalExecutionResult, // includes nestedExecutions
|
|
42
|
+
execution: fromPx,
|
|
43
|
+
returnValues: avmResult.output,
|
|
44
|
+
startSideEffectCounter: new Fr(startSideEffectCounter),
|
|
45
|
+
endSideEffectCounter: new Fr(endPersistableState.trace.accessCounter),
|
|
46
|
+
unencryptedLogs: new UnencryptedFunctionL2Logs(endPersistableState.transitionalExecutionResult.unencryptedLogs),
|
|
47
|
+
allUnencryptedLogs: new UnencryptedFunctionL2Logs(endPersistableState.transitionalExecutionResult.allUnencryptedLogs),
|
|
48
|
+
reverted: avmResult.reverted,
|
|
49
|
+
revertReason: avmResult.revertReason ? createSimulationError(avmResult.revertReason) : undefined,
|
|
50
|
+
startGasLeft: startGas,
|
|
97
51
|
endGasLeft: endMachineState.gasLeft,
|
|
98
|
-
transactionFee:
|
|
52
|
+
transactionFee: endAvmContext.environment.transactionFee,
|
|
99
53
|
};
|
|
100
54
|
}
|
|
101
|
-
export function convertPublicExecutionResult(res) {
|
|
102
|
-
return new AvmContractCallResults(res.reverted, res.returnValues, res.revertReason);
|
|
103
|
-
}
|
|
104
|
-
export function updateAvmContextFromPublicExecutionResult(ctx, result) {
|
|
105
|
-
// We have to push these manually and not use the trace* functions
|
|
106
|
-
// so that we respect the side effect counters.
|
|
107
|
-
for (const readRequest of result.contractStorageReads) {
|
|
108
|
-
ctx.persistableState.trace.publicStorageReads.push({
|
|
109
|
-
storageAddress: ctx.environment.storageAddress,
|
|
110
|
-
exists: true, // FIXME
|
|
111
|
-
slot: readRequest.storageSlot,
|
|
112
|
-
value: readRequest.currentValue,
|
|
113
|
-
counter: new Fr(readRequest.sideEffectCounter ?? Fr.ZERO),
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
for (const updateRequest of result.contractStorageUpdateRequests) {
|
|
117
|
-
ctx.persistableState.trace.publicStorageWrites.push({
|
|
118
|
-
storageAddress: ctx.environment.storageAddress,
|
|
119
|
-
slot: updateRequest.storageSlot,
|
|
120
|
-
value: updateRequest.newValue,
|
|
121
|
-
counter: new Fr(updateRequest.sideEffectCounter ?? Fr.ZERO),
|
|
122
|
-
});
|
|
123
|
-
// We need to manually populate the cache.
|
|
124
|
-
ctx.persistableState.publicStorage.write(ctx.environment.storageAddress, updateRequest.storageSlot, updateRequest.newValue);
|
|
125
|
-
}
|
|
126
|
-
for (const nullifier of result.newNullifiers) {
|
|
127
|
-
ctx.persistableState.trace.newNullifiers.push({
|
|
128
|
-
storageAddress: ctx.environment.storageAddress,
|
|
129
|
-
nullifier: nullifier.value,
|
|
130
|
-
counter: new Fr(nullifier.counter),
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
for (const noteHash of result.newNoteHashes) {
|
|
134
|
-
ctx.persistableState.trace.newNoteHashes.push({
|
|
135
|
-
storageAddress: ctx.environment.storageAddress,
|
|
136
|
-
noteHash: noteHash.value,
|
|
137
|
-
counter: new Fr(noteHash.counter),
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
for (const message of result.newL2ToL1Messages) {
|
|
141
|
-
ctx.persistableState.newL1Messages.push(message);
|
|
142
|
-
}
|
|
143
|
-
for (const log of result.unencryptedLogs.logs) {
|
|
144
|
-
ctx.persistableState.newLogs.push(new UnencryptedL2Log(log.contractAddress, log.selector, log.data));
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
55
|
const AVM_MAGIC_SUFFIX = Buffer.from([
|
|
148
56
|
Mov.opcode, // opcode
|
|
149
57
|
0x00, // indirect
|
|
@@ -157,4 +65,4 @@ export function isAvmBytecode(bytecode) {
|
|
|
157
65
|
const magicSize = AVM_MAGIC_SUFFIX.length;
|
|
158
66
|
return bytecode.subarray(-magicSize).equals(AVM_MAGIC_SUFF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BQVc7SUFDakIsR0FBRyxNQUFNLENBQUMsSUFBSSxDQUFDLFVBQVUsRUFBRSxLQUFLLENBQUMsRUFBRSxZQUFZO0lBQy9DLEdBQUcsTUFBTSxDQUFDLElBQUksQ0FBQyxVQUFVLEVBQUUsS0FBSyxDQUFDLEVBQUUsWUFBWTtDQUNoRCxDQUFDLENBQUM7QUFFSCxNQUFNLFVBQVUsaUJBQWlCLENBQUMsUUFBZ0I7SUFDaEQsT0FBTyxNQUFNLENBQUMsTUFBTSxDQUFDLENBQUMsUUFBUSxFQUFFLGdCQUFnQixDQUFDLENBQUMsQ0FBQztBQUNyRCxDQUFDO0FBRUQsTUFBTSxVQUFVLGFBQWEsQ0FBQyxRQUFnQjtJQUM1QyxNQUFNLFNBQVMsR0FBRyxnQkFBZ0IsQ0FBQyxNQUFNLENBQUM7SUFDMUMsT0FBTyxRQUFRLENBQUMsUUFBUSxDQUFDLENBQUMsU0FBUyxDQUFDLENBQUMsTUFBTSxDQUFDLGdCQUFnQixDQUFDLENBQUM7QUFDaEUsQ0FBQyJ9
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/simulator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.38.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": "./dest/index.js",
|
|
6
6
|
"typedocOptions": {
|
|
@@ -45,13 +45,13 @@
|
|
|
45
45
|
]
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@aztec/circuit-types": "0.
|
|
49
|
-
"@aztec/circuits.js": "0.
|
|
50
|
-
"@aztec/foundation": "0.
|
|
51
|
-
"@aztec/noir-protocol-circuits-types": "0.
|
|
52
|
-
"@aztec/protocol-contracts": "0.
|
|
53
|
-
"@aztec/types": "0.
|
|
54
|
-
"@aztec/world-state": "0.
|
|
48
|
+
"@aztec/circuit-types": "0.38.0",
|
|
49
|
+
"@aztec/circuits.js": "0.38.0",
|
|
50
|
+
"@aztec/foundation": "0.38.0",
|
|
51
|
+
"@aztec/noir-protocol-circuits-types": "0.38.0",
|
|
52
|
+
"@aztec/protocol-contracts": "0.38.0",
|
|
53
|
+
"@aztec/types": "0.38.0",
|
|
54
|
+
"@aztec/world-state": "0.38.0",
|
|
55
55
|
"@noir-lang/acvm_js": "portal:../../noir/packages/acvm_js",
|
|
56
56
|
"@noir-lang/types": "portal:../../noir/packages/types",
|
|
57
57
|
"levelup": "^5.1.1",
|
package/src/acvm/acvm.ts
CHANGED
|
@@ -19,7 +19,7 @@ import { type ORACLE_NAMES } from './oracle/index.js';
|
|
|
19
19
|
*/
|
|
20
20
|
type ACIRCallback = Record<
|
|
21
21
|
ORACLE_NAMES,
|
|
22
|
-
(...args: ForeignCallInput[]) => ForeignCallOutput | Promise<ForeignCallOutput>
|
|
22
|
+
(...args: ForeignCallInput[]) => void | ForeignCallOutput | Promise<ForeignCallOutput>
|
|
23
23
|
>;
|
|
24
24
|
|
|
25
25
|
/**
|
|
@@ -105,7 +105,7 @@ export async function acvm(
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
const result = await oracleFunction.call(callback, ...args);
|
|
108
|
-
return [result];
|
|
108
|
+
return typeof result === 'undefined' ? [] : [result];
|
|
109
109
|
} catch (err) {
|
|
110
110
|
let typedError: Error;
|
|
111
111
|
if (err instanceof Error) {
|
|
@@ -317,19 +317,51 @@ export class Oracle {
|
|
|
317
317
|
[publicKeyX]: ACVMField[],
|
|
318
318
|
[publicKeyY]: ACVMField[],
|
|
319
319
|
log: ACVMField[],
|
|
320
|
-
|
|
320
|
+
[counter]: ACVMField[],
|
|
321
|
+
): ACVMField[] {
|
|
321
322
|
const publicKey = new Point(fromACVMField(publicKeyX), fromACVMField(publicKeyY));
|
|
322
|
-
const
|
|
323
|
+
const encLog = this.typedOracle.emitEncryptedLog(
|
|
323
324
|
AztecAddress.fromString(contractAddress),
|
|
324
325
|
Fr.fromString(storageSlot),
|
|
325
326
|
Fr.fromString(noteTypeId),
|
|
326
327
|
publicKey,
|
|
327
328
|
log.map(fromACVMField),
|
|
329
|
+
+counter,
|
|
328
330
|
);
|
|
329
|
-
|
|
331
|
+
// TODO(1139): We should encrypt in the circuit, but instead we inject here
|
|
332
|
+
// encryption output is 112 + 32 * (N + 3) bytes, for log len N
|
|
333
|
+
// so split into N + 7 fields (gross but avoids 300+ ACVMFields)
|
|
334
|
+
const encLogFields = [];
|
|
335
|
+
for (let i = 0; i < Math.ceil(encLog.length / 31); i++) {
|
|
336
|
+
encLogFields.push(toACVMField(encLog.subarray(31 * i, Math.min(31 * (i + 1), encLog.length))));
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return encLogFields;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
emitUnencryptedLog(
|
|
343
|
+
[contractAddress]: ACVMField[],
|
|
344
|
+
[eventSelector]: ACVMField[],
|
|
345
|
+
message: ACVMField[],
|
|
346
|
+
[counter]: ACVMField[],
|
|
347
|
+
): ACVMField {
|
|
348
|
+
const logPayload = Buffer.concat(message.map(fromACVMField).map(f => f.toBuffer()));
|
|
349
|
+
const log = new UnencryptedL2Log(
|
|
350
|
+
AztecAddress.fromString(contractAddress),
|
|
351
|
+
EventSelector.fromField(fromACVMField(eventSelector)),
|
|
352
|
+
logPayload,
|
|
353
|
+
);
|
|
354
|
+
|
|
355
|
+
this.typedOracle.emitUnencryptedLog(log, +counter);
|
|
356
|
+
return toACVMField(0);
|
|
330
357
|
}
|
|
331
358
|
|
|
332
|
-
|
|
359
|
+
emitContractClassUnencryptedLog(
|
|
360
|
+
[contractAddress]: ACVMField[],
|
|
361
|
+
[eventSelector]: ACVMField[],
|
|
362
|
+
message: ACVMField[],
|
|
363
|
+
[counter]: ACVMField[],
|
|
364
|
+
): ACVMField {
|
|
333
365
|
const logPayload = Buffer.concat(message.map(fromACVMField).map(f => f.toBuffer()));
|
|
334
366
|
const log = new UnencryptedL2Log(
|
|
335
367
|
AztecAddress.fromString(contractAddress),
|
|
@@ -337,18 +369,16 @@ export class Oracle {
|
|
|
337
369
|
logPayload,
|
|
338
370
|
);
|
|
339
371
|
|
|
340
|
-
const logHash = this.typedOracle.
|
|
372
|
+
const logHash = this.typedOracle.emitContractClassUnencryptedLog(log, +counter);
|
|
341
373
|
return toACVMField(logHash);
|
|
342
374
|
}
|
|
343
375
|
|
|
344
|
-
debugLog(...args: ACVMField[][]):
|
|
376
|
+
debugLog(...args: ACVMField[][]): void {
|
|
345
377
|
this.log.verbose(oracleDebugCallToFormattedStr(args));
|
|
346
|
-
return toACVMField(0);
|
|
347
378
|
}
|
|
348
379
|
|
|
349
|
-
debugLogWithPrefix(arg0: ACVMField[], ...args: ACVMField[][]):
|
|
380
|
+
debugLogWithPrefix(arg0: ACVMField[], ...args: ACVMField[][]): void {
|
|
350
381
|
this.log.verbose(`${acvmFieldMessageToString(arg0)}: ${oracleDebugCallToFormattedStr(args)}`);
|
|
351
|
-
return toACVMField(0);
|
|
352
382
|
}
|
|
353
383
|
|
|
354
384
|
async callPrivateFunction(
|
|
@@ -197,14 +197,19 @@ export abstract class TypedOracle {
|
|
|
197
197
|
_noteTypeId: Fr,
|
|
198
198
|
_publicKey: PublicKey,
|
|
199
199
|
_log: Fr[],
|
|
200
|
-
|
|
200
|
+
_counter: number,
|
|
201
|
+
): Buffer {
|
|
201
202
|
throw new OracleMethodNotAvailableError('emitEncryptedLog');
|
|
202
203
|
}
|
|
203
204
|
|
|
204
|
-
emitUnencryptedLog(_log: UnencryptedL2Log):
|
|
205
|
+
emitUnencryptedLog(_log: UnencryptedL2Log, _counter: number): void {
|
|
205
206
|
throw new OracleMethodNotAvailableError('emitUnencryptedLog');
|
|
206
207
|
}
|
|
207
208
|
|
|
209
|
+
emitContractClassUnencryptedLog(_log: UnencryptedL2Log, _counter: number): Fr {
|
|
210
|
+
throw new OracleMethodNotAvailableError('emitContractClassUnencryptedLog');
|
|
211
|
+
}
|
|
212
|
+
|
|
208
213
|
callPrivateFunction(
|
|
209
214
|
_targetContractAddress: AztecAddress,
|
|
210
215
|
_functionSelector: FunctionSelector,
|
package/src/avm/avm_gas.ts
CHANGED
|
@@ -78,6 +78,7 @@ export const GasCosts: Record<Opcode, Gas | typeof DynamicGasCost> = {
|
|
|
78
78
|
[Opcode.SENDER]: TemporaryDefaultGasCost,
|
|
79
79
|
[Opcode.FEEPERL2GAS]: TemporaryDefaultGasCost,
|
|
80
80
|
[Opcode.FEEPERDAGAS]: TemporaryDefaultGasCost,
|
|
81
|
+
[Opcode.TRANSACTIONFEE]: TemporaryDefaultGasCost,
|
|
81
82
|
[Opcode.CONTRACTCALLDEPTH]: TemporaryDefaultGasCost,
|
|
82
83
|
[Opcode.CHAINID]: TemporaryDefaultGasCost,
|
|
83
84
|
[Opcode.VERSION]: TemporaryDefaultGasCost,
|
|
@@ -225,7 +225,7 @@ export class TaggedMemory implements TaggedMemoryInterface {
|
|
|
225
225
|
}
|
|
226
226
|
|
|
227
227
|
/** Returns a MeteredTaggedMemory instance to track the number of reads and writes if TRACK_MEMORY_ACCESSES is set. */
|
|
228
|
-
public track(type: string = 'instruction') {
|
|
228
|
+
public track(type: string = 'instruction'): TaggedMemoryInterface {
|
|
229
229
|
return TaggedMemory.TRACK_MEMORY_ACCESSES ? new MeteredTaggedMemory(this, type) : this;
|
|
230
230
|
}
|
|
231
231
|
|
package/src/avm/avm_simulator.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
|
2
2
|
|
|
3
3
|
import { strict as assert } from 'assert';
|
|
4
4
|
|
|
5
|
+
import { isAvmBytecode } from '../public/transitional_adaptors.js';
|
|
5
6
|
import type { AvmContext } from './avm_context.js';
|
|
6
7
|
import { AvmContractCallResults } from './avm_message_call_result.js';
|
|
7
8
|
import { AvmExecutionError, InvalidProgramCounterError, NoBytecodeForContractError } from './errors.js';
|
|
@@ -32,6 +33,7 @@ export class AvmSimulator {
|
|
|
32
33
|
if (!bytecode) {
|
|
33
34
|
throw new NoBytecodeForContractError(this.context.environment.address);
|
|
34
35
|
}
|
|
36
|
+
assert(isAvmBytecode(bytecode), "AVM simulator can't execute non-AVM bytecode");
|
|
35
37
|
|
|
36
38
|
return await this.executeBytecode(bytecode);
|
|
37
39
|
}
|
|
@@ -1,9 +1,21 @@
|
|
|
1
|
+
// TODO(5818): Rename file and all uses of "journal"
|
|
1
2
|
import { UnencryptedL2Log } from '@aztec/circuit-types';
|
|
2
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
AztecAddress,
|
|
5
|
+
ContractStorageRead,
|
|
6
|
+
ContractStorageUpdateRequest,
|
|
7
|
+
EthAddress,
|
|
8
|
+
L2ToL1Message,
|
|
9
|
+
NoteHash,
|
|
10
|
+
Nullifier,
|
|
11
|
+
ReadRequest,
|
|
12
|
+
SideEffect,
|
|
13
|
+
} from '@aztec/circuits.js';
|
|
3
14
|
import { EventSelector } from '@aztec/foundation/abi';
|
|
4
15
|
import { Fr } from '@aztec/foundation/fields';
|
|
5
16
|
import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
6
17
|
|
|
18
|
+
import { type PublicExecutionResult } from '../../index.js';
|
|
7
19
|
import { type HostStorage } from './host_storage.js';
|
|
8
20
|
import { Nullifiers } from './nullifiers.js';
|
|
9
21
|
import { PublicStorage } from './public_storage.js';
|
|
@@ -19,6 +31,7 @@ import {
|
|
|
19
31
|
type TracedUnencryptedL2Log,
|
|
20
32
|
} from './trace_types.js';
|
|
21
33
|
|
|
34
|
+
// TODO:(5818): do we need this type anymore?
|
|
22
35
|
/**
|
|
23
36
|
* Data held within the journal
|
|
24
37
|
*/
|
|
@@ -37,6 +50,25 @@ export type JournalData = {
|
|
|
37
50
|
newLogsHashes: TracedUnencryptedL2Log[];
|
|
38
51
|
/** contract address -\> key -\> value */
|
|
39
52
|
currentStorageValue: Map<bigint, Map<bigint, Fr>>;
|
|
53
|
+
|
|
54
|
+
sideEffectCounter: number;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// TRANSITIONAL: This should be removed once the kernel handles and entire enqueued call per circuit
|
|
58
|
+
type PartialPublicExecutionResult = {
|
|
59
|
+
nullifierReadRequests: ReadRequest[];
|
|
60
|
+
nullifierNonExistentReadRequests: ReadRequest[];
|
|
61
|
+
newNoteHashes: NoteHash[];
|
|
62
|
+
newL2ToL1Messages: L2ToL1Message[];
|
|
63
|
+
startSideEffectCounter: number;
|
|
64
|
+
newNullifiers: Nullifier[];
|
|
65
|
+
contractStorageReads: ContractStorageRead[];
|
|
66
|
+
contractStorageUpdateRequests: ContractStorageUpdateRequest[];
|
|
67
|
+
unencryptedLogsHashes: SideEffect[];
|
|
68
|
+
unencryptedLogs: UnencryptedL2Log[];
|
|
69
|
+
unencryptedLogPreimagesLength: Fr;
|
|
70
|
+
allUnencryptedLogs: UnencryptedL2Log[];
|
|
71
|
+
nestedExecutions: PublicExecutionResult[];
|
|
40
72
|
};
|
|
41
73
|
|
|
42
74
|
/**
|
|
@@ -53,7 +85,7 @@ export class AvmPersistableStateManager {
|
|
|
53
85
|
/** Reference to node storage */
|
|
54
86
|
public readonly hostStorage: HostStorage;
|
|
55
87
|
|
|
56
|
-
// TODO: make members private once this is not used in transitional_adaptors.ts.
|
|
88
|
+
// TODO(5818): make members private once this is not used in transitional_adaptors.ts.
|
|
57
89
|
/** World State */
|
|
58
90
|
/** Public storage, including cached writes */
|
|
59
91
|
public publicStorage: PublicStorage;
|
|
@@ -67,11 +99,30 @@ export class AvmPersistableStateManager {
|
|
|
67
99
|
public newL1Messages: L2ToL1Message[] = [];
|
|
68
100
|
public newLogs: UnencryptedL2Log[] = [];
|
|
69
101
|
|
|
102
|
+
// TRANSITIONAL: This should be removed once the kernel handles and entire enqueued call per circuit
|
|
103
|
+
public transitionalExecutionResult: PartialPublicExecutionResult;
|
|
104
|
+
|
|
70
105
|
constructor(hostStorage: HostStorage, parent?: AvmPersistableStateManager) {
|
|
71
106
|
this.hostStorage = hostStorage;
|
|
72
107
|
this.publicStorage = new PublicStorage(hostStorage.publicStateDb, parent?.publicStorage);
|
|
73
108
|
this.nullifiers = new Nullifiers(hostStorage.commitmentsDb, parent?.nullifiers);
|
|
74
109
|
this.trace = new WorldStateAccessTrace(parent?.trace);
|
|
110
|
+
|
|
111
|
+
this.transitionalExecutionResult = {
|
|
112
|
+
nullifierReadRequests: [],
|
|
113
|
+
nullifierNonExistentReadRequests: [],
|
|
114
|
+
newNoteHashes: [],
|
|
115
|
+
newL2ToL1Messages: [],
|
|
116
|
+
startSideEffectCounter: this.trace.accessCounter,
|
|
117
|
+
newNullifiers: [],
|
|
118
|
+
contractStorageReads: [],
|
|
119
|
+
contractStorageUpdateRequests: [],
|
|
120
|
+
unencryptedLogsHashes: [],
|
|
121
|
+
unencryptedLogs: [],
|
|
122
|
+
unencryptedLogPreimagesLength: new Fr(0),
|
|
123
|
+
allUnencryptedLogs: [],
|
|
124
|
+
nestedExecutions: [],
|
|
125
|
+
};
|
|
75
126
|
}
|
|
76
127
|
|
|
77
128
|
/**
|
|
@@ -92,6 +143,21 @@ export class AvmPersistableStateManager {
|
|
|
92
143
|
this.log.debug(`storage(${storageAddress})@${slot} <- ${value}`);
|
|
93
144
|
// Cache storage writes for later reference/reads
|
|
94
145
|
this.publicStorage.write(storageAddress, slot, value);
|
|
146
|
+
|
|
147
|
+
// TRANSITIONAL: This should be removed once the kernel handles and entire enqueued call per circuit
|
|
148
|
+
// The current info to the kernel clears any previous read or write request.
|
|
149
|
+
this.transitionalExecutionResult.contractStorageReads =
|
|
150
|
+
this.transitionalExecutionResult.contractStorageReads.filter(
|
|
151
|
+
read => !read.storageSlot.equals(slot) || !read.contractAddress!.equals(storageAddress),
|
|
152
|
+
);
|
|
153
|
+
this.transitionalExecutionResult.contractStorageUpdateRequests =
|
|
154
|
+
this.transitionalExecutionResult.contractStorageUpdateRequests.filter(
|
|
155
|
+
update => !update.storageSlot.equals(slot) || !update.contractAddress!.equals(storageAddress),
|
|
156
|
+
);
|
|
157
|
+
this.transitionalExecutionResult.contractStorageUpdateRequests.push(
|
|
158
|
+
new ContractStorageUpdateRequest(slot, value, this.trace.accessCounter, storageAddress),
|
|
159
|
+
);
|
|
160
|
+
|
|
95
161
|
// Trace all storage writes (even reverted ones)
|
|
96
162
|
this.trace.tracePublicStorageWrite(storageAddress, slot, value);
|
|
97
163
|
}
|
|
@@ -104,10 +170,24 @@ export class AvmPersistableStateManager {
|
|
|
104
170
|
* @returns the latest value written to slot, or 0 if never written to before
|
|
105
171
|
*/
|
|
106
172
|
public async readStorage(storageAddress: Fr, slot: Fr): Promise<Fr> {
|
|
107
|
-
const
|
|
108
|
-
this.log.debug(`storage(${storageAddress})@${slot} ?? value: ${value}, exists: ${exists}.`);
|
|
173
|
+
const { value, exists, cached } = await this.publicStorage.read(storageAddress, slot);
|
|
174
|
+
this.log.debug(`storage(${storageAddress})@${slot} ?? value: ${value}, exists: ${exists}, cached: ${cached}.`);
|
|
175
|
+
|
|
176
|
+
// TRANSITIONAL: This should be removed once the kernel handles and entire enqueued call per circuit
|
|
177
|
+
// The current info to the kernel kernel does not consider cached reads.
|
|
178
|
+
if (!cached) {
|
|
179
|
+
// The current info to the kernel removes any previous reads to the same slot.
|
|
180
|
+
this.transitionalExecutionResult.contractStorageReads =
|
|
181
|
+
this.transitionalExecutionResult.contractStorageReads.filter(
|
|
182
|
+
read => !read.storageSlot.equals(slot) || !read.contractAddress!.equals(storageAddress),
|
|
183
|
+
);
|
|
184
|
+
this.transitionalExecutionResult.contractStorageReads.push(
|
|
185
|
+
new ContractStorageRead(slot, value, this.trace.accessCounter, storageAddress),
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
109
189
|
// We want to keep track of all performed reads (even reverted ones)
|
|
110
|
-
this.trace.tracePublicStorageRead(storageAddress, slot, value, exists);
|
|
190
|
+
this.trace.tracePublicStorageRead(storageAddress, slot, value, exists, cached);
|
|
111
191
|
return Promise.resolve(value);
|
|
112
192
|
}
|
|
113
193
|
|
|
@@ -133,6 +213,9 @@ export class AvmPersistableStateManager {
|
|
|
133
213
|
* @param noteHash - the unsiloed note hash to write
|
|
134
214
|
*/
|
|
135
215
|
public writeNoteHash(storageAddress: Fr, noteHash: Fr) {
|
|
216
|
+
// TRANSITIONAL: This should be removed once the kernel handles and entire enqueued call per circuit
|
|
217
|
+
this.transitionalExecutionResult.newNoteHashes.push(new NoteHash(noteHash, this.trace.accessCounter));
|
|
218
|
+
|
|
136
219
|
this.log.debug(`noteHashes(${storageAddress}) += @${noteHash}.`);
|
|
137
220
|
this.trace.traceNewNoteHash(storageAddress, noteHash);
|
|
138
221
|
}
|
|
@@ -148,6 +231,16 @@ export class AvmPersistableStateManager {
|
|
|
148
231
|
this.log.debug(
|
|
149
232
|
`nullifiers(${storageAddress})@${nullifier} ?? leafIndex: ${leafIndex}, pending: ${isPending}, exists: ${exists}.`,
|
|
150
233
|
);
|
|
234
|
+
|
|
235
|
+
// TRANSITIONAL: This should be removed once the kernel handles and entire enqueued call per circuit
|
|
236
|
+
if (exists) {
|
|
237
|
+
this.transitionalExecutionResult.nullifierReadRequests.push(new ReadRequest(nullifier, this.trace.accessCounter));
|
|
238
|
+
} else {
|
|
239
|
+
this.transitionalExecutionResult.nullifierNonExistentReadRequests.push(
|
|
240
|
+
new ReadRequest(nullifier, this.trace.accessCounter),
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
|
|
151
244
|
this.trace.traceNullifierCheck(storageAddress, nullifier, exists, isPending, leafIndex);
|
|
152
245
|
return Promise.resolve(exists);
|
|
153
246
|
}
|
|
@@ -158,6 +251,9 @@ export class AvmPersistableStateManager {
|
|
|
158
251
|
* @param nullifier - the unsiloed nullifier to write
|
|
159
252
|
*/
|
|
160
253
|
public async writeNullifier(storageAddress: Fr, nullifier: Fr) {
|
|
254
|
+
// TRANSITIONAL: This should be removed once the kernel handles and entire enqueued call per circuit
|
|
255
|
+
this.transitionalExecutionResult.newNullifiers.push(new Nullifier(nullifier, this.trace.accessCounter, Fr.ZERO));
|
|
256
|
+
|
|
161
257
|
this.log.debug(`nullifiers(${storageAddress}) += ${nullifier}.`);
|
|
162
258
|
// Cache pending nullifiers for later access
|
|
163
259
|
await this.nullifiers.append(storageAddress, nullifier);
|
|
@@ -189,18 +285,39 @@ export class AvmPersistableStateManager {
|
|
|
189
285
|
public writeL1Message(recipient: EthAddress | Fr, content: Fr) {
|
|
190
286
|
this.log.debug(`L1Messages(${recipient}) += ${content}.`);
|
|
191
287
|
const recipientAddress = recipient instanceof EthAddress ? recipient : EthAddress.fromField(recipient);
|
|
192
|
-
|
|
288
|
+
const message = new L2ToL1Message(recipientAddress, content);
|
|
289
|
+
this.newL1Messages.push(message);
|
|
290
|
+
|
|
291
|
+
// TRANSITIONAL: This should be removed once the kernel handles and entire enqueued call per circuit
|
|
292
|
+
this.transitionalExecutionResult.newL2ToL1Messages.push(message);
|
|
193
293
|
}
|
|
194
294
|
|
|
195
295
|
public writeLog(contractAddress: Fr, event: Fr, log: Fr[]) {
|
|
196
296
|
this.log.debug(`UnencryptedL2Log(${contractAddress}) += event ${event} with ${log.length} fields.`);
|
|
197
|
-
const
|
|
297
|
+
const ulog = new UnencryptedL2Log(
|
|
198
298
|
AztecAddress.fromField(contractAddress),
|
|
199
299
|
EventSelector.fromField(event),
|
|
200
300
|
Buffer.concat(log.map(f => f.toBuffer())),
|
|
201
301
|
);
|
|
202
|
-
|
|
203
|
-
|
|
302
|
+
const logHash = Fr.fromBuffer(ulog.hash());
|
|
303
|
+
|
|
304
|
+
// TRANSITIONAL: This should be removed once the kernel handles and entire enqueued call per circuit
|
|
305
|
+
this.transitionalExecutionResult.unencryptedLogs.push(ulog);
|
|
306
|
+
this.transitionalExecutionResult.allUnencryptedLogs.push(ulog);
|
|
307
|
+
// this duplicates exactly what happens in the trace just for the purpose of transitional integration with the kernel
|
|
308
|
+
this.transitionalExecutionResult.unencryptedLogsHashes.push(
|
|
309
|
+
new SideEffect(logHash, new Fr(this.trace.accessCounter)),
|
|
310
|
+
);
|
|
311
|
+
// Duplicates computation performed in public_context.nr::emit_unencrypted_log
|
|
312
|
+
// 44 = addr (32) + selector (4) + raw log len (4) + processed log len (4).
|
|
313
|
+
this.transitionalExecutionResult.unencryptedLogPreimagesLength = new Fr(
|
|
314
|
+
this.transitionalExecutionResult.unencryptedLogPreimagesLength.toNumber() + 44 + log.length * Fr.SIZE_IN_BYTES,
|
|
315
|
+
);
|
|
316
|
+
// TODO(6206): likely need to track this here and not just in the transitional logic.
|
|
317
|
+
|
|
318
|
+
// TODO(6205): why are logs pushed here but logs hashes are traced?
|
|
319
|
+
this.newLogs.push(ulog);
|
|
320
|
+
this.trace.traceNewLog(logHash);
|
|
204
321
|
}
|
|
205
322
|
|
|
206
323
|
/**
|
|
@@ -216,6 +333,11 @@ export class AvmPersistableStateManager {
|
|
|
216
333
|
// Accrued Substate
|
|
217
334
|
this.newL1Messages = this.newL1Messages.concat(nestedJournal.newL1Messages);
|
|
218
335
|
this.newLogs = this.newLogs.concat(nestedJournal.newLogs);
|
|
336
|
+
|
|
337
|
+
// TRANSITIONAL: This should be removed once the kernel handles and entire enqueued call per circuit
|
|
338
|
+
this.transitionalExecutionResult.allUnencryptedLogs.concat(
|
|
339
|
+
nestedJournal.transitionalExecutionResult.allUnencryptedLogs,
|
|
340
|
+
);
|
|
219
341
|
}
|
|
220
342
|
|
|
221
343
|
/**
|
|
@@ -226,6 +348,7 @@ export class AvmPersistableStateManager {
|
|
|
226
348
|
this.trace.acceptAndMerge(nestedJournal.trace);
|
|
227
349
|
}
|
|
228
350
|
|
|
351
|
+
// TODO:(5818): do we need this type anymore?
|
|
229
352
|
/**
|
|
230
353
|
* Access the current state of the journal
|
|
231
354
|
*
|
|
@@ -244,6 +367,7 @@ export class AvmPersistableStateManager {
|
|
|
244
367
|
currentStorageValue: this.publicStorage.getCache().cachePerContract,
|
|
245
368
|
storageReads: this.trace.publicStorageReads,
|
|
246
369
|
storageWrites: this.trace.publicStorageWrites,
|
|
370
|
+
sideEffectCounter: this.trace.accessCounter,
|
|
247
371
|
};
|
|
248
372
|
}
|
|
249
373
|
}
|