@aztec/simulator 0.87.2 → 0.87.3-nightly.20250528
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/client.d.ts +2 -0
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +2 -0
- package/dest/private/acvm/acvm.d.ts +4 -0
- package/dest/private/acvm/acvm.d.ts.map +1 -1
- package/dest/private/acvm/oracle/oracle.d.ts +1 -1
- package/dest/private/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/private/acvm/oracle/oracle.js +2 -2
- package/dest/private/acvm/oracle/typed_oracle.d.ts +1 -1
- package/dest/private/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/private/acvm/oracle/typed_oracle.js +2 -2
- package/dest/private/private_execution.d.ts.map +1 -1
- package/dest/private/private_execution.js +2 -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 +1 -1
- package/dest/private/providers/circuit_recording/circuit_recorder.d.ts +39 -19
- package/dest/private/providers/circuit_recording/circuit_recorder.d.ts.map +1 -1
- package/dest/private/providers/circuit_recording/circuit_recorder.js +90 -126
- package/dest/private/providers/circuit_recording/file_circuit_recorder.d.ts +31 -0
- package/dest/private/providers/circuit_recording/file_circuit_recorder.d.ts.map +1 -0
- package/dest/private/providers/circuit_recording/file_circuit_recorder.js +135 -0
- package/dest/private/providers/circuit_recording/memory_circuit_recorder.d.ts +5 -0
- package/dest/private/providers/circuit_recording/memory_circuit_recorder.d.ts.map +1 -0
- package/dest/private/providers/circuit_recording/memory_circuit_recorder.js +9 -0
- package/dest/private/providers/circuit_recording/simulation_provider_recorder_wrapper.d.ts +3 -1
- package/dest/private/providers/circuit_recording/simulation_provider_recorder_wrapper.d.ts.map +1 -1
- package/dest/private/providers/circuit_recording/simulation_provider_recorder_wrapper.js +16 -11
- package/dest/private/utility_execution_oracle.d.ts +1 -1
- package/dest/private/utility_execution_oracle.d.ts.map +1 -1
- package/dest/private/utility_execution_oracle.js +1 -1
- package/dest/public/avm/avm_gas.d.ts +4 -5
- package/dest/public/avm/avm_gas.d.ts.map +1 -1
- package/dest/public/avm/avm_gas.js +28 -18
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +1 -0
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.js +6 -0
- package/dest/public/avm/fixtures/utils.js +1 -1
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/accrued_substate.js +8 -7
- package/dest/public/avm/opcodes/addressing_mode.d.ts +2 -0
- package/dest/public/avm/opcodes/addressing_mode.d.ts.map +1 -1
- package/dest/public/avm/opcodes/addressing_mode.js +6 -0
- package/dest/public/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/public/avm/opcodes/arithmetic.js +1 -1
- package/dest/public/avm/opcodes/bitwise.d.ts +5 -1
- package/dest/public/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/public/avm/opcodes/bitwise.js +17 -2
- package/dest/public/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/public/avm/opcodes/comparators.js +1 -1
- package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/public/avm/opcodes/contract.js +1 -1
- package/dest/public/avm/opcodes/control_flow.d.ts.map +1 -1
- package/dest/public/avm/opcodes/control_flow.js +4 -4
- package/dest/public/avm/opcodes/conversion.d.ts +1 -0
- package/dest/public/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/public/avm/opcodes/conversion.js +263 -2
- package/dest/public/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/public/avm/opcodes/ec_add.js +1 -1
- package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/public/avm/opcodes/environment_getters.js +1 -1
- package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/public/avm/opcodes/external_calls.js +6 -8
- package/dest/public/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/public/avm/opcodes/hashing.js +3 -3
- package/dest/public/avm/opcodes/instruction.d.ts +9 -3
- package/dest/public/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/public/avm/opcodes/instruction.js +12 -7
- package/dest/public/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/public/avm/opcodes/memory.js +8 -6
- package/dest/public/avm/opcodes/misc.js +1 -3
- package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/public/avm/opcodes/storage.js +5 -3
- package/dest/public/fixtures/index.d.ts +1 -0
- package/dest/public/fixtures/index.d.ts.map +1 -1
- package/dest/public/fixtures/index.js +1 -0
- package/dest/public/fixtures/minimal_public_tx.d.ts +9 -0
- package/dest/public/fixtures/minimal_public_tx.d.ts.map +1 -0
- package/dest/public/fixtures/minimal_public_tx.js +43 -0
- package/dest/public/public_tx_simulator/apps_tests/amm_test.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/apps_tests/amm_test.js +27 -55
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +5 -4
- package/dest/public/side_effect_trace.d.ts +4 -1
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +13 -2
- package/dest/public/side_effect_trace_interface.d.ts +1 -0
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/dest/public/state_manager/state_manager.d.ts +1 -0
- package/dest/public/state_manager/state_manager.d.ts.map +1 -1
- package/dest/public/state_manager/state_manager.js +3 -0
- package/dest/server.d.ts +2 -0
- package/dest/server.d.ts.map +1 -1
- package/dest/server.js +2 -0
- package/dest/testing.d.ts +1 -1
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +1 -1
- package/package.json +15 -15
- package/src/client.ts +2 -0
- package/src/private/acvm/acvm.ts +3 -0
- package/src/private/acvm/oracle/oracle.ts +2 -2
- package/src/private/acvm/oracle/typed_oracle.ts +2 -2
- package/src/private/private_execution.ts +1 -0
- package/src/private/private_execution_oracle.ts +1 -1
- package/src/private/providers/circuit_recording/circuit_recorder.ts +114 -136
- package/src/private/providers/circuit_recording/file_circuit_recorder.ts +158 -0
- package/src/private/providers/circuit_recording/memory_circuit_recorder.ts +11 -0
- package/src/private/providers/circuit_recording/simulation_provider_recorder_wrapper.ts +22 -14
- package/src/private/utility_execution_oracle.ts +1 -1
- package/src/public/avm/avm_gas.ts +20 -14
- package/src/public/avm/fixtures/base_avm_simulation_tester.ts +5 -0
- package/src/public/avm/fixtures/utils.ts +1 -1
- package/src/public/avm/opcodes/accrued_substate.ts +23 -7
- package/src/public/avm/opcodes/addressing_mode.ts +8 -0
- package/src/public/avm/opcodes/arithmetic.ts +3 -1
- package/src/public/avm/opcodes/bitwise.ts +26 -2
- package/src/public/avm/opcodes/comparators.ts +3 -1
- package/src/public/avm/opcodes/contract.ts +3 -1
- package/src/public/avm/opcodes/control_flow.ts +6 -4
- package/src/public/avm/opcodes/conversion.ts +21 -2
- package/src/public/avm/opcodes/ec_add.ts +3 -1
- package/src/public/avm/opcodes/environment_getters.ts +3 -1
- package/src/public/avm/opcodes/external_calls.ts +16 -8
- package/src/public/avm/opcodes/hashing.ts +11 -3
- package/src/public/avm/opcodes/instruction.ts +14 -7
- package/src/public/avm/opcodes/memory.ts +23 -6
- package/src/public/avm/opcodes/misc.ts +4 -4
- package/src/public/avm/opcodes/storage.ts +13 -3
- package/src/public/fixtures/index.ts +1 -0
- package/src/public/fixtures/minimal_public_tx.ts +57 -0
- package/src/public/public_tx_simulator/apps_tests/amm_test.ts +49 -44
- package/src/public/public_tx_simulator/public_tx_context.ts +26 -5
- package/src/public/side_effect_trace.ts +13 -0
- package/src/public/side_effect_trace_interface.ts +1 -0
- package/src/public/state_manager/state_manager.ts +4 -0
- package/src/server.ts +2 -0
- package/src/testing.ts +1 -1
|
@@ -68,7 +68,9 @@ export class Set extends Instruction {
|
|
|
68
68
|
const memory = context.machineState.memory;
|
|
69
69
|
const addressing = Addressing.fromWire(this.indirect);
|
|
70
70
|
|
|
71
|
-
context.machineState.consumeGas(
|
|
71
|
+
context.machineState.consumeGas(
|
|
72
|
+
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
73
|
+
);
|
|
72
74
|
|
|
73
75
|
const operands = [this.dstOffset];
|
|
74
76
|
const [dstOffset] = addressing.resolve(operands, memory);
|
|
@@ -108,7 +110,9 @@ export class Cast extends Instruction {
|
|
|
108
110
|
const memory = context.machineState.memory;
|
|
109
111
|
const addressing = Addressing.fromWire(this.indirect);
|
|
110
112
|
|
|
111
|
-
context.machineState.consumeGas(
|
|
113
|
+
context.machineState.consumeGas(
|
|
114
|
+
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
115
|
+
);
|
|
112
116
|
|
|
113
117
|
const operands = [this.srcOffset, this.dstOffset];
|
|
114
118
|
const [srcOffset, dstOffset] = addressing.resolve(operands, memory);
|
|
@@ -151,7 +155,9 @@ export class Mov extends Instruction {
|
|
|
151
155
|
const memory = context.machineState.memory;
|
|
152
156
|
const addressing = Addressing.fromWire(this.indirect);
|
|
153
157
|
|
|
154
|
-
context.machineState.consumeGas(
|
|
158
|
+
context.machineState.consumeGas(
|
|
159
|
+
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
160
|
+
);
|
|
155
161
|
|
|
156
162
|
const operands = [this.srcOffset, this.dstOffset];
|
|
157
163
|
const [srcOffset, dstOffset] = addressing.resolve(operands, memory);
|
|
@@ -185,13 +191,17 @@ export class CalldataCopy extends Instruction {
|
|
|
185
191
|
const memory = context.machineState.memory;
|
|
186
192
|
const addressing = Addressing.fromWire(this.indirect);
|
|
187
193
|
|
|
194
|
+
context.machineState.consumeGas(
|
|
195
|
+
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
196
|
+
);
|
|
197
|
+
|
|
188
198
|
const operands = [this.copySizeOffset, this.cdStartOffset, this.dstOffset];
|
|
189
199
|
const [copySizeOffset, cdStartOffset, dstOffset] = addressing.resolve(operands, memory);
|
|
190
200
|
|
|
191
201
|
memory.checkTags(TypeTag.UINT32, cdStartOffset, copySizeOffset);
|
|
192
202
|
const cdStart = memory.get(cdStartOffset).toNumber();
|
|
193
203
|
const copySize = memory.get(copySizeOffset).toNumber();
|
|
194
|
-
context.machineState.consumeGas(this.
|
|
204
|
+
context.machineState.consumeGas(this.dynamicGasCost(copySize));
|
|
195
205
|
|
|
196
206
|
// Values which are out-of-range of the calldata array will be set with Field(0);
|
|
197
207
|
const slice = context.environment.calldata.slice(cdStart, cdStart + copySize).map(f => new Field(f));
|
|
@@ -219,9 +229,12 @@ export class ReturndataSize extends Instruction {
|
|
|
219
229
|
const memory = context.machineState.memory;
|
|
220
230
|
const addressing = Addressing.fromWire(this.indirect);
|
|
221
231
|
|
|
232
|
+
context.machineState.consumeGas(
|
|
233
|
+
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
234
|
+
);
|
|
235
|
+
|
|
222
236
|
const operands = [this.dstOffset];
|
|
223
237
|
const [dstOffset] = addressing.resolve(operands, memory);
|
|
224
|
-
context.machineState.consumeGas(this.gasCost());
|
|
225
238
|
|
|
226
239
|
memory.set(dstOffset, new Uint32(context.machineState.nestedReturndata.length));
|
|
227
240
|
}
|
|
@@ -252,13 +265,17 @@ export class ReturndataCopy extends Instruction {
|
|
|
252
265
|
const memory = context.machineState.memory;
|
|
253
266
|
const addressing = Addressing.fromWire(this.indirect);
|
|
254
267
|
|
|
268
|
+
context.machineState.consumeGas(
|
|
269
|
+
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
270
|
+
);
|
|
271
|
+
|
|
255
272
|
const operands = [this.copySizeOffset, this.rdStartOffset, this.dstOffset];
|
|
256
273
|
const [copySizeOffset, rdStartOffset, dstOffset] = addressing.resolve(operands, memory);
|
|
257
274
|
|
|
258
275
|
memory.checkTags(TypeTag.UINT32, rdStartOffset, copySizeOffset);
|
|
259
276
|
const rdStart = memory.get(rdStartOffset).toNumber();
|
|
260
277
|
const copySize = memory.get(copySizeOffset).toNumber();
|
|
261
|
-
context.machineState.consumeGas(this.
|
|
278
|
+
context.machineState.consumeGas(this.dynamicGasCost(copySize));
|
|
262
279
|
|
|
263
280
|
// Values which are out-of-range of the returndata array will be set with Field(0);
|
|
264
281
|
const slice = context.machineState.nestedReturndata.slice(rdStart, rdStart + copySize).map(f => new Field(f));
|
|
@@ -35,6 +35,10 @@ export class DebugLog extends Instruction {
|
|
|
35
35
|
const memory = context.machineState.memory;
|
|
36
36
|
const addressing = Addressing.fromWire(this.indirect);
|
|
37
37
|
|
|
38
|
+
context.machineState.consumeGas(
|
|
39
|
+
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
40
|
+
);
|
|
41
|
+
|
|
38
42
|
const operands = [this.messageOffset, this.fieldsOffset, this.fieldsSizeOffset];
|
|
39
43
|
const [messageOffset, fieldsOffset, fieldsSizeOffset] = addressing.resolve(operands, memory);
|
|
40
44
|
memory.checkTag(TypeTag.UINT32, fieldsSizeOffset);
|
|
@@ -60,9 +64,5 @@ export class DebugLog extends Instruction {
|
|
|
60
64
|
|
|
61
65
|
DebugLog.logger.verbose(formattedStr);
|
|
62
66
|
}
|
|
63
|
-
|
|
64
|
-
// Despite having dynamic "size" operands, the gas cost is fixed because
|
|
65
|
-
// this opcode is a no-op except during client-initiated simulation
|
|
66
|
-
context.machineState.consumeGas(this.gasCost());
|
|
67
67
|
}
|
|
68
68
|
}
|
|
@@ -39,14 +39,22 @@ export class SStore extends BaseStorageInstruction {
|
|
|
39
39
|
const memory = context.machineState.memory;
|
|
40
40
|
const addressing = Addressing.fromWire(this.indirect);
|
|
41
41
|
|
|
42
|
-
context.machineState.consumeGas(
|
|
42
|
+
context.machineState.consumeGas(
|
|
43
|
+
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
44
|
+
);
|
|
43
45
|
|
|
44
46
|
const operands = [this.aOffset, this.bOffset];
|
|
45
47
|
const [srcOffset, slotOffset] = addressing.resolve(operands, memory);
|
|
48
|
+
// We read before tag checking since it's needed for gas cost calculation
|
|
49
|
+
const slot = memory.get(slotOffset).toFr();
|
|
50
|
+
|
|
51
|
+
context.machineState.consumeGas(
|
|
52
|
+
this.dynamicGasCost(Number(context.persistableState.isStorageCold(context.environment.address, slot))),
|
|
53
|
+
);
|
|
54
|
+
|
|
46
55
|
memory.checkTag(TypeTag.FIELD, slotOffset);
|
|
47
56
|
memory.checkTag(TypeTag.FIELD, srcOffset);
|
|
48
57
|
|
|
49
|
-
const slot = memory.get(slotOffset).toFr();
|
|
50
58
|
const value = memory.get(srcOffset).toFr();
|
|
51
59
|
await context.persistableState.writeStorage(context.environment.address, slot, value);
|
|
52
60
|
}
|
|
@@ -64,7 +72,9 @@ export class SLoad extends BaseStorageInstruction {
|
|
|
64
72
|
const memory = context.machineState.memory;
|
|
65
73
|
const addressing = Addressing.fromWire(this.indirect);
|
|
66
74
|
|
|
67
|
-
context.machineState.consumeGas(
|
|
75
|
+
context.machineState.consumeGas(
|
|
76
|
+
this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
|
|
77
|
+
);
|
|
68
78
|
|
|
69
79
|
const operands = [this.aOffset, this.bOffset];
|
|
70
80
|
const [slotOffset, dstOffset] = addressing.resolve(operands, memory);
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { FunctionType, emptyContractArtifact, emptyFunctionArtifact } from '@aztec/stdlib/abi';
|
|
2
|
+
import { AvmCircuitInputs } from '@aztec/stdlib/avm';
|
|
3
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
|
|
5
|
+
import avmMinimalCircuitInputsJson from '../../../artifacts/avm_minimal_inputs.json' with { type: 'json' };
|
|
6
|
+
import { TypeTag } from '../avm/avm_memory_types.js';
|
|
7
|
+
import { Add, Return, Set } from '../avm/opcodes/index.js';
|
|
8
|
+
import { encodeToBytecode } from '../avm/serialization/bytecode_serialization.js';
|
|
9
|
+
import { Opcode } from '../avm/serialization/instruction_serialization.js';
|
|
10
|
+
import type { PublicTxResult } from '../public_tx_simulator/public_tx_simulator.js';
|
|
11
|
+
import { PublicTxSimulationTester } from './public_tx_simulation_tester.js';
|
|
12
|
+
|
|
13
|
+
export async function createAvmMinimalPublicTx(): Promise<PublicTxResult> {
|
|
14
|
+
const deployer = AztecAddress.fromNumber(42);
|
|
15
|
+
|
|
16
|
+
const simTester = await PublicTxSimulationTester.create();
|
|
17
|
+
|
|
18
|
+
const minimalBytecode = encodeToBytecode([
|
|
19
|
+
new Set(/*indirect*/ 0, /*dstOffset*/ 0, TypeTag.UINT32, /*value*/ 1).as(Opcode.SET_8, Set.wireFormat8),
|
|
20
|
+
new Set(/*indirect*/ 0, /*dstOffset*/ 1, TypeTag.UINT32, /*value*/ 2).as(Opcode.SET_8, Set.wireFormat8),
|
|
21
|
+
new Add(/*indirect=*/ 0, /*aOffset=*/ 0, /*bOffset=*/ 1, /*dstOffset=*/ 2).as(Opcode.ADD_8, Add.wireFormat8),
|
|
22
|
+
new Return(/*indirect=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 2),
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
const minimalContractArtifact = emptyContractArtifact();
|
|
26
|
+
minimalContractArtifact.name = 'MinimalContract';
|
|
27
|
+
minimalContractArtifact.functions = [emptyFunctionArtifact()];
|
|
28
|
+
minimalContractArtifact.functions[0].name = 'public_dispatch';
|
|
29
|
+
minimalContractArtifact.functions[0].functionType = FunctionType.PUBLIC;
|
|
30
|
+
minimalContractArtifact.functions[0].bytecode = minimalBytecode;
|
|
31
|
+
|
|
32
|
+
const minimalTestContract = await simTester.registerAndDeployContract(
|
|
33
|
+
/*constructorArgs=*/ [],
|
|
34
|
+
deployer,
|
|
35
|
+
/*contractArtifact=*/ minimalContractArtifact,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
return await simTester.simulateTx(
|
|
39
|
+
/*sender=*/ deployer,
|
|
40
|
+
/*setupCalls=*/ [],
|
|
41
|
+
/*appCalls=*/ [
|
|
42
|
+
{
|
|
43
|
+
address: minimalTestContract.address,
|
|
44
|
+
fnName: 'public_dispatch',
|
|
45
|
+
args: [],
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Reads the AVM circuit inputs for the minimal public tx from a pre-generated JSON file.
|
|
53
|
+
* @returns The AvmCircuitInputs for the minimal public tx.
|
|
54
|
+
*/
|
|
55
|
+
export function readAvmMinimalPublicTxInputsFromFile(): AvmCircuitInputs {
|
|
56
|
+
return AvmCircuitInputs.schema.parse(avmMinimalCircuitInputsJson);
|
|
57
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { GeneratorIndex } from '@aztec/constants';
|
|
2
|
+
import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto';
|
|
1
3
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
4
|
import type { Logger } from '@aztec/foundation/log';
|
|
3
5
|
import { AMMContractArtifact } from '@aztec/noir-contracts.js/AMM';
|
|
@@ -137,6 +139,24 @@ async function addLiquidity(
|
|
|
137
139
|
const liquidityPartialNote = {
|
|
138
140
|
commitment: new Fr(99),
|
|
139
141
|
};
|
|
142
|
+
const refundToken0PartialNoteValidityCommitment = await computePartialNoteValidityCommitment(
|
|
143
|
+
refundToken0PartialNote,
|
|
144
|
+
amm.address,
|
|
145
|
+
);
|
|
146
|
+
const refundToken1PartialNoteValidityCommitment = await computePartialNoteValidityCommitment(
|
|
147
|
+
refundToken1PartialNote,
|
|
148
|
+
amm.address,
|
|
149
|
+
);
|
|
150
|
+
const liquidityPartialNoteValidityCommitment = await computePartialNoteValidityCommitment(
|
|
151
|
+
liquidityPartialNote,
|
|
152
|
+
amm.address,
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
// We need to inject the validity commitments into the nullifier tree as that would be performed by the private token
|
|
156
|
+
// functions that are not invoked in this test.
|
|
157
|
+
await tester.insertNullifier(token0.address, refundToken0PartialNoteValidityCommitment);
|
|
158
|
+
await tester.insertNullifier(token1.address, refundToken1PartialNoteValidityCommitment);
|
|
159
|
+
await tester.insertNullifier(liquidityToken.address, liquidityPartialNoteValidityCommitment);
|
|
140
160
|
|
|
141
161
|
return await tester.simulateTxWithLabel(
|
|
142
162
|
/*txLabel=*/ 'AMM/add_liquidity',
|
|
@@ -150,13 +170,6 @@ async function addLiquidity(
|
|
|
150
170
|
args: [/*to=*/ amm.address, /*amount=*/ amount0Max],
|
|
151
171
|
address: token0.address,
|
|
152
172
|
},
|
|
153
|
-
// token0.prepare_private_balance_increase enqueues a call to _store_balances_set_partial_note
|
|
154
|
-
{
|
|
155
|
-
sender: token0.address, // INTERNAL FUNCTION! Sender must be 'this'.
|
|
156
|
-
fnName: '_store_balances_set_partial_note',
|
|
157
|
-
args: [refundToken0PartialNote],
|
|
158
|
-
address: token0.address,
|
|
159
|
-
},
|
|
160
173
|
// token1.transfer_to_public enqueues a call to _increase_public_balance
|
|
161
174
|
{
|
|
162
175
|
sender: token1.address, // INTERNAL FUNCTION! Sender must be 'this'.
|
|
@@ -164,20 +177,6 @@ async function addLiquidity(
|
|
|
164
177
|
args: [/*to=*/ amm.address, /*amount=*/ amount1Max],
|
|
165
178
|
address: token1.address,
|
|
166
179
|
},
|
|
167
|
-
// token1.prepare_private_balance_increase enqueues a call to _store_balances_set_partial_note
|
|
168
|
-
{
|
|
169
|
-
sender: token1.address, // INTERNAL FUNCTION! Sender must be 'this'.
|
|
170
|
-
fnName: '_store_balances_set_partial_note',
|
|
171
|
-
args: [refundToken1PartialNote],
|
|
172
|
-
address: token1.address,
|
|
173
|
-
},
|
|
174
|
-
// liquidityToken.prepare_private_balance_increase enqueues a call to _store_balances_set_partial_note
|
|
175
|
-
{
|
|
176
|
-
sender: liquidityToken.address, // INTERNAL FUNCTION! Sender must be 'this'.
|
|
177
|
-
fnName: '_store_balances_set_partial_note',
|
|
178
|
-
args: [liquidityPartialNote],
|
|
179
|
-
address: liquidityToken.address,
|
|
180
|
-
},
|
|
181
180
|
// amm.add_liquidity enqueues a call to _add_liquidity
|
|
182
181
|
{
|
|
183
182
|
sender: amm.address, // INTERNAL FUNCTION! Sender must be 'this'.
|
|
@@ -214,8 +213,16 @@ async function swapExactTokensForTokens(
|
|
|
214
213
|
_nonce?: bigint,
|
|
215
214
|
) {
|
|
216
215
|
const tokenOutPartialNote = {
|
|
217
|
-
commitment: new Fr(
|
|
216
|
+
commitment: new Fr(166),
|
|
218
217
|
};
|
|
218
|
+
const tokenOutPartialNoteValidityCommitment = await computePartialNoteValidityCommitment(
|
|
219
|
+
tokenOutPartialNote,
|
|
220
|
+
amm.address,
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
// We need to inject the validity commitment into the nullifier tree as that would be performed by the private token
|
|
224
|
+
// function that is not invoked in this test.
|
|
225
|
+
await tester.insertNullifier(tokenOut.address, tokenOutPartialNoteValidityCommitment);
|
|
219
226
|
|
|
220
227
|
return await tester.simulateTxWithLabel(
|
|
221
228
|
/*txLabel=*/ 'AMM/swap_exact_tokens_for_tokens',
|
|
@@ -229,14 +236,6 @@ async function swapExactTokensForTokens(
|
|
|
229
236
|
args: [/*to=*/ amm.address, /*amount=*/ amountIn],
|
|
230
237
|
address: tokenIn.address,
|
|
231
238
|
},
|
|
232
|
-
// tokenOut.prepare_private_balance_increase enqueues a call to _store_balances_set_partial_note
|
|
233
|
-
{
|
|
234
|
-
sender: tokenOut.address, // INTERNAL FUNCTION! Sender must be 'this'.
|
|
235
|
-
fnName: '_store_balances_set_partial_note',
|
|
236
|
-
args: [tokenOutPartialNote],
|
|
237
|
-
address: tokenOut.address,
|
|
238
|
-
},
|
|
239
|
-
|
|
240
239
|
{
|
|
241
240
|
sender: amm.address, // INTERNAL FUNCTION! Sender must be 'this'.
|
|
242
241
|
fnName: '_swap_exact_tokens_for_tokens',
|
|
@@ -265,6 +264,19 @@ async function removeLiquidity(
|
|
|
265
264
|
const token1PartialNote = {
|
|
266
265
|
commitment: new Fr(222),
|
|
267
266
|
};
|
|
267
|
+
const token0PartialNoteValidityCommitment = await computePartialNoteValidityCommitment(
|
|
268
|
+
token0PartialNote,
|
|
269
|
+
amm.address,
|
|
270
|
+
);
|
|
271
|
+
const token1PartialNoteValidityCommitment = await computePartialNoteValidityCommitment(
|
|
272
|
+
token1PartialNote,
|
|
273
|
+
amm.address,
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
// We need to inject the validity commitments into the nullifier tree as that would be performed by the private token
|
|
277
|
+
// functions that are not invoked in this test.
|
|
278
|
+
await tester.insertNullifier(token0.address, token0PartialNoteValidityCommitment);
|
|
279
|
+
await tester.insertNullifier(token1.address, token1PartialNoteValidityCommitment);
|
|
268
280
|
|
|
269
281
|
return await tester.simulateTxWithLabel(
|
|
270
282
|
/*txLabel=*/ 'AMM/remove_liquidity',
|
|
@@ -278,20 +290,6 @@ async function removeLiquidity(
|
|
|
278
290
|
args: [/*to=*/ amm.address, /*amount=*/ liquidity],
|
|
279
291
|
address: liquidityToken.address,
|
|
280
292
|
},
|
|
281
|
-
// token0.prepare_private_balance_increase enqueues a call to _store_balances_set_partial_note
|
|
282
|
-
{
|
|
283
|
-
sender: token0.address, // INTERNAL FUNCTION! Sender must be 'this'.
|
|
284
|
-
fnName: '_store_balances_set_partial_note',
|
|
285
|
-
args: [token0PartialNote],
|
|
286
|
-
address: token0.address,
|
|
287
|
-
},
|
|
288
|
-
// token1.prepare_private_balance_increase enqueues a call to _store_balances_set_partial_note
|
|
289
|
-
{
|
|
290
|
-
sender: token1.address, // INTERNAL FUNCTION! Sender must be 'this'.
|
|
291
|
-
fnName: '_store_balances_set_partial_note',
|
|
292
|
-
args: [token1PartialNote],
|
|
293
|
-
address: token1.address,
|
|
294
|
-
},
|
|
295
293
|
// amm.remove_liquidity enqueues a call to _remove_liquidity
|
|
296
294
|
{
|
|
297
295
|
sender: amm.address, // INTERNAL FUNCTION! Sender must be 'this'.
|
|
@@ -314,3 +312,10 @@ async function removeLiquidity(
|
|
|
314
312
|
],
|
|
315
313
|
);
|
|
316
314
|
}
|
|
315
|
+
|
|
316
|
+
async function computePartialNoteValidityCommitment(partialNote: { commitment: Fr }, completer: AztecAddress) {
|
|
317
|
+
return await poseidon2HashWithSeparator(
|
|
318
|
+
[partialNote.commitment, completer],
|
|
319
|
+
GeneratorIndex.PARTIAL_NOTE_VALIDITY_COMMITMENT,
|
|
320
|
+
);
|
|
321
|
+
}
|
|
@@ -10,7 +10,13 @@ import {
|
|
|
10
10
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
11
11
|
import { Fr } from '@aztec/foundation/fields';
|
|
12
12
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
AvmAccumulatedData,
|
|
15
|
+
AvmAccumulatedDataArrayLengths,
|
|
16
|
+
AvmCircuitPublicInputs,
|
|
17
|
+
PublicDataWrite,
|
|
18
|
+
RevertCode,
|
|
19
|
+
} from '@aztec/stdlib/avm';
|
|
14
20
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
15
21
|
import type { SimulationError } from '@aztec/stdlib/errors';
|
|
16
22
|
import { computeTransactionFee } from '@aztec/stdlib/fees';
|
|
@@ -18,8 +24,9 @@ import { Gas, GasSettings } from '@aztec/stdlib/gas';
|
|
|
18
24
|
import {
|
|
19
25
|
PrivateToAvmAccumulatedData,
|
|
20
26
|
PrivateToAvmAccumulatedDataArrayLengths,
|
|
21
|
-
|
|
27
|
+
PrivateToPublicAccumulatedData,
|
|
22
28
|
PublicCallRequest,
|
|
29
|
+
PublicCallRequestArrayLengths,
|
|
23
30
|
countAccumulatedItems,
|
|
24
31
|
} from '@aztec/stdlib/kernel';
|
|
25
32
|
import { PublicLog } from '@aztec/stdlib/logs';
|
|
@@ -356,12 +363,20 @@ export class PublicTxContext {
|
|
|
356
363
|
// This converts the private accumulated data to the avm accumulated data format.
|
|
357
364
|
const convertAccumulatedData = (from: PrivateToPublicAccumulatedData) =>
|
|
358
365
|
new PrivateToAvmAccumulatedData(from.noteHashes, from.nullifiers, from.l2ToL1Msgs);
|
|
359
|
-
const
|
|
366
|
+
const getPreviousAccumulatedDataArrayLengths = (from: PrivateToPublicAccumulatedData) =>
|
|
360
367
|
new PrivateToAvmAccumulatedDataArrayLengths(
|
|
361
368
|
countAccumulatedItems(from.noteHashes),
|
|
362
369
|
countAccumulatedItems(from.nullifiers),
|
|
363
370
|
countAccumulatedItems(from.l2ToL1Msgs),
|
|
364
371
|
);
|
|
372
|
+
const getAvmAccumulatedDataArrayLengths = (from: AvmAccumulatedData) =>
|
|
373
|
+
new AvmAccumulatedDataArrayLengths(
|
|
374
|
+
from.noteHashes.length,
|
|
375
|
+
from.nullifiers.length,
|
|
376
|
+
from.l2ToL1Msgs.length,
|
|
377
|
+
from.publicLogs.length,
|
|
378
|
+
from.publicDataWrites.length,
|
|
379
|
+
);
|
|
365
380
|
|
|
366
381
|
return new AvmCircuitPublicInputs(
|
|
367
382
|
this.globalVariables,
|
|
@@ -369,6 +384,11 @@ export class PublicTxContext {
|
|
|
369
384
|
/*startGasUsed=*/ this.gasUsedByPrivate,
|
|
370
385
|
this.gasSettings,
|
|
371
386
|
this.feePayer,
|
|
387
|
+
/*publicCallRequestArrayLengths=*/ new PublicCallRequestArrayLengths(
|
|
388
|
+
this.setupCallRequests.length,
|
|
389
|
+
this.appLogicCallRequests.length,
|
|
390
|
+
this.teardownCallRequests.length > 0,
|
|
391
|
+
),
|
|
372
392
|
/*publicSetupCallRequests=*/ padArrayEnd(
|
|
373
393
|
this.setupCallRequests.map(r => r.request),
|
|
374
394
|
PublicCallRequest.empty(),
|
|
@@ -382,12 +402,13 @@ export class PublicTxContext {
|
|
|
382
402
|
/*publicTeardownCallRequests=*/ this.teardownCallRequests.length > 0
|
|
383
403
|
? this.teardownCallRequests[0].request
|
|
384
404
|
: PublicCallRequest.empty(),
|
|
385
|
-
|
|
386
|
-
|
|
405
|
+
getPreviousAccumulatedDataArrayLengths(this.nonRevertibleAccumulatedDataFromPrivate),
|
|
406
|
+
getPreviousAccumulatedDataArrayLengths(this.revertibleAccumulatedDataFromPrivate),
|
|
387
407
|
convertAccumulatedData(this.nonRevertibleAccumulatedDataFromPrivate),
|
|
388
408
|
convertAccumulatedData(this.revertibleAccumulatedDataFromPrivate),
|
|
389
409
|
endTreeSnapshots,
|
|
390
410
|
this.getTotalGasUsed(),
|
|
411
|
+
getAvmAccumulatedDataArrayLengths(accumulatedData),
|
|
391
412
|
accumulatedData,
|
|
392
413
|
/*transactionFee=*/ this.getTransactionFeeUnsafe(),
|
|
393
414
|
/*isReverted=*/ !this.revertCode.isOK(),
|
|
@@ -82,6 +82,7 @@ export class SideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
82
82
|
private readonly previousSideEffectArrayLengths: SideEffectArrayLengths = SideEffectArrayLengths.empty(),
|
|
83
83
|
/** We need to track the set of class IDs used, to enforce limits. */
|
|
84
84
|
private uniqueClassIds: UniqueClassIds = new UniqueClassIds(),
|
|
85
|
+
private writtenPublicDataSlots: Set<string> = new Set(),
|
|
85
86
|
) {
|
|
86
87
|
this.sideEffectCounter = startSideEffectCounter;
|
|
87
88
|
}
|
|
@@ -98,6 +99,7 @@ export class SideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
98
99
|
this.previousSideEffectArrayLengths.publicLogs + this.publicLogs.length,
|
|
99
100
|
),
|
|
100
101
|
this.uniqueClassIds.fork(),
|
|
102
|
+
new Set(this.writtenPublicDataSlots),
|
|
101
103
|
);
|
|
102
104
|
}
|
|
103
105
|
|
|
@@ -111,6 +113,8 @@ export class SideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
111
113
|
|
|
112
114
|
this.sideEffectCounter = forkedTrace.sideEffectCounter;
|
|
113
115
|
this.uniqueClassIds.acceptAndMerge(forkedTrace.uniqueClassIds);
|
|
116
|
+
// Accept even if reverted, since the user already paid for the writes
|
|
117
|
+
this.writtenPublicDataSlots = new Set(forkedTrace.writtenPublicDataSlots);
|
|
114
118
|
|
|
115
119
|
if (!reverted) {
|
|
116
120
|
this.publicDataWrites.push(...forkedTrace.publicDataWrites);
|
|
@@ -170,6 +174,15 @@ export class SideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
170
174
|
`Traced public data write (address=${contractAddress}, slot=${slot}): value=${value} (counter=${this.sideEffectCounter}, isProtocol:${protocolWrite})`,
|
|
171
175
|
);
|
|
172
176
|
this.incrementSideEffectCounter();
|
|
177
|
+
this.writtenPublicDataSlots.add(this.computePublicDataSlotKey(contractAddress, slot));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private computePublicDataSlotKey(contractAddress: AztecAddress, slot: Fr): string {
|
|
181
|
+
return `${contractAddress.toString()}:${slot.toString()}`;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
public isStorageCold(contractAddress: AztecAddress, slot: Fr): boolean {
|
|
185
|
+
return !this.writtenPublicDataSlots.has(this.computePublicDataSlotKey(contractAddress, slot));
|
|
173
186
|
}
|
|
174
187
|
|
|
175
188
|
public traceNewNoteHash(noteHash: Fr) {
|
|
@@ -12,6 +12,7 @@ export interface PublicSideEffectTraceInterface {
|
|
|
12
12
|
value: Fr,
|
|
13
13
|
protocolWrite: boolean,
|
|
14
14
|
): Promise<void>;
|
|
15
|
+
isStorageCold(contractAddress: AztecAddress, slot: Fr): boolean;
|
|
15
16
|
traceNewNoteHash(uniqueNoteHash: Fr): void;
|
|
16
17
|
getNoteHashCount(): number;
|
|
17
18
|
traceNewNullifier(siloedNullifier: Fr): void;
|
|
@@ -148,6 +148,10 @@ export class PublicPersistableStateManager {
|
|
|
148
148
|
await this.trace.tracePublicStorageWrite(contractAddress, slot, value, protocolWrite);
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
+
public isStorageCold(contractAddress: AztecAddress, slot: Fr): boolean {
|
|
152
|
+
return this.trace.isStorageCold(contractAddress, slot);
|
|
153
|
+
}
|
|
154
|
+
|
|
151
155
|
/**
|
|
152
156
|
* Read from public storage.
|
|
153
157
|
*
|
package/src/server.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from './public/index.js';
|
|
2
2
|
export { WASMSimulatorWithBlobs } from './private/providers/acvm_wasm_with_blobs.js';
|
|
3
3
|
export { NativeACVMSimulator } from './private/providers/acvm_native.js';
|
|
4
|
+
export { SimulationProviderRecorderWrapper } from './private/providers/circuit_recording/simulation_provider_recorder_wrapper.js';
|
|
5
|
+
export { MemoryCircuitRecorder } from './private/providers/circuit_recording/memory_circuit_recorder.js';
|
|
4
6
|
export { type SimulationProvider } from './private/providers/simulation_provider.js';
|
|
5
7
|
export * from './common/index.js';
|
package/src/testing.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { FileCircuitRecorder } from './private/providers/circuit_recording/file_circuit_recorder.js';
|