@aztec/simulator 0.40.1 → 0.42.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 -2
- package/dest/acvm/acvm.d.ts.map +1 -1
- package/dest/acvm/acvm.js +3 -3
- package/dest/acvm/oracle/oracle.d.ts +6 -2
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +31 -19
- package/dest/acvm/oracle/typed_oracle.d.ts +8 -11
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +17 -5
- package/dest/acvm/serialize.js +2 -2
- package/dest/avm/avm_execution_environment.d.ts +4 -3
- package/dest/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/avm/avm_execution_environment.js +7 -5
- package/dest/avm/avm_gas.d.ts +1 -5
- package/dest/avm/avm_gas.d.ts.map +1 -1
- package/dest/avm/avm_gas.js +67 -73
- package/dest/avm/avm_simulator.d.ts +5 -0
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +12 -4
- package/dest/avm/errors.d.ts +6 -0
- package/dest/avm/errors.d.ts.map +1 -1
- package/dest/avm/errors.js +10 -1
- package/dest/avm/fixtures/index.d.ts +3 -0
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +15 -3
- package/dest/avm/index.d.ts +2 -0
- package/dest/avm/index.d.ts.map +1 -0
- package/dest/avm/index.js +2 -0
- package/dest/avm/journal/host_storage.d.ts +1 -1
- package/dest/avm/journal/host_storage.d.ts.map +1 -1
- package/dest/avm/journal/journal.d.ts +4 -3
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +10 -11
- package/dest/avm/journal/nullifiers.d.ts +17 -5
- package/dest/avm/journal/nullifiers.d.ts.map +1 -1
- package/dest/avm/journal/nullifiers.js +27 -10
- package/dest/avm/journal/public_storage.d.ts +19 -6
- package/dest/avm/journal/public_storage.d.ts.map +1 -1
- package/dest/avm/journal/public_storage.js +30 -12
- package/dest/avm/journal/trace.d.ts +2 -0
- package/dest/avm/journal/trace.d.ts.map +1 -1
- package/dest/avm/journal/trace.js +7 -1
- package/dest/avm/journal/trace_types.d.ts +1 -0
- package/dest/avm/journal/trace_types.d.ts.map +1 -1
- package/dest/avm/journal/trace_types.js +1 -1
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +6 -7
- package/dest/avm/opcodes/arithmetic.d.ts +1 -7
- package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/avm/opcodes/arithmetic.js +1 -12
- package/dest/avm/opcodes/conversion.js +2 -2
- package/dest/avm/opcodes/external_calls.d.ts +2 -2
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +25 -13
- 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 +6 -4
- package/dest/avm/opcodes/memory.d.ts +0 -4
- package/dest/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/avm/opcodes/memory.js +1 -7
- package/dest/avm/opcodes/storage.d.ts +0 -12
- package/dest/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/avm/opcodes/storage.js +3 -18
- package/dest/avm/serialization/bytecode_serialization.js +2 -2
- package/dest/client/client_execution_context.d.ts +30 -20
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +59 -39
- package/dest/client/db_oracle.d.ts +17 -12
- package/dest/client/db_oracle.d.ts.map +1 -1
- package/dest/client/execution_note_cache.js +2 -2
- package/dest/client/execution_result.d.ts +17 -2
- package/dest/client/execution_result.d.ts.map +1 -1
- package/dest/client/execution_result.js +32 -4
- package/dest/client/private_execution.d.ts +2 -3
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +22 -8
- package/dest/client/simulator.d.ts +0 -16
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +13 -30
- package/dest/client/unconstrained_execution.d.ts +2 -3
- package/dest/client/unconstrained_execution.d.ts.map +1 -1
- package/dest/client/unconstrained_execution.js +5 -7
- package/dest/client/view_data_oracle.d.ts +12 -10
- package/dest/client/view_data_oracle.d.ts.map +1 -1
- package/dest/client/view_data_oracle.js +17 -11
- package/dest/common/index.d.ts +1 -0
- package/dest/common/index.d.ts.map +1 -1
- package/dest/common/index.js +2 -1
- package/dest/common/return_values.d.ts +11 -0
- package/dest/common/return_values.d.ts.map +1 -0
- package/dest/common/return_values.js +13 -0
- package/dest/index.d.ts +3 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +4 -2
- package/dest/mocks/fixtures.d.ts +15 -10
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +22 -17
- package/dest/{simulator → providers}/acvm_native.d.ts.map +1 -1
- package/dest/{simulator → providers}/acvm_native.js +13 -14
- package/dest/providers/acvm_wasm.d.ts.map +1 -0
- package/dest/providers/acvm_wasm.js +15 -0
- package/dest/providers/index.d.ts.map +1 -0
- package/dest/{simulator → providers}/index.js +1 -1
- package/dest/{simulator → providers}/simulation_provider.d.ts.map +1 -1
- package/dest/{simulator → providers}/simulation_provider.js +1 -1
- package/dest/public/abstract_phase_manager.d.ts +43 -42
- package/dest/public/abstract_phase_manager.d.ts.map +1 -1
- package/dest/public/abstract_phase_manager.js +81 -103
- package/dest/public/app_logic_phase_manager.d.ts +7 -8
- package/dest/public/app_logic_phase_manager.d.ts.map +1 -1
- package/dest/public/app_logic_phase_manager.js +14 -14
- package/dest/public/{db.d.ts → db_interfaces.d.ts} +3 -3
- package/dest/public/db_interfaces.d.ts.map +1 -0
- package/dest/public/db_interfaces.js +2 -0
- package/dest/public/execution.d.ts +17 -14
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +1 -1
- package/dest/public/executor.d.ts +3 -30
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +32 -279
- package/dest/public/fee_payment.d.ts +11 -0
- package/dest/public/fee_payment.d.ts.map +1 -0
- package/dest/public/fee_payment.js +24 -0
- package/dest/public/hints_builder.d.ts +3 -2
- package/dest/public/hints_builder.d.ts.map +1 -1
- package/dest/public/hints_builder.js +8 -4
- package/dest/public/index.d.ts +4 -2
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +5 -3
- package/dest/public/phase_manager_factory.d.ts +1 -1
- package/dest/public/phase_manager_factory.d.ts.map +1 -1
- package/dest/public/{public_executor.d.ts → public_db_sources.d.ts} +3 -2
- package/dest/public/public_db_sources.d.ts.map +1 -0
- package/dest/public/public_db_sources.js +198 -0
- package/dest/public/public_kernel.js +14 -14
- package/dest/public/public_processor.d.ts +8 -6
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +48 -29
- package/dest/public/setup_phase_manager.d.ts +7 -9
- package/dest/public/setup_phase_manager.d.ts.map +1 -1
- package/dest/public/setup_phase_manager.js +11 -20
- package/dest/public/tail_phase_manager.d.ts +5 -11
- package/dest/public/tail_phase_manager.d.ts.map +1 -1
- package/dest/public/tail_phase_manager.js +16 -36
- package/dest/public/teardown_phase_manager.d.ts +7 -9
- package/dest/public/teardown_phase_manager.d.ts.map +1 -1
- package/dest/public/teardown_phase_manager.js +15 -21
- package/dest/public/transitional_adaptors.d.ts +3 -2
- package/dest/public/transitional_adaptors.d.ts.map +1 -1
- package/dest/public/transitional_adaptors.js +24 -8
- package/dest/public/utils.d.ts +2 -2
- package/dest/public/utils.d.ts.map +1 -1
- package/dest/public/utils.js +21 -14
- package/package.json +12 -9
- package/src/acvm/acvm.ts +0 -3
- package/src/acvm/oracle/oracle.ts +53 -27
- package/src/acvm/oracle/typed_oracle.ts +25 -16
- package/src/acvm/serialize.ts +1 -1
- package/src/avm/avm_execution_environment.ts +9 -5
- package/src/avm/avm_gas.ts +66 -73
- package/src/avm/avm_simulator.ts +14 -3
- package/src/avm/errors.ts +10 -0
- package/src/avm/fixtures/index.ts +22 -2
- package/src/avm/index.ts +1 -0
- package/src/avm/journal/host_storage.ts +1 -1
- package/src/avm/journal/journal.ts +15 -14
- package/src/avm/journal/nullifiers.ts +27 -14
- package/src/avm/journal/public_storage.ts +30 -16
- package/src/avm/journal/trace.ts +12 -0
- package/src/avm/journal/trace_types.ts +1 -0
- package/src/avm/opcodes/accrued_substate.ts +5 -6
- package/src/avm/opcodes/arithmetic.ts +1 -14
- package/src/avm/opcodes/conversion.ts +1 -1
- package/src/avm/opcodes/external_calls.ts +26 -10
- package/src/avm/opcodes/instruction.ts +5 -3
- package/src/avm/opcodes/memory.ts +1 -8
- package/src/avm/opcodes/storage.ts +3 -20
- package/src/avm/serialization/bytecode_serialization.ts +1 -1
- package/src/client/client_execution_context.ts +70 -44
- package/src/client/db_oracle.ts +18 -12
- package/src/client/execution_note_cache.ts +1 -1
- package/src/client/execution_result.ts +41 -3
- package/src/client/private_execution.ts +38 -20
- package/src/client/simulator.ts +11 -32
- package/src/client/unconstrained_execution.ts +9 -12
- package/src/client/view_data_oracle.ts +20 -12
- package/src/common/index.ts +1 -0
- package/src/common/return_values.ts +18 -0
- package/src/index.ts +3 -1
- package/src/mocks/fixtures.ts +31 -33
- package/src/{simulator → providers}/acvm_native.ts +21 -19
- package/src/{simulator → providers}/acvm_wasm.ts +2 -16
- package/src/public/abstract_phase_manager.ts +146 -207
- package/src/public/app_logic_phase_manager.ts +23 -39
- package/src/public/{db.ts → db_interfaces.ts} +2 -2
- package/src/public/execution.ts +17 -14
- package/src/public/executor.ts +51 -391
- package/src/public/fee_payment.ts +26 -0
- package/src/public/hints_builder.ts +17 -3
- package/src/public/index.ts +4 -2
- package/src/public/phase_manager_factory.ts +1 -1
- package/src/public/{public_executor.ts → public_db_sources.ts} +3 -2
- package/src/public/public_kernel.ts +24 -24
- package/src/public/public_processor.ts +82 -38
- package/src/public/setup_phase_manager.ts +20 -45
- package/src/public/tail_phase_manager.ts +18 -68
- package/src/public/teardown_phase_manager.ts +22 -41
- package/src/public/transitional_adaptors.ts +24 -13
- package/src/public/utils.ts +20 -14
- package/dest/client/logs_cache.d.ts +0 -33
- package/dest/client/logs_cache.d.ts.map +0 -1
- package/dest/client/logs_cache.js +0 -59
- package/dest/public/db.d.ts.map +0 -1
- package/dest/public/db.js +0 -2
- package/dest/public/public_execution_context.d.ts +0 -121
- package/dest/public/public_execution_context.d.ts.map +0 -1
- package/dest/public/public_execution_context.js +0 -214
- package/dest/public/public_executor.d.ts.map +0 -1
- package/dest/public/public_executor.js +0 -197
- package/dest/public/state_actions.d.ts +0 -39
- package/dest/public/state_actions.d.ts.map +0 -1
- package/dest/public/state_actions.js +0 -80
- package/dest/simulator/acvm_wasm.d.ts.map +0 -1
- package/dest/simulator/acvm_wasm.js +0 -22
- package/dest/simulator/index.d.ts.map +0 -1
- package/src/client/logs_cache.ts +0 -65
- package/src/public/public_execution_context.ts +0 -289
- package/src/public/state_actions.ts +0 -102
- /package/dest/{simulator → providers}/acvm_native.d.ts +0 -0
- /package/dest/{simulator → providers}/acvm_wasm.d.ts +0 -0
- /package/dest/{simulator → providers}/index.d.ts +0 -0
- /package/dest/{simulator → providers}/simulation_provider.d.ts +0 -0
- /package/src/{simulator → providers}/index.ts +0 -0
- /package/src/{simulator → providers}/simulation_provider.ts +0 -0
|
@@ -8,18 +8,18 @@ import {
|
|
|
8
8
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
9
9
|
import { elapsed } from '@aztec/foundation/timer';
|
|
10
10
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
SimulatedPublicKernelAppLogicArtifact,
|
|
12
|
+
SimulatedPublicKernelSetupArtifact,
|
|
13
|
+
SimulatedPublicKernelTailArtifact,
|
|
14
|
+
SimulatedPublicKernelTeardownArtifact,
|
|
15
|
+
convertSimulatedPublicInnerInputsToWitnessMap,
|
|
16
|
+
convertSimulatedPublicInnerOutputFromWitnessMap,
|
|
17
|
+
convertSimulatedPublicSetupInputsToWitnessMap,
|
|
18
|
+
convertSimulatedPublicSetupOutputFromWitnessMap,
|
|
19
|
+
convertSimulatedPublicTailInputsToWitnessMap,
|
|
20
|
+
convertSimulatedPublicTailOutputFromWitnessMap,
|
|
21
|
+
convertSimulatedPublicTeardownInputsToWitnessMap,
|
|
22
|
+
convertSimulatedPublicTeardownOutputFromWitnessMap,
|
|
23
23
|
} from '@aztec/noir-protocol-circuits-types';
|
|
24
24
|
import { type SimulationProvider, WASMSimulator } from '@aztec/simulator';
|
|
25
25
|
|
|
@@ -47,11 +47,11 @@ export class RealPublicKernelCircuitSimulator implements PublicKernelCircuitSimu
|
|
|
47
47
|
if (!input.previousKernel.publicInputs.needsSetup) {
|
|
48
48
|
throw new Error(`Expected previous kernel inputs to need setup`);
|
|
49
49
|
}
|
|
50
|
-
const inputWitness =
|
|
50
|
+
const inputWitness = convertSimulatedPublicSetupInputsToWitnessMap(input);
|
|
51
51
|
const [duration, witness] = await elapsed(() =>
|
|
52
|
-
this.wasmSimulator.simulateCircuit(inputWitness,
|
|
52
|
+
this.wasmSimulator.simulateCircuit(inputWitness, SimulatedPublicKernelSetupArtifact),
|
|
53
53
|
);
|
|
54
|
-
const result =
|
|
54
|
+
const result = convertSimulatedPublicSetupOutputFromWitnessMap(witness);
|
|
55
55
|
this.log.debug(`Simulated public kernel setup circuit`, {
|
|
56
56
|
eventName: 'circuit-simulation',
|
|
57
57
|
circuitName: 'public-kernel-setup',
|
|
@@ -73,11 +73,11 @@ export class RealPublicKernelCircuitSimulator implements PublicKernelCircuitSimu
|
|
|
73
73
|
if (!input.previousKernel.publicInputs.needsAppLogic) {
|
|
74
74
|
throw new Error(`Expected previous kernel inputs to need app logic`);
|
|
75
75
|
}
|
|
76
|
-
const inputWitness =
|
|
76
|
+
const inputWitness = convertSimulatedPublicInnerInputsToWitnessMap(input);
|
|
77
77
|
const [duration, witness] = await elapsed(() =>
|
|
78
|
-
this.wasmSimulator.simulateCircuit(inputWitness,
|
|
78
|
+
this.wasmSimulator.simulateCircuit(inputWitness, SimulatedPublicKernelAppLogicArtifact),
|
|
79
79
|
);
|
|
80
|
-
const result =
|
|
80
|
+
const result = convertSimulatedPublicInnerOutputFromWitnessMap(witness);
|
|
81
81
|
this.log.debug(`Simulated public kernel app logic circuit`, {
|
|
82
82
|
eventName: 'circuit-simulation',
|
|
83
83
|
circuitName: 'public-kernel-app-logic',
|
|
@@ -99,11 +99,11 @@ export class RealPublicKernelCircuitSimulator implements PublicKernelCircuitSimu
|
|
|
99
99
|
if (!input.previousKernel.publicInputs.needsTeardown) {
|
|
100
100
|
throw new Error(`Expected previous kernel inputs to need teardown`);
|
|
101
101
|
}
|
|
102
|
-
const inputWitness =
|
|
102
|
+
const inputWitness = convertSimulatedPublicTeardownInputsToWitnessMap(input);
|
|
103
103
|
const [duration, witness] = await elapsed(() =>
|
|
104
|
-
this.wasmSimulator.simulateCircuit(inputWitness,
|
|
104
|
+
this.wasmSimulator.simulateCircuit(inputWitness, SimulatedPublicKernelTeardownArtifact),
|
|
105
105
|
);
|
|
106
|
-
const result =
|
|
106
|
+
const result = convertSimulatedPublicTeardownOutputFromWitnessMap(witness);
|
|
107
107
|
this.log.debug(`Simulated public kernel teardown circuit`, {
|
|
108
108
|
eventName: 'circuit-simulation',
|
|
109
109
|
circuitName: 'public-kernel-teardown',
|
|
@@ -122,11 +122,11 @@ export class RealPublicKernelCircuitSimulator implements PublicKernelCircuitSimu
|
|
|
122
122
|
public async publicKernelCircuitTail(
|
|
123
123
|
input: PublicKernelTailCircuitPrivateInputs,
|
|
124
124
|
): Promise<KernelCircuitPublicInputs> {
|
|
125
|
-
const inputWitness =
|
|
125
|
+
const inputWitness = convertSimulatedPublicTailInputsToWitnessMap(input);
|
|
126
126
|
const [duration, witness] = await elapsed(() =>
|
|
127
|
-
this.wasmSimulator.simulateCircuit(inputWitness,
|
|
127
|
+
this.wasmSimulator.simulateCircuit(inputWitness, SimulatedPublicKernelTailArtifact),
|
|
128
128
|
);
|
|
129
|
-
const result =
|
|
129
|
+
const result = convertSimulatedPublicTailOutputFromWitnessMap(witness);
|
|
130
130
|
this.log.debug(`Simulated public kernel tail circuit`, {
|
|
131
131
|
eventName: 'circuit-simulation',
|
|
132
132
|
circuitName: 'public-kernel-tail',
|
|
@@ -1,22 +1,34 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type BlockProver,
|
|
3
3
|
type FailedTx,
|
|
4
|
-
|
|
4
|
+
NestedProcessReturnValues,
|
|
5
5
|
type ProcessedTx,
|
|
6
|
-
type
|
|
6
|
+
type PublicProvingRequest,
|
|
7
7
|
type SimulationError,
|
|
8
8
|
Tx,
|
|
9
9
|
type TxValidator,
|
|
10
|
-
makeEmptyProcessedTx,
|
|
11
10
|
makeProcessedTx,
|
|
12
|
-
toTxEffect,
|
|
13
11
|
validateProcessedTx,
|
|
14
12
|
} from '@aztec/circuit-types';
|
|
15
|
-
import {
|
|
16
|
-
|
|
13
|
+
import {
|
|
14
|
+
AztecAddress,
|
|
15
|
+
GAS_TOKEN_ADDRESS,
|
|
16
|
+
type GlobalVariables,
|
|
17
|
+
type Header,
|
|
18
|
+
type KernelCircuitPublicInputs,
|
|
19
|
+
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
20
|
+
PROTOCOL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
21
|
+
PublicDataUpdateRequest,
|
|
22
|
+
} from '@aztec/circuits.js';
|
|
23
|
+
import { times } from '@aztec/foundation/collection';
|
|
17
24
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
18
|
-
import {
|
|
19
|
-
|
|
25
|
+
import {
|
|
26
|
+
PublicExecutor,
|
|
27
|
+
type PublicStateDB,
|
|
28
|
+
type SimulationProvider,
|
|
29
|
+
computeFeePayerBalanceLeafSlot,
|
|
30
|
+
computeFeePayerBalanceStorageSlot,
|
|
31
|
+
} from '@aztec/simulator';
|
|
20
32
|
import { type ContractDataSource } from '@aztec/types/contracts';
|
|
21
33
|
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
22
34
|
|
|
@@ -26,7 +38,7 @@ import {
|
|
|
26
38
|
publicKernelPhaseToKernelType,
|
|
27
39
|
} from './abstract_phase_manager.js';
|
|
28
40
|
import { PhaseManagerFactory } from './phase_manager_factory.js';
|
|
29
|
-
import { ContractsDataSourcePublicDB, WorldStateDB, WorldStatePublicDB } from './
|
|
41
|
+
import { ContractsDataSourcePublicDB, WorldStateDB, WorldStatePublicDB } from './public_db_sources.js';
|
|
30
42
|
import { RealPublicKernelCircuitSimulator } from './public_kernel.js';
|
|
31
43
|
import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
|
|
32
44
|
|
|
@@ -96,12 +108,12 @@ export class PublicProcessor {
|
|
|
96
108
|
maxTransactions = txs.length,
|
|
97
109
|
blockProver?: BlockProver,
|
|
98
110
|
txValidator?: TxValidator<ProcessedTx>,
|
|
99
|
-
): Promise<[ProcessedTx[], FailedTx[],
|
|
111
|
+
): Promise<[ProcessedTx[], FailedTx[], NestedProcessReturnValues[]]> {
|
|
100
112
|
// The processor modifies the tx objects in place, so we need to clone them.
|
|
101
113
|
txs = txs.map(tx => Tx.clone(tx));
|
|
102
114
|
const result: ProcessedTx[] = [];
|
|
103
115
|
const failed: FailedTx[] = [];
|
|
104
|
-
|
|
116
|
+
let returns: NestedProcessReturnValues[] = [];
|
|
105
117
|
|
|
106
118
|
for (const tx of txs) {
|
|
107
119
|
// only process up to the limit of the block
|
|
@@ -112,7 +124,14 @@ export class PublicProcessor {
|
|
|
112
124
|
const [processedTx, returnValues] = !tx.hasPublicCalls()
|
|
113
125
|
? [makeProcessedTx(tx, tx.data.toKernelCircuitPublicInputs(), tx.proof, [])]
|
|
114
126
|
: await this.processTxWithPublicCalls(tx);
|
|
127
|
+
|
|
128
|
+
// Set fee payment update request into the processed tx
|
|
129
|
+
processedTx.finalPublicDataUpdateRequests = await this.createFinalDataUpdateRequests(processedTx);
|
|
130
|
+
|
|
131
|
+
// Commit the state updates from this transaction
|
|
132
|
+
await this.publicStateDB.commit();
|
|
115
133
|
validateProcessedTx(processedTx);
|
|
134
|
+
|
|
116
135
|
// Re-validate the transaction
|
|
117
136
|
if (txValidator) {
|
|
118
137
|
// Only accept processed transactions that are not double-spends,
|
|
@@ -129,16 +148,16 @@ export class PublicProcessor {
|
|
|
129
148
|
await blockProver.addNewTx(processedTx);
|
|
130
149
|
}
|
|
131
150
|
result.push(processedTx);
|
|
132
|
-
returns.
|
|
151
|
+
returns = returns.concat(returnValues ?? []);
|
|
133
152
|
} catch (err: any) {
|
|
134
153
|
const errorMessage = err instanceof Error ? err.message : 'Unknown error';
|
|
135
|
-
this.log.warn(`Failed to process tx ${tx.getTxHash()}: ${errorMessage}`);
|
|
154
|
+
this.log.warn(`Failed to process tx ${tx.getTxHash()}: ${errorMessage} ${err?.stack}`);
|
|
136
155
|
|
|
137
156
|
failed.push({
|
|
138
157
|
tx,
|
|
139
158
|
error: err instanceof Error ? err : new Error(errorMessage),
|
|
140
159
|
});
|
|
141
|
-
returns.push([]);
|
|
160
|
+
returns.push(new NestedProcessReturnValues([]));
|
|
142
161
|
}
|
|
143
162
|
}
|
|
144
163
|
|
|
@@ -146,17 +165,55 @@ export class PublicProcessor {
|
|
|
146
165
|
}
|
|
147
166
|
|
|
148
167
|
/**
|
|
149
|
-
*
|
|
150
|
-
*
|
|
168
|
+
* Creates the final set of data update requests for the transaction. This includes the
|
|
169
|
+
* set of public data update requests as returned by the public kernel, plus a data update
|
|
170
|
+
* request for updating fee balance. It also updates the local public state db.
|
|
171
|
+
* See build_or_patch_payment_update_request in base_rollup_inputs.nr for more details.
|
|
151
172
|
*/
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
|
|
173
|
+
private async createFinalDataUpdateRequests(tx: ProcessedTx) {
|
|
174
|
+
const finalPublicDataUpdateRequests = [
|
|
175
|
+
...tx.data.end.publicDataUpdateRequests,
|
|
176
|
+
...times(PROTOCOL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, () => PublicDataUpdateRequest.empty()),
|
|
177
|
+
];
|
|
178
|
+
|
|
179
|
+
const feePayer = tx.data.feePayer;
|
|
180
|
+
if (feePayer.isZero()) {
|
|
181
|
+
return finalPublicDataUpdateRequests;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const gasToken = AztecAddress.fromBigInt(GAS_TOKEN_ADDRESS);
|
|
185
|
+
const balanceSlot = computeFeePayerBalanceStorageSlot(feePayer);
|
|
186
|
+
const leafSlot = computeFeePayerBalanceLeafSlot(feePayer);
|
|
187
|
+
const txFee = tx.data.getTransactionFee(this.globalVariables.gasFees);
|
|
188
|
+
|
|
189
|
+
this.log.debug(`Deducting ${txFee} balance in gas tokens for ${feePayer}`);
|
|
190
|
+
|
|
191
|
+
const existingBalanceWriteIndex = finalPublicDataUpdateRequests.findIndex(request =>
|
|
192
|
+
request.leafSlot.equals(leafSlot),
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
const balance =
|
|
196
|
+
existingBalanceWriteIndex > -1
|
|
197
|
+
? finalPublicDataUpdateRequests[existingBalanceWriteIndex].newValue
|
|
198
|
+
: await this.publicStateDB.storageRead(gasToken, balanceSlot);
|
|
199
|
+
|
|
200
|
+
if (balance.lt(txFee)) {
|
|
201
|
+
throw new Error(`Not enough balance for fee payer to pay for transaction (got ${balance} needs ${txFee})`);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const updatedBalance = balance.sub(txFee);
|
|
205
|
+
await this.publicStateDB.storageWrite(gasToken, balanceSlot, updatedBalance);
|
|
206
|
+
|
|
207
|
+
finalPublicDataUpdateRequests[
|
|
208
|
+
existingBalanceWriteIndex > -1 ? existingBalanceWriteIndex : MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX
|
|
209
|
+
] = new PublicDataUpdateRequest(leafSlot, updatedBalance, 0);
|
|
210
|
+
|
|
211
|
+
return finalPublicDataUpdateRequests;
|
|
155
212
|
}
|
|
156
213
|
|
|
157
|
-
private async processTxWithPublicCalls(tx: Tx): Promise<[ProcessedTx,
|
|
158
|
-
let returnValues:
|
|
159
|
-
const
|
|
214
|
+
private async processTxWithPublicCalls(tx: Tx): Promise<[ProcessedTx, NestedProcessReturnValues[]]> {
|
|
215
|
+
let returnValues: NestedProcessReturnValues[] = [];
|
|
216
|
+
const publicProvingRequests: PublicProvingRequest[] = [];
|
|
160
217
|
let phase: AbstractPhaseManager | undefined = PhaseManagerFactory.phaseFromTx(
|
|
161
218
|
tx,
|
|
162
219
|
this.db,
|
|
@@ -168,22 +225,19 @@ export class PublicProcessor {
|
|
|
168
225
|
this.publicStateDB,
|
|
169
226
|
);
|
|
170
227
|
this.log.debug(`Beginning processing in phase ${phase?.phase} for tx ${tx.getTxHash()}`);
|
|
171
|
-
let proof = tx.proof;
|
|
172
228
|
let publicKernelPublicInput = tx.data.toPublicKernelCircuitPublicInputs();
|
|
173
229
|
let finalKernelOutput: KernelCircuitPublicInputs | undefined;
|
|
174
230
|
let revertReason: SimulationError | undefined;
|
|
175
|
-
const timer = new Timer();
|
|
176
231
|
const gasUsed: ProcessedTx['gasUsed'] = {};
|
|
177
232
|
while (phase) {
|
|
178
|
-
const output = await phase.handle(tx, publicKernelPublicInput
|
|
233
|
+
const output = await phase.handle(tx, publicKernelPublicInput);
|
|
179
234
|
gasUsed[publicKernelPhaseToKernelType(phase.phase)] = output.gasUsed;
|
|
180
235
|
if (phase.phase === PublicKernelPhase.APP_LOGIC) {
|
|
181
236
|
returnValues = output.returnValues;
|
|
182
237
|
}
|
|
183
|
-
|
|
238
|
+
publicProvingRequests.push(...output.publicProvingRequests);
|
|
184
239
|
publicKernelPublicInput = output.publicKernelOutput;
|
|
185
240
|
finalKernelOutput = output.finalKernelOutput;
|
|
186
|
-
proof = output.publicKernelProof;
|
|
187
241
|
revertReason ??= output.revertReason;
|
|
188
242
|
phase = PhaseManagerFactory.phaseFromOutput(
|
|
189
243
|
publicKernelPublicInput,
|
|
@@ -202,17 +256,7 @@ export class PublicProcessor {
|
|
|
202
256
|
throw new Error('Final public kernel was not executed.');
|
|
203
257
|
}
|
|
204
258
|
|
|
205
|
-
const processedTx = makeProcessedTx(tx, finalKernelOutput, proof,
|
|
206
|
-
|
|
207
|
-
this.log.debug(`Processed public part of ${tx.getTxHash()}`, {
|
|
208
|
-
eventName: 'tx-sequencer-processing',
|
|
209
|
-
duration: timer.ms(),
|
|
210
|
-
effectsSize: toTxEffect(processedTx).toBuffer().length,
|
|
211
|
-
publicDataUpdateRequests:
|
|
212
|
-
processedTx.data.end.publicDataUpdateRequests.filter(x => !x.leafSlot.isZero()).length ?? 0,
|
|
213
|
-
...tx.getStats(),
|
|
214
|
-
} satisfies TxSequencerProcessingStats);
|
|
215
|
-
|
|
259
|
+
const processedTx = makeProcessedTx(tx, finalKernelOutput, tx.proof, publicProvingRequests, revertReason, gasUsed);
|
|
216
260
|
return [processedTx, returnValues];
|
|
217
261
|
}
|
|
218
262
|
}
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import {
|
|
3
|
-
type GlobalVariables,
|
|
4
|
-
type Header,
|
|
5
|
-
type Proof,
|
|
6
|
-
type PublicKernelCircuitPublicInputs,
|
|
7
|
-
} from '@aztec/circuits.js';
|
|
1
|
+
import { PublicKernelType, type PublicProvingRequest, type Tx } from '@aztec/circuit-types';
|
|
2
|
+
import { type GlobalVariables, type Header, type PublicKernelCircuitPublicInputs } from '@aztec/circuits.js';
|
|
8
3
|
import { type PublicExecutor, type PublicStateDB } from '@aztec/simulator';
|
|
9
4
|
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
10
5
|
|
|
11
|
-
import { AbstractPhaseManager, PublicKernelPhase } from './abstract_phase_manager.js';
|
|
12
|
-
import { type ContractsDataSourcePublicDB } from './
|
|
6
|
+
import { AbstractPhaseManager, PublicKernelPhase, makeAvmProvingRequest } from './abstract_phase_manager.js';
|
|
7
|
+
import { type ContractsDataSourcePublicDB } from './public_db_sources.js';
|
|
13
8
|
import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
|
|
14
9
|
|
|
15
10
|
/**
|
|
@@ -29,46 +24,26 @@ export class SetupPhaseManager extends AbstractPhaseManager {
|
|
|
29
24
|
super(db, publicExecutor, publicKernel, globalVariables, historicalHeader, phase);
|
|
30
25
|
}
|
|
31
26
|
|
|
32
|
-
override async handle(
|
|
33
|
-
tx: Tx,
|
|
34
|
-
previousPublicKernelOutput: PublicKernelCircuitPublicInputs,
|
|
35
|
-
previousPublicKernelProof: Proof,
|
|
36
|
-
) {
|
|
27
|
+
override async handle(tx: Tx, previousPublicKernelOutput: PublicKernelCircuitPublicInputs) {
|
|
37
28
|
this.log.verbose(`Processing tx ${tx.getTxHash()}`);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
throw err;
|
|
51
|
-
},
|
|
52
|
-
);
|
|
53
|
-
tx.unencryptedLogs.addFunctionLogs(newUnencryptedFunctionLogs);
|
|
29
|
+
// TODO(#6464): Should we allow emitting contracts in the private setup phase?
|
|
30
|
+
// if so, this should only add contracts that were deployed during private app logic.
|
|
31
|
+
await this.publicContractsDB.addNewContracts(tx);
|
|
32
|
+
const { publicProvingInformation, kernelOutput, newUnencryptedLogs, revertReason, gasUsed } =
|
|
33
|
+
await this.processEnqueuedPublicCalls(tx, previousPublicKernelOutput).catch(
|
|
34
|
+
// the abstract phase manager throws if simulation gives error in a non-revertible phase
|
|
35
|
+
async err => {
|
|
36
|
+
await this.publicStateDB.rollbackToCommit();
|
|
37
|
+
throw err;
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
tx.unencryptedLogs.addFunctionLogs(newUnencryptedLogs);
|
|
54
41
|
await this.publicStateDB.checkpoint();
|
|
55
42
|
|
|
56
43
|
// Return a list of setup proving requests
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
type: PublicKernelType.SETUP,
|
|
60
|
-
inputs: input,
|
|
61
|
-
};
|
|
62
|
-
return request;
|
|
44
|
+
const publicProvingRequests: PublicProvingRequest[] = publicProvingInformation.map(info => {
|
|
45
|
+
return makeAvmProvingRequest(info, PublicKernelType.SETUP);
|
|
63
46
|
});
|
|
64
|
-
return {
|
|
65
|
-
kernelRequests,
|
|
66
|
-
kernelInputs,
|
|
67
|
-
publicKernelOutput,
|
|
68
|
-
publicKernelProof,
|
|
69
|
-
revertReason,
|
|
70
|
-
returnValues: undefined,
|
|
71
|
-
gasUsed,
|
|
72
|
-
};
|
|
47
|
+
return { publicProvingRequests, publicKernelOutput: kernelOutput, revertReason, returnValues: [], gasUsed };
|
|
73
48
|
}
|
|
74
49
|
}
|
|
@@ -1,28 +1,20 @@
|
|
|
1
1
|
import { type PublicKernelRequest, PublicKernelType, type Tx } from '@aztec/circuit-types';
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
CombineHints,
|
|
4
4
|
type GlobalVariables,
|
|
5
5
|
type Header,
|
|
6
6
|
type KernelCircuitPublicInputs,
|
|
7
|
-
MAX_NEW_NOTE_HASHES_PER_TX,
|
|
8
7
|
MAX_NEW_NULLIFIERS_PER_TX,
|
|
9
8
|
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
10
|
-
type MAX_UNENCRYPTED_LOGS_PER_TX,
|
|
11
|
-
type NoteHash,
|
|
12
|
-
type Proof,
|
|
13
9
|
type PublicKernelCircuitPublicInputs,
|
|
14
10
|
PublicKernelTailCircuitPrivateInputs,
|
|
15
|
-
SideEffect,
|
|
16
|
-
makeEmptyProof,
|
|
17
11
|
mergeAccumulatedData,
|
|
18
|
-
sortByCounter,
|
|
19
12
|
} from '@aztec/circuits.js';
|
|
20
|
-
import { type Tuple } from '@aztec/foundation/serialize';
|
|
21
13
|
import { type PublicExecutor, type PublicStateDB } from '@aztec/simulator';
|
|
22
14
|
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
23
15
|
|
|
24
16
|
import { AbstractPhaseManager, PublicKernelPhase } from './abstract_phase_manager.js';
|
|
25
|
-
import { type ContractsDataSourcePublicDB } from './
|
|
17
|
+
import { type ContractsDataSourcePublicDB } from './public_db_sources.js';
|
|
26
18
|
import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
|
|
27
19
|
|
|
28
20
|
export class TailPhaseManager extends AbstractPhaseManager {
|
|
@@ -39,80 +31,46 @@ export class TailPhaseManager extends AbstractPhaseManager {
|
|
|
39
31
|
super(db, publicExecutor, publicKernel, globalVariables, historicalHeader, phase);
|
|
40
32
|
}
|
|
41
33
|
|
|
42
|
-
override async handle(
|
|
43
|
-
tx: Tx,
|
|
44
|
-
previousPublicKernelOutput: PublicKernelCircuitPublicInputs,
|
|
45
|
-
previousPublicKernelProof: Proof,
|
|
46
|
-
) {
|
|
34
|
+
override async handle(tx: Tx, previousPublicKernelOutput: PublicKernelCircuitPublicInputs) {
|
|
47
35
|
this.log.verbose(`Processing tx ${tx.getTxHash()}`);
|
|
48
|
-
const [inputs, finalKernelOutput] = await this.
|
|
49
|
-
previousPublicKernelOutput,
|
|
50
|
-
previousPublicKernelProof,
|
|
51
|
-
).catch(
|
|
36
|
+
const [inputs, finalKernelOutput] = await this.simulate(previousPublicKernelOutput).catch(
|
|
52
37
|
// the abstract phase manager throws if simulation gives error in non-revertible phase
|
|
53
38
|
async err => {
|
|
54
39
|
await this.publicStateDB.rollbackToCommit();
|
|
55
40
|
throw err;
|
|
56
41
|
},
|
|
57
42
|
);
|
|
58
|
-
// commit the state updates from this transaction
|
|
59
|
-
await this.publicStateDB.commit();
|
|
60
43
|
|
|
61
44
|
// Return a tail proving request
|
|
62
|
-
const
|
|
45
|
+
const kernelRequest: PublicKernelRequest = {
|
|
63
46
|
type: PublicKernelType.TAIL,
|
|
64
47
|
inputs: inputs,
|
|
65
48
|
};
|
|
66
49
|
|
|
67
50
|
return {
|
|
68
|
-
|
|
51
|
+
publicProvingRequests: [kernelRequest],
|
|
69
52
|
publicKernelOutput: previousPublicKernelOutput,
|
|
70
53
|
finalKernelOutput,
|
|
71
|
-
|
|
72
|
-
revertReason: undefined,
|
|
73
|
-
returnValues: undefined,
|
|
74
|
-
gasUsed: undefined,
|
|
54
|
+
returnValues: [],
|
|
75
55
|
};
|
|
76
56
|
}
|
|
77
57
|
|
|
78
|
-
private async runTailKernelCircuit(
|
|
79
|
-
previousOutput: PublicKernelCircuitPublicInputs,
|
|
80
|
-
previousProof: Proof,
|
|
81
|
-
): Promise<[PublicKernelTailCircuitPrivateInputs, KernelCircuitPublicInputs]> {
|
|
82
|
-
// Temporary hack. Should sort them in the tail circuit.
|
|
83
|
-
previousOutput.end.unencryptedLogsHashes = this.sortLogsHashes<typeof MAX_UNENCRYPTED_LOGS_PER_TX>(
|
|
84
|
-
previousOutput.end.unencryptedLogsHashes,
|
|
85
|
-
);
|
|
86
|
-
const [inputs, output] = await this.simulate(previousOutput, previousProof);
|
|
87
|
-
|
|
88
|
-
// Temporary hack. Should sort them in the tail circuit.
|
|
89
|
-
const noteHashes = mergeAccumulatedData(
|
|
90
|
-
previousOutput.endNonRevertibleData.newNoteHashes,
|
|
91
|
-
previousOutput.end.newNoteHashes,
|
|
92
|
-
MAX_NEW_NOTE_HASHES_PER_TX,
|
|
93
|
-
);
|
|
94
|
-
output.end.newNoteHashes = this.sortNoteHashes<typeof MAX_NEW_NOTE_HASHES_PER_TX>(noteHashes);
|
|
95
|
-
|
|
96
|
-
return [inputs, output];
|
|
97
|
-
}
|
|
98
|
-
|
|
99
58
|
private async simulate(
|
|
100
59
|
previousOutput: PublicKernelCircuitPublicInputs,
|
|
101
|
-
previousProof: Proof,
|
|
102
60
|
): Promise<[PublicKernelTailCircuitPrivateInputs, KernelCircuitPublicInputs]> {
|
|
103
|
-
const inputs = await this.buildPrivateInputs(previousOutput
|
|
61
|
+
const inputs = await this.buildPrivateInputs(previousOutput);
|
|
104
62
|
// We take a deep copy (clone) of these to pass to the prover
|
|
105
63
|
return [inputs.clone(), await this.publicKernel.publicKernelCircuitTail(inputs)];
|
|
106
64
|
}
|
|
107
65
|
|
|
108
|
-
private async buildPrivateInputs(previousOutput: PublicKernelCircuitPublicInputs
|
|
109
|
-
const previousKernel = this.getPreviousKernelData(previousOutput
|
|
66
|
+
private async buildPrivateInputs(previousOutput: PublicKernelCircuitPublicInputs) {
|
|
67
|
+
const previousKernel = this.getPreviousKernelData(previousOutput);
|
|
110
68
|
|
|
111
|
-
const { validationRequests, endNonRevertibleData, end } = previousOutput;
|
|
69
|
+
const { validationRequests, endNonRevertibleData: nonRevertibleData, end: revertibleData } = previousOutput;
|
|
112
70
|
|
|
113
71
|
const pendingNullifiers = mergeAccumulatedData(
|
|
114
|
-
|
|
115
|
-
|
|
72
|
+
nonRevertibleData.newNullifiers,
|
|
73
|
+
revertibleData.newNullifiers,
|
|
116
74
|
MAX_NEW_NULLIFIERS_PER_TX,
|
|
117
75
|
);
|
|
118
76
|
|
|
@@ -127,8 +85,8 @@ export class TailPhaseManager extends AbstractPhaseManager {
|
|
|
127
85
|
);
|
|
128
86
|
|
|
129
87
|
const pendingPublicDataWrites = mergeAccumulatedData(
|
|
130
|
-
|
|
131
|
-
|
|
88
|
+
nonRevertibleData.publicDataUpdateRequests,
|
|
89
|
+
revertibleData.publicDataUpdateRequests,
|
|
132
90
|
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
133
91
|
);
|
|
134
92
|
|
|
@@ -145,6 +103,8 @@ export class TailPhaseManager extends AbstractPhaseManager {
|
|
|
145
103
|
|
|
146
104
|
const currentState = await this.db.getStateReference();
|
|
147
105
|
|
|
106
|
+
const hints = CombineHints.fromPublicData({ nonRevertibleData, revertibleData });
|
|
107
|
+
|
|
148
108
|
return new PublicKernelTailCircuitPrivateInputs(
|
|
149
109
|
previousKernel,
|
|
150
110
|
nullifierReadRequestHints,
|
|
@@ -152,17 +112,7 @@ export class TailPhaseManager extends AbstractPhaseManager {
|
|
|
152
112
|
publicDataHints,
|
|
153
113
|
publicDataReadRequestHints,
|
|
154
114
|
currentState.partial,
|
|
115
|
+
hints,
|
|
155
116
|
);
|
|
156
117
|
}
|
|
157
|
-
|
|
158
|
-
private sortNoteHashes<N extends number>(noteHashes: Tuple<NoteHash, N>): Tuple<Fr, N> {
|
|
159
|
-
return sortByCounter(noteHashes).map(n => n.value) as Tuple<Fr, N>;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
private sortLogsHashes<N extends number>(unencryptedLogsHashes: Tuple<SideEffect, N>): Tuple<SideEffect, N> {
|
|
163
|
-
// TODO(6052): logs here may have duplicate counters from nested calls
|
|
164
|
-
return sortByCounter(
|
|
165
|
-
unencryptedLogsHashes.map(n => ({ ...n, counter: n.counter.toNumber(), isEmpty: () => n.isEmpty() })),
|
|
166
|
-
).map(h => new SideEffect(h.value, new Fr(h.counter))) as Tuple<SideEffect, N>;
|
|
167
|
-
}
|
|
168
118
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { PublicKernelType, type PublicProvingRequest, type Tx } from '@aztec/circuit-types';
|
|
2
2
|
import {
|
|
3
3
|
type Fr,
|
|
4
4
|
type Gas,
|
|
5
5
|
type GlobalVariables,
|
|
6
6
|
type Header,
|
|
7
|
-
type Proof,
|
|
8
7
|
type PublicKernelCircuitPublicInputs,
|
|
9
8
|
} from '@aztec/circuits.js';
|
|
10
9
|
import { type PublicExecutor, type PublicStateDB } from '@aztec/simulator';
|
|
@@ -12,8 +11,8 @@ import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
|
12
11
|
|
|
13
12
|
import { inspect } from 'util';
|
|
14
13
|
|
|
15
|
-
import { AbstractPhaseManager, PublicKernelPhase } from './abstract_phase_manager.js';
|
|
16
|
-
import { type ContractsDataSourcePublicDB } from './
|
|
14
|
+
import { AbstractPhaseManager, PublicKernelPhase, makeAvmProvingRequest } from './abstract_phase_manager.js';
|
|
15
|
+
import { type ContractsDataSourcePublicDB } from './public_db_sources.js';
|
|
17
16
|
import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
|
|
18
17
|
|
|
19
18
|
/**
|
|
@@ -33,47 +32,29 @@ export class TeardownPhaseManager extends AbstractPhaseManager {
|
|
|
33
32
|
super(db, publicExecutor, publicKernel, globalVariables, historicalHeader, phase);
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
override async handle(
|
|
37
|
-
tx: Tx,
|
|
38
|
-
previousPublicKernelOutput: PublicKernelCircuitPublicInputs,
|
|
39
|
-
previousPublicKernelProof: Proof,
|
|
40
|
-
) {
|
|
35
|
+
override async handle(tx: Tx, previousPublicKernelOutput: PublicKernelCircuitPublicInputs) {
|
|
41
36
|
this.log.verbose(`Processing tx ${tx.getTxHash()}`);
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
tx.unencryptedLogs.addFunctionLogs(newUnencryptedFunctionLogs);
|
|
58
|
-
await this.publicStateDB.checkpoint();
|
|
37
|
+
const { publicProvingInformation, kernelOutput, newUnencryptedLogs, revertReason, gasUsed } =
|
|
38
|
+
await this.processEnqueuedPublicCalls(tx, previousPublicKernelOutput).catch(
|
|
39
|
+
// the abstract phase manager throws if simulation gives error in a non-revertible phase
|
|
40
|
+
async err => {
|
|
41
|
+
await this.publicStateDB.rollbackToCommit();
|
|
42
|
+
throw err;
|
|
43
|
+
},
|
|
44
|
+
);
|
|
45
|
+
if (revertReason) {
|
|
46
|
+
await this.publicStateDB.rollbackToCheckpoint();
|
|
47
|
+
} else {
|
|
48
|
+
// TODO(#6464): Should we allow emitting contracts in the public teardown phase?
|
|
49
|
+
// if so, we should insert them here
|
|
50
|
+
tx.unencryptedLogs.addFunctionLogs(newUnencryptedLogs);
|
|
51
|
+
}
|
|
59
52
|
|
|
60
53
|
// Return a list of teardown proving requests
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
type: PublicKernelType.TEARDOWN,
|
|
64
|
-
inputs: input,
|
|
65
|
-
};
|
|
66
|
-
return request;
|
|
54
|
+
const publicProvingRequests: PublicProvingRequest[] = publicProvingInformation.map(info => {
|
|
55
|
+
return makeAvmProvingRequest(info, PublicKernelType.TEARDOWN);
|
|
67
56
|
});
|
|
68
|
-
return {
|
|
69
|
-
kernelRequests,
|
|
70
|
-
kernelInputs,
|
|
71
|
-
publicKernelOutput,
|
|
72
|
-
publicKernelProof,
|
|
73
|
-
revertReason,
|
|
74
|
-
returnValues: undefined,
|
|
75
|
-
gasUsed,
|
|
76
|
-
};
|
|
57
|
+
return { publicProvingRequests, publicKernelOutput: kernelOutput, revertReason, returnValues: [], gasUsed };
|
|
77
58
|
}
|
|
78
59
|
|
|
79
60
|
protected override getTransactionFee(tx: Tx, previousPublicKernelOutput: PublicKernelCircuitPublicInputs): Fr {
|