@aztec/simulator 0.61.0 → 0.63.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 +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 -3
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +11 -9
- package/dest/acvm/oracle/typed_oracle.d.ts +5 -4
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +9 -6
- package/dest/avm/avm_gas.d.ts.map +1 -1
- package/dest/avm/avm_gas.js +4 -3
- 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 +26 -11
- 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/avm/serialization/instruction_serialization.d.ts +2 -2
- package/dest/avm/serialization/instruction_serialization.js +2 -2
- package/dest/client/client_execution_context.d.ts +7 -10
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +19 -18
- package/dest/client/db_oracle.d.ts +22 -8
- 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 +21 -19
- 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/dest/test/utils.d.ts +2 -2
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +4 -4
- package/package.json +12 -9
- package/src/acvm/acvm.ts +3 -94
- package/src/acvm/oracle/oracle.ts +14 -12
- package/src/acvm/oracle/typed_oracle.ts +10 -6
- package/src/avm/avm_gas.ts +3 -2
- 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 +29 -10
- 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/avm/serialization/instruction_serialization.ts +2 -2
- package/src/client/client_execution_context.ts +24 -21
- package/src/client/db_oracle.ts +31 -8
- 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 +22 -19
- 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/src/test/utils.ts +9 -2
- 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
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { PublicExecutionRequest, UnencryptedFunctionL2Logs, UnencryptedL2Log } from '@aztec/circuit-types';
|
|
2
2
|
import {
|
|
3
|
+
AvmAppendTreeHint,
|
|
3
4
|
AvmContractBytecodeHints,
|
|
4
5
|
AvmContractInstanceHint,
|
|
5
6
|
AvmExecutionHints,
|
|
6
7
|
AvmExternalCallHint,
|
|
7
8
|
AvmKeyValueHint,
|
|
8
|
-
|
|
9
|
+
AvmNullifierReadTreeHint,
|
|
10
|
+
AvmNullifierWriteTreeHint,
|
|
11
|
+
AvmPublicDataReadTreeHint,
|
|
12
|
+
AvmPublicDataWriteTreeHint,
|
|
13
|
+
type AztecAddress,
|
|
9
14
|
CallContext,
|
|
10
15
|
type ContractClassIdPreimage,
|
|
11
16
|
type ContractInstanceWithAddress,
|
|
@@ -13,6 +18,7 @@ import {
|
|
|
13
18
|
ContractStorageUpdateRequest,
|
|
14
19
|
EthAddress,
|
|
15
20
|
Gas,
|
|
21
|
+
L1_TO_L2_MSG_TREE_HEIGHT,
|
|
16
22
|
L2ToL1Message,
|
|
17
23
|
LogHash,
|
|
18
24
|
MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_TX,
|
|
@@ -25,8 +31,14 @@ import {
|
|
|
25
31
|
MAX_PUBLIC_DATA_READS_PER_TX,
|
|
26
32
|
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
27
33
|
MAX_UNENCRYPTED_LOGS_PER_TX,
|
|
34
|
+
NOTE_HASH_TREE_HEIGHT,
|
|
35
|
+
NULLIFIER_TREE_HEIGHT,
|
|
28
36
|
NoteHash,
|
|
29
37
|
Nullifier,
|
|
38
|
+
NullifierLeafPreimage,
|
|
39
|
+
PUBLIC_DATA_TREE_HEIGHT,
|
|
40
|
+
type PublicCallRequest,
|
|
41
|
+
PublicDataTreeLeafPreimage,
|
|
30
42
|
type PublicInnerCallRequest,
|
|
31
43
|
ReadRequest,
|
|
32
44
|
SerializableContractInstance,
|
|
@@ -35,15 +47,26 @@ import {
|
|
|
35
47
|
import { Fr } from '@aztec/foundation/fields';
|
|
36
48
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
37
49
|
|
|
50
|
+
import { assert } from 'console';
|
|
51
|
+
|
|
38
52
|
import { type AvmContractCallResult } from '../avm/avm_contract_call_result.js';
|
|
39
53
|
import { type AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
|
|
40
54
|
import { createSimulationError } from '../common/errors.js';
|
|
41
|
-
import {
|
|
55
|
+
import {
|
|
56
|
+
type EnqueuedPublicCallExecutionResultWithSideEffects,
|
|
57
|
+
type PublicFunctionCallResult,
|
|
58
|
+
resultToPublicCallRequest,
|
|
59
|
+
} from './execution.js';
|
|
42
60
|
import { SideEffectLimitReachedError } from './side_effect_errors.js';
|
|
43
61
|
import { type PublicSideEffectTraceInterface } from './side_effect_trace_interface.js';
|
|
44
62
|
|
|
45
63
|
export type TracedContractInstance = { exists: boolean } & ContractInstanceWithAddress;
|
|
46
64
|
|
|
65
|
+
const emptyPublicDataPath = () => new Array(PUBLIC_DATA_TREE_HEIGHT).fill(Fr.zero());
|
|
66
|
+
const emptyNoteHashPath = () => new Array(NOTE_HASH_TREE_HEIGHT).fill(Fr.zero());
|
|
67
|
+
const emptyNullifierPath = () => new Array(NULLIFIER_TREE_HEIGHT).fill(Fr.zero());
|
|
68
|
+
const emptyL1ToL2MessagePath = () => new Array(L1_TO_L2_MSG_TREE_HEIGHT).fill(Fr.zero());
|
|
69
|
+
|
|
47
70
|
export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
|
|
48
71
|
public log = createDebugLogger('aztec:public_side_effect_trace');
|
|
49
72
|
|
|
@@ -69,7 +92,7 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
69
92
|
|
|
70
93
|
private publicCallRequests: PublicInnerCallRequest[] = [];
|
|
71
94
|
|
|
72
|
-
private nestedExecutions:
|
|
95
|
+
private nestedExecutions: PublicFunctionCallResult[] = [];
|
|
73
96
|
|
|
74
97
|
private avmCircuitHints: AvmExecutionHints;
|
|
75
98
|
|
|
@@ -93,60 +116,111 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
93
116
|
this.sideEffectCounter++;
|
|
94
117
|
}
|
|
95
118
|
|
|
96
|
-
public tracePublicStorageRead(
|
|
97
|
-
|
|
119
|
+
public tracePublicStorageRead(
|
|
120
|
+
contractAddress: AztecAddress,
|
|
121
|
+
slot: Fr,
|
|
122
|
+
value: Fr,
|
|
123
|
+
leafPreimage: PublicDataTreeLeafPreimage = PublicDataTreeLeafPreimage.empty(),
|
|
124
|
+
leafIndex: Fr = Fr.zero(),
|
|
125
|
+
path: Fr[] = emptyPublicDataPath(),
|
|
126
|
+
) {
|
|
127
|
+
if (!leafIndex.equals(Fr.zero())) {
|
|
128
|
+
// if we have real merkle hint content, make sure the value matches the the provided preimage
|
|
129
|
+
assert(leafPreimage.value.equals(value), 'Value mismatch when tracing in public data write');
|
|
130
|
+
}
|
|
98
131
|
if (this.contractStorageReads.length >= MAX_PUBLIC_DATA_READS_PER_TX) {
|
|
99
132
|
throw new SideEffectLimitReachedError('contract storage read', MAX_PUBLIC_DATA_READS_PER_TX);
|
|
100
133
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
);
|
|
134
|
+
|
|
135
|
+
this.contractStorageReads.push(new ContractStorageRead(slot, value, this.sideEffectCounter, contractAddress));
|
|
104
136
|
this.avmCircuitHints.storageValues.items.push(
|
|
105
137
|
new AvmKeyValueHint(/*key=*/ new Fr(this.sideEffectCounter), /*value=*/ value),
|
|
106
138
|
);
|
|
139
|
+
|
|
140
|
+
// New hinting
|
|
141
|
+
this.avmCircuitHints.storageReadRequest.items.push(new AvmPublicDataReadTreeHint(leafPreimage, leafIndex, path));
|
|
142
|
+
|
|
107
143
|
this.log.debug(`SLOAD cnt: ${this.sideEffectCounter} val: ${value} slot: ${slot}`);
|
|
108
144
|
this.incrementSideEffectCounter();
|
|
109
145
|
}
|
|
110
146
|
|
|
111
|
-
public tracePublicStorageWrite(
|
|
147
|
+
public tracePublicStorageWrite(
|
|
148
|
+
contractAddress: AztecAddress,
|
|
149
|
+
slot: Fr,
|
|
150
|
+
value: Fr,
|
|
151
|
+
lowLeafPreimage: PublicDataTreeLeafPreimage = PublicDataTreeLeafPreimage.empty(),
|
|
152
|
+
lowLeafIndex: Fr = Fr.zero(),
|
|
153
|
+
lowLeafPath: Fr[] = emptyPublicDataPath(),
|
|
154
|
+
newLeafPreimage: PublicDataTreeLeafPreimage = PublicDataTreeLeafPreimage.empty(),
|
|
155
|
+
insertionPath: Fr[] = emptyPublicDataPath(),
|
|
156
|
+
) {
|
|
157
|
+
if (!lowLeafIndex.equals(Fr.zero())) {
|
|
158
|
+
// if we have real merkle hint content, make sure the value matches the the provided preimage
|
|
159
|
+
assert(newLeafPreimage.value.equals(value), 'Value mismatch when tracing in public data read');
|
|
160
|
+
}
|
|
112
161
|
if (this.contractStorageUpdateRequests.length >= MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX) {
|
|
113
162
|
throw new SideEffectLimitReachedError('contract storage write', MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX);
|
|
114
163
|
}
|
|
164
|
+
|
|
115
165
|
this.contractStorageUpdateRequests.push(
|
|
116
166
|
new ContractStorageUpdateRequest(slot, value, this.sideEffectCounter, contractAddress),
|
|
117
167
|
);
|
|
168
|
+
|
|
169
|
+
// New hinting
|
|
170
|
+
const readHint = new AvmPublicDataReadTreeHint(lowLeafPreimage, lowLeafIndex, lowLeafPath);
|
|
171
|
+
this.avmCircuitHints.storageUpdateRequest.items.push(
|
|
172
|
+
new AvmPublicDataWriteTreeHint(readHint, newLeafPreimage, insertionPath),
|
|
173
|
+
);
|
|
118
174
|
this.log.debug(`SSTORE cnt: ${this.sideEffectCounter} val: ${value} slot: ${slot}`);
|
|
119
175
|
this.incrementSideEffectCounter();
|
|
120
176
|
}
|
|
121
177
|
|
|
122
178
|
// TODO(8287): _exists can be removed once we have the vm properly handling the equality check
|
|
123
|
-
public traceNoteHashCheck(
|
|
179
|
+
public traceNoteHashCheck(
|
|
180
|
+
_contractAddress: AztecAddress,
|
|
181
|
+
noteHash: Fr,
|
|
182
|
+
leafIndex: Fr,
|
|
183
|
+
exists: boolean,
|
|
184
|
+
path: Fr[] = emptyNoteHashPath(),
|
|
185
|
+
) {
|
|
124
186
|
// NOTE: contractAddress is unused but will be important when an AVM circuit processes an entire enqueued call
|
|
125
187
|
if (this.noteHashReadRequests.length >= MAX_NOTE_HASH_READ_REQUESTS_PER_TX) {
|
|
126
188
|
throw new SideEffectLimitReachedError('note hash read request', MAX_NOTE_HASH_READ_REQUESTS_PER_TX);
|
|
127
189
|
}
|
|
190
|
+
// Temp for backward compatibility
|
|
128
191
|
this.noteHashReadRequests.push(new TreeLeafReadRequest(noteHash, leafIndex));
|
|
129
192
|
this.avmCircuitHints.noteHashExists.items.push(
|
|
130
193
|
new AvmKeyValueHint(/*key=*/ new Fr(leafIndex), /*value=*/ exists ? Fr.ONE : Fr.ZERO),
|
|
131
194
|
);
|
|
195
|
+
// New Hinting
|
|
196
|
+
this.avmCircuitHints.noteHashReadRequest.items.push(new AvmAppendTreeHint(leafIndex, noteHash, path));
|
|
132
197
|
// NOTE: counter does not increment for note hash checks (because it doesn't rely on pending note hashes)
|
|
133
198
|
}
|
|
134
199
|
|
|
135
|
-
public traceNewNoteHash(
|
|
200
|
+
public traceNewNoteHash(
|
|
201
|
+
_contractAddress: AztecAddress,
|
|
202
|
+
noteHash: Fr,
|
|
203
|
+
leafIndex: Fr,
|
|
204
|
+
path: Fr[] = emptyNoteHashPath(),
|
|
205
|
+
) {
|
|
136
206
|
if (this.noteHashes.length >= MAX_NOTE_HASHES_PER_TX) {
|
|
137
207
|
throw new SideEffectLimitReachedError('note hash', MAX_NOTE_HASHES_PER_TX);
|
|
138
208
|
}
|
|
139
209
|
this.noteHashes.push(new NoteHash(noteHash, this.sideEffectCounter));
|
|
140
210
|
this.log.debug(`NEW_NOTE_HASH cnt: ${this.sideEffectCounter}`);
|
|
211
|
+
|
|
212
|
+
// New Hinting
|
|
213
|
+
this.avmCircuitHints.noteHashWriteRequest.items.push(new AvmAppendTreeHint(leafIndex, noteHash, path));
|
|
141
214
|
this.incrementSideEffectCounter();
|
|
142
215
|
}
|
|
143
216
|
|
|
144
217
|
public traceNullifierCheck(
|
|
145
|
-
_contractAddress:
|
|
218
|
+
_contractAddress: AztecAddress,
|
|
146
219
|
nullifier: Fr,
|
|
147
|
-
_leafIndex: Fr,
|
|
148
220
|
exists: boolean,
|
|
149
|
-
|
|
221
|
+
lowLeafPreimage: NullifierLeafPreimage = NullifierLeafPreimage.empty(),
|
|
222
|
+
lowLeafIndex: Fr = Fr.zero(),
|
|
223
|
+
lowLeafPath: Fr[] = emptyNullifierPath(),
|
|
150
224
|
) {
|
|
151
225
|
// NOTE: contractAddress is unused but will be important when an AVM circuit processes an entire enqueued call
|
|
152
226
|
// NOTE: isPending and leafIndex are unused for now but may be used for optimizations or kernel hints later
|
|
@@ -162,22 +236,43 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
162
236
|
this.avmCircuitHints.nullifierExists.items.push(
|
|
163
237
|
new AvmKeyValueHint(/*key=*/ new Fr(this.sideEffectCounter), /*value=*/ new Fr(exists ? 1 : 0)),
|
|
164
238
|
);
|
|
239
|
+
|
|
240
|
+
// New Hints
|
|
241
|
+
this.avmCircuitHints.nullifierReadRequest.items.push(
|
|
242
|
+
new AvmNullifierReadTreeHint(lowLeafPreimage, lowLeafIndex, lowLeafPath),
|
|
243
|
+
);
|
|
165
244
|
this.log.debug(`NULLIFIER_EXISTS cnt: ${this.sideEffectCounter}`);
|
|
166
245
|
this.incrementSideEffectCounter();
|
|
167
246
|
}
|
|
168
247
|
|
|
169
|
-
public traceNewNullifier(
|
|
248
|
+
public traceNewNullifier(
|
|
249
|
+
_contractAddress: AztecAddress,
|
|
250
|
+
nullifier: Fr,
|
|
251
|
+
lowLeafPreimage: NullifierLeafPreimage = NullifierLeafPreimage.empty(),
|
|
252
|
+
lowLeafIndex: Fr = Fr.zero(),
|
|
253
|
+
lowLeafPath: Fr[] = emptyNullifierPath(),
|
|
254
|
+
insertionPath: Fr[] = emptyNullifierPath(),
|
|
255
|
+
) {
|
|
170
256
|
// NOTE: contractAddress is unused but will be important when an AVM circuit processes an entire enqueued call
|
|
171
257
|
if (this.nullifiers.length >= MAX_NULLIFIERS_PER_TX) {
|
|
172
258
|
throw new SideEffectLimitReachedError('nullifier', MAX_NULLIFIERS_PER_TX);
|
|
173
259
|
}
|
|
174
260
|
this.nullifiers.push(new Nullifier(nullifier, this.sideEffectCounter, /*noteHash=*/ Fr.ZERO));
|
|
261
|
+
// New hinting
|
|
262
|
+
const lowLeafReadHint = new AvmNullifierReadTreeHint(lowLeafPreimage, lowLeafIndex, lowLeafPath);
|
|
263
|
+
this.avmCircuitHints.nullifierWriteHints.items.push(new AvmNullifierWriteTreeHint(lowLeafReadHint, insertionPath));
|
|
175
264
|
this.log.debug(`NEW_NULLIFIER cnt: ${this.sideEffectCounter}`);
|
|
176
265
|
this.incrementSideEffectCounter();
|
|
177
266
|
}
|
|
178
267
|
|
|
179
268
|
// TODO(8287): _exists can be removed once we have the vm properly handling the equality check
|
|
180
|
-
public traceL1ToL2MessageCheck(
|
|
269
|
+
public traceL1ToL2MessageCheck(
|
|
270
|
+
_contractAddress: AztecAddress,
|
|
271
|
+
msgHash: Fr,
|
|
272
|
+
msgLeafIndex: Fr,
|
|
273
|
+
exists: boolean,
|
|
274
|
+
path: Fr[] = emptyL1ToL2MessagePath(),
|
|
275
|
+
) {
|
|
181
276
|
// NOTE: contractAddress is unused but will be important when an AVM circuit processes an entire enqueued call
|
|
182
277
|
if (this.l1ToL2MsgReadRequests.length >= MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_TX) {
|
|
183
278
|
throw new SideEffectLimitReachedError('l1 to l2 message read request', MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_TX);
|
|
@@ -186,10 +281,13 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
186
281
|
this.avmCircuitHints.l1ToL2MessageExists.items.push(
|
|
187
282
|
new AvmKeyValueHint(/*key=*/ new Fr(msgLeafIndex), /*value=*/ exists ? Fr.ONE : Fr.ZERO),
|
|
188
283
|
);
|
|
284
|
+
|
|
285
|
+
// New Hinting
|
|
286
|
+
this.avmCircuitHints.l1ToL2MessageReadRequest.items.push(new AvmAppendTreeHint(msgLeafIndex, msgHash, path));
|
|
189
287
|
// NOTE: counter does not increment for l1tol2 message checks (because it doesn't rely on pending messages)
|
|
190
288
|
}
|
|
191
289
|
|
|
192
|
-
public traceNewL2ToL1Message(_contractAddress:
|
|
290
|
+
public traceNewL2ToL1Message(_contractAddress: AztecAddress, recipient: Fr, content: Fr) {
|
|
193
291
|
if (this.newL2ToL1Messages.length >= MAX_L2_TO_L1_MSGS_PER_TX) {
|
|
194
292
|
throw new SideEffectLimitReachedError('l2 to l1 message', MAX_L2_TO_L1_MSGS_PER_TX);
|
|
195
293
|
}
|
|
@@ -199,14 +297,11 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
199
297
|
this.incrementSideEffectCounter();
|
|
200
298
|
}
|
|
201
299
|
|
|
202
|
-
public traceUnencryptedLog(contractAddress:
|
|
300
|
+
public traceUnencryptedLog(contractAddress: AztecAddress, log: Fr[]) {
|
|
203
301
|
if (this.unencryptedLogs.length >= MAX_UNENCRYPTED_LOGS_PER_TX) {
|
|
204
302
|
throw new SideEffectLimitReachedError('unencrypted log', MAX_UNENCRYPTED_LOGS_PER_TX);
|
|
205
303
|
}
|
|
206
|
-
const ulog = new UnencryptedL2Log(
|
|
207
|
-
AztecAddress.fromField(contractAddress),
|
|
208
|
-
Buffer.concat(log.map(f => f.toBuffer())),
|
|
209
|
-
);
|
|
304
|
+
const ulog = new UnencryptedL2Log(contractAddress, Buffer.concat(log.map(f => f.toBuffer())));
|
|
210
305
|
const basicLogHash = Fr.fromBuffer(ulog.hash());
|
|
211
306
|
this.unencryptedLogs.push(ulog);
|
|
212
307
|
this.allUnencryptedLogs.push(ulog);
|
|
@@ -218,7 +313,7 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
218
313
|
}
|
|
219
314
|
|
|
220
315
|
public traceGetContractInstance(
|
|
221
|
-
contractAddress:
|
|
316
|
+
contractAddress: AztecAddress,
|
|
222
317
|
exists: boolean,
|
|
223
318
|
instance: SerializableContractInstance = SerializableContractInstance.default(),
|
|
224
319
|
) {
|
|
@@ -242,8 +337,9 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
242
337
|
// This tracing function gets called everytime we start simulation/execution.
|
|
243
338
|
// This happens both when starting a new top-level trace and the start of every nested trace
|
|
244
339
|
// We use this to collect the AvmContractBytecodeHints
|
|
340
|
+
// We need to trace teh merkle tree as well here
|
|
245
341
|
public traceGetBytecode(
|
|
246
|
-
contractAddress:
|
|
342
|
+
contractAddress: AztecAddress,
|
|
247
343
|
exists: boolean,
|
|
248
344
|
bytecode: Buffer = Buffer.alloc(0),
|
|
249
345
|
contractInstance: SerializableContractInstance = SerializableContractInstance.default(),
|
|
@@ -298,7 +394,7 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
298
394
|
// one for max unique contract calls, and another based on max nullifier reads.
|
|
299
395
|
// Since this trace function happens _after_ a nested call, such threshold limits must take
|
|
300
396
|
// place in another trace function that occurs _before_ a nested call.
|
|
301
|
-
const result = nestedCallTrace.
|
|
397
|
+
const result = nestedCallTrace.toPublicFunctionCallResult(
|
|
302
398
|
nestedEnvironment,
|
|
303
399
|
startGasLeft,
|
|
304
400
|
endGasLeft,
|
|
@@ -331,10 +427,25 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
331
427
|
);
|
|
332
428
|
}
|
|
333
429
|
|
|
430
|
+
public traceEnqueuedCall(
|
|
431
|
+
/** The call request from private that enqueued this call. */
|
|
432
|
+
_publicCallRequest: PublicCallRequest,
|
|
433
|
+
/** The call's calldata */
|
|
434
|
+
_calldata: Fr[],
|
|
435
|
+
/** Did the call revert? */
|
|
436
|
+
_reverted: boolean,
|
|
437
|
+
) {
|
|
438
|
+
throw new Error('Not implemented');
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
public merge(_nestedTrace: this, _reverted: boolean = false) {
|
|
442
|
+
throw new Error('Not implemented');
|
|
443
|
+
}
|
|
444
|
+
|
|
334
445
|
/**
|
|
335
446
|
* Convert this trace to a PublicExecutionResult for use externally to the simulator.
|
|
336
447
|
*/
|
|
337
|
-
public
|
|
448
|
+
public toPublicFunctionCallResult(
|
|
338
449
|
/** The execution environment of the nested call. */
|
|
339
450
|
avmEnvironment: AvmExecutionEnvironment,
|
|
340
451
|
/** How much gas was available for this public execution. */
|
|
@@ -347,7 +458,7 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
347
458
|
avmCallResults: AvmContractCallResult,
|
|
348
459
|
/** Function name for logging */
|
|
349
460
|
functionName: string = 'unknown',
|
|
350
|
-
):
|
|
461
|
+
): PublicFunctionCallResult {
|
|
351
462
|
return {
|
|
352
463
|
executionRequest: createPublicExecutionRequest(avmEnvironment),
|
|
353
464
|
|
|
@@ -361,7 +472,9 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
361
472
|
calldata: avmEnvironment.calldata,
|
|
362
473
|
returnValues: avmCallResults.output,
|
|
363
474
|
reverted: avmCallResults.reverted,
|
|
364
|
-
revertReason: avmCallResults.revertReason
|
|
475
|
+
revertReason: avmCallResults.revertReason
|
|
476
|
+
? createSimulationError(avmCallResults.revertReason, avmCallResults.output)
|
|
477
|
+
: undefined,
|
|
365
478
|
|
|
366
479
|
contractStorageReads: this.contractStorageReads,
|
|
367
480
|
contractStorageUpdateRequests: this.contractStorageUpdateRequests,
|
|
@@ -386,6 +499,15 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
386
499
|
};
|
|
387
500
|
}
|
|
388
501
|
|
|
502
|
+
public toPublicEnqueuedCallExecutionResult(
|
|
503
|
+
/** How much gas was left after this public execution. */
|
|
504
|
+
_endGasLeft: Gas,
|
|
505
|
+
/** The call's results */
|
|
506
|
+
_avmCallResults: AvmContractCallResult,
|
|
507
|
+
): EnqueuedPublicCallExecutionResultWithSideEffects {
|
|
508
|
+
throw new Error('Not implemented');
|
|
509
|
+
}
|
|
510
|
+
|
|
389
511
|
private enforceLimitOnNullifierChecks(errorMsgOrigin: string = '') {
|
|
390
512
|
// NOTE: Why error if _either_ limit was reached? If user code emits either an existent or non-existent
|
|
391
513
|
// nullifier read request (NULLIFIEREXISTS, GETCONTRACTINSTANCE, *CALL), and one of the limits has been
|
|
@@ -406,6 +528,10 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
406
528
|
);
|
|
407
529
|
}
|
|
408
530
|
}
|
|
531
|
+
|
|
532
|
+
public getUnencryptedLogs(): UnencryptedL2Log[] {
|
|
533
|
+
throw new Error('Not implemented');
|
|
534
|
+
}
|
|
409
535
|
}
|
|
410
536
|
|
|
411
537
|
/**
|
|
@@ -1,25 +1,76 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type UnencryptedL2Log } from '@aztec/circuit-types';
|
|
2
|
+
import {
|
|
3
|
+
type ContractClassIdPreimage,
|
|
4
|
+
type Gas,
|
|
5
|
+
type NullifierLeafPreimage,
|
|
6
|
+
type PublicCallRequest,
|
|
7
|
+
type PublicDataTreeLeafPreimage,
|
|
8
|
+
type SerializableContractInstance,
|
|
9
|
+
} from '@aztec/circuits.js';
|
|
10
|
+
import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
2
11
|
import { type Fr } from '@aztec/foundation/fields';
|
|
3
12
|
|
|
4
13
|
import { type AvmContractCallResult } from '../avm/avm_contract_call_result.js';
|
|
5
14
|
import { type AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
|
|
15
|
+
import { type EnqueuedPublicCallExecutionResultWithSideEffects, type PublicFunctionCallResult } from './execution.js';
|
|
6
16
|
|
|
7
17
|
export interface PublicSideEffectTraceInterface {
|
|
8
18
|
fork(): PublicSideEffectTraceInterface;
|
|
19
|
+
merge(nestedTrace: PublicSideEffectTraceInterface, reverted?: boolean): void;
|
|
9
20
|
getCounter(): number;
|
|
10
21
|
// all "trace*" functions can throw SideEffectLimitReachedError
|
|
11
|
-
tracePublicStorageRead(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
tracePublicStorageRead(
|
|
23
|
+
contractAddress: AztecAddress,
|
|
24
|
+
slot: Fr,
|
|
25
|
+
value: Fr,
|
|
26
|
+
leafPreimage?: PublicDataTreeLeafPreimage,
|
|
27
|
+
leafIndex?: Fr,
|
|
28
|
+
path?: Fr[],
|
|
29
|
+
): void;
|
|
30
|
+
tracePublicStorageWrite(
|
|
31
|
+
contractAddress: AztecAddress,
|
|
32
|
+
slot: Fr, // This is the storage slot not the computed leaf slot
|
|
33
|
+
value: Fr,
|
|
34
|
+
lowLeafPreimage?: PublicDataTreeLeafPreimage,
|
|
35
|
+
lowLeafIndex?: Fr,
|
|
36
|
+
lowLeafPath?: Fr[],
|
|
37
|
+
newLeafPreimage?: PublicDataTreeLeafPreimage,
|
|
38
|
+
insertionPath?: Fr[],
|
|
39
|
+
): void;
|
|
40
|
+
traceNoteHashCheck(contractAddress: AztecAddress, noteHash: Fr, leafIndex: Fr, exists: boolean, path?: Fr[]): void;
|
|
41
|
+
traceNewNoteHash(contractAddress: AztecAddress, noteHash: Fr, leafIndex?: Fr, path?: Fr[]): void;
|
|
42
|
+
traceNullifierCheck(
|
|
43
|
+
contractAddress: AztecAddress,
|
|
44
|
+
nullifier: Fr,
|
|
45
|
+
exists: boolean,
|
|
46
|
+
lowLeafPreimage?: NullifierLeafPreimage,
|
|
47
|
+
lowLeafIndex?: Fr,
|
|
48
|
+
lowLeafPath?: Fr[],
|
|
49
|
+
): void;
|
|
50
|
+
traceNewNullifier(
|
|
51
|
+
contractAddress: AztecAddress,
|
|
52
|
+
nullifier: Fr,
|
|
53
|
+
lowLeafPreimage?: NullifierLeafPreimage,
|
|
54
|
+
lowLeafIndex?: Fr,
|
|
55
|
+
lowLeafPath?: Fr[],
|
|
56
|
+
insertionPath?: Fr[],
|
|
57
|
+
): void;
|
|
58
|
+
traceL1ToL2MessageCheck(
|
|
59
|
+
contractAddress: AztecAddress,
|
|
60
|
+
msgHash: Fr,
|
|
61
|
+
msgLeafIndex: Fr,
|
|
62
|
+
exists: boolean,
|
|
63
|
+
path?: Fr[],
|
|
64
|
+
): void;
|
|
65
|
+
traceNewL2ToL1Message(contractAddress: AztecAddress, recipient: Fr, content: Fr): void;
|
|
66
|
+
traceUnencryptedLog(contractAddress: AztecAddress, log: Fr[]): void;
|
|
67
|
+
traceGetContractInstance(
|
|
68
|
+
contractAddress: AztecAddress,
|
|
69
|
+
exists: boolean,
|
|
70
|
+
instance?: SerializableContractInstance,
|
|
71
|
+
): void;
|
|
21
72
|
traceGetBytecode(
|
|
22
|
-
contractAddress:
|
|
73
|
+
contractAddress: AztecAddress,
|
|
23
74
|
exists: boolean,
|
|
24
75
|
bytecode?: Buffer,
|
|
25
76
|
contractInstance?: SerializableContractInstance,
|
|
@@ -31,10 +82,8 @@ export interface PublicSideEffectTraceInterface {
|
|
|
31
82
|
/** The execution environment of the nested call. */
|
|
32
83
|
nestedEnvironment: AvmExecutionEnvironment,
|
|
33
84
|
/** How much gas was available for this public execution. */
|
|
34
|
-
// TODO(dbanks12): consider moving to AvmExecutionEnvironment
|
|
35
85
|
startGasLeft: Gas,
|
|
36
86
|
/** How much gas was left after this public execution. */
|
|
37
|
-
// TODO(dbanks12): consider moving to AvmContractCallResults
|
|
38
87
|
endGasLeft: Gas,
|
|
39
88
|
/** Bytecode used for this execution. */
|
|
40
89
|
bytecode: Buffer,
|
|
@@ -43,4 +92,33 @@ export interface PublicSideEffectTraceInterface {
|
|
|
43
92
|
/** Function name */
|
|
44
93
|
functionName: string,
|
|
45
94
|
): void;
|
|
95
|
+
traceEnqueuedCall(
|
|
96
|
+
/** The call request from private that enqueued this call. */
|
|
97
|
+
publicCallRequest: PublicCallRequest,
|
|
98
|
+
/** The call's calldata */
|
|
99
|
+
calldata: Fr[],
|
|
100
|
+
/** Did the call revert? */
|
|
101
|
+
reverted: boolean,
|
|
102
|
+
): void;
|
|
103
|
+
toPublicEnqueuedCallExecutionResult(
|
|
104
|
+
/** How much gas was left after this public execution. */
|
|
105
|
+
endGasLeft: Gas,
|
|
106
|
+
/** The call's results */
|
|
107
|
+
avmCallResults: AvmContractCallResult,
|
|
108
|
+
): EnqueuedPublicCallExecutionResultWithSideEffects;
|
|
109
|
+
toPublicFunctionCallResult(
|
|
110
|
+
/** The execution environment of the nested call. */
|
|
111
|
+
avmEnvironment: AvmExecutionEnvironment,
|
|
112
|
+
/** How much gas was available for this public execution. */
|
|
113
|
+
startGasLeft: Gas,
|
|
114
|
+
/** How much gas was left after this public execution. */
|
|
115
|
+
endGasLeft: Gas,
|
|
116
|
+
/** Bytecode used for this execution. */
|
|
117
|
+
bytecode: Buffer,
|
|
118
|
+
/** The call's results */
|
|
119
|
+
avmCallResults: AvmContractCallResult,
|
|
120
|
+
/** Function name for logging */
|
|
121
|
+
functionName: string,
|
|
122
|
+
): PublicFunctionCallResult;
|
|
123
|
+
getUnencryptedLogs(): UnencryptedL2Log[];
|
|
46
124
|
}
|