@aztec/simulator 0.85.0 → 0.86.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/private/providers/acvm_native.d.ts +1 -1
- package/dest/private/providers/acvm_native.d.ts.map +1 -1
- package/dest/private/providers/acvm_native.js +4 -3
- package/dest/private/providers/acvm_wasm.d.ts +2 -1
- package/dest/private/providers/acvm_wasm.d.ts.map +1 -1
- package/dest/private/providers/acvm_wasm.js +6 -1
- package/dest/private/providers/acvm_wasm_with_blobs.d.ts +2 -1
- package/dest/private/providers/acvm_wasm_with_blobs.d.ts.map +1 -1
- package/dest/private/providers/acvm_wasm_with_blobs.js +6 -1
- package/dest/private/providers/circuit_recording/simulation_provider_recorder_wrapper.d.ts +2 -1
- package/dest/private/providers/circuit_recording/simulation_provider_recorder_wrapper.d.ts.map +1 -1
- package/dest/private/providers/simulation_provider.d.ts +2 -1
- package/dest/private/providers/simulation_provider.d.ts.map +1 -1
- package/dest/public/avm/avm_context.d.ts +2 -2
- package/dest/public/avm/avm_context.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.d.ts +2 -1
- package/dest/public/avm/avm_simulator.d.ts.map +1 -1
- package/dest/public/avm/avm_simulator.js +2 -1
- package/dest/public/avm/avm_simulator_interface.d.ts +11 -0
- package/dest/public/avm/avm_simulator_interface.d.ts.map +1 -0
- package/dest/public/avm/avm_simulator_interface.js +3 -0
- package/dest/public/avm/errors.d.ts +1 -16
- package/dest/public/avm/errors.d.ts.map +1 -1
- package/dest/public/avm/errors.js +0 -37
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/avm_simulation_tester.js +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/index.d.ts +2 -85
- package/dest/public/avm/fixtures/index.d.ts.map +1 -1
- package/dest/public/avm/fixtures/index.js +2 -174
- package/dest/public/avm/fixtures/initializers.d.ts +42 -0
- package/dest/public/avm/fixtures/initializers.d.ts.map +1 -0
- package/dest/public/avm/fixtures/initializers.js +42 -0
- package/dest/public/avm/fixtures/utils.d.ts +46 -0
- package/dest/public/avm/fixtures/utils.d.ts.map +1 -0
- package/dest/public/avm/fixtures/utils.js +136 -0
- package/dest/public/avm/index.d.ts +0 -1
- package/dest/public/avm/index.d.ts.map +1 -1
- package/dest/public/avm/index.js +0 -1
- package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/public/avm/opcodes/accrued_substate.js +1 -1
- package/dest/public/avm/opcodes/external_calls.d.ts +3 -2
- package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/public/avm/opcodes/external_calls.js +14 -9
- package/dest/public/avm/opcodes/instruction.d.ts +5 -5
- package/dest/public/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/public/avm/opcodes/instruction.js +6 -6
- package/dest/public/avm/revert_reason.d.ts +18 -0
- package/dest/public/avm/revert_reason.d.ts.map +1 -0
- package/dest/public/avm/revert_reason.js +38 -0
- package/dest/public/avm/serialization/bytecode_serialization.d.ts +2 -4
- package/dest/public/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/public/avm/serialization/bytecode_serialization.js +70 -69
- package/dest/{common → public}/debug_fn_name.d.ts +1 -1
- package/dest/{common → public}/debug_fn_name.d.ts.map +1 -1
- 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/public_tx_simulation_tester.d.ts +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
- package/dest/public/fixtures/public_tx_simulation_tester.js +3 -4
- package/dest/public/fixtures/simple_contract_data_source.d.ts.map +1 -0
- package/dest/public/{avm/fixtures → fixtures}/simple_contract_data_source.js +1 -1
- package/dest/public/hinting_db_sources.d.ts +15 -5
- package/dest/public/hinting_db_sources.d.ts.map +1 -1
- package/dest/public/hinting_db_sources.js +65 -27
- package/dest/public/index.d.ts +2 -6
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +2 -6
- package/dest/public/public_db_sources.d.ts +19 -52
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +96 -107
- package/dest/public/public_processor/public_processor.d.ts +6 -6
- package/dest/public/public_processor/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor/public_processor.js +24 -26
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +3 -2
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/measured_public_tx_simulator.js +2 -2
- package/dest/public/public_tx_simulator/public_tx_context.d.ts +3 -4
- package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_context.js +11 -21
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +5 -4
- package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/public_tx_simulator.js +21 -10
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +3 -2
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +2 -2
- package/dest/public/side_effect_trace.d.ts +1 -3
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +3 -2
- package/dest/public/state_manager/state_manager.d.ts +6 -4
- package/dest/public/state_manager/state_manager.d.ts.map +1 -1
- package/dest/public/state_manager/state_manager.js +20 -41
- package/package.json +14 -16
- package/src/private/providers/acvm_native.ts +5 -4
- package/src/private/providers/acvm_wasm.ts +5 -2
- package/src/private/providers/acvm_wasm_with_blobs.ts +5 -3
- package/src/private/providers/circuit_recording/simulation_provider_recorder_wrapper.ts +3 -2
- package/src/private/providers/simulation_provider.ts +2 -1
- package/src/public/avm/avm_context.ts +2 -2
- package/src/public/avm/avm_simulator.ts +4 -8
- package/src/public/avm/avm_simulator_interface.ts +8 -0
- package/src/public/avm/errors.ts +1 -53
- package/src/public/avm/fixtures/avm_simulation_tester.ts +1 -1
- package/src/public/avm/fixtures/base_avm_simulation_tester.ts +1 -1
- package/src/public/avm/fixtures/index.ts +2 -308
- package/src/public/avm/fixtures/initializers.ts +101 -0
- package/src/public/avm/fixtures/utils.ts +213 -0
- package/src/public/avm/index.ts +0 -1
- package/src/public/avm/opcodes/accrued_substate.ts +1 -5
- package/src/public/avm/opcodes/external_calls.ts +17 -11
- package/src/public/avm/opcodes/instruction.ts +9 -8
- package/src/public/avm/revert_reason.ts +55 -0
- package/src/public/avm/serialization/bytecode_serialization.ts +72 -74
- package/src/{common → public}/debug_fn_name.ts +1 -1
- package/src/public/fixtures/index.ts +1 -0
- package/src/public/fixtures/public_tx_simulation_tester.ts +3 -5
- package/src/public/{avm/fixtures → fixtures}/simple_contract_data_source.ts +1 -1
- package/src/public/hinting_db_sources.ts +104 -39
- package/src/public/index.ts +2 -6
- package/src/public/public_db_sources.ts +111 -164
- package/src/public/public_processor/public_processor.ts +27 -29
- package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +4 -3
- package/src/public/public_tx_simulator/public_tx_context.ts +10 -47
- package/src/public/public_tx_simulator/public_tx_simulator.ts +25 -10
- package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +4 -3
- package/src/public/side_effect_trace.ts +2 -4
- package/src/public/state_manager/state_manager.ts +24 -50
- package/dest/public/avm/fixtures/simple_contract_data_source.d.ts.map +0 -1
- /package/dest/{common → public}/debug_fn_name.js +0 -0
- /package/dest/public/{avm/fixtures → fixtures}/simple_contract_data_source.d.ts +0 -0
|
@@ -9,13 +9,7 @@ import { padArrayEnd } from '@aztec/foundation/collection';
|
|
|
9
9
|
import { Fr } from '@aztec/foundation/fields';
|
|
10
10
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
11
11
|
import { assertLength } from '@aztec/foundation/serialize';
|
|
12
|
-
import {
|
|
13
|
-
type AvmCircuitPublicInputs,
|
|
14
|
-
AvmExecutionHints,
|
|
15
|
-
AvmTxHint,
|
|
16
|
-
PublicDataWrite,
|
|
17
|
-
RevertCode,
|
|
18
|
-
} from '@aztec/stdlib/avm';
|
|
12
|
+
import { type AvmCircuitPublicInputs, PublicDataWrite, RevertCode } from '@aztec/stdlib/avm';
|
|
19
13
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
20
14
|
import type { SimulationError } from '@aztec/stdlib/errors';
|
|
21
15
|
import { computeTransactionFee } from '@aztec/stdlib/fees';
|
|
@@ -32,7 +26,6 @@ import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
|
32
26
|
import {
|
|
33
27
|
type GlobalVariables,
|
|
34
28
|
PublicCallRequestWithCalldata,
|
|
35
|
-
type StateReference,
|
|
36
29
|
TreeSnapshots,
|
|
37
30
|
type Tx,
|
|
38
31
|
TxExecutionPhase,
|
|
@@ -42,8 +35,7 @@ import {
|
|
|
42
35
|
import { strict as assert } from 'assert';
|
|
43
36
|
import { inspect } from 'util';
|
|
44
37
|
|
|
45
|
-
import type { PublicContractsDBInterface } from '
|
|
46
|
-
import { HintingPublicContractsDB, HintingPublicTreesDB } from '../hinting_db_sources.js';
|
|
38
|
+
import type { PublicContractsDBInterface } from '../db_interfaces.js';
|
|
47
39
|
import type { PublicTreesDB } from '../public_db_sources.js';
|
|
48
40
|
import { SideEffectArrayLengths, SideEffectTrace } from '../side_effect_trace.js';
|
|
49
41
|
import { PublicPersistableStateManager } from '../state_manager/state_manager.js';
|
|
@@ -66,12 +58,11 @@ export class PublicTxContext {
|
|
|
66
58
|
private revertCode: RevertCode = RevertCode.OK;
|
|
67
59
|
/* What caused a revert (if one occurred)? */
|
|
68
60
|
public revertReason: SimulationError | undefined;
|
|
69
|
-
|
|
70
61
|
private constructor(
|
|
71
62
|
public readonly txHash: TxHash,
|
|
72
63
|
public readonly state: PhaseStateManager,
|
|
64
|
+
private readonly startTreeSnapshots: TreeSnapshots,
|
|
73
65
|
private readonly globalVariables: GlobalVariables,
|
|
74
|
-
private readonly startStateReference: StateReference,
|
|
75
66
|
private readonly gasSettings: GasSettings,
|
|
76
67
|
private readonly gasUsedByPrivate: Gas,
|
|
77
68
|
private readonly gasAllocatedToPublic: Gas,
|
|
@@ -82,7 +73,6 @@ export class PublicTxContext {
|
|
|
82
73
|
public readonly revertibleAccumulatedDataFromPrivate: PrivateToPublicAccumulatedData,
|
|
83
74
|
public readonly feePayer: AztecAddress,
|
|
84
75
|
private readonly trace: SideEffectTrace,
|
|
85
|
-
public readonly hints: AvmExecutionHints, // This is public due to enqueued call hinting.
|
|
86
76
|
) {
|
|
87
77
|
this.log = createLogger(`simulator:public_tx_context`);
|
|
88
78
|
}
|
|
@@ -109,22 +99,10 @@ export class PublicTxContext {
|
|
|
109
99
|
|
|
110
100
|
const firstNullifier = nonRevertibleAccumulatedDataFromPrivate.nullifiers[0];
|
|
111
101
|
|
|
112
|
-
// We wrap the DB to collect AVM hints.
|
|
113
|
-
const hints = new AvmExecutionHints(await AvmTxHint.fromTx(tx));
|
|
114
|
-
const hintingContractsDB = new HintingPublicContractsDB(contractsDB, hints);
|
|
115
|
-
const hintingTreesDB = new HintingPublicTreesDB(treesDB, hints);
|
|
116
|
-
const startStateReference = await treesDB.getStateReference();
|
|
117
|
-
hints.startingTreeRoots = new TreeSnapshots(
|
|
118
|
-
startStateReference.l1ToL2MessageTree,
|
|
119
|
-
startStateReference.partial.noteHashTree,
|
|
120
|
-
startStateReference.partial.nullifierTree,
|
|
121
|
-
startStateReference.partial.publicDataTree,
|
|
122
|
-
);
|
|
123
|
-
|
|
124
102
|
// Transaction level state manager that will be forked for revertible phases.
|
|
125
103
|
const txStateManager = PublicPersistableStateManager.create(
|
|
126
|
-
|
|
127
|
-
|
|
104
|
+
treesDB,
|
|
105
|
+
contractsDB,
|
|
128
106
|
trace,
|
|
129
107
|
doMerkleOperations,
|
|
130
108
|
firstNullifier,
|
|
@@ -139,8 +117,8 @@ export class PublicTxContext {
|
|
|
139
117
|
return new PublicTxContext(
|
|
140
118
|
await tx.getTxHash(),
|
|
141
119
|
new PhaseStateManager(txStateManager),
|
|
120
|
+
await txStateManager.getTreeSnapshots(),
|
|
142
121
|
globalVariables,
|
|
143
|
-
await treesDB.getStateReference(),
|
|
144
122
|
gasSettings,
|
|
145
123
|
gasUsedByPrivate,
|
|
146
124
|
gasAllocatedToPublic,
|
|
@@ -151,7 +129,6 @@ export class PublicTxContext {
|
|
|
151
129
|
tx.data.forPublic!.revertibleAccumulatedData,
|
|
152
130
|
tx.data.feePayer,
|
|
153
131
|
trace,
|
|
154
|
-
hints,
|
|
155
132
|
);
|
|
156
133
|
}
|
|
157
134
|
|
|
@@ -324,20 +301,12 @@ export class PublicTxContext {
|
|
|
324
301
|
assert(this.halted, 'Can only get AvmCircuitPublicInputs after tx execution ends');
|
|
325
302
|
const stateManager = this.state.getActiveStateManager();
|
|
326
303
|
|
|
327
|
-
const startTreeSnapshots = new TreeSnapshots(
|
|
328
|
-
this.startStateReference.l1ToL2MessageTree,
|
|
329
|
-
this.startStateReference.partial.noteHashTree,
|
|
330
|
-
this.startStateReference.partial.nullifierTree,
|
|
331
|
-
this.startStateReference.partial.publicDataTree,
|
|
332
|
-
);
|
|
333
|
-
|
|
334
304
|
// FIXME: We are first creating the PIs with the wrong endTreeSnapshots, then patching them.
|
|
335
305
|
// This is because we need to know the lengths of the accumulated data arrays to pad them.
|
|
336
306
|
// We should refactor this to avoid this hack.
|
|
337
307
|
// We should just get the info we need from the trace, and create the rest of the PIs here.
|
|
338
308
|
const avmCircuitPublicInputs = this.trace.toAvmCircuitPublicInputs(
|
|
339
309
|
this.globalVariables,
|
|
340
|
-
startTreeSnapshots,
|
|
341
310
|
/*startGasUsed=*/ this.gasUsedByPrivate,
|
|
342
311
|
this.gasSettings,
|
|
343
312
|
this.feePayer,
|
|
@@ -351,6 +320,7 @@ export class PublicTxContext {
|
|
|
351
320
|
/*transactionFee=*/ this.getTransactionFeeUnsafe(),
|
|
352
321
|
/*reverted=*/ !this.revertCode.isOK(),
|
|
353
322
|
);
|
|
323
|
+
avmCircuitPublicInputs.startTreeSnapshots = this.startTreeSnapshots;
|
|
354
324
|
|
|
355
325
|
const getArrayLengths = (from: PrivateToPublicAccumulatedData) =>
|
|
356
326
|
new PrivateToAvmAccumulatedDataArrayLengths(
|
|
@@ -400,18 +370,11 @@ export class PublicTxContext {
|
|
|
400
370
|
);
|
|
401
371
|
const numNoteHashesToPad =
|
|
402
372
|
MAX_NOTE_HASHES_PER_TX - countAccumulatedItems(avmCircuitPublicInputs.accumulatedData.noteHashes);
|
|
403
|
-
await stateManager.
|
|
373
|
+
await stateManager.padTree(MerkleTreeId.NOTE_HASH_TREE, numNoteHashesToPad);
|
|
404
374
|
const numNullifiersToPad =
|
|
405
375
|
MAX_NULLIFIERS_PER_TX - countAccumulatedItems(avmCircuitPublicInputs.accumulatedData.nullifiers);
|
|
406
|
-
await stateManager.
|
|
407
|
-
|
|
408
|
-
const paddedState = await stateManager.deprecatedGetTreesForPIGeneration().getStateReference();
|
|
409
|
-
avmCircuitPublicInputs.endTreeSnapshots = new TreeSnapshots(
|
|
410
|
-
paddedState.l1ToL2MessageTree,
|
|
411
|
-
paddedState.partial.noteHashTree,
|
|
412
|
-
paddedState.partial.nullifierTree,
|
|
413
|
-
paddedState.partial.publicDataTree,
|
|
414
|
-
);
|
|
376
|
+
await stateManager.padTree(MerkleTreeId.NULLIFIER_TREE, numNullifiersToPad);
|
|
377
|
+
avmCircuitPublicInputs.endTreeSnapshots = await stateManager.getTreeSnapshots();
|
|
415
378
|
|
|
416
379
|
return avmCircuitPublicInputs;
|
|
417
380
|
}
|
|
@@ -7,11 +7,13 @@ import {
|
|
|
7
7
|
AvmCircuitPublicInputs,
|
|
8
8
|
AvmExecutionHints,
|
|
9
9
|
type AvmProvingRequest,
|
|
10
|
+
AvmTxHint,
|
|
10
11
|
type RevertCode,
|
|
11
12
|
} from '@aztec/stdlib/avm';
|
|
12
13
|
import { SimulationError } from '@aztec/stdlib/errors';
|
|
13
14
|
import type { Gas, GasUsed } from '@aztec/stdlib/gas';
|
|
14
15
|
import { ProvingRequestType } from '@aztec/stdlib/proofs';
|
|
16
|
+
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
15
17
|
import {
|
|
16
18
|
type GlobalVariables,
|
|
17
19
|
NestedProcessReturnValues,
|
|
@@ -22,10 +24,11 @@ import {
|
|
|
22
24
|
|
|
23
25
|
import { strict as assert } from 'assert';
|
|
24
26
|
|
|
25
|
-
import { getPublicFunctionDebugName } from '../../common/debug_fn_name.js';
|
|
26
27
|
import type { AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
|
|
27
28
|
import { AvmSimulator } from '../avm/index.js';
|
|
28
|
-
import
|
|
29
|
+
import { getPublicFunctionDebugName } from '../debug_fn_name.js';
|
|
30
|
+
import { HintingMerkleWriteOperations, HintingPublicContractsDB } from '../hinting_db_sources.js';
|
|
31
|
+
import { type PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
|
|
29
32
|
import { NullifierCollisionError } from '../state_manager/nullifiers.js';
|
|
30
33
|
import type { PublicPersistableStateManager } from '../state_manager/state_manager.js';
|
|
31
34
|
import { PublicTxContext } from './public_tx_context.js';
|
|
@@ -52,8 +55,8 @@ export class PublicTxSimulator {
|
|
|
52
55
|
protected log: Logger;
|
|
53
56
|
|
|
54
57
|
constructor(
|
|
55
|
-
private
|
|
56
|
-
|
|
58
|
+
private merkleTree: MerkleTreeWriteOperations,
|
|
59
|
+
private contractsDB: PublicContractsDB,
|
|
57
60
|
private globalVariables: GlobalVariables,
|
|
58
61
|
private doMerkleOperations: boolean = false,
|
|
59
62
|
private skipFeeEnforcement: boolean = false,
|
|
@@ -71,9 +74,15 @@ export class PublicTxSimulator {
|
|
|
71
74
|
const txHash = await this.computeTxHash(tx);
|
|
72
75
|
this.log.debug(`Simulating ${tx.publicFunctionCalldata.length} public calls for tx ${txHash}`, { txHash });
|
|
73
76
|
|
|
77
|
+
// Create hinting DBs.
|
|
78
|
+
const hints = new AvmExecutionHints(await AvmTxHint.fromTx(tx));
|
|
79
|
+
const hintingMerkleTree = await HintingMerkleWriteOperations.create(this.merkleTree, hints);
|
|
80
|
+
const hintingTreesDB = new PublicTreesDB(hintingMerkleTree);
|
|
81
|
+
const hintingContractsDB = new HintingPublicContractsDB(this.contractsDB, hints);
|
|
82
|
+
|
|
74
83
|
const context = await PublicTxContext.create(
|
|
75
|
-
|
|
76
|
-
|
|
84
|
+
hintingTreesDB,
|
|
85
|
+
hintingContractsDB,
|
|
77
86
|
tx,
|
|
78
87
|
this.globalVariables,
|
|
79
88
|
this.doMerkleOperations,
|
|
@@ -107,7 +116,7 @@ export class PublicTxSimulator {
|
|
|
107
116
|
await this.payFee(context);
|
|
108
117
|
|
|
109
118
|
const publicInputs = await context.generateAvmCircuitPublicInputs();
|
|
110
|
-
const avmProvingRequest = PublicTxSimulator.generateProvingRequest(publicInputs,
|
|
119
|
+
const avmProvingRequest = PublicTxSimulator.generateProvingRequest(publicInputs, hints);
|
|
111
120
|
|
|
112
121
|
const revertCode = context.getFinalRevertCode();
|
|
113
122
|
|
|
@@ -267,7 +276,7 @@ export class PublicTxSimulator {
|
|
|
267
276
|
stateManager.traceEnqueuedCall(callRequest.request);
|
|
268
277
|
|
|
269
278
|
const result = await this.simulateEnqueuedCallInternal(
|
|
270
|
-
|
|
279
|
+
stateManager,
|
|
271
280
|
callRequest,
|
|
272
281
|
allocatedGas,
|
|
273
282
|
/*transactionFee=*/ context.getTransactionFee(phase),
|
|
@@ -335,7 +344,11 @@ export class PublicTxSimulator {
|
|
|
335
344
|
protected async insertNonRevertiblesFromPrivate(context: PublicTxContext, tx: Tx) {
|
|
336
345
|
const stateManager = context.state.getActiveStateManager();
|
|
337
346
|
try {
|
|
338
|
-
|
|
347
|
+
for (const siloedNullifier of context.nonRevertibleAccumulatedDataFromPrivate.nullifiers.filter(
|
|
348
|
+
n => !n.isEmpty(),
|
|
349
|
+
)) {
|
|
350
|
+
await stateManager.writeSiloedNullifier(siloedNullifier);
|
|
351
|
+
}
|
|
339
352
|
} catch (e) {
|
|
340
353
|
if (e instanceof NullifierCollisionError) {
|
|
341
354
|
throw new NullifierCollisionError(
|
|
@@ -364,7 +377,9 @@ export class PublicTxSimulator {
|
|
|
364
377
|
await context.state.fork();
|
|
365
378
|
const stateManager = context.state.getActiveStateManager();
|
|
366
379
|
try {
|
|
367
|
-
|
|
380
|
+
for (const siloedNullifier of context.revertibleAccumulatedDataFromPrivate.nullifiers.filter(n => !n.isEmpty())) {
|
|
381
|
+
await stateManager.writeSiloedNullifier(siloedNullifier);
|
|
382
|
+
}
|
|
368
383
|
} catch (e) {
|
|
369
384
|
if (e instanceof NullifierCollisionError) {
|
|
370
385
|
// Instead of throwing, revert the app_logic phase
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { Fr } from '@aztec/foundation/fields';
|
|
2
2
|
import type { Gas } from '@aztec/stdlib/gas';
|
|
3
|
+
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
3
4
|
import { type GlobalVariables, PublicCallRequestWithCalldata, TxExecutionPhase } from '@aztec/stdlib/tx';
|
|
4
5
|
import { Attributes, type TelemetryClient, type Tracer, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
5
6
|
|
|
6
7
|
import type { AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
|
|
7
8
|
import { ExecutorMetrics } from '../executor_metrics.js';
|
|
8
|
-
import type { PublicContractsDB
|
|
9
|
+
import type { PublicContractsDB } from '../public_db_sources.js';
|
|
9
10
|
import type { PublicPersistableStateManager } from '../state_manager/state_manager.js';
|
|
10
11
|
import { MeasuredPublicTxSimulator } from './measured_public_tx_simulator.js';
|
|
11
12
|
import { PublicTxContext } from './public_tx_context.js';
|
|
@@ -18,7 +19,7 @@ export class TelemetryPublicTxSimulator extends MeasuredPublicTxSimulator {
|
|
|
18
19
|
public readonly tracer: Tracer;
|
|
19
20
|
|
|
20
21
|
constructor(
|
|
21
|
-
|
|
22
|
+
merkleTree: MerkleTreeWriteOperations,
|
|
22
23
|
contractsDB: PublicContractsDB,
|
|
23
24
|
globalVariables: GlobalVariables,
|
|
24
25
|
doMerkleOperations: boolean = false,
|
|
@@ -26,7 +27,7 @@ export class TelemetryPublicTxSimulator extends MeasuredPublicTxSimulator {
|
|
|
26
27
|
telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
27
28
|
) {
|
|
28
29
|
const metrics = new ExecutorMetrics(telemetryClient, 'PublicTxSimulator');
|
|
29
|
-
super(
|
|
30
|
+
super(merkleTree, contractsDB, globalVariables, doMerkleOperations, skipFeeEnforcement, metrics);
|
|
30
31
|
this.tracer = metrics.tracer;
|
|
31
32
|
}
|
|
32
33
|
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
} from '@aztec/stdlib/kernel';
|
|
33
33
|
import { PublicLog } from '@aztec/stdlib/logs';
|
|
34
34
|
import { L2ToL1Message, ScopedL2ToL1Message } from '@aztec/stdlib/messaging';
|
|
35
|
-
import type
|
|
35
|
+
import { type GlobalVariables, TreeSnapshots } from '@aztec/stdlib/tx';
|
|
36
36
|
|
|
37
37
|
import { strict as assert } from 'assert';
|
|
38
38
|
|
|
@@ -277,8 +277,6 @@ export class SideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
277
277
|
public toAvmCircuitPublicInputs(
|
|
278
278
|
/** Globals. */
|
|
279
279
|
globalVariables: GlobalVariables,
|
|
280
|
-
/** Start tree snapshots. */
|
|
281
|
-
startTreeSnapshots: TreeSnapshots,
|
|
282
280
|
/** Gas used at start of TX. */
|
|
283
281
|
startGasUsed: Gas,
|
|
284
282
|
/** How much gas was available for this public execution. */
|
|
@@ -305,7 +303,7 @@ export class SideEffectTrace implements PublicSideEffectTraceInterface {
|
|
|
305
303
|
): AvmCircuitPublicInputs {
|
|
306
304
|
return new AvmCircuitPublicInputs(
|
|
307
305
|
globalVariables,
|
|
308
|
-
|
|
306
|
+
TreeSnapshots.empty(), // will be patched later.
|
|
309
307
|
startGasUsed,
|
|
310
308
|
gasLimits,
|
|
311
309
|
feePayer,
|
|
@@ -11,26 +11,20 @@ import { Fr } from '@aztec/foundation/fields';
|
|
|
11
11
|
import { jsonStringify } from '@aztec/foundation/json-rpc';
|
|
12
12
|
import { createLogger } from '@aztec/foundation/log';
|
|
13
13
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
14
|
-
import { PublicDataWrite } from '@aztec/stdlib/avm';
|
|
15
14
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
16
15
|
import type { ContractClassPublicWithCommitment, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
17
16
|
import { SerializableContractInstance } from '@aztec/stdlib/contract';
|
|
18
|
-
import {
|
|
19
|
-
computeNoteHashNonce,
|
|
20
|
-
computePublicDataTreeLeafSlot,
|
|
21
|
-
computeUniqueNoteHash,
|
|
22
|
-
siloNoteHash,
|
|
23
|
-
siloNullifier,
|
|
24
|
-
} from '@aztec/stdlib/hash';
|
|
17
|
+
import { computeNoteHashNonce, computeUniqueNoteHash, siloNoteHash, siloNullifier } from '@aztec/stdlib/hash';
|
|
25
18
|
import type { PublicCallRequest } from '@aztec/stdlib/kernel';
|
|
26
19
|
import { SharedMutableValues, SharedMutableValuesWithHash } from '@aztec/stdlib/shared-mutable';
|
|
27
20
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
21
|
+
import type { TreeSnapshots } from '@aztec/stdlib/tx';
|
|
28
22
|
|
|
29
23
|
import { strict as assert } from 'assert';
|
|
30
24
|
|
|
31
|
-
import { getPublicFunctionDebugName } from '../../common/debug_fn_name.js';
|
|
32
|
-
import type { PublicContractsDBInterface } from '../../server.js';
|
|
33
25
|
import type { AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
|
|
26
|
+
import type { PublicContractsDBInterface } from '../db_interfaces.js';
|
|
27
|
+
import { getPublicFunctionDebugName } from '../debug_fn_name.js';
|
|
34
28
|
import type { PublicTreesDB } from '../public_db_sources.js';
|
|
35
29
|
import type { PublicSideEffectTraceInterface } from '../side_effect_trace_interface.js';
|
|
36
30
|
import { NullifierCollisionError, NullifierManager } from './nullifiers.js';
|
|
@@ -83,12 +77,6 @@ export class PublicPersistableStateManager {
|
|
|
83
77
|
);
|
|
84
78
|
}
|
|
85
79
|
|
|
86
|
-
// DO NOT USE!
|
|
87
|
-
// FIXME(fcarreiro): refactor and remove this.
|
|
88
|
-
public deprecatedGetTreesForPIGeneration() {
|
|
89
|
-
return this.treesDB;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
80
|
/**
|
|
93
81
|
* Create a new state manager forked from this one
|
|
94
82
|
*/
|
|
@@ -131,14 +119,8 @@ export class PublicPersistableStateManager {
|
|
|
131
119
|
this.nullifiers.acceptAndMerge(forkedState.nullifiers);
|
|
132
120
|
this.trace.merge(forkedState.trace, reverted);
|
|
133
121
|
if (reverted) {
|
|
122
|
+
this.log.trace('Reverting forked state...');
|
|
134
123
|
await this.treesDB.revertCheckpoint();
|
|
135
|
-
if (this.doMerkleOperations) {
|
|
136
|
-
this.log.trace(
|
|
137
|
-
`Rolled back nullifier tree to root ${new Fr(
|
|
138
|
-
(await this.treesDB.getTreeInfo(MerkleTreeId.NULLIFIER_TREE)).root,
|
|
139
|
-
)}`,
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
124
|
} else {
|
|
143
125
|
this.log.trace('Merging forked state into parent...');
|
|
144
126
|
await this.treesDB.commitCheckpoint();
|
|
@@ -153,15 +135,11 @@ export class PublicPersistableStateManager {
|
|
|
153
135
|
* @param value - the value being written to the slot
|
|
154
136
|
*/
|
|
155
137
|
public async writeStorage(contractAddress: AztecAddress, slot: Fr, value: Fr, protocolWrite = false): Promise<void> {
|
|
156
|
-
|
|
157
|
-
this.log.trace(`Storage write (address=${contractAddress}, slot=${slot}): value=${value}, leafSlot=${leafSlot}`);
|
|
138
|
+
this.log.trace(`Storage write (address=${contractAddress}, slot=${slot}): value=${value}`);
|
|
158
139
|
|
|
159
140
|
if (this.doMerkleOperations) {
|
|
160
141
|
// write to native merkle trees
|
|
161
|
-
|
|
162
|
-
const result = await this.treesDB.sequentialInsert(MerkleTreeId.PUBLIC_DATA_TREE, [publicDataWrite.toBuffer()]);
|
|
163
|
-
assert(result !== undefined, 'Public data tree insertion error. You might want to disable doMerkleOperations.');
|
|
164
|
-
this.log.trace(`Inserted public data tree leaf at leafSlot ${leafSlot}, value: ${value}`);
|
|
142
|
+
await this.treesDB.storageWrite(contractAddress, slot, value);
|
|
165
143
|
} else {
|
|
166
144
|
// Cache storage writes for later reference/reads
|
|
167
145
|
this.publicStorage.write(contractAddress, slot, value);
|
|
@@ -179,8 +157,7 @@ export class PublicPersistableStateManager {
|
|
|
179
157
|
*/
|
|
180
158
|
public async readStorage(contractAddress: AztecAddress, slot: Fr): Promise<Fr> {
|
|
181
159
|
if (this.doMerkleOperations) {
|
|
182
|
-
|
|
183
|
-
return value;
|
|
160
|
+
return await this.treesDB.storageRead(contractAddress, slot);
|
|
184
161
|
} else {
|
|
185
162
|
// TODO(fcarreiro): I don't get this. PublicStorage CAN end up reading the tree. Why is it in the "dont do merkle operations" branch?
|
|
186
163
|
const read = await this.publicStorage.read(contractAddress, slot);
|
|
@@ -201,8 +178,8 @@ export class PublicPersistableStateManager {
|
|
|
201
178
|
* @returns true if the note hash exists at the given leaf index, false otherwise
|
|
202
179
|
*/
|
|
203
180
|
public async checkNoteHashExists(contractAddress: AztecAddress, noteHash: Fr, leafIndex: Fr): Promise<boolean> {
|
|
204
|
-
const gotLeafValue =
|
|
205
|
-
const exists = gotLeafValue.equals(noteHash);
|
|
181
|
+
const gotLeafValue = await this.treesDB.getNoteHash(leafIndex.toBigInt());
|
|
182
|
+
const exists = gotLeafValue !== undefined && gotLeafValue.equals(noteHash);
|
|
206
183
|
this.log.trace(
|
|
207
184
|
`noteHashes(${contractAddress})@${noteHash} ?? leafIndex: ${leafIndex} | gotLeafValue: ${gotLeafValue}, exists: ${exists}.`,
|
|
208
185
|
);
|
|
@@ -236,7 +213,7 @@ export class PublicPersistableStateManager {
|
|
|
236
213
|
public async writeUniqueNoteHash(uniqueNoteHash: Fr): Promise<void> {
|
|
237
214
|
this.log.trace(`noteHashes += @${uniqueNoteHash}.`);
|
|
238
215
|
if (this.doMerkleOperations) {
|
|
239
|
-
await this.treesDB.
|
|
216
|
+
await this.treesDB.writeNoteHash(uniqueNoteHash);
|
|
240
217
|
}
|
|
241
218
|
this.trace.traceNewNoteHash(uniqueNoteHash);
|
|
242
219
|
}
|
|
@@ -256,7 +233,6 @@ export class PublicPersistableStateManager {
|
|
|
256
233
|
this.log.trace(`Checked siloed nullifier ${siloedNullifier} (exists=${exists})`);
|
|
257
234
|
return Promise.resolve(exists);
|
|
258
235
|
} else {
|
|
259
|
-
// TODO: same here, this CAN hit the db.
|
|
260
236
|
const { exists, cacheHit } = await this.nullifiers.checkExists(siloedNullifier);
|
|
261
237
|
this.log.trace(`Checked siloed nullifier ${siloedNullifier} (exists=${exists}), cacheHit=${cacheHit}`);
|
|
262
238
|
return Promise.resolve(exists);
|
|
@@ -290,7 +266,7 @@ export class PublicPersistableStateManager {
|
|
|
290
266
|
`Siloed nullifier ${siloedNullifier} already exists in parent cache or host.`,
|
|
291
267
|
);
|
|
292
268
|
} else {
|
|
293
|
-
await this.treesDB.
|
|
269
|
+
await this.treesDB.writeNullifier(siloedNullifier);
|
|
294
270
|
}
|
|
295
271
|
} else {
|
|
296
272
|
// Cache pending nullifiers for later access
|
|
@@ -300,25 +276,15 @@ export class PublicPersistableStateManager {
|
|
|
300
276
|
this.trace.traceNewNullifier(siloedNullifier);
|
|
301
277
|
}
|
|
302
278
|
|
|
303
|
-
public async writeSiloedNullifiersFromPrivate(siloedNullifiers: Fr[]) {
|
|
304
|
-
for (const siloedNullifier of siloedNullifiers.filter(n => !n.isEmpty())) {
|
|
305
|
-
await this.writeSiloedNullifier(siloedNullifier);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
279
|
/**
|
|
310
280
|
* Check if an L1 to L2 message exists, trace the check.
|
|
311
281
|
* @param msgHash - the message hash to check existence of
|
|
312
282
|
* @param msgLeafIndex - the message leaf index to use in the check
|
|
313
283
|
* @returns exists - whether the message exists in the L1 to L2 Messages tree
|
|
314
284
|
*/
|
|
315
|
-
public async checkL1ToL2MessageExists(
|
|
316
|
-
|
|
317
|
-
msgHash
|
|
318
|
-
msgLeafIndex: Fr,
|
|
319
|
-
): Promise<boolean> {
|
|
320
|
-
const valueAtIndex = (await this.treesDB.getL1ToL2LeafValue(msgLeafIndex.toBigInt())) ?? Fr.ZERO;
|
|
321
|
-
const exists = valueAtIndex.equals(msgHash);
|
|
285
|
+
public async checkL1ToL2MessageExists(msgHash: Fr, msgLeafIndex: Fr): Promise<boolean> {
|
|
286
|
+
const valueAtIndex = await this.treesDB.getL1ToL2LeafValue(msgLeafIndex.toBigInt());
|
|
287
|
+
const exists = valueAtIndex !== undefined && valueAtIndex.equals(msgHash);
|
|
322
288
|
this.log.trace(
|
|
323
289
|
`l1ToL2Messages(@${msgLeafIndex}) ?? exists: ${exists}, expected: ${msgHash}, found: ${valueAtIndex}.`,
|
|
324
290
|
);
|
|
@@ -375,7 +341,7 @@ export class PublicPersistableStateManager {
|
|
|
375
341
|
);
|
|
376
342
|
assert(
|
|
377
343
|
exists == nullifierExistsInTree,
|
|
378
|
-
|
|
344
|
+
`Contract instance for address ${contractAddress} in DB: ${exists} != nullifier tree: ${nullifierExistsInTree}. This is a bug!`,
|
|
379
345
|
);
|
|
380
346
|
|
|
381
347
|
// All that is left is tocheck that the contract updatability information is correct.
|
|
@@ -501,6 +467,14 @@ export class PublicPersistableStateManager {
|
|
|
501
467
|
public async getPublicFunctionDebugName(avmEnvironment: AvmExecutionEnvironment): Promise<string> {
|
|
502
468
|
return await getPublicFunctionDebugName(this.contractsDB, avmEnvironment.address, avmEnvironment.calldata);
|
|
503
469
|
}
|
|
470
|
+
|
|
471
|
+
public async padTree(treeId: MerkleTreeId, leavesToInsert: number): Promise<void> {
|
|
472
|
+
await this.treesDB.padTree(treeId, leavesToInsert);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
public async getTreeSnapshots(): Promise<TreeSnapshots> {
|
|
476
|
+
return await this.treesDB.getTreeSnapshots();
|
|
477
|
+
}
|
|
504
478
|
}
|
|
505
479
|
|
|
506
480
|
function contractAddressIsCanonical(contractAddress: AztecAddress): boolean {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"simple_contract_data_source.d.ts","sourceRoot":"","sources":["../../../../src/public/avm/fixtures/simple_contract_data_source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAInH;;;;;;GAMG;AACH,qBAAa,wBAAyB,YAAW,kBAAkB;IAC1D,MAAM,yCAA+C;IAG5D,OAAO,CAAC,eAAe,CAA+C;IAEtE,OAAO,CAAC,iBAAiB,CAAuD;IAEhF,OAAO,CAAC,iBAAiB,CAA4C;IAErE,OAAO,CAAC,iBAAiB,CAAkC;IAI3D;;;OAGG;IACG,cAAc,CAClB,gBAAgB,EAAE,gBAAgB,EAClC,aAAa,EAAE,mBAAmB,EAClC,gBAAgB,EAAE,2BAA2B;IAOzC,mBAAmB,CAAC,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,gBAAgB;IAkBjE,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAIjC,gBAAgB,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC;IAIlE,qBAAqB,CAAC,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC;IAIvD,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,2BAA2B,GAAG,SAAS,CAAC;IAIpF,mBAAmB,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC;IAI9B,mBAAmB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAWjF,oBAAoB,CAAC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC;IAiB9F,kCAAkC,CAAC,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhG,gBAAgB,CAAC,aAAa,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAKnE,mBAAmB,CAAC,gBAAgB,EAAE,2BAA2B,GAAG,OAAO,CAAC,IAAI,CAAC;CAIlF"}
|
|
File without changes
|
|
File without changes
|