@aztec/simulator 0.41.0 → 0.43.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 +7 -4
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +32 -12
- package/dest/acvm/oracle/typed_oracle.d.ts +6 -3
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +15 -6
- package/dest/acvm/serialize.js +2 -2
- 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 +69 -73
- package/dest/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/avm/avm_memory_types.js +2 -4
- 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 +8 -1
- package/dest/avm/fixtures/index.d.ts +6 -0
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +18 -1
- 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 +5 -3
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +23 -14
- package/dest/avm/journal/trace.d.ts +3 -1
- package/dest/avm/journal/trace.d.ts.map +1 -1
- package/dest/avm/journal/trace.js +8 -1
- package/dest/avm/journal/trace_types.d.ts +5 -0
- package/dest/avm/journal/trace_types.d.ts.map +1 -1
- package/dest/avm/journal/trace_types.js +1 -5
- package/dest/avm/opcodes/accrued_substate.d.ts +2 -2
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +36 -21
- 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 +12 -20
- package/dest/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/avm/opcodes/bitwise.js +11 -8
- package/dest/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/avm/opcodes/comparators.js +7 -5
- package/dest/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/avm/opcodes/contract.js +20 -24
- package/dest/avm/opcodes/control_flow.d.ts.map +1 -1
- package/dest/avm/opcodes/control_flow.js +4 -2
- package/dest/avm/opcodes/conversion.js +2 -2
- package/dest/avm/opcodes/ec_add.d.ts +19 -0
- package/dest/avm/opcodes/ec_add.d.ts.map +1 -0
- package/dest/avm/opcodes/ec_add.js +78 -0
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +11 -5
- package/dest/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/avm/opcodes/hashing.js +10 -2
- 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/instruction_impl.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction_impl.js +4 -2
- package/dest/avm/opcodes/memory.d.ts +1 -5
- package/dest/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/avm/opcodes/memory.js +14 -18
- package/dest/avm/opcodes/multi_scalar_mul.d.ts +16 -0
- package/dest/avm/opcodes/multi_scalar_mul.d.ts.map +1 -0
- package/dest/avm/opcodes/multi_scalar_mul.js +95 -0
- package/dest/avm/opcodes/storage.d.ts +1 -6
- package/dest/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/avm/opcodes/storage.js +11 -14
- package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/bytecode_serialization.js +6 -2
- package/dest/avm/serialization/instruction_serialization.d.ts +3 -1
- package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/instruction_serialization.js +4 -2
- package/dest/client/client_execution_context.d.ts +24 -20
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +52 -55
- package/dest/client/db_oracle.d.ts +7 -1
- package/dest/client/db_oracle.d.ts.map +1 -1
- package/dest/client/execution_note_cache.d.ts +0 -17
- package/dest/client/execution_note_cache.d.ts.map +1 -1
- package/dest/client/execution_note_cache.js +1 -24
- package/dest/client/execution_result.d.ts +8 -4
- package/dest/client/execution_result.d.ts.map +1 -1
- package/dest/client/execution_result.js +16 -6
- 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 +20 -9
- package/dest/client/simulator.d.ts +2 -17
- package/dest/client/simulator.d.ts.map +1 -1
- package/dest/client/simulator.js +24 -33
- 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 +2 -0
- package/dest/client/view_data_oracle.d.ts.map +1 -1
- package/dest/client/view_data_oracle.js +7 -1
- 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 +14 -10
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +22 -16
- 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 +53 -53
- package/dest/public/abstract_phase_manager.d.ts.map +1 -1
- package/dest/public/abstract_phase_manager.js +146 -153
- package/dest/public/app_logic_phase_manager.d.ts +8 -9
- package/dest/public/app_logic_phase_manager.d.ts.map +1 -1
- package/dest/public/app_logic_phase_manager.js +15 -15
- package/dest/public/{db.d.ts → db_interfaces.d.ts} +4 -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 +16 -23
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +1 -51
- package/dest/public/executor.d.ts +4 -31
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +40 -283
- 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 +2 -1
- package/dest/public/hints_builder.d.ts.map +1 -1
- package/dest/public/hints_builder.js +6 -2
- package/dest/public/index.d.ts +8 -6
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +9 -7
- package/dest/public/phase_manager_factory.d.ts +4 -4
- package/dest/public/phase_manager_factory.d.ts.map +1 -1
- package/dest/public/phase_manager_factory.js +5 -5
- package/dest/public/{public_executor.d.ts → public_db_sources.d.ts} +6 -3
- package/dest/public/public_db_sources.d.ts.map +1 -0
- package/dest/public/public_db_sources.js +244 -0
- package/dest/public/public_kernel.js +14 -14
- package/dest/public/public_processor.d.ts +6 -4
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +48 -30
- package/dest/public/setup_phase_manager.d.ts +8 -10
- package/dest/public/setup_phase_manager.d.ts.map +1 -1
- package/dest/public/setup_phase_manager.js +12 -21
- package/dest/public/tail_phase_manager.d.ts +7 -13
- package/dest/public/tail_phase_manager.d.ts.map +1 -1
- package/dest/public/tail_phase_manager.js +17 -37
- package/dest/public/teardown_phase_manager.d.ts +8 -10
- package/dest/public/teardown_phase_manager.d.ts.map +1 -1
- package/dest/public/teardown_phase_manager.js +16 -22
- package/dest/public/transitional_adaptors.d.ts +2 -2
- package/dest/public/transitional_adaptors.d.ts.map +1 -1
- package/dest/public/transitional_adaptors.js +14 -6
- package/package.json +12 -9
- package/src/acvm/acvm.ts +0 -3
- package/src/acvm/oracle/oracle.ts +68 -16
- package/src/acvm/oracle/typed_oracle.ts +31 -6
- package/src/acvm/serialize.ts +1 -1
- package/src/avm/avm_gas.ts +68 -73
- package/src/avm/avm_memory_types.ts +1 -3
- package/src/avm/avm_simulator.ts +9 -0
- package/src/avm/fixtures/index.ts +24 -0
- package/src/avm/index.ts +1 -0
- package/src/avm/journal/host_storage.ts +1 -1
- package/src/avm/journal/journal.ts +32 -22
- package/src/avm/journal/trace.ts +9 -0
- package/src/avm/journal/trace_types.ts +4 -0
- package/src/avm/opcodes/accrued_substate.ts +53 -20
- package/src/avm/opcodes/arithmetic.ts +18 -22
- package/src/avm/opcodes/bitwise.ts +13 -8
- package/src/avm/opcodes/comparators.ts +9 -4
- package/src/avm/opcodes/contract.ts +22 -26
- package/src/avm/opcodes/control_flow.ts +3 -1
- package/src/avm/opcodes/conversion.ts +1 -1
- package/src/avm/opcodes/ec_add.ts +92 -0
- package/src/avm/opcodes/external_calls.ts +11 -3
- package/src/avm/opcodes/hashing.ts +11 -1
- package/src/avm/opcodes/instruction.ts +5 -3
- package/src/avm/opcodes/instruction_impl.ts +4 -1
- package/src/avm/opcodes/memory.ts +19 -19
- package/src/avm/opcodes/multi_scalar_mul.ts +114 -0
- package/src/avm/opcodes/storage.ts +10 -17
- package/src/avm/serialization/bytecode_serialization.ts +5 -1
- package/src/avm/serialization/instruction_serialization.ts +2 -0
- package/src/client/client_execution_context.ts +76 -60
- package/src/client/db_oracle.ts +8 -1
- package/src/client/execution_note_cache.ts +0 -28
- package/src/client/execution_result.ts +21 -7
- package/src/client/private_execution.ts +36 -21
- package/src/client/simulator.ts +25 -35
- package/src/client/unconstrained_execution.ts +9 -12
- package/src/client/view_data_oracle.ts +8 -0
- package/src/index.ts +3 -1
- package/src/mocks/fixtures.ts +30 -32
- 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 +209 -258
- package/src/public/app_logic_phase_manager.ts +24 -40
- package/src/public/{db.ts → db_interfaces.ts} +4 -2
- package/src/public/execution.ts +15 -77
- package/src/public/executor.ts +61 -399
- package/src/public/fee_payment.ts +26 -0
- package/src/public/hints_builder.ts +6 -0
- package/src/public/index.ts +8 -12
- package/src/public/phase_manager_factory.ts +7 -7
- package/src/public/{public_executor.ts → public_db_sources.ts} +65 -9
- package/src/public/public_kernel.ts +24 -24
- package/src/public/public_processor.ts +81 -40
- package/src/public/setup_phase_manager.ts +21 -46
- package/src/public/tail_phase_manager.ts +19 -67
- package/src/public/teardown_phase_manager.ts +23 -42
- package/src/public/transitional_adaptors.ts +41 -5
- 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/public/utils.d.ts +0 -8
- package/dest/public/utils.d.ts.map +0 -1
- package/dest/public/utils.js +0 -31
- 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/public/public_execution_context.ts +0 -289
- package/src/public/state_actions.ts +0 -102
- package/src/public/utils.ts +0 -33
- /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,101 +1,134 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AVM_REQUEST,
|
|
3
|
+
type AvmProvingRequest,
|
|
2
4
|
MerkleTreeId,
|
|
3
5
|
type NestedProcessReturnValues,
|
|
4
|
-
type
|
|
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,
|
|
21
26
|
LogHash,
|
|
27
|
+
MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL,
|
|
22
28
|
MAX_NEW_L2_TO_L1_MSGS_PER_CALL,
|
|
23
29
|
MAX_NEW_NOTE_HASHES_PER_CALL,
|
|
24
30
|
MAX_NEW_NULLIFIERS_PER_CALL,
|
|
31
|
+
MAX_NOTE_HASH_READ_REQUESTS_PER_CALL,
|
|
25
32
|
MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL,
|
|
26
33
|
MAX_NULLIFIER_READ_REQUESTS_PER_CALL,
|
|
27
34
|
MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL,
|
|
28
35
|
MAX_PUBLIC_DATA_READS_PER_CALL,
|
|
29
|
-
MAX_PUBLIC_DATA_READS_PER_TX,
|
|
30
36
|
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,
|
|
31
|
-
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
32
37
|
MAX_UNENCRYPTED_LOGS_PER_CALL,
|
|
33
38
|
MembershipWitness,
|
|
39
|
+
NESTED_RECURSIVE_PROOF_LENGTH,
|
|
34
40
|
NoteHash,
|
|
35
41
|
Nullifier,
|
|
36
|
-
type Proof,
|
|
37
42
|
PublicCallData,
|
|
38
43
|
type PublicCallRequest,
|
|
39
44
|
PublicCallStackItem,
|
|
40
45
|
PublicCircuitPublicInputs,
|
|
41
|
-
PublicDataRead,
|
|
42
|
-
PublicDataUpdateRequest,
|
|
43
46
|
PublicKernelCircuitPrivateInputs,
|
|
44
47
|
type PublicKernelCircuitPublicInputs,
|
|
45
48
|
PublicKernelData,
|
|
46
49
|
ReadRequest,
|
|
47
50
|
RevertCode,
|
|
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
63
|
accumulateReturnValues,
|
|
61
|
-
collectPublicDataReads,
|
|
62
|
-
collectPublicDataUpdateRequests,
|
|
63
64
|
isPublicExecutionResult,
|
|
64
65
|
} from '@aztec/simulator';
|
|
65
66
|
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
66
67
|
|
|
67
68
|
import { HintsBuilder } from './hints_builder.js';
|
|
68
69
|
import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
|
|
69
|
-
import { lastSideEffectCounter } from './utils.js';
|
|
70
70
|
|
|
71
|
-
export
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
export const PhaseIsRevertible: Record<PublicKernelType, boolean> = {
|
|
72
|
+
[PublicKernelType.NON_PUBLIC]: false,
|
|
73
|
+
[PublicKernelType.SETUP]: false,
|
|
74
|
+
[PublicKernelType.APP_LOGIC]: true,
|
|
75
|
+
[PublicKernelType.TEARDOWN]: true,
|
|
76
|
+
[PublicKernelType.TAIL]: false,
|
|
77
|
+
};
|
|
77
78
|
|
|
78
|
-
export
|
|
79
|
-
[
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
export type PublicProvingInformation = {
|
|
80
|
+
calldata: Fr[];
|
|
81
|
+
bytecode: Buffer;
|
|
82
|
+
inputs: PublicKernelCircuitPrivateInputs;
|
|
83
|
+
avmHints: AvmExecutionHints;
|
|
83
84
|
};
|
|
84
85
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
86
|
+
export function makeAvmProvingRequest(
|
|
87
|
+
info: PublicProvingInformation,
|
|
88
|
+
kernelType: PublicKernelNonTailRequest['type'],
|
|
89
|
+
): AvmProvingRequest {
|
|
90
|
+
return {
|
|
91
|
+
type: AVM_REQUEST,
|
|
92
|
+
bytecode: info.bytecode,
|
|
93
|
+
calldata: info.calldata,
|
|
94
|
+
avmHints: info.avmHints,
|
|
95
|
+
kernelRequest: {
|
|
96
|
+
type: kernelType,
|
|
97
|
+
inputs: info.inputs,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
97
100
|
}
|
|
98
101
|
|
|
102
|
+
export type TxPublicCallsResult = {
|
|
103
|
+
/** Inputs to be used for proving */
|
|
104
|
+
publicProvingInformation: PublicProvingInformation[];
|
|
105
|
+
/** The public kernel output at the end of the Tx */
|
|
106
|
+
kernelOutput: PublicKernelCircuitPublicInputs;
|
|
107
|
+
/** Unencrypted logs generated during the execution of this Tx */
|
|
108
|
+
newUnencryptedLogs: UnencryptedFunctionL2Logs[];
|
|
109
|
+
/** Revert reason, if any */
|
|
110
|
+
revertReason?: SimulationError;
|
|
111
|
+
/** Return values of simulating complete callstack */
|
|
112
|
+
returnValues: NestedProcessReturnValues[];
|
|
113
|
+
/** Gas used during the execution this Tx */
|
|
114
|
+
gasUsed?: Gas;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export type PhaseResult = {
|
|
118
|
+
/** The collection of public proving requests */
|
|
119
|
+
publicProvingRequests: PublicProvingRequest[];
|
|
120
|
+
/** The output of the public kernel circuit simulation for this phase */
|
|
121
|
+
publicKernelOutput: PublicKernelCircuitPublicInputs;
|
|
122
|
+
/** The final output of the public kernel circuit for this phase */
|
|
123
|
+
finalKernelOutput?: KernelCircuitPublicInputs;
|
|
124
|
+
/** Revert reason, if any */
|
|
125
|
+
revertReason?: SimulationError;
|
|
126
|
+
/** Return values of simulating complete callstack */
|
|
127
|
+
returnValues: NestedProcessReturnValues[];
|
|
128
|
+
/** Gas used during the execution this phase */
|
|
129
|
+
gasUsed?: Gas;
|
|
130
|
+
};
|
|
131
|
+
|
|
99
132
|
export abstract class AbstractPhaseManager {
|
|
100
133
|
protected hintsBuilder: HintsBuilder;
|
|
101
134
|
protected log: DebugLogger;
|
|
@@ -105,55 +138,27 @@ export abstract class AbstractPhaseManager {
|
|
|
105
138
|
protected publicKernel: PublicKernelCircuitSimulator,
|
|
106
139
|
protected globalVariables: GlobalVariables,
|
|
107
140
|
protected historicalHeader: Header,
|
|
108
|
-
public phase:
|
|
141
|
+
public phase: PublicKernelType,
|
|
109
142
|
) {
|
|
110
143
|
this.hintsBuilder = new HintsBuilder(db);
|
|
111
144
|
this.log = createDebugLogger(`aztec:sequencer:${phase}`);
|
|
112
145
|
}
|
|
146
|
+
|
|
113
147
|
/**
|
|
114
|
-
*
|
|
115
148
|
* @param tx - the tx to be processed
|
|
116
149
|
* @param publicKernelPublicInputs - the output of the public kernel circuit for the previous phase
|
|
117
|
-
* @param previousPublicKernelProof - the proof of the public kernel circuit for the previous phase
|
|
118
150
|
*/
|
|
119
|
-
abstract handle(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
previousPublicKernelProof: Proof,
|
|
123
|
-
): Promise<{
|
|
124
|
-
/**
|
|
125
|
-
* The collection of public kernel requests
|
|
126
|
-
*/
|
|
127
|
-
kernelRequests: PublicKernelRequest[];
|
|
128
|
-
/**
|
|
129
|
-
* the output of the public kernel circuit for this phase
|
|
130
|
-
*/
|
|
131
|
-
publicKernelOutput: PublicKernelCircuitPublicInputs;
|
|
132
|
-
/**
|
|
133
|
-
* the final output of the public kernel circuit for this phase
|
|
134
|
-
*/
|
|
135
|
-
finalKernelOutput?: KernelCircuitPublicInputs;
|
|
136
|
-
/**
|
|
137
|
-
* the proof of the public kernel circuit for this phase
|
|
138
|
-
*/
|
|
139
|
-
publicKernelProof: Proof;
|
|
140
|
-
/**
|
|
141
|
-
* revert reason, if any
|
|
142
|
-
*/
|
|
143
|
-
revertReason: SimulationError | undefined;
|
|
144
|
-
returnValues: NestedProcessReturnValues[];
|
|
145
|
-
/** Gas used during the execution this particular phase. */
|
|
146
|
-
gasUsed: Gas | undefined;
|
|
147
|
-
}>;
|
|
148
|
-
|
|
149
|
-
public static extractEnqueuedPublicCallsByPhase(tx: Tx): Record<PublicKernelPhase, PublicCallRequest[]> {
|
|
151
|
+
abstract handle(tx: Tx, publicKernelPublicInputs: PublicKernelCircuitPublicInputs): Promise<PhaseResult>;
|
|
152
|
+
|
|
153
|
+
public static extractEnqueuedPublicCallsByPhase(tx: Tx): Record<PublicKernelType, PublicCallRequest[]> {
|
|
150
154
|
const data = tx.data.forPublic;
|
|
151
155
|
if (!data) {
|
|
152
156
|
return {
|
|
153
|
-
[
|
|
154
|
-
[
|
|
155
|
-
[
|
|
156
|
-
[
|
|
157
|
+
[PublicKernelType.NON_PUBLIC]: [],
|
|
158
|
+
[PublicKernelType.SETUP]: [],
|
|
159
|
+
[PublicKernelType.APP_LOGIC]: [],
|
|
160
|
+
[PublicKernelType.TEARDOWN]: [],
|
|
161
|
+
[PublicKernelType.TAIL]: [],
|
|
157
162
|
};
|
|
158
163
|
}
|
|
159
164
|
const publicCallsStack = tx.enqueuedPublicFunctionCalls.slice().reverse();
|
|
@@ -171,10 +176,11 @@ export abstract class AbstractPhaseManager {
|
|
|
171
176
|
|
|
172
177
|
if (callRequestsStack.length === 0) {
|
|
173
178
|
return {
|
|
174
|
-
[
|
|
175
|
-
[
|
|
176
|
-
[
|
|
177
|
-
[
|
|
179
|
+
[PublicKernelType.NON_PUBLIC]: [],
|
|
180
|
+
[PublicKernelType.SETUP]: [],
|
|
181
|
+
[PublicKernelType.APP_LOGIC]: [],
|
|
182
|
+
[PublicKernelType.TEARDOWN]: [],
|
|
183
|
+
[PublicKernelType.TAIL]: [],
|
|
178
184
|
};
|
|
179
185
|
}
|
|
180
186
|
|
|
@@ -187,25 +193,28 @@ export abstract class AbstractPhaseManager {
|
|
|
187
193
|
|
|
188
194
|
if (firstRevertibleCallIndex === 0) {
|
|
189
195
|
return {
|
|
190
|
-
[
|
|
191
|
-
[
|
|
192
|
-
[
|
|
193
|
-
[
|
|
196
|
+
[PublicKernelType.NON_PUBLIC]: [],
|
|
197
|
+
[PublicKernelType.SETUP]: [],
|
|
198
|
+
[PublicKernelType.APP_LOGIC]: publicCallsStack,
|
|
199
|
+
[PublicKernelType.TEARDOWN]: teardownCallStack,
|
|
200
|
+
[PublicKernelType.TAIL]: [],
|
|
194
201
|
};
|
|
195
202
|
} else if (firstRevertibleCallIndex === -1) {
|
|
196
203
|
// there's no app logic, split the functions between setup (many) and teardown (just one function call)
|
|
197
204
|
return {
|
|
198
|
-
[
|
|
199
|
-
[
|
|
200
|
-
[
|
|
201
|
-
[
|
|
205
|
+
[PublicKernelType.NON_PUBLIC]: [],
|
|
206
|
+
[PublicKernelType.SETUP]: publicCallsStack,
|
|
207
|
+
[PublicKernelType.APP_LOGIC]: [],
|
|
208
|
+
[PublicKernelType.TEARDOWN]: teardownCallStack,
|
|
209
|
+
[PublicKernelType.TAIL]: [],
|
|
202
210
|
};
|
|
203
211
|
} else {
|
|
204
212
|
return {
|
|
205
|
-
[
|
|
206
|
-
[
|
|
207
|
-
[
|
|
208
|
-
[
|
|
213
|
+
[PublicKernelType.NON_PUBLIC]: [],
|
|
214
|
+
[PublicKernelType.SETUP]: publicCallsStack.slice(0, firstRevertibleCallIndex),
|
|
215
|
+
[PublicKernelType.APP_LOGIC]: publicCallsStack.slice(firstRevertibleCallIndex),
|
|
216
|
+
[PublicKernelType.TEARDOWN]: teardownCallStack,
|
|
217
|
+
[PublicKernelType.TAIL]: [],
|
|
209
218
|
};
|
|
210
219
|
}
|
|
211
220
|
}
|
|
@@ -216,43 +225,32 @@ export abstract class AbstractPhaseManager {
|
|
|
216
225
|
return calls;
|
|
217
226
|
}
|
|
218
227
|
|
|
219
|
-
// REFACTOR: Do not return an array and instead return a struct with similar shape to that returned by `handle`
|
|
220
228
|
protected async processEnqueuedPublicCalls(
|
|
221
229
|
tx: Tx,
|
|
222
230
|
previousPublicKernelOutput: PublicKernelCircuitPublicInputs,
|
|
223
|
-
|
|
224
|
-
): Promise<
|
|
225
|
-
[
|
|
226
|
-
PublicKernelCircuitPrivateInputs[],
|
|
227
|
-
PublicKernelCircuitPublicInputs,
|
|
228
|
-
Proof,
|
|
229
|
-
UnencryptedFunctionL2Logs[],
|
|
230
|
-
SimulationError | undefined,
|
|
231
|
-
NestedProcessReturnValues[],
|
|
232
|
-
Gas,
|
|
233
|
-
]
|
|
234
|
-
> {
|
|
235
|
-
let kernelOutput = previousPublicKernelOutput;
|
|
236
|
-
const kernelProof = previousPublicKernelProof;
|
|
237
|
-
const publicKernelInputs: PublicKernelCircuitPrivateInputs[] = [];
|
|
238
|
-
|
|
231
|
+
): Promise<TxPublicCallsResult> {
|
|
239
232
|
const enqueuedCalls = this.extractEnqueuedPublicCalls(tx);
|
|
240
233
|
|
|
241
234
|
if (!enqueuedCalls || !enqueuedCalls.length) {
|
|
242
|
-
return
|
|
235
|
+
return {
|
|
236
|
+
publicProvingInformation: [],
|
|
237
|
+
kernelOutput: previousPublicKernelOutput,
|
|
238
|
+
newUnencryptedLogs: [],
|
|
239
|
+
returnValues: [],
|
|
240
|
+
gasUsed: Gas.empty(),
|
|
241
|
+
};
|
|
243
242
|
}
|
|
244
243
|
|
|
245
|
-
const newUnencryptedFunctionLogs: UnencryptedFunctionL2Logs[] = [];
|
|
246
|
-
|
|
247
|
-
// Transaction fee is zero for all phases except teardown
|
|
248
|
-
const transactionFee = this.getTransactionFee(tx, previousPublicKernelOutput);
|
|
249
|
-
|
|
250
244
|
// TODO(#1684): Should multiple separately enqueued public calls be treated as
|
|
251
245
|
// separate public callstacks to be proven by separate public kernel sequences
|
|
252
246
|
// and submitted separately to the base rollup?
|
|
253
247
|
|
|
248
|
+
const provingInformationList: PublicProvingInformation[] = [];
|
|
249
|
+
const newUnencryptedFunctionLogs: UnencryptedFunctionL2Logs[] = [];
|
|
250
|
+
// Transaction fee is zero for all phases except teardown
|
|
251
|
+
const transactionFee = this.getTransactionFee(tx, previousPublicKernelOutput);
|
|
254
252
|
let gasUsed = Gas.empty();
|
|
255
|
-
|
|
253
|
+
let kernelPublicOutput: PublicKernelCircuitPublicInputs = previousPublicKernelOutput;
|
|
256
254
|
const enqueuedCallResults = [];
|
|
257
255
|
|
|
258
256
|
for (const enqueuedCall of enqueuedCalls) {
|
|
@@ -264,35 +262,30 @@ export abstract class AbstractPhaseManager {
|
|
|
264
262
|
while (executionStack.length) {
|
|
265
263
|
const current = executionStack.pop()!;
|
|
266
264
|
const isExecutionRequest = !isPublicExecutionResult(current);
|
|
267
|
-
// TODO(6052): Extract correct new counter from nested calls
|
|
268
|
-
const sideEffectCounter = lastSideEffectCounter(tx) + 1;
|
|
269
|
-
const availableGas = this.getAvailableGas(tx, kernelOutput);
|
|
270
|
-
const pendingNullifiers = this.getSiloedPendingNullifiers(kernelOutput);
|
|
271
|
-
|
|
272
265
|
const result = isExecutionRequest
|
|
273
266
|
? await this.publicExecutor.simulate(
|
|
274
267
|
current,
|
|
275
268
|
this.globalVariables,
|
|
276
|
-
availableGas,
|
|
269
|
+
/*availableGas=*/ this.getAvailableGas(tx, kernelPublicOutput),
|
|
277
270
|
tx.data.constants.txContext,
|
|
278
|
-
pendingNullifiers,
|
|
271
|
+
/*pendingNullifiers=*/ this.getSiloedPendingNullifiers(kernelPublicOutput),
|
|
279
272
|
transactionFee,
|
|
280
|
-
|
|
273
|
+
/*startSideEffectCounter=*/ AbstractPhaseManager.getMaxSideEffectCounter(kernelPublicOutput) + 1,
|
|
281
274
|
)
|
|
282
275
|
: current;
|
|
283
276
|
|
|
277
|
+
// Accumulate gas used in this execution
|
|
278
|
+
gasUsed = gasUsed.add(Gas.from(result.startGasLeft).sub(Gas.from(result.endGasLeft)));
|
|
279
|
+
|
|
284
280
|
// Sanity check for a current upstream assumption.
|
|
285
281
|
// Consumers of the result seem to expect "reverted <=> revertReason !== undefined".
|
|
286
|
-
const functionSelector = result.execution.
|
|
282
|
+
const functionSelector = result.execution.functionSelector.toString();
|
|
287
283
|
if (result.reverted && !result.revertReason) {
|
|
288
284
|
throw new Error(
|
|
289
285
|
`Simulation of ${result.execution.contractAddress.toString()}:${functionSelector} reverted with no reason.`,
|
|
290
286
|
);
|
|
291
287
|
}
|
|
292
288
|
|
|
293
|
-
// Accumulate gas used in this execution
|
|
294
|
-
gasUsed = gasUsed.add(Gas.from(result.startGasLeft).sub(Gas.from(result.endGasLeft)));
|
|
295
|
-
|
|
296
289
|
if (result.reverted && !PhaseIsRevertible[this.phase]) {
|
|
297
290
|
this.log.debug(
|
|
298
291
|
`Simulation error on ${result.execution.contractAddress.toString()}:${functionSelector} with reason: ${
|
|
@@ -305,23 +298,29 @@ export abstract class AbstractPhaseManager {
|
|
|
305
298
|
if (isExecutionRequest) {
|
|
306
299
|
newUnencryptedFunctionLogs.push(result.allUnencryptedLogs);
|
|
307
300
|
}
|
|
301
|
+
executionStack.push(...result.nestedExecutions);
|
|
308
302
|
|
|
303
|
+
// Simulate the public kernel circuit.
|
|
309
304
|
this.log.debug(
|
|
310
305
|
`Running public kernel circuit for ${result.execution.contractAddress.toString()}:${functionSelector}`,
|
|
311
306
|
);
|
|
312
|
-
executionStack.push(...result.nestedExecutions);
|
|
313
307
|
const callData = await this.getPublicCallData(result, isExecutionRequest);
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
308
|
+
const [privateInputs, publicInputs] = await this.runKernelCircuit(kernelPublicOutput, callData);
|
|
309
|
+
kernelPublicOutput = publicInputs;
|
|
310
|
+
|
|
311
|
+
// Capture the inputs for later proving in the AVM and kernel.
|
|
312
|
+
const publicProvingInformation: PublicProvingInformation = {
|
|
313
|
+
calldata: result.calldata,
|
|
314
|
+
bytecode: result.bytecode!,
|
|
315
|
+
inputs: privateInputs,
|
|
316
|
+
avmHints: result.avmHints,
|
|
317
|
+
};
|
|
318
|
+
provingInformationList.push(publicProvingInformation);
|
|
319
|
+
|
|
320
|
+
// Sanity check: Note we can't expect them to just be equal, because e.g.
|
|
322
321
|
// if the simulator reverts in app logic, it "resets" and result.reverted will be false when we run teardown,
|
|
323
322
|
// but the kernel carries the reverted flag forward. But if the simulator reverts, so should the kernel.
|
|
324
|
-
if (result.reverted &&
|
|
323
|
+
if (result.reverted && kernelPublicOutput.revertCode.isOK()) {
|
|
325
324
|
throw new Error(
|
|
326
325
|
`Public kernel circuit did not revert on ${result.execution.contractAddress.toString()}:${functionSelector}, but simulator did.`,
|
|
327
326
|
);
|
|
@@ -336,7 +335,14 @@ export abstract class AbstractPhaseManager {
|
|
|
336
335
|
}`,
|
|
337
336
|
);
|
|
338
337
|
// TODO(@spalladino): Check gasUsed is correct. The AVM should take care of setting gasLeft to zero upon a revert.
|
|
339
|
-
return
|
|
338
|
+
return {
|
|
339
|
+
publicProvingInformation: [],
|
|
340
|
+
kernelOutput: kernelPublicOutput,
|
|
341
|
+
newUnencryptedLogs: [],
|
|
342
|
+
revertReason: result.revertReason,
|
|
343
|
+
returnValues: [],
|
|
344
|
+
gasUsed,
|
|
345
|
+
};
|
|
340
346
|
}
|
|
341
347
|
|
|
342
348
|
if (!enqueuedExecutionResult) {
|
|
@@ -345,26 +351,18 @@ export abstract class AbstractPhaseManager {
|
|
|
345
351
|
|
|
346
352
|
enqueuedCallResults.push(accumulateReturnValues(enqueuedExecutionResult));
|
|
347
353
|
}
|
|
348
|
-
// HACK(#1622): Manually patches the ordering of public state actions
|
|
349
|
-
// TODO(#757): Enforce proper ordering of public state actions
|
|
350
|
-
patchPublicStorageActionOrdering(kernelOutput, enqueuedExecutionResult!, this.phase);
|
|
351
354
|
}
|
|
352
355
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
kernelOutput,
|
|
359
|
-
kernelProof,
|
|
360
|
-
newUnencryptedFunctionLogs,
|
|
361
|
-
undefined,
|
|
362
|
-
enqueuedCallResults,
|
|
356
|
+
return {
|
|
357
|
+
publicProvingInformation: provingInformationList,
|
|
358
|
+
kernelOutput: kernelPublicOutput,
|
|
359
|
+
newUnencryptedLogs: newUnencryptedFunctionLogs,
|
|
360
|
+
returnValues: enqueuedCallResults,
|
|
363
361
|
gasUsed,
|
|
364
|
-
|
|
362
|
+
};
|
|
365
363
|
}
|
|
366
364
|
|
|
367
|
-
/** Returns all pending private and public nullifiers.
|
|
365
|
+
/** Returns all pending private and public nullifiers. */
|
|
368
366
|
private getSiloedPendingNullifiers(ko: PublicKernelCircuitPublicInputs) {
|
|
369
367
|
return [...ko.end.newNullifiers, ...ko.endNonRevertibleData.newNullifiers].filter(n => !n.isEmpty());
|
|
370
368
|
}
|
|
@@ -380,44 +378,33 @@ export abstract class AbstractPhaseManager {
|
|
|
380
378
|
return Fr.ZERO;
|
|
381
379
|
}
|
|
382
380
|
|
|
383
|
-
|
|
381
|
+
private async runKernelCircuit(
|
|
384
382
|
previousOutput: PublicKernelCircuitPublicInputs,
|
|
385
|
-
previousProof: Proof,
|
|
386
383
|
callData: PublicCallData,
|
|
387
384
|
): Promise<[PublicKernelCircuitPrivateInputs, PublicKernelCircuitPublicInputs]> {
|
|
388
|
-
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
protected async getKernelCircuitOutput(
|
|
392
|
-
previousOutput: PublicKernelCircuitPublicInputs,
|
|
393
|
-
previousProof: Proof,
|
|
394
|
-
callData: PublicCallData,
|
|
395
|
-
): Promise<[PublicKernelCircuitPrivateInputs, PublicKernelCircuitPublicInputs]> {
|
|
396
|
-
const previousKernel = this.getPreviousKernelData(previousOutput, previousProof);
|
|
385
|
+
const previousKernel = this.getPreviousKernelData(previousOutput);
|
|
397
386
|
|
|
398
387
|
// We take a deep copy (clone) of these inputs to be passed to the prover
|
|
399
388
|
const inputs = new PublicKernelCircuitPrivateInputs(previousKernel, callData);
|
|
400
389
|
switch (this.phase) {
|
|
401
|
-
case
|
|
390
|
+
case PublicKernelType.SETUP:
|
|
402
391
|
return [inputs.clone(), await this.publicKernel.publicKernelCircuitSetup(inputs)];
|
|
403
|
-
case
|
|
392
|
+
case PublicKernelType.APP_LOGIC:
|
|
404
393
|
return [inputs.clone(), await this.publicKernel.publicKernelCircuitAppLogic(inputs)];
|
|
405
|
-
case
|
|
394
|
+
case PublicKernelType.TEARDOWN:
|
|
406
395
|
return [inputs.clone(), await this.publicKernel.publicKernelCircuitTeardown(inputs)];
|
|
407
396
|
default:
|
|
408
397
|
throw new Error(`No public kernel circuit for inputs`);
|
|
409
398
|
}
|
|
410
399
|
}
|
|
411
400
|
|
|
412
|
-
protected getPreviousKernelData(
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
// TODO(@PhilWindle) Fix once we move this to prover-client
|
|
417
|
-
const vk = VerificationKey.makeFake();
|
|
401
|
+
protected getPreviousKernelData(previousOutput: PublicKernelCircuitPublicInputs): PublicKernelData {
|
|
402
|
+
// The proof and verification key are not used in simulation
|
|
403
|
+
const vk = VerificationKeyData.makeFake();
|
|
404
|
+
const proof = makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH);
|
|
418
405
|
const vkIndex = 0;
|
|
419
406
|
const vkSiblingPath = MembershipWitness.random(VK_TREE_HEIGHT).siblingPath;
|
|
420
|
-
return new PublicKernelData(previousOutput,
|
|
407
|
+
return new PublicKernelData(previousOutput, proof, vk, vkIndex, vkSiblingPath);
|
|
421
408
|
}
|
|
422
409
|
|
|
423
410
|
protected async getPublicCallStackItem(result: PublicExecutionResult, isExecutionRequest = false) {
|
|
@@ -441,6 +428,11 @@ export abstract class AbstractPhaseManager {
|
|
|
441
428
|
startSideEffectCounter: result.startSideEffectCounter,
|
|
442
429
|
endSideEffectCounter: result.endSideEffectCounter,
|
|
443
430
|
returnsHash: computeVarArgsHash(result.returnValues),
|
|
431
|
+
noteHashReadRequests: padArrayEnd(
|
|
432
|
+
result.noteHashReadRequests,
|
|
433
|
+
ReadRequest.empty(),
|
|
434
|
+
MAX_NOTE_HASH_READ_REQUESTS_PER_CALL,
|
|
435
|
+
),
|
|
444
436
|
nullifierReadRequests: padArrayEnd(
|
|
445
437
|
result.nullifierReadRequests,
|
|
446
438
|
ReadRequest.empty(),
|
|
@@ -451,6 +443,11 @@ export abstract class AbstractPhaseManager {
|
|
|
451
443
|
ReadRequest.empty(),
|
|
452
444
|
MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL,
|
|
453
445
|
),
|
|
446
|
+
l1ToL2MsgReadRequests: padArrayEnd(
|
|
447
|
+
result.l1ToL2MsgReadRequests,
|
|
448
|
+
ReadRequest.empty(),
|
|
449
|
+
MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL,
|
|
450
|
+
),
|
|
454
451
|
contractStorageReads: padArrayEnd(
|
|
455
452
|
result.contractStorageReads,
|
|
456
453
|
ContractStorageRead.empty(),
|
|
@@ -469,12 +466,12 @@ export abstract class AbstractPhaseManager {
|
|
|
469
466
|
endGasLeft: Gas.from(result.endGasLeft),
|
|
470
467
|
transactionFee: result.transactionFee,
|
|
471
468
|
// TODO(@just-mitch): need better mapping from simulator to revert code.
|
|
472
|
-
revertCode: result.reverted ? RevertCode.
|
|
469
|
+
revertCode: result.reverted ? RevertCode.APP_LOGIC_REVERTED : RevertCode.OK,
|
|
473
470
|
});
|
|
474
471
|
|
|
475
472
|
return new PublicCallStackItem(
|
|
476
473
|
result.execution.contractAddress,
|
|
477
|
-
result.execution.
|
|
474
|
+
new FunctionData(result.execution.functionSelector, false),
|
|
478
475
|
publicCircuitPublicInputs,
|
|
479
476
|
isExecutionRequest,
|
|
480
477
|
);
|
|
@@ -491,6 +488,44 @@ export abstract class AbstractPhaseManager {
|
|
|
491
488
|
return await Promise.all(nested.map(n => this.getPublicCallStackItem(n)));
|
|
492
489
|
}
|
|
493
490
|
|
|
491
|
+
/**
|
|
492
|
+
* Looks at the side effects of a transaction and returns the highest counter
|
|
493
|
+
* @param tx - A transaction
|
|
494
|
+
* @returns The highest side effect counter in the transaction so far
|
|
495
|
+
*/
|
|
496
|
+
static getMaxSideEffectCounter(inputs: PublicKernelCircuitPublicInputs): number {
|
|
497
|
+
const sideEffectCounters = [
|
|
498
|
+
...inputs.endNonRevertibleData.newNoteHashes,
|
|
499
|
+
...inputs.endNonRevertibleData.newNullifiers,
|
|
500
|
+
...inputs.endNonRevertibleData.noteEncryptedLogsHashes,
|
|
501
|
+
...inputs.endNonRevertibleData.encryptedLogsHashes,
|
|
502
|
+
...inputs.endNonRevertibleData.unencryptedLogsHashes,
|
|
503
|
+
...inputs.endNonRevertibleData.publicCallStack,
|
|
504
|
+
...inputs.endNonRevertibleData.publicDataUpdateRequests,
|
|
505
|
+
...inputs.end.newNoteHashes,
|
|
506
|
+
...inputs.end.newNullifiers,
|
|
507
|
+
...inputs.end.noteEncryptedLogsHashes,
|
|
508
|
+
...inputs.end.encryptedLogsHashes,
|
|
509
|
+
...inputs.end.unencryptedLogsHashes,
|
|
510
|
+
...inputs.end.publicCallStack,
|
|
511
|
+
...inputs.end.publicDataUpdateRequests,
|
|
512
|
+
];
|
|
513
|
+
|
|
514
|
+
let max = 0;
|
|
515
|
+
for (const sideEffect of sideEffectCounters) {
|
|
516
|
+
if ('startSideEffectCounter' in sideEffect) {
|
|
517
|
+
// look at both start and end counters because for enqueued public calls start > 0 while end === 0
|
|
518
|
+
max = Math.max(max, sideEffect.startSideEffectCounter.toNumber(), sideEffect.endSideEffectCounter.toNumber());
|
|
519
|
+
} else if ('counter' in sideEffect) {
|
|
520
|
+
max = Math.max(max, sideEffect.counter);
|
|
521
|
+
} else {
|
|
522
|
+
throw new Error('Unknown side effect type');
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
return max;
|
|
527
|
+
}
|
|
528
|
+
|
|
494
529
|
protected getBytecodeHash(_result: PublicExecutionResult) {
|
|
495
530
|
// TODO: Determine how to calculate bytecode hash. Circuits just check it isn't zero for now.
|
|
496
531
|
// See https://github.com/AztecProtocol/aztec3-packages/issues/378
|
|
@@ -516,87 +551,3 @@ export abstract class AbstractPhaseManager {
|
|
|
516
551
|
return new PublicCallData(callStackItem, publicCallStack, makeEmptyProof(), bytecodeHash);
|
|
517
552
|
}
|
|
518
553
|
}
|
|
519
|
-
|
|
520
|
-
function removeRedundantPublicDataWrites(publicInputs: PublicKernelCircuitPublicInputs, phase: PublicKernelPhase) {
|
|
521
|
-
const lastWritesMap = new Map<string, boolean>();
|
|
522
|
-
const patch = <N extends number>(requests: Tuple<PublicDataUpdateRequest, N>) =>
|
|
523
|
-
requests.filter(write => {
|
|
524
|
-
const leafSlot = write.leafSlot.toString();
|
|
525
|
-
const exists = lastWritesMap.get(leafSlot);
|
|
526
|
-
lastWritesMap.set(leafSlot, true);
|
|
527
|
-
return !exists;
|
|
528
|
-
});
|
|
529
|
-
|
|
530
|
-
const [prev, curr] = PhaseIsRevertible[phase]
|
|
531
|
-
? [publicInputs.endNonRevertibleData, publicInputs.end]
|
|
532
|
-
: [publicInputs.end, publicInputs.endNonRevertibleData];
|
|
533
|
-
|
|
534
|
-
curr.publicDataUpdateRequests = padArrayEnd(
|
|
535
|
-
patch(curr.publicDataUpdateRequests.reverse()).reverse(),
|
|
536
|
-
PublicDataUpdateRequest.empty(),
|
|
537
|
-
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
538
|
-
);
|
|
539
|
-
|
|
540
|
-
prev.publicDataUpdateRequests = padArrayEnd(
|
|
541
|
-
patch(prev.publicDataUpdateRequests.reverse()),
|
|
542
|
-
PublicDataUpdateRequest.empty(),
|
|
543
|
-
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
544
|
-
);
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
// HACK(#1622): this is a hack to fix ordering of public state in the call stack. Since the private kernel
|
|
548
|
-
// cannot keep track of side effects that happen after or before a nested call, we override the public
|
|
549
|
-
// state actions it emits with whatever we got from the simulator. As a sanity check, we at least verify
|
|
550
|
-
// that the elements are the same, so we are only tweaking their ordering.
|
|
551
|
-
// See yarn-project/end-to-end/src/e2e_ordering.test.ts
|
|
552
|
-
// See https://github.com/AztecProtocol/aztec-packages/issues/1616
|
|
553
|
-
// TODO(#757): Enforce proper ordering of public state actions
|
|
554
|
-
/**
|
|
555
|
-
* Patch the ordering of storage actions output from the public kernel.
|
|
556
|
-
* @param publicInputs - to be patched here: public inputs to the kernel iteration up to this point
|
|
557
|
-
* @param execResult - result of the top/first execution for this enqueued public call
|
|
558
|
-
*/
|
|
559
|
-
function patchPublicStorageActionOrdering(
|
|
560
|
-
publicInputs: PublicKernelCircuitPublicInputs,
|
|
561
|
-
execResult: PublicExecutionResult,
|
|
562
|
-
phase: PublicKernelPhase,
|
|
563
|
-
) {
|
|
564
|
-
const { publicDataUpdateRequests } = PhaseIsRevertible[phase] ? publicInputs.end : publicInputs.endNonRevertibleData;
|
|
565
|
-
const { publicDataReads } = publicInputs.validationRequests;
|
|
566
|
-
|
|
567
|
-
// Convert ContractStorage* objects to PublicData* objects and sort them in execution order.
|
|
568
|
-
// Note, this only pulls simulated reads/writes from the current phase,
|
|
569
|
-
// so the returned result will be a subset of the public kernel output.
|
|
570
|
-
|
|
571
|
-
const simPublicDataReads = collectPublicDataReads(execResult);
|
|
572
|
-
|
|
573
|
-
const simPublicDataUpdateRequests = collectPublicDataUpdateRequests(execResult);
|
|
574
|
-
|
|
575
|
-
// We only want to reorder the items from the public inputs of the
|
|
576
|
-
// most recently processed top/enqueued call.
|
|
577
|
-
|
|
578
|
-
const effectSet = PhaseIsRevertible[phase] ? 'end' : 'endNonRevertibleData';
|
|
579
|
-
|
|
580
|
-
const numReadsInKernel = arrayNonEmptyLength(publicDataReads, f => f.isEmpty());
|
|
581
|
-
const numReadsBeforeThisEnqueuedCall = numReadsInKernel - simPublicDataReads.length;
|
|
582
|
-
publicInputs.validationRequests.publicDataReads = padArrayEnd(
|
|
583
|
-
[
|
|
584
|
-
// do not mess with items from previous top/enqueued calls in kernel output
|
|
585
|
-
...publicInputs.validationRequests.publicDataReads.slice(0, numReadsBeforeThisEnqueuedCall),
|
|
586
|
-
...simPublicDataReads,
|
|
587
|
-
],
|
|
588
|
-
PublicDataRead.empty(),
|
|
589
|
-
MAX_PUBLIC_DATA_READS_PER_TX,
|
|
590
|
-
);
|
|
591
|
-
|
|
592
|
-
const numUpdatesInKernel = arrayNonEmptyLength(publicDataUpdateRequests, f => f.isEmpty());
|
|
593
|
-
const numUpdatesBeforeThisEnqueuedCall = numUpdatesInKernel - simPublicDataUpdateRequests.length;
|
|
594
|
-
publicInputs[effectSet].publicDataUpdateRequests = padArrayEnd(
|
|
595
|
-
[
|
|
596
|
-
...publicInputs[effectSet].publicDataUpdateRequests.slice(0, numUpdatesBeforeThisEnqueuedCall),
|
|
597
|
-
...simPublicDataUpdateRequests,
|
|
598
|
-
],
|
|
599
|
-
PublicDataUpdateRequest.empty(),
|
|
600
|
-
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
601
|
-
);
|
|
602
|
-
}
|