@aztec/simulator 0.63.1 → 0.64.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/avm/avm_contract_call_result.d.ts +18 -1
- package/dest/avm/avm_contract_call_result.d.ts.map +1 -1
- package/dest/avm/avm_contract_call_result.js +30 -3
- package/dest/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/avm/avm_memory_types.js +7 -11
- package/dest/avm/avm_simulator.d.ts +6 -1
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +29 -8
- package/dest/avm/avm_tree.d.ts +4 -18
- package/dest/avm/avm_tree.d.ts.map +1 -1
- package/dest/avm/avm_tree.js +71 -53
- package/dest/avm/errors.d.ts +7 -0
- package/dest/avm/errors.d.ts.map +1 -1
- package/dest/avm/errors.js +11 -1
- package/dest/avm/fixtures/index.d.ts +2 -2
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +1 -1
- 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 +14 -13
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +81 -68
- package/dest/avm/journal/public_storage.d.ts +0 -1
- package/dest/avm/journal/public_storage.d.ts.map +1 -1
- package/dest/avm/journal/public_storage.js +6 -6
- package/dest/avm/opcodes/accrued_substate.js +2 -2
- package/dest/avm/opcodes/addressing_mode.d.ts.map +1 -1
- package/dest/avm/opcodes/addressing_mode.js +8 -2
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +2 -4
- package/dest/avm/opcodes/instruction.d.ts +1 -1
- package/dest/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction.js +1 -1
- package/dest/index.d.ts +0 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- package/dest/public/dual_side_effect_trace.d.ts +3 -9
- package/dest/public/dual_side_effect_trace.d.ts.map +1 -1
- package/dest/public/dual_side_effect_trace.js +5 -11
- package/dest/public/enqueued_call_side_effect_trace.d.ts +4 -10
- package/dest/public/enqueued_call_side_effect_trace.d.ts.map +1 -1
- package/dest/public/enqueued_call_side_effect_trace.js +6 -15
- package/dest/public/executor_metrics.d.ts +1 -2
- package/dest/public/executor_metrics.d.ts.map +1 -1
- package/dest/public/executor_metrics.js +2 -8
- package/dest/public/fixtures/index.d.ts +14 -0
- package/dest/public/fixtures/index.d.ts.map +1 -0
- package/dest/public/fixtures/index.js +100 -0
- package/dest/public/index.d.ts +1 -2
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +1 -2
- package/dest/public/public_processor.d.ts +0 -2
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +5 -12
- package/dest/public/public_tx_context.d.ts +6 -4
- package/dest/public/public_tx_context.d.ts.map +1 -1
- package/dest/public/public_tx_context.js +11 -7
- package/dest/public/public_tx_simulator.d.ts +56 -5
- package/dest/public/public_tx_simulator.d.ts.map +1 -1
- package/dest/public/public_tx_simulator.js +106 -26
- package/dest/public/side_effect_trace.d.ts +4 -10
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +6 -15
- package/dest/public/side_effect_trace_interface.d.ts +3 -9
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/dest/public/transitional_adapters.d.ts +1 -2
- package/dest/public/transitional_adapters.d.ts.map +1 -1
- package/dest/public/transitional_adapters.js +8 -10
- package/package.json +10 -10
- package/src/avm/avm_contract_call_result.ts +39 -2
- package/src/avm/avm_memory_types.ts +6 -10
- package/src/avm/avm_simulator.ts +58 -8
- package/src/avm/avm_tree.ts +88 -64
- package/src/avm/errors.ts +11 -0
- package/src/avm/fixtures/index.ts +4 -3
- package/src/avm/index.ts +1 -0
- package/src/avm/journal/journal.ts +118 -126
- package/src/avm/journal/public_storage.ts +5 -6
- package/src/avm/opcodes/accrued_substate.ts +1 -1
- package/src/avm/opcodes/addressing_mode.ts +7 -2
- package/src/avm/opcodes/external_calls.ts +1 -3
- package/src/avm/opcodes/instruction.ts +1 -1
- package/src/index.ts +0 -1
- package/src/public/dual_side_effect_trace.ts +4 -13
- package/src/public/enqueued_call_side_effect_trace.ts +14 -17
- package/src/public/executor_metrics.ts +1 -9
- package/src/public/fixtures/index.ts +158 -0
- package/src/public/index.ts +1 -5
- package/src/public/public_processor.ts +5 -27
- package/src/public/public_tx_context.ts +13 -8
- package/src/public/public_tx_simulator.ts +182 -50
- package/src/public/side_effect_trace.ts +9 -19
- package/src/public/side_effect_trace_interface.ts +3 -9
- package/src/public/transitional_adapters.ts +12 -12
- package/dest/mocks/fixtures.d.ts +0 -28
- package/dest/mocks/fixtures.d.ts.map +0 -1
- package/dest/mocks/fixtures.js +0 -48
- package/dest/mocks/index.d.ts +0 -2
- package/dest/mocks/index.d.ts.map +0 -1
- package/dest/mocks/index.js +0 -2
- package/dest/public/executor.d.ts +0 -47
- package/dest/public/executor.d.ts.map +0 -1
- package/dest/public/executor.js +0 -90
- package/src/mocks/fixtures.ts +0 -72
- package/src/mocks/index.ts +0 -1
- package/src/public/executor.ts +0 -154
|
@@ -62,9 +62,8 @@ import { createDebugLogger } from '@aztec/foundation/log';
|
|
|
62
62
|
|
|
63
63
|
import { assert } from 'console';
|
|
64
64
|
|
|
65
|
-
import { type AvmContractCallResult } from '../avm/avm_contract_call_result.js';
|
|
65
|
+
import { type AvmContractCallResult, type AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
|
|
66
66
|
import { type AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
|
|
67
|
-
import { createSimulationError } from '../common/errors.js';
|
|
68
67
|
import { type EnqueuedPublicCallExecutionResultWithSideEffects, type PublicFunctionCallResult } from './execution.js';
|
|
69
68
|
import { SideEffectLimitReachedError } from './side_effect_errors.js';
|
|
70
69
|
import { type PublicSideEffectTraceInterface } from './side_effect_trace_interface.js';
|
|
@@ -188,7 +187,10 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
|
|
|
188
187
|
|
|
189
188
|
public merge(forkedTrace: this, reverted: boolean = false) {
|
|
190
189
|
// sanity check to avoid merging the same forked trace twice
|
|
191
|
-
assert(
|
|
190
|
+
assert(
|
|
191
|
+
!forkedTrace.alreadyMergedIntoParent,
|
|
192
|
+
'Cannot merge a forked trace that has already been merged into its parent!',
|
|
193
|
+
);
|
|
192
194
|
forkedTrace.alreadyMergedIntoParent = true;
|
|
193
195
|
|
|
194
196
|
// TODO(dbanks12): accept & merge forked trace's hints!
|
|
@@ -318,7 +320,7 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
|
|
|
318
320
|
public traceNewNoteHash(
|
|
319
321
|
contractAddress: AztecAddress,
|
|
320
322
|
noteHash: Fr,
|
|
321
|
-
leafIndex: Fr,
|
|
323
|
+
leafIndex: Fr = Fr.zero(),
|
|
322
324
|
path: Fr[] = emptyNoteHashPath(),
|
|
323
325
|
) {
|
|
324
326
|
if (this.noteHashes.length + this.previousSideEffectArrayLengths.noteHashes >= MAX_NOTE_HASHES_PER_TX) {
|
|
@@ -510,8 +512,6 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
|
|
|
510
512
|
nestedEnvironment: AvmExecutionEnvironment,
|
|
511
513
|
/** How much gas was available for this public execution. */
|
|
512
514
|
startGasLeft: Gas,
|
|
513
|
-
/** How much gas was left after this public execution. */
|
|
514
|
-
endGasLeft: Gas,
|
|
515
515
|
/** Bytecode used for this execution. */
|
|
516
516
|
_bytecode: Buffer,
|
|
517
517
|
/** The call's results */
|
|
@@ -524,7 +524,10 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
|
|
|
524
524
|
// Store end side effect counter before it gets updated by absorbing nested call trace
|
|
525
525
|
const endSideEffectCounter = new Fr(this.sideEffectCounter);
|
|
526
526
|
|
|
527
|
-
const gasUsed = new Gas(
|
|
527
|
+
const gasUsed = new Gas(
|
|
528
|
+
startGasLeft.daGas - avmCallResults.gasLeft.daGas,
|
|
529
|
+
startGasLeft.l2Gas - avmCallResults.gasLeft.l2Gas,
|
|
530
|
+
);
|
|
528
531
|
|
|
529
532
|
this.avmCircuitHints.externalCalls.items.push(
|
|
530
533
|
new AvmExternalCallHint(
|
|
@@ -576,19 +579,15 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
|
|
|
576
579
|
* Get the results of public execution.
|
|
577
580
|
*/
|
|
578
581
|
public toPublicEnqueuedCallExecutionResult(
|
|
579
|
-
/** How much gas was left after this public execution. */
|
|
580
|
-
endGasLeft: Gas,
|
|
581
582
|
/** The call's results */
|
|
582
|
-
avmCallResults:
|
|
583
|
+
avmCallResults: AvmFinalizedCallResult,
|
|
583
584
|
): EnqueuedPublicCallExecutionResultWithSideEffects {
|
|
584
585
|
return {
|
|
585
|
-
endGasLeft,
|
|
586
|
+
endGasLeft: Gas.from(avmCallResults.gasLeft),
|
|
586
587
|
endSideEffectCounter: new Fr(this.sideEffectCounter),
|
|
587
588
|
returnValues: avmCallResults.output,
|
|
588
589
|
reverted: avmCallResults.reverted,
|
|
589
|
-
revertReason: avmCallResults.revertReason
|
|
590
|
-
? createSimulationError(avmCallResults.revertReason, avmCallResults.output)
|
|
591
|
-
: undefined,
|
|
590
|
+
revertReason: avmCallResults.revertReason,
|
|
592
591
|
sideEffects: {
|
|
593
592
|
publicDataWrites: this.publicDataWrites,
|
|
594
593
|
noteHashes: this.noteHashes,
|
|
@@ -652,12 +651,10 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
|
|
|
652
651
|
_avmEnvironment: AvmExecutionEnvironment,
|
|
653
652
|
/** How much gas was available for this public execution. */
|
|
654
653
|
_startGasLeft: Gas,
|
|
655
|
-
/** How much gas was left after this public execution. */
|
|
656
|
-
_endGasLeft: Gas,
|
|
657
654
|
/** Bytecode used for this execution. */
|
|
658
655
|
_bytecode: Buffer,
|
|
659
656
|
/** The call's results */
|
|
660
|
-
_avmCallResults:
|
|
657
|
+
_avmCallResults: AvmFinalizedCallResult,
|
|
661
658
|
/** Function name for logging */
|
|
662
659
|
_functionName: string = 'unknown',
|
|
663
660
|
): PublicFunctionCallResult {
|
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
export class ExecutorMetrics {
|
|
11
11
|
private fnCount: UpDownCounter;
|
|
12
12
|
private fnDuration: Histogram;
|
|
13
|
-
private bytecodeSize: Histogram;
|
|
14
13
|
|
|
15
14
|
constructor(client: TelemetryClient, name = 'PublicExecutor') {
|
|
16
15
|
const meter = client.getMeter(name);
|
|
@@ -24,19 +23,12 @@ export class ExecutorMetrics {
|
|
|
24
23
|
unit: 'ms',
|
|
25
24
|
valueType: ValueType.INT,
|
|
26
25
|
});
|
|
27
|
-
|
|
28
|
-
this.bytecodeSize = meter.createHistogram(Metrics.PUBLIC_EXECUTION_SIMULATION_BYTECODE_SIZE, {
|
|
29
|
-
description: 'Size of the function bytecode',
|
|
30
|
-
unit: 'By',
|
|
31
|
-
valueType: ValueType.INT,
|
|
32
|
-
});
|
|
33
26
|
}
|
|
34
27
|
|
|
35
|
-
recordFunctionSimulation(
|
|
28
|
+
recordFunctionSimulation(durationMs: number) {
|
|
36
29
|
this.fnCount.add(1, {
|
|
37
30
|
[Attributes.OK]: true,
|
|
38
31
|
});
|
|
39
|
-
this.bytecodeSize.record(bytecodeSize);
|
|
40
32
|
this.fnDuration.record(Math.ceil(durationMs));
|
|
41
33
|
}
|
|
42
34
|
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { PublicExecutionRequest, Tx } from '@aztec/circuit-types';
|
|
2
|
+
import {
|
|
3
|
+
type AvmCircuitInputs,
|
|
4
|
+
CallContext,
|
|
5
|
+
DEFAULT_GAS_LIMIT,
|
|
6
|
+
Gas,
|
|
7
|
+
GasFees,
|
|
8
|
+
GasSettings,
|
|
9
|
+
GlobalVariables,
|
|
10
|
+
Header,
|
|
11
|
+
MAX_L2_GAS_PER_ENQUEUED_CALL,
|
|
12
|
+
PartialPrivateTailPublicInputsForPublic,
|
|
13
|
+
PrivateKernelTailCircuitPublicInputs,
|
|
14
|
+
type PublicFunction,
|
|
15
|
+
PublicKeys,
|
|
16
|
+
RollupValidationRequests,
|
|
17
|
+
SerializableContractInstance,
|
|
18
|
+
TxConstantData,
|
|
19
|
+
TxContext,
|
|
20
|
+
} from '@aztec/circuits.js';
|
|
21
|
+
import { makeContractClassPublic, makeContractInstanceFromClassId } from '@aztec/circuits.js/testing';
|
|
22
|
+
import { AztecAddress } from '@aztec/foundation/aztec-address';
|
|
23
|
+
import { Fr, Point } from '@aztec/foundation/fields';
|
|
24
|
+
import { openTmpStore } from '@aztec/kv-store/utils';
|
|
25
|
+
import { PublicTxSimulator, type WorldStateDB } from '@aztec/simulator';
|
|
26
|
+
import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';
|
|
27
|
+
import { MerkleTrees } from '@aztec/world-state';
|
|
28
|
+
|
|
29
|
+
import { mock } from 'jest-mock-extended';
|
|
30
|
+
|
|
31
|
+
import { getAvmTestContractBytecode, getAvmTestContractFunctionSelector } from '../../avm/fixtures/index.js';
|
|
32
|
+
|
|
33
|
+
const TIMESTAMP = new Fr(99833);
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* If assertionErrString is set, we expect a (non exceptional halting) revert due to a failing assertion and
|
|
37
|
+
* we check that the revert reason error contains this string. However, the circuit must correctly prove the
|
|
38
|
+
* execution.
|
|
39
|
+
*/
|
|
40
|
+
export async function simulateAvmTestContractGenerateCircuitInputs(
|
|
41
|
+
functionName: string,
|
|
42
|
+
calldata: Fr[] = [],
|
|
43
|
+
assertionErrString?: string,
|
|
44
|
+
): Promise<AvmCircuitInputs> {
|
|
45
|
+
const sender = AztecAddress.random();
|
|
46
|
+
const functionSelector = getAvmTestContractFunctionSelector(functionName);
|
|
47
|
+
calldata = [functionSelector.toField(), ...calldata];
|
|
48
|
+
|
|
49
|
+
const globalVariables = GlobalVariables.empty();
|
|
50
|
+
globalVariables.gasFees = GasFees.default();
|
|
51
|
+
globalVariables.timestamp = TIMESTAMP;
|
|
52
|
+
|
|
53
|
+
const worldStateDB = mock<WorldStateDB>();
|
|
54
|
+
const telemetry = new NoopTelemetryClient();
|
|
55
|
+
const merkleTrees = await (await MerkleTrees.new(openTmpStore(), telemetry)).fork();
|
|
56
|
+
worldStateDB.getMerkleInterface.mockReturnValue(merkleTrees);
|
|
57
|
+
|
|
58
|
+
// Top level contract call
|
|
59
|
+
const bytecode = getAvmTestContractBytecode('public_dispatch');
|
|
60
|
+
const dispatchSelector = getAvmTestContractFunctionSelector('public_dispatch');
|
|
61
|
+
const publicFn: PublicFunction = { bytecode, selector: dispatchSelector };
|
|
62
|
+
const contractClass = makeContractClassPublic(0, publicFn);
|
|
63
|
+
const contractInstance = makeContractInstanceFromClassId(contractClass.id);
|
|
64
|
+
|
|
65
|
+
// The values here should match those in `avm_simulator.test.ts`
|
|
66
|
+
const instanceGet = new SerializableContractInstance({
|
|
67
|
+
version: 1,
|
|
68
|
+
salt: new Fr(0x123),
|
|
69
|
+
deployer: new AztecAddress(new Fr(0x456)),
|
|
70
|
+
contractClassId: new Fr(0x789),
|
|
71
|
+
initializationHash: new Fr(0x101112),
|
|
72
|
+
publicKeys: new PublicKeys(
|
|
73
|
+
new Point(new Fr(0x131415), new Fr(0x161718), false),
|
|
74
|
+
new Point(new Fr(0x192021), new Fr(0x222324), false),
|
|
75
|
+
new Point(new Fr(0x252627), new Fr(0x282930), false),
|
|
76
|
+
new Point(new Fr(0x313233), new Fr(0x343536), false),
|
|
77
|
+
),
|
|
78
|
+
}).withAddress(contractInstance.address);
|
|
79
|
+
worldStateDB.getContractInstance
|
|
80
|
+
.mockResolvedValueOnce(contractInstance)
|
|
81
|
+
.mockResolvedValueOnce(instanceGet) // test gets deployer
|
|
82
|
+
.mockResolvedValueOnce(instanceGet) // test gets class id
|
|
83
|
+
.mockResolvedValueOnce(instanceGet) // test gets init hash
|
|
84
|
+
.mockResolvedValue(contractInstance);
|
|
85
|
+
worldStateDB.getContractClass.mockResolvedValue(contractClass);
|
|
86
|
+
worldStateDB.getBytecode.mockResolvedValue(bytecode);
|
|
87
|
+
|
|
88
|
+
const storageValue = new Fr(5);
|
|
89
|
+
worldStateDB.storageRead.mockResolvedValue(Promise.resolve(storageValue));
|
|
90
|
+
|
|
91
|
+
const simulator = new PublicTxSimulator(
|
|
92
|
+
merkleTrees,
|
|
93
|
+
worldStateDB,
|
|
94
|
+
new NoopTelemetryClient(),
|
|
95
|
+
globalVariables,
|
|
96
|
+
/*doMerkleOperations=*/ true,
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
const callContext = new CallContext(sender, contractInstance.address, dispatchSelector, /*isStaticCall=*/ false);
|
|
100
|
+
const executionRequest = new PublicExecutionRequest(callContext, calldata);
|
|
101
|
+
|
|
102
|
+
const tx: Tx = createTxForPublicCall(executionRequest);
|
|
103
|
+
|
|
104
|
+
const avmResult = await simulator.simulate(tx);
|
|
105
|
+
|
|
106
|
+
if (assertionErrString == undefined) {
|
|
107
|
+
expect(avmResult.revertCode.isOK()).toBe(true);
|
|
108
|
+
} else {
|
|
109
|
+
// Explicit revert when an assertion failed.
|
|
110
|
+
expect(avmResult.revertCode.isOK()).toBe(false);
|
|
111
|
+
expect(avmResult.revertReason).toBeDefined();
|
|
112
|
+
expect(avmResult.revertReason?.getMessage()).toContain(assertionErrString);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const avmCircuitInputs: AvmCircuitInputs = avmResult.avmProvingRequest.inputs;
|
|
116
|
+
return avmCircuitInputs;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Craft a carrier transaction for a public call for simulation by PublicTxSimulator.
|
|
121
|
+
*/
|
|
122
|
+
export function createTxForPublicCall(
|
|
123
|
+
executionRequest: PublicExecutionRequest,
|
|
124
|
+
gasUsedByPrivate: Gas = Gas.empty(),
|
|
125
|
+
isTeardown: boolean = false,
|
|
126
|
+
): Tx {
|
|
127
|
+
const callRequest = executionRequest.toCallRequest();
|
|
128
|
+
// use max limits
|
|
129
|
+
const gasLimits = new Gas(DEFAULT_GAS_LIMIT, MAX_L2_GAS_PER_ENQUEUED_CALL);
|
|
130
|
+
|
|
131
|
+
const forPublic = PartialPrivateTailPublicInputsForPublic.empty();
|
|
132
|
+
// TODO(#9269): Remove this fake nullifier method as we move away from 1st nullifier as hash.
|
|
133
|
+
forPublic.nonRevertibleAccumulatedData.nullifiers[0] = Fr.random(); // fake tx nullifier
|
|
134
|
+
if (isTeardown) {
|
|
135
|
+
forPublic.publicTeardownCallRequest = callRequest;
|
|
136
|
+
} else {
|
|
137
|
+
forPublic.revertibleAccumulatedData.publicCallRequests[0] = callRequest;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const teardownGasLimits = isTeardown ? gasLimits : Gas.empty();
|
|
141
|
+
const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty());
|
|
142
|
+
const txContext = new TxContext(Fr.zero(), Fr.zero(), gasSettings);
|
|
143
|
+
const constantData = new TxConstantData(Header.empty(), txContext, Fr.zero(), Fr.zero());
|
|
144
|
+
|
|
145
|
+
const txData = new PrivateKernelTailCircuitPublicInputs(
|
|
146
|
+
constantData,
|
|
147
|
+
RollupValidationRequests.empty(),
|
|
148
|
+
/*gasUsed=*/ gasUsedByPrivate,
|
|
149
|
+
AztecAddress.zero(),
|
|
150
|
+
forPublic,
|
|
151
|
+
);
|
|
152
|
+
const tx = isTeardown ? Tx.newWithTxData(txData, executionRequest) : Tx.newWithTxData(txData);
|
|
153
|
+
if (!isTeardown) {
|
|
154
|
+
tx.enqueuedPublicFunctionCalls[0] = executionRequest;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return tx;
|
|
158
|
+
}
|
package/src/public/index.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
export * from './db_interfaces.js';
|
|
2
2
|
export * from './public_tx_simulator.js';
|
|
3
|
-
export {
|
|
4
|
-
type EnqueuedPublicCallExecutionResult as PublicExecutionResult,
|
|
5
|
-
type PublicFunctionCallResult,
|
|
6
|
-
} from './execution.js';
|
|
7
|
-
export { PublicExecutor } from './executor.js';
|
|
3
|
+
export { type EnqueuedPublicCallExecutionResult, type PublicFunctionCallResult } from './execution.js';
|
|
8
4
|
export * from './fee_payment.js';
|
|
9
5
|
export * from './public_db_sources.js';
|
|
10
6
|
export { PublicProcessor, PublicProcessorFactory } from './public_processor.js';
|
|
@@ -20,9 +20,7 @@ import {
|
|
|
20
20
|
type Header,
|
|
21
21
|
MAX_NOTE_HASHES_PER_TX,
|
|
22
22
|
MAX_NULLIFIERS_PER_TX,
|
|
23
|
-
MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
24
23
|
NULLIFIER_SUBTREE_HEIGHT,
|
|
25
|
-
PUBLIC_DATA_SUBTREE_HEIGHT,
|
|
26
24
|
PublicDataWrite,
|
|
27
25
|
} from '@aztec/circuits.js';
|
|
28
26
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
@@ -31,7 +29,6 @@ import { Timer } from '@aztec/foundation/timer';
|
|
|
31
29
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
32
30
|
import { Attributes, type TelemetryClient, type Tracer, trackSpan } from '@aztec/telemetry-client';
|
|
33
31
|
|
|
34
|
-
import { PublicExecutor } from './executor.js';
|
|
35
32
|
import { computeFeePayerBalanceLeafSlot, computeFeePayerBalanceStorageSlot } from './fee_payment.js';
|
|
36
33
|
import { WorldStateDB } from './public_db_sources.js';
|
|
37
34
|
import { PublicProcessorMetrics } from './public_processor_metrics.js';
|
|
@@ -54,18 +51,17 @@ export class PublicProcessorFactory {
|
|
|
54
51
|
maybeHistoricalHeader: Header | undefined,
|
|
55
52
|
globalVariables: GlobalVariables,
|
|
56
53
|
): PublicProcessor {
|
|
57
|
-
const { telemetryClient } = this;
|
|
58
54
|
const historicalHeader = maybeHistoricalHeader ?? merkleTree.getInitialHeader();
|
|
59
55
|
|
|
60
56
|
const worldStateDB = new WorldStateDB(merkleTree, this.contractDataSource);
|
|
61
|
-
const
|
|
57
|
+
const publicTxSimulator = new PublicTxSimulator(merkleTree, worldStateDB, this.telemetryClient, globalVariables);
|
|
62
58
|
|
|
63
|
-
return PublicProcessor
|
|
59
|
+
return new PublicProcessor(
|
|
64
60
|
merkleTree,
|
|
65
|
-
publicExecutor,
|
|
66
61
|
globalVariables,
|
|
67
62
|
historicalHeader,
|
|
68
63
|
worldStateDB,
|
|
64
|
+
publicTxSimulator,
|
|
69
65
|
this.telemetryClient,
|
|
70
66
|
);
|
|
71
67
|
}
|
|
@@ -89,19 +85,6 @@ export class PublicProcessor {
|
|
|
89
85
|
this.metrics = new PublicProcessorMetrics(telemetryClient, 'PublicProcessor');
|
|
90
86
|
}
|
|
91
87
|
|
|
92
|
-
static create(
|
|
93
|
-
db: MerkleTreeWriteOperations,
|
|
94
|
-
publicExecutor: PublicExecutor,
|
|
95
|
-
globalVariables: GlobalVariables,
|
|
96
|
-
historicalHeader: Header,
|
|
97
|
-
worldStateDB: WorldStateDB,
|
|
98
|
-
telemetryClient: TelemetryClient,
|
|
99
|
-
) {
|
|
100
|
-
const publicTxSimulator = PublicTxSimulator.create(db, publicExecutor, globalVariables, worldStateDB);
|
|
101
|
-
|
|
102
|
-
return new PublicProcessor(db, globalVariables, historicalHeader, worldStateDB, publicTxSimulator, telemetryClient);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
88
|
get tracer(): Tracer {
|
|
106
89
|
return this.metrics.tracer;
|
|
107
90
|
}
|
|
@@ -184,15 +167,10 @@ export class PublicProcessor {
|
|
|
184
167
|
}
|
|
185
168
|
}
|
|
186
169
|
|
|
187
|
-
const allPublicDataWrites = padArrayEnd(
|
|
188
|
-
processedTx.txEffect.publicDataWrites,
|
|
189
|
-
PublicDataWrite.empty(),
|
|
190
|
-
MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
191
|
-
);
|
|
192
170
|
await this.db.batchInsert(
|
|
193
171
|
MerkleTreeId.PUBLIC_DATA_TREE,
|
|
194
|
-
|
|
195
|
-
|
|
172
|
+
processedTx.txEffect.publicDataWrites.map(x => x.toBuffer()),
|
|
173
|
+
0,
|
|
196
174
|
);
|
|
197
175
|
result.push(processedTx);
|
|
198
176
|
returns = returns.concat(returnValues ?? []);
|
|
@@ -25,10 +25,10 @@ import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
|
25
25
|
import { strict as assert } from 'assert';
|
|
26
26
|
import { inspect } from 'util';
|
|
27
27
|
|
|
28
|
+
import { type AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
|
|
28
29
|
import { AvmPersistableStateManager } from '../avm/index.js';
|
|
29
30
|
import { DualSideEffectTrace } from './dual_side_effect_trace.js';
|
|
30
31
|
import { PublicEnqueuedCallSideEffectTrace, SideEffectArrayLengths } from './enqueued_call_side_effect_trace.js';
|
|
31
|
-
import { type EnqueuedPublicCallExecutionResult } from './execution.js';
|
|
32
32
|
import { type WorldStateDB } from './public_db_sources.js';
|
|
33
33
|
import { PublicSideEffectTrace } from './side_effect_trace.js';
|
|
34
34
|
import { generateAvmCircuitPublicInputs, generateAvmProvingRequest } from './transitional_adapters.js';
|
|
@@ -70,6 +70,7 @@ export class PublicTxContext {
|
|
|
70
70
|
private readonly nonRevertibleAccumulatedDataFromPrivate: PrivateToPublicAccumulatedData,
|
|
71
71
|
private readonly revertibleAccumulatedDataFromPrivate: PrivateToPublicAccumulatedData,
|
|
72
72
|
public trace: PublicEnqueuedCallSideEffectTrace, // FIXME(dbanks12): should be private
|
|
73
|
+
private doMerkleOperations: boolean,
|
|
73
74
|
) {
|
|
74
75
|
this.log = createDebugLogger(`aztec:public_tx_context`);
|
|
75
76
|
this.gasUsed = startGasUsed;
|
|
@@ -80,6 +81,7 @@ export class PublicTxContext {
|
|
|
80
81
|
worldStateDB: WorldStateDB,
|
|
81
82
|
tx: Tx,
|
|
82
83
|
globalVariables: GlobalVariables,
|
|
84
|
+
doMerkleOperations: boolean,
|
|
83
85
|
) {
|
|
84
86
|
const nonRevertibleAccumulatedDataFromPrivate = tx.data.forPublic!.nonRevertibleAccumulatedData;
|
|
85
87
|
const revertibleAccumulatedDataFromPrivate = tx.data.forPublic!.revertibleAccumulatedData;
|
|
@@ -109,10 +111,11 @@ export class PublicTxContext {
|
|
|
109
111
|
const trace = new DualSideEffectTrace(innerCallTrace, enqueuedCallTrace);
|
|
110
112
|
|
|
111
113
|
// Transaction level state manager that will be forked for revertible phases.
|
|
112
|
-
const txStateManager = AvmPersistableStateManager.newWithPendingSiloedNullifiers(
|
|
114
|
+
const txStateManager = await AvmPersistableStateManager.newWithPendingSiloedNullifiers(
|
|
113
115
|
worldStateDB,
|
|
114
116
|
trace,
|
|
115
117
|
nonRevertibleNullifiersFromPrivate,
|
|
118
|
+
doMerkleOperations,
|
|
116
119
|
);
|
|
117
120
|
|
|
118
121
|
return new PublicTxContext(
|
|
@@ -131,6 +134,7 @@ export class PublicTxContext {
|
|
|
131
134
|
tx.data.forPublic!.nonRevertibleAccumulatedData,
|
|
132
135
|
tx.data.forPublic!.revertibleAccumulatedData,
|
|
133
136
|
enqueuedCallTrace,
|
|
137
|
+
doMerkleOperations,
|
|
134
138
|
);
|
|
135
139
|
}
|
|
136
140
|
|
|
@@ -340,26 +344,27 @@ export class PublicTxContext {
|
|
|
340
344
|
}
|
|
341
345
|
|
|
342
346
|
// TODO(dbanks12): remove once AVM proves entire public tx
|
|
343
|
-
|
|
347
|
+
updateProvingRequest(
|
|
344
348
|
real: boolean,
|
|
345
349
|
phase: TxExecutionPhase,
|
|
346
|
-
|
|
350
|
+
fnName: string,
|
|
347
351
|
stateManager: AvmPersistableStateManager,
|
|
348
352
|
executionRequest: PublicExecutionRequest,
|
|
349
|
-
result:
|
|
353
|
+
result: AvmFinalizedCallResult,
|
|
350
354
|
allocatedGas: Gas,
|
|
351
355
|
) {
|
|
352
356
|
if (this.avmProvingRequest === undefined) {
|
|
353
357
|
// Propagate the very first avmProvingRequest of the tx for now.
|
|
354
358
|
// Eventually this will be the proof for the entire public portion of the transaction.
|
|
355
|
-
this.avmProvingRequest =
|
|
359
|
+
this.avmProvingRequest = generateAvmProvingRequest(
|
|
356
360
|
real,
|
|
357
|
-
|
|
361
|
+
fnName,
|
|
358
362
|
stateManager,
|
|
359
363
|
this.historicalHeader,
|
|
360
364
|
this.globalVariables,
|
|
361
365
|
executionRequest,
|
|
362
|
-
|
|
366
|
+
// TODO(dbanks12): do we need this return type unless we are doing an isolated call?
|
|
367
|
+
stateManager.trace.toPublicEnqueuedCallExecutionResult(result),
|
|
363
368
|
allocatedGas,
|
|
364
369
|
this.getTransactionFee(phase),
|
|
365
370
|
);
|