@aztec/simulator 0.62.0 → 0.63.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/acvm/acvm.d.ts +2 -16
- package/dest/acvm/acvm.d.ts.map +1 -1
- package/dest/acvm/acvm.js +2 -70
- package/dest/acvm/oracle/oracle.d.ts +4 -4
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +10 -11
- package/dest/acvm/oracle/typed_oracle.d.ts +5 -5
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +8 -8
- package/dest/avm/avm_gas.d.ts.map +1 -1
- package/dest/avm/avm_gas.js +2 -1
- package/dest/avm/avm_machine_state.d.ts +27 -8
- package/dest/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/avm/avm_machine_state.js +6 -10
- package/dest/avm/avm_memory_types.d.ts +8 -0
- package/dest/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/avm/avm_memory_types.js +5 -1
- package/dest/avm/avm_simulator.d.ts +2 -19
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +12 -14
- package/dest/avm/avm_tree.d.ts +249 -0
- package/dest/avm/avm_tree.d.ts.map +1 -0
- package/dest/avm/avm_tree.js +637 -0
- package/dest/avm/errors.d.ts +4 -17
- package/dest/avm/errors.d.ts.map +1 -1
- package/dest/avm/errors.js +21 -50
- package/dest/avm/fixtures/index.d.ts +7 -2
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +12 -12
- package/dest/avm/index.d.ts +1 -0
- package/dest/avm/index.d.ts.map +1 -1
- package/dest/avm/index.js +2 -1
- package/dest/avm/journal/journal.d.ts +43 -24
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +172 -39
- package/dest/avm/journal/nullifiers.d.ts +5 -4
- package/dest/avm/journal/nullifiers.d.ts.map +1 -1
- package/dest/avm/journal/nullifiers.js +2 -3
- package/dest/avm/journal/public_storage.d.ts +6 -5
- package/dest/avm/journal/public_storage.d.ts.map +1 -1
- package/dest/avm/journal/public_storage.js +1 -1
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +4 -10
- package/dest/avm/opcodes/arithmetic.d.ts +4 -1
- package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/avm/opcodes/arithmetic.js +18 -4
- package/dest/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/avm/opcodes/bitwise.js +1 -3
- package/dest/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/avm/opcodes/comparators.js +1 -2
- package/dest/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/avm/opcodes/contract.js +2 -3
- package/dest/avm/opcodes/control_flow.d.ts +4 -0
- package/dest/avm/opcodes/control_flow.d.ts.map +1 -1
- package/dest/avm/opcodes/control_flow.js +21 -6
- package/dest/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/avm/opcodes/conversion.js +1 -2
- package/dest/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/avm/opcodes/ec_add.js +5 -11
- package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/avm/opcodes/environment_getters.js +1 -2
- package/dest/avm/opcodes/external_calls.d.ts +4 -2
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +38 -22
- package/dest/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/avm/opcodes/hashing.js +1 -4
- package/dest/avm/opcodes/instruction.d.ts +4 -0
- package/dest/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction.js +7 -1
- package/dest/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/avm/opcodes/memory.js +1 -7
- package/dest/avm/opcodes/misc.js +3 -3
- package/dest/avm/opcodes/multi_scalar_mul.d.ts.map +1 -1
- package/dest/avm/opcodes/multi_scalar_mul.js +6 -5
- package/dest/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/avm/opcodes/storage.js +2 -4
- package/dest/avm/serialization/bytecode_serialization.d.ts +1 -6
- package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/bytecode_serialization.js +24 -20
- package/dest/client/client_execution_context.d.ts +7 -11
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +18 -20
- package/dest/client/db_oracle.d.ts +17 -10
- package/dest/client/db_oracle.d.ts.map +1 -1
- package/dest/client/db_oracle.js +1 -1
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +5 -4
- package/dest/client/unconstrained_execution.d.ts.map +1 -1
- package/dest/client/unconstrained_execution.js +3 -2
- package/dest/client/view_data_oracle.d.ts +6 -12
- package/dest/client/view_data_oracle.d.ts.map +1 -1
- package/dest/client/view_data_oracle.js +10 -12
- package/dest/common/errors.d.ts +15 -2
- package/dest/common/errors.d.ts.map +1 -1
- package/dest/common/errors.js +85 -4
- package/dest/mocks/fixtures.d.ts +9 -28
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +12 -57
- package/dest/public/dual_side_effect_trace.d.ts +34 -26
- package/dest/public/dual_side_effect_trace.d.ts.map +1 -1
- package/dest/public/dual_side_effect_trace.js +48 -36
- package/dest/public/enqueued_call_side_effect_trace.d.ts +96 -33
- package/dest/public/enqueued_call_side_effect_trace.d.ts.map +1 -1
- package/dest/public/enqueued_call_side_effect_trace.js +212 -138
- package/dest/public/execution.d.ts +50 -17
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +1 -29
- package/dest/public/executor.d.ts +28 -11
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +33 -33
- package/dest/public/index.d.ts +4 -5
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +4 -5
- package/dest/public/public_db_sources.d.ts +1 -0
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +12 -5
- package/dest/public/public_processor.d.ts +7 -11
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +60 -42
- package/dest/public/public_processor_metrics.d.ts +3 -3
- package/dest/public/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_processor_metrics.js +1 -1
- package/dest/public/public_tx_context.d.ts +130 -0
- package/dest/public/public_tx_context.d.ts.map +1 -0
- package/dest/public/public_tx_context.js +293 -0
- package/dest/public/public_tx_simulator.d.ts +36 -0
- package/dest/public/public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator.js +148 -0
- package/dest/public/side_effect_trace.d.ts +30 -15
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +70 -16
- package/dest/public/side_effect_trace_interface.d.ts +43 -12
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/dest/public/transitional_adapters.d.ts +9 -0
- package/dest/public/transitional_adapters.d.ts.map +1 -0
- package/dest/public/transitional_adapters.js +127 -0
- package/dest/public/utils.d.ts +5 -0
- package/dest/public/utils.d.ts.map +1 -0
- package/dest/public/utils.js +30 -0
- package/package.json +12 -9
- package/src/acvm/acvm.ts +3 -94
- package/src/acvm/oracle/oracle.ts +9 -14
- package/src/acvm/oracle/typed_oracle.ts +8 -8
- package/src/avm/avm_gas.ts +1 -0
- package/src/avm/avm_machine_state.ts +28 -12
- package/src/avm/avm_memory_types.ts +5 -0
- package/src/avm/avm_simulator.ts +13 -16
- package/src/avm/avm_tree.ts +785 -0
- package/src/avm/errors.ts +25 -48
- package/src/avm/fixtures/index.ts +16 -12
- package/src/avm/index.ts +1 -0
- package/src/avm/journal/journal.ts +291 -52
- package/src/avm/journal/nullifiers.ts +7 -7
- package/src/avm/journal/public_storage.ts +5 -5
- package/src/avm/opcodes/accrued_substate.ts +3 -9
- package/src/avm/opcodes/arithmetic.ts +26 -4
- package/src/avm/opcodes/bitwise.ts +0 -2
- package/src/avm/opcodes/comparators.ts +0 -1
- package/src/avm/opcodes/contract.ts +1 -2
- package/src/avm/opcodes/control_flow.ts +24 -5
- package/src/avm/opcodes/conversion.ts +0 -1
- package/src/avm/opcodes/ec_add.ts +6 -9
- package/src/avm/opcodes/environment_getters.ts +0 -1
- package/src/avm/opcodes/external_calls.ts +39 -21
- package/src/avm/opcodes/hashing.ts +0 -3
- package/src/avm/opcodes/instruction.ts +7 -0
- package/src/avm/opcodes/memory.ts +0 -6
- package/src/avm/opcodes/misc.ts +2 -2
- package/src/avm/opcodes/multi_scalar_mul.ts +5 -4
- package/src/avm/opcodes/storage.ts +1 -3
- package/src/avm/serialization/bytecode_serialization.ts +31 -22
- package/src/client/client_execution_context.ts +22 -23
- package/src/client/db_oracle.ts +22 -11
- package/src/client/private_execution.ts +5 -4
- package/src/client/unconstrained_execution.ts +2 -1
- package/src/client/view_data_oracle.ts +14 -13
- package/src/common/errors.ts +119 -3
- package/src/mocks/fixtures.ts +15 -106
- package/src/public/dual_side_effect_trace.ts +138 -50
- package/src/public/enqueued_call_side_effect_trace.ts +352 -212
- package/src/public/execution.ts +58 -42
- package/src/public/executor.ts +52 -67
- package/src/public/index.ts +7 -5
- package/src/public/public_db_sources.ts +12 -4
- package/src/public/public_processor.ts +111 -73
- package/src/public/public_processor_metrics.ts +3 -3
- package/src/public/public_tx_context.ts +411 -0
- package/src/public/public_tx_simulator.ts +232 -0
- package/src/public/side_effect_trace.ts +154 -28
- package/src/public/side_effect_trace_interface.ts +92 -14
- package/src/public/transitional_adapters.ts +347 -0
- package/src/public/utils.ts +32 -0
- package/dest/public/enqueued_call_simulator.d.ts +0 -43
- package/dest/public/enqueued_call_simulator.d.ts.map +0 -1
- package/dest/public/enqueued_call_simulator.js +0 -156
- package/dest/public/enqueued_calls_processor.d.ts +0 -43
- package/dest/public/enqueued_calls_processor.d.ts.map +0 -1
- package/dest/public/enqueued_calls_processor.js +0 -209
- package/dest/public/hints_builder.d.ts +0 -29
- package/dest/public/hints_builder.d.ts.map +0 -1
- package/dest/public/hints_builder.js +0 -75
- package/dest/public/public_kernel.d.ts +0 -30
- package/dest/public/public_kernel.d.ts.map +0 -1
- package/dest/public/public_kernel.js +0 -67
- package/dest/public/public_kernel_circuit_simulator.d.ts +0 -25
- package/dest/public/public_kernel_circuit_simulator.d.ts.map +0 -1
- package/dest/public/public_kernel_circuit_simulator.js +0 -2
- package/dest/public/public_kernel_tail_simulator.d.ts +0 -15
- package/dest/public/public_kernel_tail_simulator.d.ts.map +0 -1
- package/dest/public/public_kernel_tail_simulator.js +0 -39
- package/src/public/enqueued_call_simulator.ts +0 -360
- package/src/public/enqueued_calls_processor.ts +0 -372
- package/src/public/hints_builder.ts +0 -168
- package/src/public/public_kernel.ts +0 -100
- package/src/public/public_kernel_circuit_simulator.ts +0 -32
- package/src/public/public_kernel_tail_simulator.ts +0 -97
|
@@ -1,47 +1,47 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type FailedTx,
|
|
3
|
+
MerkleTreeId,
|
|
3
4
|
type MerkleTreeWriteOperations,
|
|
4
5
|
NestedProcessReturnValues,
|
|
5
6
|
type ProcessedTx,
|
|
6
7
|
type ProcessedTxHandler,
|
|
7
8
|
Tx,
|
|
9
|
+
TxExecutionPhase,
|
|
8
10
|
type TxValidator,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
makeProcessedTxFromPrivateOnlyTx,
|
|
12
|
+
makeProcessedTxFromTxWithPublicCalls,
|
|
11
13
|
} from '@aztec/circuit-types';
|
|
12
14
|
import {
|
|
15
|
+
type AztecAddress,
|
|
13
16
|
ContractClassRegisteredEvent,
|
|
14
17
|
type ContractDataSource,
|
|
18
|
+
Fr,
|
|
15
19
|
type GlobalVariables,
|
|
16
20
|
type Header,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
MAX_NOTE_HASHES_PER_TX,
|
|
22
|
+
MAX_NULLIFIERS_PER_TX,
|
|
23
|
+
MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
24
|
+
NULLIFIER_SUBTREE_HEIGHT,
|
|
25
|
+
PUBLIC_DATA_SUBTREE_HEIGHT,
|
|
26
|
+
PublicDataWrite,
|
|
20
27
|
} from '@aztec/circuits.js';
|
|
21
|
-
import {
|
|
28
|
+
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
22
29
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
23
30
|
import { Timer } from '@aztec/foundation/timer';
|
|
24
31
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
25
32
|
import { Attributes, type TelemetryClient, type Tracer, trackSpan } from '@aztec/telemetry-client';
|
|
26
33
|
|
|
27
|
-
import { type SimulationProvider } from '../providers/index.js';
|
|
28
|
-
import { EnqueuedCallsProcessor } from './enqueued_calls_processor.js';
|
|
29
34
|
import { PublicExecutor } from './executor.js';
|
|
30
35
|
import { computeFeePayerBalanceLeafSlot, computeFeePayerBalanceStorageSlot } from './fee_payment.js';
|
|
31
36
|
import { WorldStateDB } from './public_db_sources.js';
|
|
32
|
-
import { RealPublicKernelCircuitSimulator } from './public_kernel.js';
|
|
33
|
-
import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
|
|
34
37
|
import { PublicProcessorMetrics } from './public_processor_metrics.js';
|
|
38
|
+
import { PublicTxSimulator } from './public_tx_simulator.js';
|
|
35
39
|
|
|
36
40
|
/**
|
|
37
41
|
* Creates new instances of PublicProcessor given the provided merkle tree db and contract data source.
|
|
38
42
|
*/
|
|
39
43
|
export class PublicProcessorFactory {
|
|
40
|
-
constructor(
|
|
41
|
-
private contractDataSource: ContractDataSource,
|
|
42
|
-
private simulator: SimulationProvider,
|
|
43
|
-
private telemetryClient: TelemetryClient,
|
|
44
|
-
) {}
|
|
44
|
+
constructor(private contractDataSource: ContractDataSource, private telemetryClient: TelemetryClient) {}
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* Creates a new instance of a PublicProcessor.
|
|
@@ -59,12 +59,10 @@ export class PublicProcessorFactory {
|
|
|
59
59
|
|
|
60
60
|
const worldStateDB = new WorldStateDB(merkleTree, this.contractDataSource);
|
|
61
61
|
const publicExecutor = new PublicExecutor(worldStateDB, telemetryClient);
|
|
62
|
-
const publicKernelSimulator = new RealPublicKernelCircuitSimulator(this.simulator);
|
|
63
62
|
|
|
64
63
|
return PublicProcessor.create(
|
|
65
64
|
merkleTree,
|
|
66
65
|
publicExecutor,
|
|
67
|
-
publicKernelSimulator,
|
|
68
66
|
globalVariables,
|
|
69
67
|
historicalHeader,
|
|
70
68
|
worldStateDB,
|
|
@@ -81,12 +79,10 @@ export class PublicProcessor {
|
|
|
81
79
|
private metrics: PublicProcessorMetrics;
|
|
82
80
|
constructor(
|
|
83
81
|
protected db: MerkleTreeWriteOperations,
|
|
84
|
-
protected publicExecutor: PublicExecutor,
|
|
85
|
-
protected publicKernel: PublicKernelCircuitSimulator,
|
|
86
82
|
protected globalVariables: GlobalVariables,
|
|
87
83
|
protected historicalHeader: Header,
|
|
88
84
|
protected worldStateDB: WorldStateDB,
|
|
89
|
-
protected
|
|
85
|
+
protected publicTxSimulator: PublicTxSimulator,
|
|
90
86
|
telemetryClient: TelemetryClient,
|
|
91
87
|
private log = createDebugLogger('aztec:sequencer:public-processor'),
|
|
92
88
|
) {
|
|
@@ -96,31 +92,14 @@ export class PublicProcessor {
|
|
|
96
92
|
static create(
|
|
97
93
|
db: MerkleTreeWriteOperations,
|
|
98
94
|
publicExecutor: PublicExecutor,
|
|
99
|
-
publicKernelSimulator: PublicKernelCircuitSimulator,
|
|
100
95
|
globalVariables: GlobalVariables,
|
|
101
96
|
historicalHeader: Header,
|
|
102
97
|
worldStateDB: WorldStateDB,
|
|
103
98
|
telemetryClient: TelemetryClient,
|
|
104
99
|
) {
|
|
105
|
-
const
|
|
106
|
-
db,
|
|
107
|
-
publicExecutor,
|
|
108
|
-
publicKernelSimulator,
|
|
109
|
-
globalVariables,
|
|
110
|
-
historicalHeader,
|
|
111
|
-
worldStateDB,
|
|
112
|
-
);
|
|
100
|
+
const publicTxSimulator = PublicTxSimulator.create(db, publicExecutor, globalVariables, worldStateDB);
|
|
113
101
|
|
|
114
|
-
return new PublicProcessor(
|
|
115
|
-
db,
|
|
116
|
-
publicExecutor,
|
|
117
|
-
publicKernelSimulator,
|
|
118
|
-
globalVariables,
|
|
119
|
-
historicalHeader,
|
|
120
|
-
worldStateDB,
|
|
121
|
-
enqueuedCallsProcessor,
|
|
122
|
-
telemetryClient,
|
|
123
|
-
);
|
|
102
|
+
return new PublicProcessor(db, globalVariables, historicalHeader, worldStateDB, publicTxSimulator, telemetryClient);
|
|
124
103
|
}
|
|
125
104
|
|
|
126
105
|
get tracer(): Tracer {
|
|
@@ -152,21 +131,17 @@ export class PublicProcessor {
|
|
|
152
131
|
}
|
|
153
132
|
try {
|
|
154
133
|
const [processedTx, returnValues] = !tx.hasPublicCalls()
|
|
155
|
-
?
|
|
134
|
+
? await this.processPrivateOnlyTx(tx)
|
|
156
135
|
: await this.processTxWithPublicCalls(tx);
|
|
157
136
|
this.log.debug(`Processed tx`, {
|
|
158
137
|
txHash: processedTx.hash,
|
|
159
|
-
historicalHeaderHash: processedTx.
|
|
160
|
-
blockNumber: processedTx.
|
|
161
|
-
lastArchiveRoot: processedTx.
|
|
138
|
+
historicalHeaderHash: processedTx.constants.historicalHeader.hash(),
|
|
139
|
+
blockNumber: processedTx.constants.globalVariables.blockNumber,
|
|
140
|
+
lastArchiveRoot: processedTx.constants.historicalHeader.lastArchive.root,
|
|
162
141
|
});
|
|
163
142
|
|
|
164
|
-
// Set fee payment update request into the processed tx
|
|
165
|
-
processedTx.finalPublicDataUpdateRequests = await this.createFinalDataUpdateRequests(processedTx);
|
|
166
|
-
|
|
167
143
|
// Commit the state updates from this transaction
|
|
168
144
|
await this.worldStateDB.commit();
|
|
169
|
-
validateProcessedTx(processedTx);
|
|
170
145
|
|
|
171
146
|
// Re-validate the transaction
|
|
172
147
|
if (txValidator) {
|
|
@@ -183,6 +158,42 @@ export class PublicProcessor {
|
|
|
183
158
|
if (processedTxHandler) {
|
|
184
159
|
await processedTxHandler.addNewTx(processedTx);
|
|
185
160
|
}
|
|
161
|
+
// Update the state so that the next tx in the loop has the correct .startState
|
|
162
|
+
// NB: before this change, all .startStates were actually incorrect, but the issue was never caught because we either:
|
|
163
|
+
// a) had only 1 tx with public calls per block, so this loop had len 1
|
|
164
|
+
// b) always had a txHandler with the same db passed to it as this.db, which updated the db in buildBaseRollupHints in this loop
|
|
165
|
+
// To see how this ^ happens, move back to one shared db in test_context and run orchestrator_multi_public_functions.test.ts
|
|
166
|
+
// The below is taken from buildBaseRollupHints:
|
|
167
|
+
await this.db.appendLeaves(
|
|
168
|
+
MerkleTreeId.NOTE_HASH_TREE,
|
|
169
|
+
padArrayEnd(processedTx.txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX),
|
|
170
|
+
);
|
|
171
|
+
try {
|
|
172
|
+
await this.db.batchInsert(
|
|
173
|
+
MerkleTreeId.NULLIFIER_TREE,
|
|
174
|
+
padArrayEnd(processedTx.txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX).map(n => n.toBuffer()),
|
|
175
|
+
NULLIFIER_SUBTREE_HEIGHT,
|
|
176
|
+
);
|
|
177
|
+
} catch (error) {
|
|
178
|
+
if (txValidator) {
|
|
179
|
+
// Ideally the validator has already caught this above, but just in case:
|
|
180
|
+
throw new Error(`Transaction ${processedTx.hash} invalid after processing public functions`);
|
|
181
|
+
} else {
|
|
182
|
+
// We have no validator and assume this call should blindly process txs with duplicates being caught later
|
|
183
|
+
this.log.warn(`Detected duplicate nullifier after public processing for: ${processedTx.hash}.`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const allPublicDataWrites = padArrayEnd(
|
|
188
|
+
processedTx.txEffect.publicDataWrites,
|
|
189
|
+
PublicDataWrite.empty(),
|
|
190
|
+
MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
191
|
+
);
|
|
192
|
+
await this.db.batchInsert(
|
|
193
|
+
MerkleTreeId.PUBLIC_DATA_TREE,
|
|
194
|
+
allPublicDataWrites.map(x => x.toBuffer()),
|
|
195
|
+
PUBLIC_DATA_SUBTREE_HEIGHT,
|
|
196
|
+
);
|
|
186
197
|
result.push(processedTx);
|
|
187
198
|
returns = returns.concat(returnValues ?? []);
|
|
188
199
|
} catch (err: any) {
|
|
@@ -206,32 +217,26 @@ export class PublicProcessor {
|
|
|
206
217
|
* request for updating fee balance. It also updates the local public state db.
|
|
207
218
|
* See build_or_patch_payment_update_request in base_rollup_inputs.nr for more details.
|
|
208
219
|
*/
|
|
209
|
-
private async
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const feePayer = tx.data.feePayer;
|
|
220
|
+
private async getFeePaymentPublicDataWrite(
|
|
221
|
+
publicDataWrites: PublicDataWrite[],
|
|
222
|
+
txFee: Fr,
|
|
223
|
+
feePayer: AztecAddress,
|
|
224
|
+
): Promise<PublicDataWrite | undefined> {
|
|
216
225
|
if (feePayer.isZero()) {
|
|
217
|
-
return
|
|
226
|
+
return;
|
|
218
227
|
}
|
|
219
228
|
|
|
220
229
|
const feeJuiceAddress = ProtocolContractAddress.FeeJuice;
|
|
221
230
|
const balanceSlot = computeFeePayerBalanceStorageSlot(feePayer);
|
|
222
231
|
const leafSlot = computeFeePayerBalanceLeafSlot(feePayer);
|
|
223
|
-
const txFee = tx.data.getTransactionFee(this.globalVariables.gasFees);
|
|
224
232
|
|
|
225
233
|
this.log.debug(`Deducting ${txFee} balance in Fee Juice for ${feePayer}`);
|
|
226
234
|
|
|
227
|
-
const
|
|
228
|
-
request.leafSlot.equals(leafSlot),
|
|
229
|
-
);
|
|
235
|
+
const existingBalanceWrite = publicDataWrites.find(write => write.leafSlot.equals(leafSlot));
|
|
230
236
|
|
|
231
|
-
const balance =
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
: await this.worldStateDB.storageRead(feeJuiceAddress, balanceSlot);
|
|
237
|
+
const balance = existingBalanceWrite
|
|
238
|
+
? existingBalanceWrite.value
|
|
239
|
+
: await this.worldStateDB.storageRead(feeJuiceAddress, balanceSlot);
|
|
235
240
|
|
|
236
241
|
if (balance.lt(txFee)) {
|
|
237
242
|
throw new Error(`Not enough balance for fee payer to pay for transaction (got ${balance} needs ${txFee})`);
|
|
@@ -240,11 +245,27 @@ export class PublicProcessor {
|
|
|
240
245
|
const updatedBalance = balance.sub(txFee);
|
|
241
246
|
await this.worldStateDB.storageWrite(feeJuiceAddress, balanceSlot, updatedBalance);
|
|
242
247
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
248
|
+
return new PublicDataWrite(leafSlot, updatedBalance);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
private async processPrivateOnlyTx(tx: Tx): Promise<[ProcessedTx]> {
|
|
252
|
+
const gasFees = this.globalVariables.gasFees;
|
|
253
|
+
const transactionFee = tx.data.gasUsed.computeFee(gasFees);
|
|
254
|
+
|
|
255
|
+
const accumulatedData = tx.data.forRollup!.end;
|
|
256
|
+
const feePaymentPublicDataWrite = await this.getFeePaymentPublicDataWrite(
|
|
257
|
+
accumulatedData.publicDataWrites,
|
|
258
|
+
transactionFee,
|
|
259
|
+
tx.data.feePayer,
|
|
260
|
+
);
|
|
246
261
|
|
|
247
|
-
|
|
262
|
+
const processedTx = makeProcessedTxFromPrivateOnlyTx(
|
|
263
|
+
tx,
|
|
264
|
+
transactionFee,
|
|
265
|
+
feePaymentPublicDataWrite,
|
|
266
|
+
this.globalVariables,
|
|
267
|
+
);
|
|
268
|
+
return [processedTx];
|
|
248
269
|
}
|
|
249
270
|
|
|
250
271
|
@trackSpan('PublicProcessor.processTxWithPublicCalls', tx => ({
|
|
@@ -253,12 +274,12 @@ export class PublicProcessor {
|
|
|
253
274
|
private async processTxWithPublicCalls(tx: Tx): Promise<[ProcessedTx, NestedProcessReturnValues[]]> {
|
|
254
275
|
const timer = new Timer();
|
|
255
276
|
|
|
256
|
-
const { avmProvingRequest,
|
|
257
|
-
await this.
|
|
277
|
+
const { avmProvingRequest, gasUsed, revertCode, revertReason, processedPhases } =
|
|
278
|
+
await this.publicTxSimulator.simulate(tx);
|
|
258
279
|
|
|
259
|
-
if (!
|
|
280
|
+
if (!avmProvingRequest) {
|
|
260
281
|
this.metrics.recordFailedTx();
|
|
261
|
-
throw new Error('
|
|
282
|
+
throw new Error('Avm proving result was not generated.');
|
|
262
283
|
}
|
|
263
284
|
|
|
264
285
|
processedPhases.forEach(phase => {
|
|
@@ -271,7 +292,7 @@ export class PublicProcessor {
|
|
|
271
292
|
|
|
272
293
|
this.metrics.recordClassRegistration(
|
|
273
294
|
...ContractClassRegisteredEvent.fromLogs(
|
|
274
|
-
tx.
|
|
295
|
+
tx.contractClassLogs.unrollLogs(),
|
|
275
296
|
ProtocolContractAddress.ContractClassRegisterer,
|
|
276
297
|
),
|
|
277
298
|
);
|
|
@@ -279,7 +300,24 @@ export class PublicProcessor {
|
|
|
279
300
|
const phaseCount = processedPhases.length;
|
|
280
301
|
this.metrics.recordTx(phaseCount, timer.ms());
|
|
281
302
|
|
|
282
|
-
const
|
|
303
|
+
const data = avmProvingRequest.inputs.output;
|
|
304
|
+
const feePaymentPublicDataWrite = await this.getFeePaymentPublicDataWrite(
|
|
305
|
+
data.accumulatedData.publicDataWrites,
|
|
306
|
+
data.transactionFee,
|
|
307
|
+
tx.data.feePayer,
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
const processedTx = makeProcessedTxFromTxWithPublicCalls(
|
|
311
|
+
tx,
|
|
312
|
+
avmProvingRequest,
|
|
313
|
+
feePaymentPublicDataWrite,
|
|
314
|
+
gasUsed,
|
|
315
|
+
revertCode,
|
|
316
|
+
revertReason,
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
const returnValues = processedPhases.find(({ phase }) => phase === TxExecutionPhase.APP_LOGIC)?.returnValues ?? [];
|
|
320
|
+
|
|
283
321
|
return [processedTx, returnValues];
|
|
284
322
|
}
|
|
285
323
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type TxExecutionPhase } from '@aztec/circuit-types';
|
|
2
2
|
import { type ContractClassRegisteredEvent } from '@aztec/circuits.js';
|
|
3
3
|
import {
|
|
4
4
|
Attributes,
|
|
@@ -56,7 +56,7 @@ export class PublicProcessorMetrics {
|
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
recordPhaseDuration(phaseName:
|
|
59
|
+
recordPhaseDuration(phaseName: TxExecutionPhase, durationMs: number) {
|
|
60
60
|
this.phaseCount.add(1, { [Attributes.TX_PHASE_NAME]: phaseName, [Attributes.OK]: true });
|
|
61
61
|
this.phaseDuration.record(Math.ceil(durationMs), { [Attributes.TX_PHASE_NAME]: phaseName });
|
|
62
62
|
}
|
|
@@ -75,7 +75,7 @@ export class PublicProcessorMetrics {
|
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
recordRevertedPhase(phaseName:
|
|
78
|
+
recordRevertedPhase(phaseName: TxExecutionPhase) {
|
|
79
79
|
this.phaseCount.add(1, { [Attributes.TX_PHASE_NAME]: phaseName, [Attributes.OK]: false });
|
|
80
80
|
}
|
|
81
81
|
|