@aztec/simulator 0.55.1 → 0.57.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/oracle/oracle.d.ts +2 -5
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +6 -37
- package/dest/acvm/oracle/typed_oracle.d.ts +3 -6
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +1 -10
- package/dest/avm/avm_execution_environment.d.ts +2 -11
- package/dest/avm/avm_execution_environment.d.ts.map +1 -1
- package/dest/avm/avm_execution_environment.js +3 -22
- package/dest/avm/avm_gas.d.ts +2 -2
- package/dest/avm/avm_gas.d.ts.map +1 -1
- package/dest/avm/avm_gas.js +31 -116
- package/dest/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/avm/avm_machine_state.js +6 -6
- package/dest/avm/avm_memory_types.d.ts +38 -9
- package/dest/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/avm/avm_memory_types.js +27 -13
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +5 -6
- package/dest/avm/bytecode_utils.d.ts +1 -2
- package/dest/avm/bytecode_utils.d.ts.map +1 -1
- package/dest/avm/bytecode_utils.js +3 -17
- package/dest/avm/errors.d.ts +1 -1
- package/dest/avm/errors.d.ts.map +1 -1
- package/dest/avm/errors.js +12 -3
- package/dest/avm/fixtures/index.d.ts +4 -16
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +11 -27
- package/dest/avm/journal/index.d.ts +0 -1
- package/dest/avm/journal/index.d.ts.map +1 -1
- package/dest/avm/journal/index.js +1 -2
- package/dest/avm/journal/journal.d.ts +6 -5
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +18 -16
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +37 -30
- package/dest/avm/opcodes/addressing_mode.d.ts +3 -2
- package/dest/avm/opcodes/addressing_mode.d.ts.map +1 -1
- package/dest/avm/opcodes/addressing_mode.js +25 -21
- package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/avm/opcodes/arithmetic.js +6 -5
- package/dest/avm/opcodes/bitwise.d.ts +10 -4
- package/dest/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/avm/opcodes/bitwise.js +26 -18
- package/dest/avm/opcodes/commitment.d.ts.map +1 -1
- package/dest/avm/opcodes/commitment.js +6 -5
- package/dest/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/avm/opcodes/comparators.js +8 -7
- package/dest/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/avm/opcodes/contract.js +6 -5
- package/dest/avm/opcodes/control_flow.js +6 -6
- package/dest/avm/opcodes/conversion.d.ts +3 -2
- package/dest/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/avm/opcodes/conversion.js +21 -13
- package/dest/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/avm/opcodes/ec_add.js +8 -7
- package/dest/avm/opcodes/environment_getters.d.ts +27 -63
- package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/avm/opcodes/environment_getters.js +76 -80
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +27 -16
- package/dest/avm/opcodes/hashing.d.ts +5 -5
- package/dest/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/avm/opcodes/hashing.js +47 -40
- package/dest/avm/opcodes/index.d.ts +3 -0
- package/dest/avm/opcodes/index.d.ts.map +1 -1
- package/dest/avm/opcodes/index.js +4 -1
- package/dest/avm/opcodes/instruction.d.ts +2 -6
- package/dest/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction.js +3 -9
- package/dest/avm/opcodes/instruction_impl.d.ts +0 -26
- package/dest/avm/opcodes/instruction_impl.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction_impl.js +1 -51
- package/dest/avm/opcodes/memory.d.ts +5 -12
- package/dest/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/avm/opcodes/memory.js +40 -53
- package/dest/avm/opcodes/misc.d.ts.map +1 -1
- package/dest/avm/opcodes/misc.js +6 -5
- package/dest/avm/opcodes/multi_scalar_mul.d.ts.map +1 -1
- package/dest/avm/opcodes/multi_scalar_mul.js +17 -16
- package/dest/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/avm/opcodes/storage.js +11 -9
- package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/bytecode_serialization.js +5 -25
- package/dest/avm/serialization/instruction_serialization.d.ts +40 -54
- package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/instruction_serialization.js +41 -57
- package/dest/avm/test_utils.d.ts +8 -8
- package/dest/avm/test_utils.d.ts.map +1 -1
- package/dest/avm/test_utils.js +15 -15
- package/dest/client/client_execution_context.d.ts +6 -30
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +31 -53
- package/dest/client/index.d.ts +0 -1
- package/dest/client/index.d.ts.map +1 -1
- package/dest/client/index.js +1 -2
- package/dest/client/private_execution.d.ts +2 -2
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +5 -19
- package/dest/client/simulator.d.ts +3 -4
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +1 -1
- package/dest/client/test_utils.d.ts.map +1 -1
- package/dest/client/test_utils.js +12 -6
- package/dest/client/unconstrained_execution.d.ts +2 -2
- package/dest/client/unconstrained_execution.d.ts.map +1 -1
- package/dest/client/unconstrained_execution.js +3 -3
- package/dest/common/debug_fn_name.d.ts +4 -0
- package/dest/common/debug_fn_name.d.ts.map +1 -0
- package/dest/common/debug_fn_name.js +15 -0
- package/dest/common/index.d.ts +0 -1
- package/dest/common/index.d.ts.map +1 -1
- package/dest/common/index.js +1 -2
- package/dest/public/enqueued_call_simulator.d.ts +43 -0
- package/dest/public/enqueued_call_simulator.d.ts.map +1 -0
- package/dest/public/enqueued_call_simulator.js +154 -0
- package/dest/public/enqueued_calls_processor.d.ts +44 -0
- package/dest/public/enqueued_calls_processor.d.ts.map +1 -0
- package/dest/public/enqueued_calls_processor.js +218 -0
- package/dest/public/execution.d.ts +10 -8
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +15 -8
- package/dest/public/executor.d.ts +4 -7
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +10 -14
- package/dest/public/hints_builder.d.ts +4 -3
- package/dest/public/hints_builder.d.ts.map +1 -1
- package/dest/public/hints_builder.js +5 -5
- package/dest/public/index.d.ts +3 -2
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +3 -3
- package/dest/public/public_db_sources.d.ts +17 -24
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +58 -65
- package/dest/public/public_kernel.d.ts +3 -9
- package/dest/public/public_kernel.d.ts.map +1 -1
- package/dest/public/public_kernel.js +13 -40
- package/dest/public/public_kernel_circuit_simulator.d.ts +5 -11
- package/dest/public/public_kernel_circuit_simulator.d.ts.map +1 -1
- package/dest/public/public_kernel_tail_simulator.d.ts +19 -0
- package/dest/public/public_kernel_tail_simulator.d.ts.map +1 -0
- package/dest/public/public_kernel_tail_simulator.js +45 -0
- package/dest/public/public_processor.d.ts +9 -5
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +34 -48
- 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/side_effect_errors.d.ts +4 -0
- package/dest/public/side_effect_errors.d.ts.map +1 -0
- package/dest/public/side_effect_errors.js +7 -0
- package/dest/public/side_effect_trace.d.ts +2 -2
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +56 -35
- package/dest/public/side_effect_trace_interface.d.ts +1 -1
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/package.json +12 -9
- package/src/acvm/oracle/oracle.ts +7 -85
- package/src/acvm/oracle/typed_oracle.ts +2 -31
- package/src/avm/avm_execution_environment.ts +2 -24
- package/src/avm/avm_gas.ts +30 -115
- package/src/avm/avm_machine_state.ts +5 -5
- package/src/avm/avm_memory_types.ts +41 -14
- package/src/avm/avm_simulator.ts +4 -5
- package/src/avm/bytecode_utils.ts +2 -17
- package/src/avm/errors.ts +11 -3
- package/src/avm/fixtures/index.ts +13 -46
- package/src/avm/journal/index.ts +0 -1
- package/src/avm/journal/journal.ts +22 -22
- package/src/avm/opcodes/accrued_substate.ts +36 -44
- package/src/avm/opcodes/addressing_mode.ts +27 -24
- package/src/avm/opcodes/arithmetic.ts +5 -7
- package/src/avm/opcodes/bitwise.ts +23 -20
- package/src/avm/opcodes/commitment.ts +6 -7
- package/src/avm/opcodes/comparators.ts +7 -9
- package/src/avm/opcodes/contract.ts +5 -7
- package/src/avm/opcodes/control_flow.ts +5 -5
- package/src/avm/opcodes/conversion.ts +19 -12
- package/src/avm/opcodes/ec_add.ts +14 -16
- package/src/avm/opcodes/environment_getters.ts +73 -99
- package/src/avm/opcodes/external_calls.ts +27 -20
- package/src/avm/opcodes/hashing.ts +52 -52
- package/src/avm/opcodes/index.ts +3 -0
- package/src/avm/opcodes/instruction.ts +3 -10
- package/src/avm/opcodes/instruction_impl.ts +0 -62
- package/src/avm/opcodes/memory.ts +37 -67
- package/src/avm/opcodes/misc.ts +5 -7
- package/src/avm/opcodes/multi_scalar_mul.ts +16 -19
- package/src/avm/opcodes/storage.ts +10 -8
- package/src/avm/serialization/bytecode_serialization.ts +11 -35
- package/src/avm/serialization/instruction_serialization.ts +3 -19
- package/src/avm/test_utils.ts +20 -16
- package/src/client/client_execution_context.ts +40 -96
- package/src/client/index.ts +0 -1
- package/src/client/private_execution.ts +9 -9
- package/src/client/simulator.ts +2 -3
- package/src/client/test_utils.ts +36 -9
- package/src/client/unconstrained_execution.ts +3 -8
- package/src/common/debug_fn_name.ts +22 -0
- package/src/common/index.ts +0 -1
- package/src/public/enqueued_call_simulator.ts +335 -0
- package/src/public/enqueued_calls_processor.ts +388 -0
- package/src/public/execution.ts +16 -12
- package/src/public/executor.ts +8 -22
- package/src/public/hints_builder.ts +21 -21
- package/src/public/index.ts +3 -2
- package/src/public/public_db_sources.ts +62 -67
- package/src/public/public_kernel.ts +15 -49
- package/src/public/public_kernel_circuit_simulator.ts +6 -10
- package/src/public/public_kernel_tail_simulator.ts +106 -0
- package/src/public/public_processor.ts +65 -86
- package/src/public/public_processor_metrics.ts +3 -3
- package/src/public/side_effect_errors.ts +6 -0
- package/src/public/side_effect_trace.ts +77 -39
- package/src/public/side_effect_trace_interface.ts +2 -2
- package/dest/avm/journal/host_storage.d.ts +0 -13
- package/dest/avm/journal/host_storage.d.ts.map +0 -1
- package/dest/avm/journal/host_storage.js +0 -13
- package/dest/avm/opcodes/context_getters.d.ts +0 -15
- package/dest/avm/opcodes/context_getters.d.ts.map +0 -1
- package/dest/avm/opcodes/context_getters.js +0 -19
- package/dest/client/execution_result.d.ts +0 -104
- package/dest/client/execution_result.d.ts.map +0 -1
- package/dest/client/execution_result.js +0 -136
- package/dest/common/return_values.d.ts +0 -11
- package/dest/common/return_values.d.ts.map +0 -1
- package/dest/common/return_values.js +0 -13
- package/dest/public/abstract_phase_manager.d.ts +0 -93
- package/dest/public/abstract_phase_manager.d.ts.map +0 -1
- package/dest/public/abstract_phase_manager.js +0 -285
- package/dest/public/app_logic_phase_manager.d.ts +0 -25
- package/dest/public/app_logic_phase_manager.d.ts.map +0 -1
- package/dest/public/app_logic_phase_manager.js +0 -52
- package/dest/public/phase_manager_factory.d.ts +0 -18
- package/dest/public/phase_manager_factory.d.ts.map +0 -1
- package/dest/public/phase_manager_factory.js +0 -56
- package/dest/public/setup_phase_manager.d.ts +0 -25
- package/dest/public/setup_phase_manager.d.ts.map +0 -1
- package/dest/public/setup_phase_manager.js +0 -39
- package/dest/public/tail_phase_manager.d.ts +0 -23
- package/dest/public/tail_phase_manager.d.ts.map +0 -1
- package/dest/public/tail_phase_manager.js +0 -50
- package/dest/public/teardown_phase_manager.d.ts +0 -27
- package/dest/public/teardown_phase_manager.d.ts.map +0 -1
- package/dest/public/teardown_phase_manager.js +0 -56
- package/src/avm/journal/host_storage.ts +0 -14
- package/src/avm/opcodes/context_getters.ts +0 -23
- package/src/client/execution_result.ts +0 -228
- package/src/common/return_values.ts +0 -18
- package/src/public/abstract_phase_manager.ts +0 -522
- package/src/public/app_logic_phase_manager.ts +0 -81
- package/src/public/phase_manager_factory.ts +0 -126
- package/src/public/setup_phase_manager.ts +0 -61
- package/src/public/tail_phase_manager.ts +0 -127
- package/src/public/teardown_phase_manager.ts +0 -86
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type MerkleTreeOperations,
|
|
3
|
+
type NestedProcessReturnValues,
|
|
4
|
+
type ProcessedTx,
|
|
5
|
+
ProvingRequestType,
|
|
6
|
+
type PublicExecutionRequest,
|
|
7
|
+
type PublicKernelMergeRequest,
|
|
8
|
+
PublicKernelPhase,
|
|
9
|
+
type PublicProvingRequest,
|
|
10
|
+
type SimulationError,
|
|
11
|
+
type Tx,
|
|
12
|
+
} from '@aztec/circuit-types';
|
|
13
|
+
import {
|
|
14
|
+
EnqueuedCallData,
|
|
15
|
+
Fr,
|
|
16
|
+
Gas,
|
|
17
|
+
type GlobalVariables,
|
|
18
|
+
type Header,
|
|
19
|
+
type KernelCircuitPublicInputs,
|
|
20
|
+
NESTED_RECURSIVE_PROOF_LENGTH,
|
|
21
|
+
type PublicCallRequest,
|
|
22
|
+
PublicKernelCircuitPrivateInputs,
|
|
23
|
+
type PublicKernelCircuitPublicInputs,
|
|
24
|
+
PublicKernelData,
|
|
25
|
+
type VMCircuitPublicInputs,
|
|
26
|
+
makeEmptyProof,
|
|
27
|
+
makeEmptyRecursiveProof,
|
|
28
|
+
} from '@aztec/circuits.js';
|
|
29
|
+
import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
30
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
31
|
+
import { ProtocolCircuitVks, getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types';
|
|
32
|
+
|
|
33
|
+
import { inspect } from 'util';
|
|
34
|
+
|
|
35
|
+
import { EnqueuedCallSimulator } from './enqueued_call_simulator.js';
|
|
36
|
+
import { type PublicExecutor } from './executor.js';
|
|
37
|
+
import { type WorldStateDB } from './public_db_sources.js';
|
|
38
|
+
import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
|
|
39
|
+
import { PublicKernelTailSimulator } from './public_kernel_tail_simulator.js';
|
|
40
|
+
|
|
41
|
+
const PhaseIsRevertible: Record<PublicKernelPhase, boolean> = {
|
|
42
|
+
[PublicKernelPhase.SETUP]: false,
|
|
43
|
+
[PublicKernelPhase.APP_LOGIC]: true,
|
|
44
|
+
[PublicKernelPhase.TEARDOWN]: true,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
type PublicPhaseResult = {
|
|
48
|
+
/** The output of the public kernel circuit simulation for this phase */
|
|
49
|
+
publicKernelOutput: PublicKernelCircuitPublicInputs;
|
|
50
|
+
/** The collection of public proving requests */
|
|
51
|
+
provingRequests: PublicProvingRequest[];
|
|
52
|
+
/** Return values of simulating complete callstack */
|
|
53
|
+
returnValues: NestedProcessReturnValues[];
|
|
54
|
+
/** Gas used during the execution this phase */
|
|
55
|
+
gasUsed: Gas;
|
|
56
|
+
/** Time spent for the execution this phase */
|
|
57
|
+
durationMs: number;
|
|
58
|
+
/** Revert reason, if any */
|
|
59
|
+
revertReason?: SimulationError;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export type ProcessedPhase = {
|
|
63
|
+
phase: PublicKernelPhase;
|
|
64
|
+
durationMs: number;
|
|
65
|
+
revertReason?: SimulationError;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export type TxPublicCallsResult = {
|
|
69
|
+
/** The collection of public proving requests */
|
|
70
|
+
provingRequests: PublicProvingRequest[];
|
|
71
|
+
/** The output of the public kernel tail circuit simulation for this tx */
|
|
72
|
+
tailKernelOutput: KernelCircuitPublicInputs;
|
|
73
|
+
/** Return values of simulating complete callstack */
|
|
74
|
+
returnValues: NestedProcessReturnValues[];
|
|
75
|
+
/** Gas used during the execution this tx */
|
|
76
|
+
gasUsed: ProcessedTx['gasUsed'];
|
|
77
|
+
/** Revert reason, if any */
|
|
78
|
+
revertReason?: SimulationError;
|
|
79
|
+
processedPhases: ProcessedPhase[];
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export class EnqueuedCallsProcessor {
|
|
83
|
+
private log: DebugLogger;
|
|
84
|
+
|
|
85
|
+
constructor(
|
|
86
|
+
private publicKernelSimulator: PublicKernelCircuitSimulator,
|
|
87
|
+
private globalVariables: GlobalVariables,
|
|
88
|
+
private worldStateDB: WorldStateDB,
|
|
89
|
+
private enqueuedCallSimulator: EnqueuedCallSimulator,
|
|
90
|
+
private publicKernelTailSimulator: PublicKernelTailSimulator,
|
|
91
|
+
) {
|
|
92
|
+
this.log = createDebugLogger(`aztec:sequencer`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
static create(
|
|
96
|
+
db: MerkleTreeOperations,
|
|
97
|
+
publicExecutor: PublicExecutor,
|
|
98
|
+
publicKernelSimulator: PublicKernelCircuitSimulator,
|
|
99
|
+
globalVariables: GlobalVariables,
|
|
100
|
+
historicalHeader: Header,
|
|
101
|
+
worldStateDB: WorldStateDB,
|
|
102
|
+
) {
|
|
103
|
+
const enqueuedCallSimulator = new EnqueuedCallSimulator(
|
|
104
|
+
db,
|
|
105
|
+
publicExecutor,
|
|
106
|
+
publicKernelSimulator,
|
|
107
|
+
globalVariables,
|
|
108
|
+
historicalHeader,
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const publicKernelTailSimulator = PublicKernelTailSimulator.create(db, publicKernelSimulator);
|
|
112
|
+
|
|
113
|
+
return new EnqueuedCallsProcessor(
|
|
114
|
+
publicKernelSimulator,
|
|
115
|
+
globalVariables,
|
|
116
|
+
worldStateDB,
|
|
117
|
+
enqueuedCallSimulator,
|
|
118
|
+
publicKernelTailSimulator,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
static getExecutionRequestsByPhase(tx: Tx, phase: PublicKernelPhase): PublicExecutionRequest[] {
|
|
123
|
+
switch (phase) {
|
|
124
|
+
case PublicKernelPhase.SETUP:
|
|
125
|
+
return tx.getNonRevertiblePublicExecutionRequests();
|
|
126
|
+
case PublicKernelPhase.APP_LOGIC:
|
|
127
|
+
return tx.getRevertiblePublicExecutionRequests();
|
|
128
|
+
case PublicKernelPhase.TEARDOWN: {
|
|
129
|
+
const request = tx.getPublicTeardownExecutionRequest();
|
|
130
|
+
return request ? [request] : [];
|
|
131
|
+
}
|
|
132
|
+
default:
|
|
133
|
+
throw new Error(`Unknown phase: ${phase}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
static getCallRequestsByPhase(tx: Tx, phase: PublicKernelPhase): PublicCallRequest[] {
|
|
138
|
+
switch (phase) {
|
|
139
|
+
case PublicKernelPhase.SETUP:
|
|
140
|
+
return tx.data.getNonRevertiblePublicCallRequests();
|
|
141
|
+
case PublicKernelPhase.APP_LOGIC:
|
|
142
|
+
return tx.data.getRevertiblePublicCallRequests();
|
|
143
|
+
case PublicKernelPhase.TEARDOWN: {
|
|
144
|
+
const request = tx.data.getTeardownPublicCallRequest();
|
|
145
|
+
return request ? [request] : [];
|
|
146
|
+
}
|
|
147
|
+
default:
|
|
148
|
+
throw new Error(`Unknown phase: ${phase}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async process(tx: Tx): Promise<TxPublicCallsResult> {
|
|
153
|
+
this.log.verbose(`Processing tx ${tx.getTxHash()}`);
|
|
154
|
+
|
|
155
|
+
const phases: PublicKernelPhase[] = [
|
|
156
|
+
PublicKernelPhase.SETUP,
|
|
157
|
+
PublicKernelPhase.APP_LOGIC,
|
|
158
|
+
PublicKernelPhase.TEARDOWN,
|
|
159
|
+
];
|
|
160
|
+
const processedPhases: ProcessedPhase[] = [];
|
|
161
|
+
const provingRequests: PublicProvingRequest[] = [];
|
|
162
|
+
const gasUsed: ProcessedTx['gasUsed'] = {};
|
|
163
|
+
let publicKernelOutput = tx.data.toPublicKernelCircuitPublicInputs();
|
|
164
|
+
let isFromPrivate = true;
|
|
165
|
+
let returnValues: NestedProcessReturnValues[] = [];
|
|
166
|
+
let revertReason: SimulationError | undefined;
|
|
167
|
+
for (let i = 0; i < phases.length; i++) {
|
|
168
|
+
const phase = phases[i];
|
|
169
|
+
const callRequests = EnqueuedCallsProcessor.getCallRequestsByPhase(tx, phase);
|
|
170
|
+
if (callRequests.length) {
|
|
171
|
+
const executionRequests = EnqueuedCallsProcessor.getExecutionRequestsByPhase(tx, phase);
|
|
172
|
+
const result = await this.processPhase(
|
|
173
|
+
tx,
|
|
174
|
+
callRequests,
|
|
175
|
+
executionRequests,
|
|
176
|
+
publicKernelOutput,
|
|
177
|
+
phase,
|
|
178
|
+
isFromPrivate,
|
|
179
|
+
).catch(async err => {
|
|
180
|
+
await this.worldStateDB.rollbackToCommit();
|
|
181
|
+
throw err;
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
publicKernelOutput = result.publicKernelOutput;
|
|
185
|
+
isFromPrivate = false;
|
|
186
|
+
|
|
187
|
+
provingRequests.push(...result.provingRequests);
|
|
188
|
+
if (phase === PublicKernelPhase.APP_LOGIC) {
|
|
189
|
+
returnValues = result.returnValues;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
gasUsed[phase] = result.gasUsed;
|
|
193
|
+
|
|
194
|
+
processedPhases.push({
|
|
195
|
+
phase,
|
|
196
|
+
durationMs: result.durationMs,
|
|
197
|
+
revertReason: result.revertReason,
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
revertReason ??= result.revertReason;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const { output: tailKernelOutput, provingRequest } = await this.publicKernelTailSimulator
|
|
205
|
+
.simulate(publicKernelOutput)
|
|
206
|
+
.catch(
|
|
207
|
+
// the abstract phase manager throws if simulation gives error in non-revertible phase
|
|
208
|
+
async err => {
|
|
209
|
+
await this.worldStateDB.rollbackToCommit();
|
|
210
|
+
throw err;
|
|
211
|
+
},
|
|
212
|
+
);
|
|
213
|
+
provingRequests.push(provingRequest);
|
|
214
|
+
|
|
215
|
+
return {
|
|
216
|
+
provingRequests: provingRequests,
|
|
217
|
+
tailKernelOutput,
|
|
218
|
+
returnValues,
|
|
219
|
+
gasUsed,
|
|
220
|
+
processedPhases,
|
|
221
|
+
revertReason,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
private async processPhase(
|
|
226
|
+
tx: Tx,
|
|
227
|
+
callRequests: PublicCallRequest[],
|
|
228
|
+
executionRequests: PublicExecutionRequest[],
|
|
229
|
+
previousPublicKernelOutput: PublicKernelCircuitPublicInputs,
|
|
230
|
+
phase: PublicKernelPhase,
|
|
231
|
+
isFromPrivate: boolean,
|
|
232
|
+
): Promise<PublicPhaseResult> {
|
|
233
|
+
this.log.debug(`Beginning processing in phase ${PublicKernelPhase[phase]} for tx ${tx.getTxHash()}`);
|
|
234
|
+
|
|
235
|
+
const phaseTimer = new Timer();
|
|
236
|
+
const provingRequests: PublicProvingRequest[] = [];
|
|
237
|
+
const returnValues: NestedProcessReturnValues[] = [];
|
|
238
|
+
let publicKernelOutput = previousPublicKernelOutput;
|
|
239
|
+
let gasUsed = Gas.empty();
|
|
240
|
+
let revertReason: SimulationError | undefined;
|
|
241
|
+
for (let i = callRequests.length - 1; i >= 0 && !revertReason; i--) {
|
|
242
|
+
const callRequest = callRequests[i];
|
|
243
|
+
const executionRequest = executionRequests[i];
|
|
244
|
+
|
|
245
|
+
// add new contracts to the contracts db so that their functions may be found and called
|
|
246
|
+
// TODO(#4073): This is catching only private deployments, when we add public ones, we'll
|
|
247
|
+
// have to capture contracts emitted in that phase as well.
|
|
248
|
+
// TODO(@spalladino): Should we allow emitting contracts in the fee preparation phase?
|
|
249
|
+
// TODO(#6464): Should we allow emitting contracts in the private setup phase?
|
|
250
|
+
// if so, this should only add contracts that were deployed during private app logic.
|
|
251
|
+
await this.worldStateDB.addNewContracts(tx);
|
|
252
|
+
|
|
253
|
+
const availableGas = this.getAvailableGas(tx, publicKernelOutput, phase);
|
|
254
|
+
const transactionFee = this.getTransactionFee(tx, publicKernelOutput, phase);
|
|
255
|
+
|
|
256
|
+
const enqueuedCallResult = await this.enqueuedCallSimulator.simulate(
|
|
257
|
+
callRequest,
|
|
258
|
+
executionRequest,
|
|
259
|
+
tx,
|
|
260
|
+
publicKernelOutput,
|
|
261
|
+
availableGas,
|
|
262
|
+
transactionFee,
|
|
263
|
+
phase,
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
if (enqueuedCallResult.revertReason && !PhaseIsRevertible[phase]) {
|
|
267
|
+
this.log.debug(
|
|
268
|
+
`Simulation error on ${executionRequest.contractAddress.toString()}:${
|
|
269
|
+
executionRequest.callContext.functionSelector
|
|
270
|
+
} with reason: ${enqueuedCallResult.revertReason}`,
|
|
271
|
+
);
|
|
272
|
+
throw enqueuedCallResult.revertReason;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
provingRequests.push(...enqueuedCallResult.provingRequests);
|
|
276
|
+
returnValues.push(enqueuedCallResult.returnValues);
|
|
277
|
+
gasUsed = gasUsed.add(enqueuedCallResult.gasUsed);
|
|
278
|
+
revertReason ??= enqueuedCallResult.revertReason;
|
|
279
|
+
|
|
280
|
+
if (revertReason) {
|
|
281
|
+
// TODO(#6464): Should we allow emitting contracts in the private setup phase?
|
|
282
|
+
// if so, this is removing contracts deployed in private setup
|
|
283
|
+
await this.worldStateDB.removeNewContracts(tx);
|
|
284
|
+
await this.worldStateDB.rollbackToCheckpoint();
|
|
285
|
+
tx.filterRevertedLogs(publicKernelOutput);
|
|
286
|
+
} else {
|
|
287
|
+
// TODO(#6470): we should be adding contracts deployed in those logs to the publicContractsDB
|
|
288
|
+
tx.unencryptedLogs.addFunctionLogs([enqueuedCallResult.newUnencryptedLogs]);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const { output, provingRequest } = await this.runMergeKernelCircuit(
|
|
292
|
+
publicKernelOutput,
|
|
293
|
+
enqueuedCallResult.kernelOutput,
|
|
294
|
+
isFromPrivate,
|
|
295
|
+
);
|
|
296
|
+
publicKernelOutput = output;
|
|
297
|
+
isFromPrivate = false;
|
|
298
|
+
provingRequests.push(provingRequest);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (phase === PublicKernelPhase.SETUP) {
|
|
302
|
+
await this.worldStateDB.checkpoint();
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
return {
|
|
306
|
+
publicKernelOutput,
|
|
307
|
+
provingRequests,
|
|
308
|
+
durationMs: phaseTimer.ms(),
|
|
309
|
+
gasUsed,
|
|
310
|
+
returnValues: revertReason ? [] : returnValues,
|
|
311
|
+
revertReason,
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
private getAvailableGas(
|
|
316
|
+
tx: Tx,
|
|
317
|
+
previousPublicKernelOutput: PublicKernelCircuitPublicInputs,
|
|
318
|
+
phase: PublicKernelPhase,
|
|
319
|
+
) {
|
|
320
|
+
if (phase === PublicKernelPhase.TEARDOWN) {
|
|
321
|
+
return tx.data.constants.txContext.gasSettings.getTeardownLimits();
|
|
322
|
+
} else {
|
|
323
|
+
return tx.data.constants.txContext.gasSettings
|
|
324
|
+
.getLimits() // No need to subtract teardown limits since they are already included in end.gasUsed
|
|
325
|
+
.sub(previousPublicKernelOutput.end.gasUsed)
|
|
326
|
+
.sub(previousPublicKernelOutput.endNonRevertibleData.gasUsed);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
private getTransactionFee(
|
|
331
|
+
tx: Tx,
|
|
332
|
+
previousPublicKernelOutput: PublicKernelCircuitPublicInputs,
|
|
333
|
+
phase: PublicKernelPhase,
|
|
334
|
+
): Fr {
|
|
335
|
+
if (phase !== PublicKernelPhase.TEARDOWN) {
|
|
336
|
+
return Fr.ZERO;
|
|
337
|
+
} else {
|
|
338
|
+
const gasSettings = tx.data.constants.txContext.gasSettings;
|
|
339
|
+
const gasFees = this.globalVariables.gasFees;
|
|
340
|
+
// No need to add teardown limits since they are already included in end.gasUsed
|
|
341
|
+
const gasUsed = previousPublicKernelOutput.end.gasUsed.add(
|
|
342
|
+
previousPublicKernelOutput.endNonRevertibleData.gasUsed,
|
|
343
|
+
);
|
|
344
|
+
const txFee = gasSettings.inclusionFee.add(gasUsed.computeFee(gasFees));
|
|
345
|
+
this.log.debug(`Computed tx fee`, { txFee, gasUsed: inspect(gasUsed), gasFees: inspect(gasFees) });
|
|
346
|
+
return txFee;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
private async runMergeKernelCircuit(
|
|
351
|
+
previousOutput: PublicKernelCircuitPublicInputs,
|
|
352
|
+
enqueuedCallData: VMCircuitPublicInputs,
|
|
353
|
+
isFromPrivate: boolean,
|
|
354
|
+
): Promise<{ output: PublicKernelCircuitPublicInputs; provingRequest: PublicKernelMergeRequest }> {
|
|
355
|
+
const previousKernel = this.getPreviousKernelData(previousOutput, isFromPrivate);
|
|
356
|
+
|
|
357
|
+
// The proof is not used in simulation.
|
|
358
|
+
const vmProof = makeEmptyProof();
|
|
359
|
+
const callData = new EnqueuedCallData(enqueuedCallData, vmProof);
|
|
360
|
+
|
|
361
|
+
const inputs = new PublicKernelCircuitPrivateInputs(previousKernel, callData);
|
|
362
|
+
|
|
363
|
+
const output = await this.publicKernelSimulator.publicKernelCircuitMerge(inputs);
|
|
364
|
+
|
|
365
|
+
const provingRequest: PublicKernelMergeRequest = {
|
|
366
|
+
type: ProvingRequestType.PUBLIC_KERNEL_MERGE,
|
|
367
|
+
inputs,
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
return { output, provingRequest };
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
private getPreviousKernelData(
|
|
374
|
+
previousOutput: PublicKernelCircuitPublicInputs,
|
|
375
|
+
isFromPrivate: boolean,
|
|
376
|
+
): PublicKernelData {
|
|
377
|
+
// The proof is not used in simulation.
|
|
378
|
+
const proof = makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH);
|
|
379
|
+
|
|
380
|
+
const vk = isFromPrivate
|
|
381
|
+
? ProtocolCircuitVks.PrivateKernelTailToPublicArtifact
|
|
382
|
+
: ProtocolCircuitVks.PublicKernelMergeArtifact;
|
|
383
|
+
const vkIndex = getVKIndex(vk);
|
|
384
|
+
const siblingPath = getVKSiblingPath(vkIndex);
|
|
385
|
+
|
|
386
|
+
return new PublicKernelData(previousOutput, proof, vk, vkIndex, siblingPath);
|
|
387
|
+
}
|
|
388
|
+
}
|
package/src/public/execution.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
NestedProcessReturnValues,
|
|
2
3
|
type PublicExecutionRequest,
|
|
3
4
|
type SimulationError,
|
|
4
5
|
type UnencryptedFunctionL2Logs,
|
|
@@ -13,8 +14,8 @@ import {
|
|
|
13
14
|
type LogHash,
|
|
14
15
|
type NoteHash,
|
|
15
16
|
type Nullifier,
|
|
16
|
-
PublicCallRequest,
|
|
17
17
|
PublicCallStackItemCompressed,
|
|
18
|
+
PublicInnerCallRequest,
|
|
18
19
|
type ReadRequest,
|
|
19
20
|
RevertCode,
|
|
20
21
|
type TreeLeafReadRequest,
|
|
@@ -86,10 +87,8 @@ export interface PublicExecutionResult {
|
|
|
86
87
|
*/
|
|
87
88
|
allUnencryptedLogs: UnencryptedFunctionL2Logs;
|
|
88
89
|
|
|
89
|
-
// TODO(dbanks12): add contract instance read requests
|
|
90
|
-
|
|
91
90
|
/** The requests to call public functions made by this call. */
|
|
92
|
-
publicCallRequests:
|
|
91
|
+
publicCallRequests: PublicInnerCallRequest[];
|
|
93
92
|
/** The results of nested calls. */
|
|
94
93
|
nestedExecutions: this[];
|
|
95
94
|
|
|
@@ -101,14 +100,19 @@ export interface PublicExecutionResult {
|
|
|
101
100
|
}
|
|
102
101
|
|
|
103
102
|
/**
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
* @
|
|
103
|
+
* Recursively accummulate the return values of a call result and its nested executions,
|
|
104
|
+
* so they can be retrieved in order.
|
|
105
|
+
* @param executionResult
|
|
106
|
+
* @returns
|
|
107
107
|
*/
|
|
108
|
-
export function
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return
|
|
108
|
+
export function accumulatePublicReturnValues(executionResult: PublicExecutionResult): NestedProcessReturnValues {
|
|
109
|
+
const acc = new NestedProcessReturnValues(executionResult.returnValues);
|
|
110
|
+
acc.nested = executionResult.nestedExecutions.map(nestedExecution => accumulatePublicReturnValues(nestedExecution));
|
|
111
|
+
return acc;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function collectExecutionResults(result: PublicExecutionResult): PublicExecutionResult[] {
|
|
115
|
+
return [result, ...result.nestedExecutions.map(collectExecutionResults)].flat();
|
|
112
116
|
}
|
|
113
117
|
|
|
114
118
|
/**
|
|
@@ -146,5 +150,5 @@ export function resultToPublicCallRequest(result: PublicExecutionResult) {
|
|
|
146
150
|
Gas.from(result.startGasLeft),
|
|
147
151
|
Gas.from(result.endGasLeft),
|
|
148
152
|
);
|
|
149
|
-
return new
|
|
153
|
+
return new PublicInnerCallRequest(item, result.startSideEffectCounter.toNumber());
|
|
150
154
|
}
|
package/src/public/executor.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type PublicExecutionRequest } from '@aztec/circuit-types';
|
|
2
2
|
import { type AvmSimulationStats } from '@aztec/circuit-types/stats';
|
|
3
|
-
import { Fr, Gas, type GlobalVariables, type
|
|
3
|
+
import { Fr, Gas, type GlobalVariables, type Nullifier, type TxContext } from '@aztec/circuits.js';
|
|
4
4
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
5
5
|
import { Timer } from '@aztec/foundation/timer';
|
|
6
6
|
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
@@ -9,11 +9,11 @@ import { AvmContext } from '../avm/avm_context.js';
|
|
|
9
9
|
import { AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
|
|
10
10
|
import { AvmMachineState } from '../avm/avm_machine_state.js';
|
|
11
11
|
import { AvmSimulator } from '../avm/avm_simulator.js';
|
|
12
|
-
import { HostStorage } from '../avm/journal/host_storage.js';
|
|
13
12
|
import { AvmPersistableStateManager } from '../avm/journal/index.js';
|
|
14
|
-
import {
|
|
13
|
+
import { getPublicFunctionDebugName } from '../common/debug_fn_name.js';
|
|
15
14
|
import { type PublicExecutionResult } from './execution.js';
|
|
16
15
|
import { ExecutorMetrics } from './executor_metrics.js';
|
|
16
|
+
import { type WorldStateDB } from './public_db_sources.js';
|
|
17
17
|
import { PublicSideEffectTrace } from './side_effect_trace.js';
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -22,13 +22,7 @@ import { PublicSideEffectTrace } from './side_effect_trace.js';
|
|
|
22
22
|
export class PublicExecutor {
|
|
23
23
|
metrics: ExecutorMetrics;
|
|
24
24
|
|
|
25
|
-
constructor(
|
|
26
|
-
private readonly publicStorageDB: PublicStateDB,
|
|
27
|
-
private readonly contractsDb: PublicContractsDB,
|
|
28
|
-
private readonly commitmentsDb: CommitmentsDB,
|
|
29
|
-
private readonly header: Header,
|
|
30
|
-
client: TelemetryClient,
|
|
31
|
-
) {
|
|
25
|
+
constructor(private readonly worldStateDB: WorldStateDB, client: TelemetryClient) {
|
|
32
26
|
this.metrics = new ExecutorMetrics(client, 'PublicExecutor');
|
|
33
27
|
}
|
|
34
28
|
|
|
@@ -56,25 +50,19 @@ export class PublicExecutor {
|
|
|
56
50
|
): Promise<PublicExecutionResult> {
|
|
57
51
|
const address = executionRequest.contractAddress;
|
|
58
52
|
const selector = executionRequest.callContext.functionSelector;
|
|
59
|
-
const fnName =
|
|
53
|
+
const fnName = await getPublicFunctionDebugName(this.worldStateDB, address, selector, executionRequest.args);
|
|
60
54
|
|
|
61
|
-
PublicExecutor.log.verbose(`[AVM] Executing public external function ${fnName}.`);
|
|
55
|
+
PublicExecutor.log.verbose(`[AVM] Executing public external function ${fnName}@${address}.`);
|
|
62
56
|
const timer = new Timer();
|
|
63
57
|
|
|
64
|
-
const hostStorage = new HostStorage(this.publicStorageDB, this.contractsDb, this.commitmentsDb);
|
|
65
58
|
const trace = new PublicSideEffectTrace(startSideEffectCounter);
|
|
66
59
|
const avmPersistableState = AvmPersistableStateManager.newWithPendingSiloedNullifiers(
|
|
67
|
-
|
|
60
|
+
this.worldStateDB,
|
|
68
61
|
trace,
|
|
69
62
|
pendingSiloedNullifiers.map(n => n.value),
|
|
70
63
|
);
|
|
71
64
|
|
|
72
|
-
const avmExecutionEnv = createAvmExecutionEnvironment(
|
|
73
|
-
executionRequest,
|
|
74
|
-
this.header,
|
|
75
|
-
globalVariables,
|
|
76
|
-
transactionFee,
|
|
77
|
-
);
|
|
65
|
+
const avmExecutionEnv = createAvmExecutionEnvironment(executionRequest, globalVariables, transactionFee);
|
|
78
66
|
|
|
79
67
|
const avmMachineState = new AvmMachineState(availableGas);
|
|
80
68
|
const avmContext = new AvmContext(avmPersistableState, avmExecutionEnv, avmMachineState);
|
|
@@ -128,7 +116,6 @@ export class PublicExecutor {
|
|
|
128
116
|
*/
|
|
129
117
|
function createAvmExecutionEnvironment(
|
|
130
118
|
executionRequest: PublicExecutionRequest,
|
|
131
|
-
header: Header,
|
|
132
119
|
globalVariables: GlobalVariables,
|
|
133
120
|
transactionFee: Fr,
|
|
134
121
|
): AvmExecutionEnvironment {
|
|
@@ -139,7 +126,6 @@ function createAvmExecutionEnvironment(
|
|
|
139
126
|
executionRequest.callContext.functionSelector,
|
|
140
127
|
/*contractCallDepth=*/ Fr.zero(),
|
|
141
128
|
transactionFee,
|
|
142
|
-
header,
|
|
143
129
|
globalVariables,
|
|
144
130
|
executionRequest.callContext.isStaticCall,
|
|
145
131
|
executionRequest.callContext.isDelegateCall,
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
NOTE_HASH_TREE_HEIGHT,
|
|
14
14
|
NULLIFIER_TREE_HEIGHT,
|
|
15
15
|
type Nullifier,
|
|
16
|
+
type NullifierLeafPreimage,
|
|
16
17
|
PUBLIC_DATA_TREE_HEIGHT,
|
|
17
18
|
type PublicDataRead,
|
|
18
19
|
type PublicDataTreeLeafPreimage,
|
|
@@ -27,6 +28,7 @@ import {
|
|
|
27
28
|
} from '@aztec/circuits.js';
|
|
28
29
|
import { makeTuple } from '@aztec/foundation/array';
|
|
29
30
|
import { type Tuple } from '@aztec/foundation/serialize';
|
|
31
|
+
import { type IndexedTreeLeafPreimage } from '@aztec/foundation/trees';
|
|
30
32
|
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
31
33
|
|
|
32
34
|
export class HintsBuilder {
|
|
@@ -47,15 +49,13 @@ export class HintsBuilder {
|
|
|
47
49
|
nullifierReadRequests: Tuple<ScopedReadRequest, typeof MAX_NULLIFIER_READ_REQUESTS_PER_TX>,
|
|
48
50
|
pendingNullifiers: Tuple<Nullifier, typeof MAX_NULLIFIERS_PER_TX>,
|
|
49
51
|
) {
|
|
50
|
-
return (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
)
|
|
58
|
-
).hints;
|
|
52
|
+
return await buildSiloedNullifierReadRequestHints(
|
|
53
|
+
this,
|
|
54
|
+
nullifierReadRequests,
|
|
55
|
+
pendingNullifiers,
|
|
56
|
+
MAX_NULLIFIER_READ_REQUESTS_PER_TX,
|
|
57
|
+
MAX_NULLIFIER_READ_REQUESTS_PER_TX,
|
|
58
|
+
);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
getNullifierNonExistentReadRequestHints(
|
|
@@ -112,7 +112,8 @@ export class HintsBuilder {
|
|
|
112
112
|
throw new Error(`Nullifier ${nullifier.toBigInt()} already exists in the tree.`);
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
|
|
115
|
+
// Should find a way to stop casting IndexedTreeLeafPreimage as NullifierLeafPreimage
|
|
116
|
+
return this.getMembershipWitnessWithPreimage<typeof NULLIFIER_TREE_HEIGHT, NullifierLeafPreimage>(
|
|
116
117
|
MerkleTreeId.NULLIFIER_TREE,
|
|
117
118
|
NULLIFIER_TREE_HEIGHT,
|
|
118
119
|
index,
|
|
@@ -125,23 +126,22 @@ export class HintsBuilder {
|
|
|
125
126
|
throw new Error(`Cannot find the previous value index for public data ${leafSlot}.`);
|
|
126
127
|
}
|
|
127
128
|
|
|
128
|
-
const { membershipWitness, leafPreimage } = await this.getMembershipWitnessWithPreimage<
|
|
129
|
-
typeof PUBLIC_DATA_TREE_HEIGHT
|
|
130
|
-
>(MerkleTreeId.PUBLIC_DATA_TREE, PUBLIC_DATA_TREE_HEIGHT, res.index);
|
|
131
|
-
|
|
132
129
|
// Should find a way to stop casting IndexedTreeLeafPreimage as PublicDataTreeLeafPreimage everywhere.
|
|
133
|
-
return
|
|
130
|
+
return this.getMembershipWitnessWithPreimage<typeof PUBLIC_DATA_TREE_HEIGHT, PublicDataTreeLeafPreimage>(
|
|
131
|
+
MerkleTreeId.PUBLIC_DATA_TREE,
|
|
132
|
+
PUBLIC_DATA_TREE_HEIGHT,
|
|
133
|
+
res.index,
|
|
134
|
+
);
|
|
134
135
|
}
|
|
135
136
|
|
|
136
|
-
private async getMembershipWitnessWithPreimage<
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
) {
|
|
137
|
+
private async getMembershipWitnessWithPreimage<
|
|
138
|
+
TREE_HEIGHT extends number,
|
|
139
|
+
LEAF_PREIMAGE extends IndexedTreeLeafPreimage = IndexedTreeLeafPreimage,
|
|
140
|
+
>(treeId: IndexedTreeId, treeHeight: TREE_HEIGHT, index: bigint) {
|
|
141
141
|
const siblingPath = await this.db.getSiblingPath<TREE_HEIGHT>(treeId, index);
|
|
142
142
|
const membershipWitness = new MembershipWitness(treeHeight, index, siblingPath.toTuple());
|
|
143
143
|
|
|
144
|
-
const leafPreimage = await this.db.getLeafPreimage(treeId, index);
|
|
144
|
+
const leafPreimage = (await this.db.getLeafPreimage(treeId, index)) as LEAF_PREIMAGE;
|
|
145
145
|
if (!leafPreimage) {
|
|
146
146
|
throw new Error(`Cannot find the leaf preimage for tree ${treeId} at index ${index}.`);
|
|
147
147
|
}
|
package/src/public/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from './abstract_phase_manager.js';
|
|
2
1
|
export * from './db_interfaces.js';
|
|
3
|
-
export
|
|
2
|
+
export * from './enqueued_calls_processor.js';
|
|
3
|
+
export { type PublicExecutionResult } from './execution.js';
|
|
4
4
|
export { PublicExecutor } from './executor.js';
|
|
5
5
|
export * from './fee_payment.js';
|
|
6
6
|
export { HintsBuilder } from './hints_builder.js';
|
|
@@ -8,3 +8,4 @@ export * from './public_db_sources.js';
|
|
|
8
8
|
export * from './public_kernel.js';
|
|
9
9
|
export * from './public_kernel_circuit_simulator.js';
|
|
10
10
|
export { PublicProcessor, PublicProcessorFactory } from './public_processor.js';
|
|
11
|
+
export { PublicSideEffectTrace } from './side_effect_trace.js';
|