@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
|
@@ -1,64 +1,66 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AVM_REQUEST,
|
|
3
|
+
type AvmProvingRequest,
|
|
2
4
|
MerkleTreeId,
|
|
3
|
-
type
|
|
4
|
-
type
|
|
5
|
+
type NestedProcessReturnValues,
|
|
6
|
+
type PublicKernelNonTailRequest,
|
|
5
7
|
PublicKernelType,
|
|
8
|
+
type PublicProvingRequest,
|
|
6
9
|
type SimulationError,
|
|
7
10
|
type Tx,
|
|
8
11
|
type UnencryptedFunctionL2Logs,
|
|
9
12
|
} from '@aztec/circuit-types';
|
|
10
13
|
import {
|
|
14
|
+
type AvmExecutionHints,
|
|
11
15
|
AztecAddress,
|
|
12
16
|
CallRequest,
|
|
13
17
|
ContractStorageRead,
|
|
14
18
|
ContractStorageUpdateRequest,
|
|
15
19
|
Fr,
|
|
20
|
+
FunctionData,
|
|
16
21
|
Gas,
|
|
17
22
|
type GlobalVariables,
|
|
18
23
|
type Header,
|
|
19
24
|
type KernelCircuitPublicInputs,
|
|
20
25
|
L2ToL1Message,
|
|
26
|
+
LogHash,
|
|
27
|
+
MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL,
|
|
21
28
|
MAX_NEW_L2_TO_L1_MSGS_PER_CALL,
|
|
22
29
|
MAX_NEW_NOTE_HASHES_PER_CALL,
|
|
23
30
|
MAX_NEW_NULLIFIERS_PER_CALL,
|
|
31
|
+
MAX_NOTE_HASH_READ_REQUESTS_PER_CALL,
|
|
24
32
|
MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL,
|
|
25
33
|
MAX_NULLIFIER_READ_REQUESTS_PER_CALL,
|
|
26
34
|
MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL,
|
|
27
35
|
MAX_PUBLIC_DATA_READS_PER_CALL,
|
|
28
|
-
MAX_PUBLIC_DATA_READS_PER_TX,
|
|
29
36
|
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,
|
|
30
|
-
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
31
37
|
MAX_UNENCRYPTED_LOGS_PER_CALL,
|
|
32
38
|
MembershipWitness,
|
|
39
|
+
NESTED_RECURSIVE_PROOF_LENGTH,
|
|
33
40
|
NoteHash,
|
|
34
41
|
Nullifier,
|
|
35
|
-
type Proof,
|
|
36
42
|
PublicCallData,
|
|
37
43
|
type PublicCallRequest,
|
|
38
44
|
PublicCallStackItem,
|
|
39
45
|
PublicCircuitPublicInputs,
|
|
40
|
-
PublicDataRead,
|
|
41
|
-
PublicDataUpdateRequest,
|
|
42
46
|
PublicKernelCircuitPrivateInputs,
|
|
43
47
|
type PublicKernelCircuitPublicInputs,
|
|
44
48
|
PublicKernelData,
|
|
45
49
|
ReadRequest,
|
|
46
50
|
RevertCode,
|
|
47
|
-
SideEffect,
|
|
48
51
|
VK_TREE_HEIGHT,
|
|
49
|
-
|
|
52
|
+
VerificationKeyData,
|
|
50
53
|
makeEmptyProof,
|
|
54
|
+
makeEmptyRecursiveProof,
|
|
51
55
|
} from '@aztec/circuits.js';
|
|
52
56
|
import { computeVarArgsHash } from '@aztec/circuits.js/hash';
|
|
53
|
-
import {
|
|
57
|
+
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
54
58
|
import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
55
|
-
import { type Tuple } from '@aztec/foundation/serialize';
|
|
56
59
|
import {
|
|
57
60
|
type PublicExecution,
|
|
58
61
|
type PublicExecutionResult,
|
|
59
62
|
type PublicExecutor,
|
|
60
|
-
|
|
61
|
-
collectPublicDataUpdateRequests,
|
|
63
|
+
accumulateReturnValues,
|
|
62
64
|
isPublicExecutionResult,
|
|
63
65
|
} from '@aztec/simulator';
|
|
64
66
|
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
@@ -77,7 +79,7 @@ export enum PublicKernelPhase {
|
|
|
77
79
|
export const PhaseIsRevertible: Record<PublicKernelPhase, boolean> = {
|
|
78
80
|
[PublicKernelPhase.SETUP]: false,
|
|
79
81
|
[PublicKernelPhase.APP_LOGIC]: true,
|
|
80
|
-
[PublicKernelPhase.TEARDOWN]:
|
|
82
|
+
[PublicKernelPhase.TEARDOWN]: true,
|
|
81
83
|
[PublicKernelPhase.TAIL]: false,
|
|
82
84
|
};
|
|
83
85
|
|
|
@@ -95,6 +97,59 @@ export function publicKernelPhaseToKernelType(phase: PublicKernelPhase): PublicK
|
|
|
95
97
|
}
|
|
96
98
|
}
|
|
97
99
|
|
|
100
|
+
export type PublicProvingInformation = {
|
|
101
|
+
calldata: Fr[];
|
|
102
|
+
bytecode: Buffer;
|
|
103
|
+
inputs: PublicKernelCircuitPrivateInputs;
|
|
104
|
+
avmHints: AvmExecutionHints;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export function makeAvmProvingRequest(
|
|
108
|
+
info: PublicProvingInformation,
|
|
109
|
+
kernelType: PublicKernelNonTailRequest['type'],
|
|
110
|
+
): AvmProvingRequest {
|
|
111
|
+
return {
|
|
112
|
+
type: AVM_REQUEST,
|
|
113
|
+
bytecode: info.bytecode,
|
|
114
|
+
calldata: info.calldata,
|
|
115
|
+
avmHints: info.avmHints,
|
|
116
|
+
kernelRequest: {
|
|
117
|
+
type: kernelType,
|
|
118
|
+
inputs: info.inputs,
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export type TxPublicCallsResult = {
|
|
124
|
+
/** Inputs to be used for proving */
|
|
125
|
+
publicProvingInformation: PublicProvingInformation[];
|
|
126
|
+
/** The public kernel output at the end of the Tx */
|
|
127
|
+
kernelOutput: PublicKernelCircuitPublicInputs;
|
|
128
|
+
/** Unencrypted logs generated during the execution of this Tx */
|
|
129
|
+
newUnencryptedLogs: UnencryptedFunctionL2Logs[];
|
|
130
|
+
/** Revert reason, if any */
|
|
131
|
+
revertReason?: SimulationError;
|
|
132
|
+
/** Return values of simulating complete callstack */
|
|
133
|
+
returnValues: NestedProcessReturnValues[];
|
|
134
|
+
/** Gas used during the execution this Tx */
|
|
135
|
+
gasUsed?: Gas;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export type PhaseResult = {
|
|
139
|
+
/** The collection of public proving requests */
|
|
140
|
+
publicProvingRequests: PublicProvingRequest[];
|
|
141
|
+
/** The output of the public kernel circuit simulation for this phase */
|
|
142
|
+
publicKernelOutput: PublicKernelCircuitPublicInputs;
|
|
143
|
+
/** The final output of the public kernel circuit for this phase */
|
|
144
|
+
finalKernelOutput?: KernelCircuitPublicInputs;
|
|
145
|
+
/** Revert reason, if any */
|
|
146
|
+
revertReason?: SimulationError;
|
|
147
|
+
/** Return values of simulating complete callstack */
|
|
148
|
+
returnValues: NestedProcessReturnValues[];
|
|
149
|
+
/** Gas used during the execution this phase */
|
|
150
|
+
gasUsed?: Gas;
|
|
151
|
+
};
|
|
152
|
+
|
|
98
153
|
export abstract class AbstractPhaseManager {
|
|
99
154
|
protected hintsBuilder: HintsBuilder;
|
|
100
155
|
protected log: DebugLogger;
|
|
@@ -109,41 +164,12 @@ export abstract class AbstractPhaseManager {
|
|
|
109
164
|
this.hintsBuilder = new HintsBuilder(db);
|
|
110
165
|
this.log = createDebugLogger(`aztec:sequencer:${phase}`);
|
|
111
166
|
}
|
|
167
|
+
|
|
112
168
|
/**
|
|
113
|
-
*
|
|
114
169
|
* @param tx - the tx to be processed
|
|
115
170
|
* @param publicKernelPublicInputs - the output of the public kernel circuit for the previous phase
|
|
116
|
-
* @param previousPublicKernelProof - the proof of the public kernel circuit for the previous phase
|
|
117
171
|
*/
|
|
118
|
-
abstract handle(
|
|
119
|
-
tx: Tx,
|
|
120
|
-
publicKernelPublicInputs: PublicKernelCircuitPublicInputs,
|
|
121
|
-
previousPublicKernelProof: Proof,
|
|
122
|
-
): Promise<{
|
|
123
|
-
/**
|
|
124
|
-
* The collection of public kernel requests
|
|
125
|
-
*/
|
|
126
|
-
kernelRequests: PublicKernelRequest[];
|
|
127
|
-
/**
|
|
128
|
-
* the output of the public kernel circuit for this phase
|
|
129
|
-
*/
|
|
130
|
-
publicKernelOutput: PublicKernelCircuitPublicInputs;
|
|
131
|
-
/**
|
|
132
|
-
* the final output of the public kernel circuit for this phase
|
|
133
|
-
*/
|
|
134
|
-
finalKernelOutput?: KernelCircuitPublicInputs;
|
|
135
|
-
/**
|
|
136
|
-
* the proof of the public kernel circuit for this phase
|
|
137
|
-
*/
|
|
138
|
-
publicKernelProof: Proof;
|
|
139
|
-
/**
|
|
140
|
-
* revert reason, if any
|
|
141
|
-
*/
|
|
142
|
-
revertReason: SimulationError | undefined;
|
|
143
|
-
returnValues: ProcessReturnValues;
|
|
144
|
-
/** Gas used during the execution this particular phase. */
|
|
145
|
-
gasUsed: Gas | undefined;
|
|
146
|
-
}>;
|
|
172
|
+
abstract handle(tx: Tx, publicKernelPublicInputs: PublicKernelCircuitPublicInputs): Promise<PhaseResult>;
|
|
147
173
|
|
|
148
174
|
public static extractEnqueuedPublicCallsByPhase(tx: Tx): Record<PublicKernelPhase, PublicCallRequest[]> {
|
|
149
175
|
const data = tx.data.forPublic;
|
|
@@ -215,43 +241,33 @@ export abstract class AbstractPhaseManager {
|
|
|
215
241
|
return calls;
|
|
216
242
|
}
|
|
217
243
|
|
|
218
|
-
// REFACTOR: Do not return an array and instead return a struct with similar shape to that returned by `handle`
|
|
219
244
|
protected async processEnqueuedPublicCalls(
|
|
220
245
|
tx: Tx,
|
|
221
246
|
previousPublicKernelOutput: PublicKernelCircuitPublicInputs,
|
|
222
|
-
|
|
223
|
-
): Promise<
|
|
224
|
-
[
|
|
225
|
-
PublicKernelCircuitPrivateInputs[],
|
|
226
|
-
PublicKernelCircuitPublicInputs,
|
|
227
|
-
Proof,
|
|
228
|
-
UnencryptedFunctionL2Logs[],
|
|
229
|
-
SimulationError | undefined,
|
|
230
|
-
ProcessReturnValues,
|
|
231
|
-
Gas,
|
|
232
|
-
]
|
|
233
|
-
> {
|
|
234
|
-
let kernelOutput = previousPublicKernelOutput;
|
|
235
|
-
const kernelProof = previousPublicKernelProof;
|
|
236
|
-
const publicKernelInputs: PublicKernelCircuitPrivateInputs[] = [];
|
|
237
|
-
|
|
247
|
+
): Promise<TxPublicCallsResult> {
|
|
238
248
|
const enqueuedCalls = this.extractEnqueuedPublicCalls(tx);
|
|
239
249
|
|
|
240
250
|
if (!enqueuedCalls || !enqueuedCalls.length) {
|
|
241
|
-
return
|
|
251
|
+
return {
|
|
252
|
+
publicProvingInformation: [],
|
|
253
|
+
kernelOutput: previousPublicKernelOutput,
|
|
254
|
+
newUnencryptedLogs: [],
|
|
255
|
+
returnValues: [],
|
|
256
|
+
gasUsed: Gas.empty(),
|
|
257
|
+
};
|
|
242
258
|
}
|
|
243
259
|
|
|
244
|
-
const newUnencryptedFunctionLogs: UnencryptedFunctionL2Logs[] = [];
|
|
245
|
-
|
|
246
|
-
// Transaction fee is zero for all phases except teardown
|
|
247
|
-
const transactionFee = this.getTransactionFee(tx, previousPublicKernelOutput);
|
|
248
|
-
|
|
249
260
|
// TODO(#1684): Should multiple separately enqueued public calls be treated as
|
|
250
261
|
// separate public callstacks to be proven by separate public kernel sequences
|
|
251
262
|
// and submitted separately to the base rollup?
|
|
252
263
|
|
|
253
|
-
|
|
264
|
+
const provingInformationList: PublicProvingInformation[] = [];
|
|
265
|
+
const newUnencryptedFunctionLogs: UnencryptedFunctionL2Logs[] = [];
|
|
266
|
+
// Transaction fee is zero for all phases except teardown
|
|
267
|
+
const transactionFee = this.getTransactionFee(tx, previousPublicKernelOutput);
|
|
254
268
|
let gasUsed = Gas.empty();
|
|
269
|
+
let kernelPublicOutput: PublicKernelCircuitPublicInputs = previousPublicKernelOutput;
|
|
270
|
+
const enqueuedCallResults = [];
|
|
255
271
|
|
|
256
272
|
for (const enqueuedCall of enqueuedCalls) {
|
|
257
273
|
const executionStack: (PublicExecution | PublicExecutionResult)[] = [enqueuedCall];
|
|
@@ -262,10 +278,9 @@ export abstract class AbstractPhaseManager {
|
|
|
262
278
|
while (executionStack.length) {
|
|
263
279
|
const current = executionStack.pop()!;
|
|
264
280
|
const isExecutionRequest = !isPublicExecutionResult(current);
|
|
265
|
-
|
|
266
|
-
const
|
|
267
|
-
const
|
|
268
|
-
const pendingNullifiers = this.getSiloedPendingNullifiers(kernelOutput);
|
|
281
|
+
const sideEffectCounter = lastSideEffectCounter(kernelPublicOutput) + 1;
|
|
282
|
+
const availableGas = this.getAvailableGas(tx, kernelPublicOutput);
|
|
283
|
+
const pendingNullifiers = this.getSiloedPendingNullifiers(kernelPublicOutput);
|
|
269
284
|
|
|
270
285
|
const result = isExecutionRequest
|
|
271
286
|
? await this.publicExecutor.simulate(
|
|
@@ -279,18 +294,18 @@ export abstract class AbstractPhaseManager {
|
|
|
279
294
|
)
|
|
280
295
|
: current;
|
|
281
296
|
|
|
297
|
+
// Accumulate gas used in this execution
|
|
298
|
+
gasUsed = gasUsed.add(Gas.from(result.startGasLeft).sub(Gas.from(result.endGasLeft)));
|
|
299
|
+
|
|
282
300
|
// Sanity check for a current upstream assumption.
|
|
283
301
|
// Consumers of the result seem to expect "reverted <=> revertReason !== undefined".
|
|
284
|
-
const functionSelector = result.execution.
|
|
302
|
+
const functionSelector = result.execution.functionSelector.toString();
|
|
285
303
|
if (result.reverted && !result.revertReason) {
|
|
286
304
|
throw new Error(
|
|
287
305
|
`Simulation of ${result.execution.contractAddress.toString()}:${functionSelector} reverted with no reason.`,
|
|
288
306
|
);
|
|
289
307
|
}
|
|
290
308
|
|
|
291
|
-
// Accumulate gas used in this execution
|
|
292
|
-
gasUsed = gasUsed.add(Gas.from(result.startGasLeft).sub(Gas.from(result.endGasLeft)));
|
|
293
|
-
|
|
294
309
|
if (result.reverted && !PhaseIsRevertible[this.phase]) {
|
|
295
310
|
this.log.debug(
|
|
296
311
|
`Simulation error on ${result.execution.contractAddress.toString()}:${functionSelector} with reason: ${
|
|
@@ -303,23 +318,29 @@ export abstract class AbstractPhaseManager {
|
|
|
303
318
|
if (isExecutionRequest) {
|
|
304
319
|
newUnencryptedFunctionLogs.push(result.allUnencryptedLogs);
|
|
305
320
|
}
|
|
321
|
+
executionStack.push(...result.nestedExecutions);
|
|
306
322
|
|
|
323
|
+
// Simulate the public kernel circuit.
|
|
307
324
|
this.log.debug(
|
|
308
325
|
`Running public kernel circuit for ${result.execution.contractAddress.toString()}:${functionSelector}`,
|
|
309
326
|
);
|
|
310
|
-
executionStack.push(...result.nestedExecutions);
|
|
311
327
|
const callData = await this.getPublicCallData(result, isExecutionRequest);
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
328
|
+
const [privateInputs, publicInputs] = await this.runKernelCircuit(kernelPublicOutput, callData);
|
|
329
|
+
kernelPublicOutput = publicInputs;
|
|
330
|
+
|
|
331
|
+
// Capture the inputs for later proving in the AVM and kernel.
|
|
332
|
+
const publicProvingInformation: PublicProvingInformation = {
|
|
333
|
+
calldata: result.calldata,
|
|
334
|
+
bytecode: result.bytecode!,
|
|
335
|
+
inputs: privateInputs,
|
|
336
|
+
avmHints: result.avmHints,
|
|
337
|
+
};
|
|
338
|
+
provingInformationList.push(publicProvingInformation);
|
|
339
|
+
|
|
340
|
+
// Sanity check: Note we can't expect them to just be equal, because e.g.
|
|
320
341
|
// if the simulator reverts in app logic, it "resets" and result.reverted will be false when we run teardown,
|
|
321
342
|
// but the kernel carries the reverted flag forward. But if the simulator reverts, so should the kernel.
|
|
322
|
-
if (result.reverted &&
|
|
343
|
+
if (result.reverted && kernelPublicOutput.revertCode.isOK()) {
|
|
323
344
|
throw new Error(
|
|
324
345
|
`Public kernel circuit did not revert on ${result.execution.contractAddress.toString()}:${functionSelector}, but simulator did.`,
|
|
325
346
|
);
|
|
@@ -334,26 +355,34 @@ export abstract class AbstractPhaseManager {
|
|
|
334
355
|
}`,
|
|
335
356
|
);
|
|
336
357
|
// TODO(@spalladino): Check gasUsed is correct. The AVM should take care of setting gasLeft to zero upon a revert.
|
|
337
|
-
return
|
|
358
|
+
return {
|
|
359
|
+
publicProvingInformation: [],
|
|
360
|
+
kernelOutput: kernelPublicOutput,
|
|
361
|
+
newUnencryptedLogs: [],
|
|
362
|
+
revertReason: result.revertReason,
|
|
363
|
+
returnValues: [],
|
|
364
|
+
gasUsed,
|
|
365
|
+
};
|
|
338
366
|
}
|
|
339
367
|
|
|
340
368
|
if (!enqueuedExecutionResult) {
|
|
341
369
|
enqueuedExecutionResult = result;
|
|
342
|
-
returns = result.returnValues;
|
|
343
370
|
}
|
|
371
|
+
|
|
372
|
+
enqueuedCallResults.push(accumulateReturnValues(enqueuedExecutionResult));
|
|
344
373
|
}
|
|
345
|
-
// HACK(#1622): Manually patches the ordering of public state actions
|
|
346
|
-
// TODO(#757): Enforce proper ordering of public state actions
|
|
347
|
-
patchPublicStorageActionOrdering(kernelOutput, enqueuedExecutionResult!, this.phase);
|
|
348
374
|
}
|
|
349
375
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
376
|
+
return {
|
|
377
|
+
publicProvingInformation: provingInformationList,
|
|
378
|
+
kernelOutput: kernelPublicOutput,
|
|
379
|
+
newUnencryptedLogs: newUnencryptedFunctionLogs,
|
|
380
|
+
returnValues: enqueuedCallResults,
|
|
381
|
+
gasUsed,
|
|
382
|
+
};
|
|
354
383
|
}
|
|
355
384
|
|
|
356
|
-
/** Returns all pending private and public nullifiers.
|
|
385
|
+
/** Returns all pending private and public nullifiers. */
|
|
357
386
|
private getSiloedPendingNullifiers(ko: PublicKernelCircuitPublicInputs) {
|
|
358
387
|
return [...ko.end.newNullifiers, ...ko.endNonRevertibleData.newNullifiers].filter(n => !n.isEmpty());
|
|
359
388
|
}
|
|
@@ -369,20 +398,11 @@ export abstract class AbstractPhaseManager {
|
|
|
369
398
|
return Fr.ZERO;
|
|
370
399
|
}
|
|
371
400
|
|
|
372
|
-
|
|
373
|
-
previousOutput: PublicKernelCircuitPublicInputs,
|
|
374
|
-
previousProof: Proof,
|
|
375
|
-
callData: PublicCallData,
|
|
376
|
-
): Promise<[PublicKernelCircuitPrivateInputs, PublicKernelCircuitPublicInputs]> {
|
|
377
|
-
return await this.getKernelCircuitOutput(previousOutput, previousProof, callData);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
protected async getKernelCircuitOutput(
|
|
401
|
+
private async runKernelCircuit(
|
|
381
402
|
previousOutput: PublicKernelCircuitPublicInputs,
|
|
382
|
-
previousProof: Proof,
|
|
383
403
|
callData: PublicCallData,
|
|
384
404
|
): Promise<[PublicKernelCircuitPrivateInputs, PublicKernelCircuitPublicInputs]> {
|
|
385
|
-
const previousKernel = this.getPreviousKernelData(previousOutput
|
|
405
|
+
const previousKernel = this.getPreviousKernelData(previousOutput);
|
|
386
406
|
|
|
387
407
|
// We take a deep copy (clone) of these inputs to be passed to the prover
|
|
388
408
|
const inputs = new PublicKernelCircuitPrivateInputs(previousKernel, callData);
|
|
@@ -398,15 +418,13 @@ export abstract class AbstractPhaseManager {
|
|
|
398
418
|
}
|
|
399
419
|
}
|
|
400
420
|
|
|
401
|
-
protected getPreviousKernelData(
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
// TODO(@PhilWindle) Fix once we move this to prover-client
|
|
406
|
-
const vk = VerificationKey.makeFake();
|
|
421
|
+
protected getPreviousKernelData(previousOutput: PublicKernelCircuitPublicInputs): PublicKernelData {
|
|
422
|
+
// The proof and verification key are not used in simulation
|
|
423
|
+
const vk = VerificationKeyData.makeFake();
|
|
424
|
+
const proof = makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH);
|
|
407
425
|
const vkIndex = 0;
|
|
408
426
|
const vkSiblingPath = MembershipWitness.random(VK_TREE_HEIGHT).siblingPath;
|
|
409
|
-
return new PublicKernelData(previousOutput,
|
|
427
|
+
return new PublicKernelData(previousOutput, proof, vk, vkIndex, vkSiblingPath);
|
|
410
428
|
}
|
|
411
429
|
|
|
412
430
|
protected async getPublicCallStackItem(result: PublicExecutionResult, isExecutionRequest = false) {
|
|
@@ -430,6 +448,11 @@ export abstract class AbstractPhaseManager {
|
|
|
430
448
|
startSideEffectCounter: result.startSideEffectCounter,
|
|
431
449
|
endSideEffectCounter: result.endSideEffectCounter,
|
|
432
450
|
returnsHash: computeVarArgsHash(result.returnValues),
|
|
451
|
+
noteHashReadRequests: padArrayEnd(
|
|
452
|
+
result.noteHashReadRequests,
|
|
453
|
+
ReadRequest.empty(),
|
|
454
|
+
MAX_NOTE_HASH_READ_REQUESTS_PER_CALL,
|
|
455
|
+
),
|
|
433
456
|
nullifierReadRequests: padArrayEnd(
|
|
434
457
|
result.nullifierReadRequests,
|
|
435
458
|
ReadRequest.empty(),
|
|
@@ -440,6 +463,11 @@ export abstract class AbstractPhaseManager {
|
|
|
440
463
|
ReadRequest.empty(),
|
|
441
464
|
MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL,
|
|
442
465
|
),
|
|
466
|
+
l1ToL2MsgReadRequests: padArrayEnd(
|
|
467
|
+
result.l1ToL2MsgReadRequests,
|
|
468
|
+
ReadRequest.empty(),
|
|
469
|
+
MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL,
|
|
470
|
+
),
|
|
443
471
|
contractStorageReads: padArrayEnd(
|
|
444
472
|
result.contractStorageReads,
|
|
445
473
|
ContractStorageRead.empty(),
|
|
@@ -451,24 +479,19 @@ export abstract class AbstractPhaseManager {
|
|
|
451
479
|
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,
|
|
452
480
|
),
|
|
453
481
|
publicCallStackHashes,
|
|
454
|
-
unencryptedLogsHashes: padArrayEnd(
|
|
455
|
-
result.unencryptedLogsHashes,
|
|
456
|
-
SideEffect.empty(),
|
|
457
|
-
MAX_UNENCRYPTED_LOGS_PER_CALL,
|
|
458
|
-
),
|
|
459
|
-
unencryptedLogPreimagesLength: result.unencryptedLogPreimagesLength,
|
|
482
|
+
unencryptedLogsHashes: padArrayEnd(result.unencryptedLogsHashes, LogHash.empty(), MAX_UNENCRYPTED_LOGS_PER_CALL),
|
|
460
483
|
historicalHeader: this.historicalHeader,
|
|
461
484
|
globalVariables: this.globalVariables,
|
|
462
485
|
startGasLeft: Gas.from(result.startGasLeft),
|
|
463
486
|
endGasLeft: Gas.from(result.endGasLeft),
|
|
464
487
|
transactionFee: result.transactionFee,
|
|
465
488
|
// TODO(@just-mitch): need better mapping from simulator to revert code.
|
|
466
|
-
revertCode: result.reverted ? RevertCode.
|
|
489
|
+
revertCode: result.reverted ? RevertCode.APP_LOGIC_REVERTED : RevertCode.OK,
|
|
467
490
|
});
|
|
468
491
|
|
|
469
492
|
return new PublicCallStackItem(
|
|
470
493
|
result.execution.contractAddress,
|
|
471
|
-
result.execution.
|
|
494
|
+
new FunctionData(result.execution.functionSelector, false),
|
|
472
495
|
publicCircuitPublicInputs,
|
|
473
496
|
isExecutionRequest,
|
|
474
497
|
);
|
|
@@ -510,87 +533,3 @@ export abstract class AbstractPhaseManager {
|
|
|
510
533
|
return new PublicCallData(callStackItem, publicCallStack, makeEmptyProof(), bytecodeHash);
|
|
511
534
|
}
|
|
512
535
|
}
|
|
513
|
-
|
|
514
|
-
function removeRedundantPublicDataWrites(publicInputs: PublicKernelCircuitPublicInputs, phase: PublicKernelPhase) {
|
|
515
|
-
const lastWritesMap = new Map<string, boolean>();
|
|
516
|
-
const patch = <N extends number>(requests: Tuple<PublicDataUpdateRequest, N>) =>
|
|
517
|
-
requests.filter(write => {
|
|
518
|
-
const leafSlot = write.leafSlot.toString();
|
|
519
|
-
const exists = lastWritesMap.get(leafSlot);
|
|
520
|
-
lastWritesMap.set(leafSlot, true);
|
|
521
|
-
return !exists;
|
|
522
|
-
});
|
|
523
|
-
|
|
524
|
-
const [prev, curr] = PhaseIsRevertible[phase]
|
|
525
|
-
? [publicInputs.endNonRevertibleData, publicInputs.end]
|
|
526
|
-
: [publicInputs.end, publicInputs.endNonRevertibleData];
|
|
527
|
-
|
|
528
|
-
curr.publicDataUpdateRequests = padArrayEnd(
|
|
529
|
-
patch(curr.publicDataUpdateRequests.reverse()).reverse(),
|
|
530
|
-
PublicDataUpdateRequest.empty(),
|
|
531
|
-
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
532
|
-
);
|
|
533
|
-
|
|
534
|
-
prev.publicDataUpdateRequests = padArrayEnd(
|
|
535
|
-
patch(prev.publicDataUpdateRequests.reverse()),
|
|
536
|
-
PublicDataUpdateRequest.empty(),
|
|
537
|
-
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
538
|
-
);
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
// HACK(#1622): this is a hack to fix ordering of public state in the call stack. Since the private kernel
|
|
542
|
-
// cannot keep track of side effects that happen after or before a nested call, we override the public
|
|
543
|
-
// state actions it emits with whatever we got from the simulator. As a sanity check, we at least verify
|
|
544
|
-
// that the elements are the same, so we are only tweaking their ordering.
|
|
545
|
-
// See yarn-project/end-to-end/src/e2e_ordering.test.ts
|
|
546
|
-
// See https://github.com/AztecProtocol/aztec-packages/issues/1616
|
|
547
|
-
// TODO(#757): Enforce proper ordering of public state actions
|
|
548
|
-
/**
|
|
549
|
-
* Patch the ordering of storage actions output from the public kernel.
|
|
550
|
-
* @param publicInputs - to be patched here: public inputs to the kernel iteration up to this point
|
|
551
|
-
* @param execResult - result of the top/first execution for this enqueued public call
|
|
552
|
-
*/
|
|
553
|
-
function patchPublicStorageActionOrdering(
|
|
554
|
-
publicInputs: PublicKernelCircuitPublicInputs,
|
|
555
|
-
execResult: PublicExecutionResult,
|
|
556
|
-
phase: PublicKernelPhase,
|
|
557
|
-
) {
|
|
558
|
-
const { publicDataUpdateRequests } = PhaseIsRevertible[phase] ? publicInputs.end : publicInputs.endNonRevertibleData;
|
|
559
|
-
const { publicDataReads } = publicInputs.validationRequests;
|
|
560
|
-
|
|
561
|
-
// Convert ContractStorage* objects to PublicData* objects and sort them in execution order.
|
|
562
|
-
// Note, this only pulls simulated reads/writes from the current phase,
|
|
563
|
-
// so the returned result will be a subset of the public kernel output.
|
|
564
|
-
|
|
565
|
-
const simPublicDataReads = collectPublicDataReads(execResult);
|
|
566
|
-
|
|
567
|
-
const simPublicDataUpdateRequests = collectPublicDataUpdateRequests(execResult);
|
|
568
|
-
|
|
569
|
-
// We only want to reorder the items from the public inputs of the
|
|
570
|
-
// most recently processed top/enqueued call.
|
|
571
|
-
|
|
572
|
-
const effectSet = PhaseIsRevertible[phase] ? 'end' : 'endNonRevertibleData';
|
|
573
|
-
|
|
574
|
-
const numReadsInKernel = arrayNonEmptyLength(publicDataReads, f => f.isEmpty());
|
|
575
|
-
const numReadsBeforeThisEnqueuedCall = numReadsInKernel - simPublicDataReads.length;
|
|
576
|
-
publicInputs.validationRequests.publicDataReads = padArrayEnd(
|
|
577
|
-
[
|
|
578
|
-
// do not mess with items from previous top/enqueued calls in kernel output
|
|
579
|
-
...publicInputs.validationRequests.publicDataReads.slice(0, numReadsBeforeThisEnqueuedCall),
|
|
580
|
-
...simPublicDataReads,
|
|
581
|
-
],
|
|
582
|
-
PublicDataRead.empty(),
|
|
583
|
-
MAX_PUBLIC_DATA_READS_PER_TX,
|
|
584
|
-
);
|
|
585
|
-
|
|
586
|
-
const numUpdatesInKernel = arrayNonEmptyLength(publicDataUpdateRequests, f => f.isEmpty());
|
|
587
|
-
const numUpdatesBeforeThisEnqueuedCall = numUpdatesInKernel - simPublicDataUpdateRequests.length;
|
|
588
|
-
publicInputs[effectSet].publicDataUpdateRequests = padArrayEnd(
|
|
589
|
-
[
|
|
590
|
-
...publicInputs[effectSet].publicDataUpdateRequests.slice(0, numUpdatesBeforeThisEnqueuedCall),
|
|
591
|
-
...simPublicDataUpdateRequests,
|
|
592
|
-
],
|
|
593
|
-
PublicDataUpdateRequest.empty(),
|
|
594
|
-
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
595
|
-
);
|
|
596
|
-
}
|
|
@@ -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,49 +24,38 @@ export class AppLogicPhaseManager extends AbstractPhaseManager {
|
|
|
29
24
|
super(db, publicExecutor, publicKernel, globalVariables, historicalHeader, phase);
|
|
30
25
|
}
|
|
31
26
|
|
|
32
|
-
override async handle(
|
|
33
|
-
tx
|
|
34
|
-
previousPublicKernelOutput: PublicKernelCircuitPublicInputs,
|
|
35
|
-
previousPublicKernelProof: Proof,
|
|
36
|
-
) {
|
|
27
|
+
override async handle(tx: Tx, previousPublicKernelOutput: PublicKernelCircuitPublicInputs) {
|
|
28
|
+
this.log.verbose(`Processing tx ${tx.getTxHash()}`);
|
|
37
29
|
// add new contracts to the contracts db so that their functions may be found and called
|
|
38
30
|
// TODO(#4073): This is catching only private deployments, when we add public ones, we'll
|
|
39
31
|
// have to capture contracts emitted in that phase as well.
|
|
40
32
|
// TODO(@spalladino): Should we allow emitting contracts in the fee preparation phase?
|
|
41
|
-
|
|
33
|
+
// TODO(#6464): Should we allow emitting contracts in the private setup phase?
|
|
34
|
+
// if so, this should only add contracts that were deployed during private app logic.
|
|
42
35
|
await this.publicContractsDB.addNewContracts(tx);
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
] = await this.processEnqueuedPublicCalls(tx, previousPublicKernelOutput, previousPublicKernelProof).catch(
|
|
52
|
-
// if we throw for any reason other than simulation, we need to rollback and drop the TX
|
|
53
|
-
async err => {
|
|
54
|
-
await this.publicStateDB.rollbackToCommit();
|
|
55
|
-
throw err;
|
|
56
|
-
},
|
|
57
|
-
);
|
|
36
|
+
const { publicProvingInformation, kernelOutput, newUnencryptedLogs, revertReason, returnValues, gasUsed } =
|
|
37
|
+
await this.processEnqueuedPublicCalls(tx, previousPublicKernelOutput).catch(
|
|
38
|
+
// if we throw for any reason other than simulation, we need to rollback and drop the TX
|
|
39
|
+
async err => {
|
|
40
|
+
await this.publicStateDB.rollbackToCommit();
|
|
41
|
+
throw err;
|
|
42
|
+
},
|
|
43
|
+
);
|
|
58
44
|
|
|
59
45
|
if (revertReason) {
|
|
46
|
+
// TODO(#6464): Should we allow emitting contracts in the private setup phase?
|
|
47
|
+
// if so, this is removing contracts deployed in private setup
|
|
60
48
|
await this.publicContractsDB.removeNewContracts(tx);
|
|
61
49
|
await this.publicStateDB.rollbackToCheckpoint();
|
|
62
50
|
} else {
|
|
63
|
-
tx.unencryptedLogs.addFunctionLogs(
|
|
64
|
-
|
|
51
|
+
tx.unencryptedLogs.addFunctionLogs(newUnencryptedLogs);
|
|
52
|
+
// TODO(#6470): we should be adding contracts deployed in those logs to the publicContractsDB
|
|
65
53
|
}
|
|
66
54
|
|
|
67
55
|
// Return a list of app logic proving requests
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
type: PublicKernelType.APP_LOGIC,
|
|
71
|
-
inputs: input,
|
|
72
|
-
};
|
|
73
|
-
return request;
|
|
56
|
+
const publicProvingRequests: PublicProvingRequest[] = publicProvingInformation.map(info => {
|
|
57
|
+
return makeAvmProvingRequest(info, PublicKernelType.APP_LOGIC);
|
|
74
58
|
});
|
|
75
|
-
return {
|
|
59
|
+
return { publicProvingRequests, publicKernelOutput: kernelOutput, revertReason, returnValues, gasUsed };
|
|
76
60
|
}
|
|
77
61
|
}
|
|
@@ -23,9 +23,9 @@ export interface PublicStateDB {
|
|
|
23
23
|
* @param contract - Owner of the storage.
|
|
24
24
|
* @param slot - Slot to read in the contract storage.
|
|
25
25
|
* @param newValue - The new value to store.
|
|
26
|
-
* @returns
|
|
26
|
+
* @returns The slot of the written leaf in the public data tree.
|
|
27
27
|
*/
|
|
28
|
-
storageWrite(contract: AztecAddress, slot: Fr, newValue: Fr): Promise<
|
|
28
|
+
storageWrite(contract: AztecAddress, slot: Fr, newValue: Fr): Promise<bigint>;
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Mark the uncommitted changes in this TX as a checkpoint.
|