@aztec/simulator 0.61.0 → 0.63.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/acvm/acvm.d.ts +2 -16
- package/dest/acvm/acvm.d.ts.map +1 -1
- package/dest/acvm/acvm.js +2 -70
- package/dest/acvm/oracle/oracle.d.ts +4 -3
- package/dest/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/oracle.js +11 -9
- package/dest/acvm/oracle/typed_oracle.d.ts +5 -4
- package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/acvm/oracle/typed_oracle.js +9 -6
- package/dest/avm/avm_gas.d.ts.map +1 -1
- package/dest/avm/avm_gas.js +4 -3
- package/dest/avm/avm_machine_state.d.ts +27 -8
- package/dest/avm/avm_machine_state.d.ts.map +1 -1
- package/dest/avm/avm_machine_state.js +6 -10
- package/dest/avm/avm_memory_types.d.ts +8 -0
- package/dest/avm/avm_memory_types.d.ts.map +1 -1
- package/dest/avm/avm_memory_types.js +5 -1
- package/dest/avm/avm_simulator.d.ts +2 -19
- package/dest/avm/avm_simulator.d.ts.map +1 -1
- package/dest/avm/avm_simulator.js +12 -14
- package/dest/avm/avm_tree.d.ts +249 -0
- package/dest/avm/avm_tree.d.ts.map +1 -0
- package/dest/avm/avm_tree.js +637 -0
- package/dest/avm/errors.d.ts +4 -17
- package/dest/avm/errors.d.ts.map +1 -1
- package/dest/avm/errors.js +21 -50
- package/dest/avm/fixtures/index.d.ts +7 -2
- package/dest/avm/fixtures/index.d.ts.map +1 -1
- package/dest/avm/fixtures/index.js +12 -12
- package/dest/avm/index.d.ts +1 -0
- package/dest/avm/index.d.ts.map +1 -1
- package/dest/avm/index.js +2 -1
- package/dest/avm/journal/journal.d.ts +43 -24
- package/dest/avm/journal/journal.d.ts.map +1 -1
- package/dest/avm/journal/journal.js +172 -39
- package/dest/avm/journal/nullifiers.d.ts +5 -4
- package/dest/avm/journal/nullifiers.d.ts.map +1 -1
- package/dest/avm/journal/nullifiers.js +2 -3
- package/dest/avm/journal/public_storage.d.ts +6 -5
- package/dest/avm/journal/public_storage.d.ts.map +1 -1
- package/dest/avm/journal/public_storage.js +1 -1
- package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
- package/dest/avm/opcodes/accrued_substate.js +4 -10
- package/dest/avm/opcodes/arithmetic.d.ts +4 -1
- package/dest/avm/opcodes/arithmetic.d.ts.map +1 -1
- package/dest/avm/opcodes/arithmetic.js +18 -4
- package/dest/avm/opcodes/bitwise.d.ts.map +1 -1
- package/dest/avm/opcodes/bitwise.js +1 -3
- package/dest/avm/opcodes/comparators.d.ts.map +1 -1
- package/dest/avm/opcodes/comparators.js +1 -2
- package/dest/avm/opcodes/contract.d.ts.map +1 -1
- package/dest/avm/opcodes/contract.js +2 -3
- package/dest/avm/opcodes/control_flow.d.ts +4 -0
- package/dest/avm/opcodes/control_flow.d.ts.map +1 -1
- package/dest/avm/opcodes/control_flow.js +26 -11
- package/dest/avm/opcodes/conversion.d.ts.map +1 -1
- package/dest/avm/opcodes/conversion.js +1 -2
- package/dest/avm/opcodes/ec_add.d.ts.map +1 -1
- package/dest/avm/opcodes/ec_add.js +5 -11
- package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
- package/dest/avm/opcodes/environment_getters.js +1 -2
- package/dest/avm/opcodes/external_calls.d.ts +4 -2
- package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
- package/dest/avm/opcodes/external_calls.js +38 -22
- package/dest/avm/opcodes/hashing.d.ts.map +1 -1
- package/dest/avm/opcodes/hashing.js +1 -4
- package/dest/avm/opcodes/instruction.d.ts +4 -0
- package/dest/avm/opcodes/instruction.d.ts.map +1 -1
- package/dest/avm/opcodes/instruction.js +7 -1
- package/dest/avm/opcodes/memory.d.ts.map +1 -1
- package/dest/avm/opcodes/memory.js +1 -7
- package/dest/avm/opcodes/misc.js +3 -3
- package/dest/avm/opcodes/multi_scalar_mul.d.ts.map +1 -1
- package/dest/avm/opcodes/multi_scalar_mul.js +6 -5
- package/dest/avm/opcodes/storage.d.ts.map +1 -1
- package/dest/avm/opcodes/storage.js +2 -4
- package/dest/avm/serialization/bytecode_serialization.d.ts +1 -6
- package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
- package/dest/avm/serialization/bytecode_serialization.js +24 -20
- package/dest/avm/serialization/instruction_serialization.d.ts +2 -2
- package/dest/avm/serialization/instruction_serialization.js +2 -2
- package/dest/client/client_execution_context.d.ts +7 -10
- package/dest/client/client_execution_context.d.ts.map +1 -1
- package/dest/client/client_execution_context.js +19 -18
- package/dest/client/db_oracle.d.ts +22 -8
- package/dest/client/db_oracle.d.ts.map +1 -1
- package/dest/client/db_oracle.js +1 -1
- package/dest/client/private_execution.d.ts.map +1 -1
- package/dest/client/private_execution.js +5 -4
- package/dest/client/unconstrained_execution.d.ts.map +1 -1
- package/dest/client/unconstrained_execution.js +3 -2
- package/dest/client/view_data_oracle.d.ts +6 -12
- package/dest/client/view_data_oracle.d.ts.map +1 -1
- package/dest/client/view_data_oracle.js +10 -12
- package/dest/common/errors.d.ts +15 -2
- package/dest/common/errors.d.ts.map +1 -1
- package/dest/common/errors.js +85 -4
- package/dest/mocks/fixtures.d.ts +9 -28
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +12 -57
- package/dest/public/dual_side_effect_trace.d.ts +34 -26
- package/dest/public/dual_side_effect_trace.d.ts.map +1 -1
- package/dest/public/dual_side_effect_trace.js +48 -36
- package/dest/public/enqueued_call_side_effect_trace.d.ts +96 -33
- package/dest/public/enqueued_call_side_effect_trace.d.ts.map +1 -1
- package/dest/public/enqueued_call_side_effect_trace.js +212 -138
- package/dest/public/execution.d.ts +50 -17
- package/dest/public/execution.d.ts.map +1 -1
- package/dest/public/execution.js +1 -29
- package/dest/public/executor.d.ts +28 -11
- package/dest/public/executor.d.ts.map +1 -1
- package/dest/public/executor.js +33 -33
- package/dest/public/index.d.ts +4 -5
- package/dest/public/index.d.ts.map +1 -1
- package/dest/public/index.js +4 -5
- package/dest/public/public_db_sources.d.ts +1 -0
- package/dest/public/public_db_sources.d.ts.map +1 -1
- package/dest/public/public_db_sources.js +21 -19
- package/dest/public/public_processor.d.ts +7 -11
- package/dest/public/public_processor.d.ts.map +1 -1
- package/dest/public/public_processor.js +60 -42
- package/dest/public/public_processor_metrics.d.ts +3 -3
- package/dest/public/public_processor_metrics.d.ts.map +1 -1
- package/dest/public/public_processor_metrics.js +1 -1
- package/dest/public/public_tx_context.d.ts +130 -0
- package/dest/public/public_tx_context.d.ts.map +1 -0
- package/dest/public/public_tx_context.js +293 -0
- package/dest/public/public_tx_simulator.d.ts +36 -0
- package/dest/public/public_tx_simulator.d.ts.map +1 -0
- package/dest/public/public_tx_simulator.js +148 -0
- package/dest/public/side_effect_trace.d.ts +30 -15
- package/dest/public/side_effect_trace.d.ts.map +1 -1
- package/dest/public/side_effect_trace.js +70 -16
- package/dest/public/side_effect_trace_interface.d.ts +43 -12
- package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
- package/dest/public/transitional_adapters.d.ts +9 -0
- package/dest/public/transitional_adapters.d.ts.map +1 -0
- package/dest/public/transitional_adapters.js +127 -0
- package/dest/public/utils.d.ts +5 -0
- package/dest/public/utils.d.ts.map +1 -0
- package/dest/public/utils.js +30 -0
- package/dest/test/utils.d.ts +2 -2
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +4 -4
- package/package.json +12 -9
- package/src/acvm/acvm.ts +3 -94
- package/src/acvm/oracle/oracle.ts +14 -12
- package/src/acvm/oracle/typed_oracle.ts +10 -6
- package/src/avm/avm_gas.ts +3 -2
- package/src/avm/avm_machine_state.ts +28 -12
- package/src/avm/avm_memory_types.ts +5 -0
- package/src/avm/avm_simulator.ts +13 -16
- package/src/avm/avm_tree.ts +785 -0
- package/src/avm/errors.ts +25 -48
- package/src/avm/fixtures/index.ts +16 -12
- package/src/avm/index.ts +1 -0
- package/src/avm/journal/journal.ts +291 -52
- package/src/avm/journal/nullifiers.ts +7 -7
- package/src/avm/journal/public_storage.ts +5 -5
- package/src/avm/opcodes/accrued_substate.ts +3 -9
- package/src/avm/opcodes/arithmetic.ts +26 -4
- package/src/avm/opcodes/bitwise.ts +0 -2
- package/src/avm/opcodes/comparators.ts +0 -1
- package/src/avm/opcodes/contract.ts +1 -2
- package/src/avm/opcodes/control_flow.ts +29 -10
- package/src/avm/opcodes/conversion.ts +0 -1
- package/src/avm/opcodes/ec_add.ts +6 -9
- package/src/avm/opcodes/environment_getters.ts +0 -1
- package/src/avm/opcodes/external_calls.ts +39 -21
- package/src/avm/opcodes/hashing.ts +0 -3
- package/src/avm/opcodes/instruction.ts +7 -0
- package/src/avm/opcodes/memory.ts +0 -6
- package/src/avm/opcodes/misc.ts +2 -2
- package/src/avm/opcodes/multi_scalar_mul.ts +5 -4
- package/src/avm/opcodes/storage.ts +1 -3
- package/src/avm/serialization/bytecode_serialization.ts +31 -22
- package/src/avm/serialization/instruction_serialization.ts +2 -2
- package/src/client/client_execution_context.ts +24 -21
- package/src/client/db_oracle.ts +31 -8
- package/src/client/private_execution.ts +5 -4
- package/src/client/unconstrained_execution.ts +2 -1
- package/src/client/view_data_oracle.ts +14 -13
- package/src/common/errors.ts +119 -3
- package/src/mocks/fixtures.ts +15 -106
- package/src/public/dual_side_effect_trace.ts +138 -50
- package/src/public/enqueued_call_side_effect_trace.ts +352 -212
- package/src/public/execution.ts +58 -42
- package/src/public/executor.ts +52 -67
- package/src/public/index.ts +7 -5
- package/src/public/public_db_sources.ts +22 -19
- package/src/public/public_processor.ts +111 -73
- package/src/public/public_processor_metrics.ts +3 -3
- package/src/public/public_tx_context.ts +411 -0
- package/src/public/public_tx_simulator.ts +232 -0
- package/src/public/side_effect_trace.ts +154 -28
- package/src/public/side_effect_trace_interface.ts +92 -14
- package/src/public/transitional_adapters.ts +347 -0
- package/src/public/utils.ts +32 -0
- package/src/test/utils.ts +9 -2
- package/dest/public/enqueued_call_simulator.d.ts +0 -43
- package/dest/public/enqueued_call_simulator.d.ts.map +0 -1
- package/dest/public/enqueued_call_simulator.js +0 -156
- package/dest/public/enqueued_calls_processor.d.ts +0 -43
- package/dest/public/enqueued_calls_processor.d.ts.map +0 -1
- package/dest/public/enqueued_calls_processor.js +0 -209
- package/dest/public/hints_builder.d.ts +0 -29
- package/dest/public/hints_builder.d.ts.map +0 -1
- package/dest/public/hints_builder.js +0 -75
- package/dest/public/public_kernel.d.ts +0 -30
- package/dest/public/public_kernel.d.ts.map +0 -1
- package/dest/public/public_kernel.js +0 -67
- package/dest/public/public_kernel_circuit_simulator.d.ts +0 -25
- package/dest/public/public_kernel_circuit_simulator.d.ts.map +0 -1
- package/dest/public/public_kernel_circuit_simulator.js +0 -2
- package/dest/public/public_kernel_tail_simulator.d.ts +0 -15
- package/dest/public/public_kernel_tail_simulator.d.ts.map +0 -1
- package/dest/public/public_kernel_tail_simulator.js +0 -39
- package/src/public/enqueued_call_simulator.ts +0 -360
- package/src/public/enqueued_calls_processor.ts +0 -372
- package/src/public/hints_builder.ts +0 -168
- package/src/public/public_kernel.ts +0 -100
- package/src/public/public_kernel_circuit_simulator.ts +0 -32
- package/src/public/public_kernel_tail_simulator.ts +0 -97
|
@@ -1,372 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type AvmProvingRequest,
|
|
3
|
-
type MerkleTreeReadOperations,
|
|
4
|
-
type NestedProcessReturnValues,
|
|
5
|
-
type ProcessedTx,
|
|
6
|
-
type PublicExecutionRequest,
|
|
7
|
-
PublicKernelPhase,
|
|
8
|
-
type SimulationError,
|
|
9
|
-
type Tx,
|
|
10
|
-
} from '@aztec/circuit-types';
|
|
11
|
-
import {
|
|
12
|
-
EnqueuedCallData,
|
|
13
|
-
Fr,
|
|
14
|
-
Gas,
|
|
15
|
-
type GlobalVariables,
|
|
16
|
-
type Header,
|
|
17
|
-
type KernelCircuitPublicInputs,
|
|
18
|
-
NESTED_RECURSIVE_PROOF_LENGTH,
|
|
19
|
-
type PublicCallRequest,
|
|
20
|
-
PublicKernelCircuitPrivateInputs,
|
|
21
|
-
type PublicKernelCircuitPublicInputs,
|
|
22
|
-
PublicKernelData,
|
|
23
|
-
type VMCircuitPublicInputs,
|
|
24
|
-
VerificationKeyData,
|
|
25
|
-
makeEmptyProof,
|
|
26
|
-
makeEmptyRecursiveProof,
|
|
27
|
-
} from '@aztec/circuits.js';
|
|
28
|
-
import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
29
|
-
import { Timer } from '@aztec/foundation/timer';
|
|
30
|
-
import { getVKSiblingPath } from '@aztec/noir-protocol-circuits-types';
|
|
31
|
-
|
|
32
|
-
import { inspect } from 'util';
|
|
33
|
-
|
|
34
|
-
import { EnqueuedCallSimulator } from './enqueued_call_simulator.js';
|
|
35
|
-
import { type PublicExecutor } from './executor.js';
|
|
36
|
-
import { type WorldStateDB } from './public_db_sources.js';
|
|
37
|
-
import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
|
|
38
|
-
import { PublicKernelTailSimulator } from './public_kernel_tail_simulator.js';
|
|
39
|
-
|
|
40
|
-
const PhaseIsRevertible: Record<PublicKernelPhase, boolean> = {
|
|
41
|
-
[PublicKernelPhase.SETUP]: false,
|
|
42
|
-
[PublicKernelPhase.APP_LOGIC]: true,
|
|
43
|
-
[PublicKernelPhase.TEARDOWN]: true,
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
type PublicPhaseResult = {
|
|
47
|
-
avmProvingRequest: AvmProvingRequest;
|
|
48
|
-
/** The output of the public kernel circuit simulation for this phase */
|
|
49
|
-
publicKernelOutput: PublicKernelCircuitPublicInputs;
|
|
50
|
-
/** Return values of simulating complete callstack */
|
|
51
|
-
returnValues: NestedProcessReturnValues[];
|
|
52
|
-
/** Gas used during the execution this phase */
|
|
53
|
-
gasUsed: Gas;
|
|
54
|
-
/** Time spent for the execution this phase */
|
|
55
|
-
durationMs: number;
|
|
56
|
-
/** Revert reason, if any */
|
|
57
|
-
revertReason?: SimulationError;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export type ProcessedPhase = {
|
|
61
|
-
phase: PublicKernelPhase;
|
|
62
|
-
durationMs: number;
|
|
63
|
-
revertReason?: SimulationError;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export type TxPublicCallsResult = {
|
|
67
|
-
avmProvingRequest: AvmProvingRequest;
|
|
68
|
-
/** The output of the public kernel tail circuit simulation for this tx */
|
|
69
|
-
tailKernelOutput: KernelCircuitPublicInputs;
|
|
70
|
-
/** Return values of simulating complete callstack */
|
|
71
|
-
returnValues: NestedProcessReturnValues[];
|
|
72
|
-
/** Gas used during the execution this tx */
|
|
73
|
-
gasUsed: ProcessedTx['gasUsed'];
|
|
74
|
-
/** Revert reason, if any */
|
|
75
|
-
revertReason?: SimulationError;
|
|
76
|
-
processedPhases: ProcessedPhase[];
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export class EnqueuedCallsProcessor {
|
|
80
|
-
private log: DebugLogger;
|
|
81
|
-
|
|
82
|
-
constructor(
|
|
83
|
-
private publicKernelSimulator: PublicKernelCircuitSimulator,
|
|
84
|
-
private globalVariables: GlobalVariables,
|
|
85
|
-
private worldStateDB: WorldStateDB,
|
|
86
|
-
private enqueuedCallSimulator: EnqueuedCallSimulator,
|
|
87
|
-
private publicKernelTailSimulator: PublicKernelTailSimulator,
|
|
88
|
-
) {
|
|
89
|
-
this.log = createDebugLogger(`aztec:sequencer`);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
static create(
|
|
93
|
-
db: MerkleTreeReadOperations,
|
|
94
|
-
publicExecutor: PublicExecutor,
|
|
95
|
-
publicKernelSimulator: PublicKernelCircuitSimulator,
|
|
96
|
-
globalVariables: GlobalVariables,
|
|
97
|
-
historicalHeader: Header,
|
|
98
|
-
worldStateDB: WorldStateDB,
|
|
99
|
-
) {
|
|
100
|
-
const enqueuedCallSimulator = new EnqueuedCallSimulator(
|
|
101
|
-
db,
|
|
102
|
-
publicExecutor,
|
|
103
|
-
publicKernelSimulator,
|
|
104
|
-
globalVariables,
|
|
105
|
-
historicalHeader,
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
const publicKernelTailSimulator = PublicKernelTailSimulator.create(db, publicKernelSimulator);
|
|
109
|
-
|
|
110
|
-
return new EnqueuedCallsProcessor(
|
|
111
|
-
publicKernelSimulator,
|
|
112
|
-
globalVariables,
|
|
113
|
-
worldStateDB,
|
|
114
|
-
enqueuedCallSimulator,
|
|
115
|
-
publicKernelTailSimulator,
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
static getExecutionRequestsByPhase(tx: Tx, phase: PublicKernelPhase): PublicExecutionRequest[] {
|
|
120
|
-
switch (phase) {
|
|
121
|
-
case PublicKernelPhase.SETUP:
|
|
122
|
-
return tx.getNonRevertiblePublicExecutionRequests();
|
|
123
|
-
case PublicKernelPhase.APP_LOGIC:
|
|
124
|
-
return tx.getRevertiblePublicExecutionRequests();
|
|
125
|
-
case PublicKernelPhase.TEARDOWN: {
|
|
126
|
-
const request = tx.getPublicTeardownExecutionRequest();
|
|
127
|
-
return request ? [request] : [];
|
|
128
|
-
}
|
|
129
|
-
default:
|
|
130
|
-
throw new Error(`Unknown phase: ${phase}`);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
static getCallRequestsByPhase(tx: Tx, phase: PublicKernelPhase): PublicCallRequest[] {
|
|
135
|
-
switch (phase) {
|
|
136
|
-
case PublicKernelPhase.SETUP:
|
|
137
|
-
return tx.data.getNonRevertiblePublicCallRequests();
|
|
138
|
-
case PublicKernelPhase.APP_LOGIC:
|
|
139
|
-
return tx.data.getRevertiblePublicCallRequests();
|
|
140
|
-
case PublicKernelPhase.TEARDOWN: {
|
|
141
|
-
const request = tx.data.getTeardownPublicCallRequest();
|
|
142
|
-
return request ? [request] : [];
|
|
143
|
-
}
|
|
144
|
-
default:
|
|
145
|
-
throw new Error(`Unknown phase: ${phase}`);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
async process(tx: Tx): Promise<TxPublicCallsResult> {
|
|
150
|
-
this.log.verbose(`Processing tx ${tx.getTxHash()}`);
|
|
151
|
-
|
|
152
|
-
const phases: PublicKernelPhase[] = [
|
|
153
|
-
PublicKernelPhase.SETUP,
|
|
154
|
-
PublicKernelPhase.APP_LOGIC,
|
|
155
|
-
PublicKernelPhase.TEARDOWN,
|
|
156
|
-
];
|
|
157
|
-
const processedPhases: ProcessedPhase[] = [];
|
|
158
|
-
const gasUsed: ProcessedTx['gasUsed'] = {};
|
|
159
|
-
let avmProvingRequest: AvmProvingRequest;
|
|
160
|
-
let publicKernelOutput = tx.data.toPublicKernelCircuitPublicInputs();
|
|
161
|
-
let isFromPrivate = true;
|
|
162
|
-
let returnValues: NestedProcessReturnValues[] = [];
|
|
163
|
-
let revertReason: SimulationError | undefined;
|
|
164
|
-
for (let i = 0; i < phases.length; i++) {
|
|
165
|
-
const phase = phases[i];
|
|
166
|
-
const callRequests = EnqueuedCallsProcessor.getCallRequestsByPhase(tx, phase);
|
|
167
|
-
if (callRequests.length) {
|
|
168
|
-
const executionRequests = EnqueuedCallsProcessor.getExecutionRequestsByPhase(tx, phase);
|
|
169
|
-
const result = await this.processPhase(
|
|
170
|
-
tx,
|
|
171
|
-
callRequests,
|
|
172
|
-
executionRequests,
|
|
173
|
-
publicKernelOutput,
|
|
174
|
-
phase,
|
|
175
|
-
isFromPrivate,
|
|
176
|
-
).catch(async err => {
|
|
177
|
-
await this.worldStateDB.rollbackToCommit();
|
|
178
|
-
throw err;
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
publicKernelOutput = result.publicKernelOutput;
|
|
182
|
-
isFromPrivate = false;
|
|
183
|
-
|
|
184
|
-
// Propagate only one avmProvingRequest of a function call for now, so that we know it's still provable.
|
|
185
|
-
// Eventually this will be the proof for the entire public call stack.
|
|
186
|
-
avmProvingRequest = result.avmProvingRequest;
|
|
187
|
-
if (phase === PublicKernelPhase.APP_LOGIC) {
|
|
188
|
-
returnValues = result.returnValues;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
gasUsed[phase] = result.gasUsed;
|
|
192
|
-
|
|
193
|
-
processedPhases.push({
|
|
194
|
-
phase,
|
|
195
|
-
durationMs: result.durationMs,
|
|
196
|
-
revertReason: result.revertReason,
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
revertReason ??= result.revertReason;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
const tailKernelOutput = await this.publicKernelTailSimulator.simulate(publicKernelOutput).catch(
|
|
204
|
-
// the abstract phase manager throws if simulation gives error in non-revertible phase
|
|
205
|
-
async err => {
|
|
206
|
-
await this.worldStateDB.rollbackToCommit();
|
|
207
|
-
throw err;
|
|
208
|
-
},
|
|
209
|
-
);
|
|
210
|
-
|
|
211
|
-
return {
|
|
212
|
-
avmProvingRequest: avmProvingRequest!,
|
|
213
|
-
tailKernelOutput,
|
|
214
|
-
returnValues,
|
|
215
|
-
gasUsed,
|
|
216
|
-
processedPhases,
|
|
217
|
-
revertReason,
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
private async processPhase(
|
|
222
|
-
tx: Tx,
|
|
223
|
-
callRequests: PublicCallRequest[],
|
|
224
|
-
executionRequests: PublicExecutionRequest[],
|
|
225
|
-
previousPublicKernelOutput: PublicKernelCircuitPublicInputs,
|
|
226
|
-
phase: PublicKernelPhase,
|
|
227
|
-
isFromPrivate: boolean,
|
|
228
|
-
): Promise<PublicPhaseResult> {
|
|
229
|
-
this.log.debug(`Beginning processing in phase ${PublicKernelPhase[phase]} for tx ${tx.getTxHash()}`);
|
|
230
|
-
|
|
231
|
-
const phaseTimer = new Timer();
|
|
232
|
-
const returnValues: NestedProcessReturnValues[] = [];
|
|
233
|
-
let avmProvingRequest: AvmProvingRequest;
|
|
234
|
-
let publicKernelOutput = previousPublicKernelOutput;
|
|
235
|
-
let gasUsed = Gas.empty();
|
|
236
|
-
let revertReason: SimulationError | undefined;
|
|
237
|
-
for (let i = callRequests.length - 1; i >= 0 && !revertReason; i--) {
|
|
238
|
-
const callRequest = callRequests[i];
|
|
239
|
-
const executionRequest = executionRequests[i];
|
|
240
|
-
|
|
241
|
-
// add new contracts to the contracts db so that their functions may be found and called
|
|
242
|
-
// TODO(#4073): This is catching only private deployments, when we add public ones, we'll
|
|
243
|
-
// have to capture contracts emitted in that phase as well.
|
|
244
|
-
// TODO(@spalladino): Should we allow emitting contracts in the fee preparation phase?
|
|
245
|
-
// TODO(#6464): Should we allow emitting contracts in the private setup phase?
|
|
246
|
-
// if so, this should only add contracts that were deployed during private app logic.
|
|
247
|
-
await this.worldStateDB.addNewContracts(tx);
|
|
248
|
-
|
|
249
|
-
const availableGas = this.getAvailableGas(tx, publicKernelOutput, phase);
|
|
250
|
-
const transactionFee = this.getTransactionFee(tx, publicKernelOutput, phase);
|
|
251
|
-
|
|
252
|
-
const enqueuedCallResult = await this.enqueuedCallSimulator.simulate(
|
|
253
|
-
callRequest,
|
|
254
|
-
executionRequest,
|
|
255
|
-
tx,
|
|
256
|
-
publicKernelOutput,
|
|
257
|
-
availableGas,
|
|
258
|
-
transactionFee,
|
|
259
|
-
phase,
|
|
260
|
-
);
|
|
261
|
-
|
|
262
|
-
if (enqueuedCallResult.revertReason && !PhaseIsRevertible[phase]) {
|
|
263
|
-
this.log.debug(
|
|
264
|
-
`Simulation error on ${executionRequest.callContext.contractAddress}:${executionRequest.callContext.functionSelector} with reason: ${enqueuedCallResult.revertReason}`,
|
|
265
|
-
);
|
|
266
|
-
throw enqueuedCallResult.revertReason;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
avmProvingRequest = enqueuedCallResult.avmProvingRequest;
|
|
270
|
-
returnValues.push(enqueuedCallResult.returnValues);
|
|
271
|
-
gasUsed = gasUsed.add(enqueuedCallResult.gasUsed);
|
|
272
|
-
revertReason ??= enqueuedCallResult.revertReason;
|
|
273
|
-
|
|
274
|
-
if (revertReason) {
|
|
275
|
-
// TODO(#6464): Should we allow emitting contracts in the private setup phase?
|
|
276
|
-
// if so, this is removing contracts deployed in private setup
|
|
277
|
-
await this.worldStateDB.removeNewContracts(tx);
|
|
278
|
-
await this.worldStateDB.rollbackToCheckpoint();
|
|
279
|
-
tx.filterRevertedLogs(publicKernelOutput);
|
|
280
|
-
} else {
|
|
281
|
-
// TODO(#6470): we should be adding contracts deployed in those logs to the publicContractsDB
|
|
282
|
-
tx.unencryptedLogs.addFunctionLogs([enqueuedCallResult.newUnencryptedLogs]);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
const output = await this.runMergeKernelCircuit(
|
|
286
|
-
publicKernelOutput,
|
|
287
|
-
enqueuedCallResult.kernelOutput,
|
|
288
|
-
isFromPrivate,
|
|
289
|
-
);
|
|
290
|
-
publicKernelOutput = output;
|
|
291
|
-
isFromPrivate = false;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
if (phase === PublicKernelPhase.SETUP) {
|
|
295
|
-
await this.worldStateDB.checkpoint();
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
return {
|
|
299
|
-
avmProvingRequest: avmProvingRequest!,
|
|
300
|
-
publicKernelOutput,
|
|
301
|
-
durationMs: phaseTimer.ms(),
|
|
302
|
-
gasUsed,
|
|
303
|
-
returnValues: revertReason ? [] : returnValues,
|
|
304
|
-
revertReason,
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
private getAvailableGas(
|
|
309
|
-
tx: Tx,
|
|
310
|
-
previousPublicKernelOutput: PublicKernelCircuitPublicInputs,
|
|
311
|
-
phase: PublicKernelPhase,
|
|
312
|
-
) {
|
|
313
|
-
if (phase === PublicKernelPhase.TEARDOWN) {
|
|
314
|
-
return tx.data.constants.txContext.gasSettings.getTeardownLimits();
|
|
315
|
-
} else {
|
|
316
|
-
return tx.data.constants.txContext.gasSettings
|
|
317
|
-
.getLimits() // No need to subtract teardown limits since they are already included in end.gasUsed
|
|
318
|
-
.sub(previousPublicKernelOutput.end.gasUsed)
|
|
319
|
-
.sub(previousPublicKernelOutput.endNonRevertibleData.gasUsed);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
private getTransactionFee(
|
|
324
|
-
tx: Tx,
|
|
325
|
-
previousPublicKernelOutput: PublicKernelCircuitPublicInputs,
|
|
326
|
-
phase: PublicKernelPhase,
|
|
327
|
-
): Fr {
|
|
328
|
-
if (phase !== PublicKernelPhase.TEARDOWN) {
|
|
329
|
-
return Fr.ZERO;
|
|
330
|
-
} else {
|
|
331
|
-
const gasSettings = tx.data.constants.txContext.gasSettings;
|
|
332
|
-
const gasFees = this.globalVariables.gasFees;
|
|
333
|
-
// No need to add teardown limits since they are already included in end.gasUsed
|
|
334
|
-
const gasUsed = previousPublicKernelOutput.end.gasUsed.add(
|
|
335
|
-
previousPublicKernelOutput.endNonRevertibleData.gasUsed,
|
|
336
|
-
);
|
|
337
|
-
const txFee = gasSettings.inclusionFee.add(gasUsed.computeFee(gasFees));
|
|
338
|
-
this.log.debug(`Computed tx fee`, { txFee, gasUsed: inspect(gasUsed), gasFees: inspect(gasFees) });
|
|
339
|
-
return txFee;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
private async runMergeKernelCircuit(
|
|
344
|
-
previousOutput: PublicKernelCircuitPublicInputs,
|
|
345
|
-
enqueuedCallData: VMCircuitPublicInputs,
|
|
346
|
-
isFromPrivate: boolean,
|
|
347
|
-
): Promise<PublicKernelCircuitPublicInputs> {
|
|
348
|
-
const previousKernel = this.getPreviousKernelData(previousOutput, isFromPrivate);
|
|
349
|
-
|
|
350
|
-
// The proof is not used in simulation.
|
|
351
|
-
const vmProof = makeEmptyProof();
|
|
352
|
-
const callData = new EnqueuedCallData(enqueuedCallData, vmProof);
|
|
353
|
-
|
|
354
|
-
const inputs = new PublicKernelCircuitPrivateInputs(previousKernel, callData);
|
|
355
|
-
|
|
356
|
-
return await this.publicKernelSimulator.publicKernelCircuitMerge(inputs);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
private getPreviousKernelData(
|
|
360
|
-
previousOutput: PublicKernelCircuitPublicInputs,
|
|
361
|
-
_isFromPrivate: boolean,
|
|
362
|
-
): PublicKernelData {
|
|
363
|
-
// The proof is not used in simulation.
|
|
364
|
-
const proof = makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH);
|
|
365
|
-
|
|
366
|
-
const vk = VerificationKeyData.makeFakeHonk();
|
|
367
|
-
const vkIndex = 0;
|
|
368
|
-
const siblingPath = getVKSiblingPath(vkIndex);
|
|
369
|
-
|
|
370
|
-
return new PublicKernelData(previousOutput, proof, vk, vkIndex, siblingPath);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import { type IndexedTreeId, MerkleTreeId } from '@aztec/circuit-types';
|
|
2
|
-
import {
|
|
3
|
-
type Fr,
|
|
4
|
-
L1_TO_L2_MSG_TREE_HEIGHT,
|
|
5
|
-
MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_TX,
|
|
6
|
-
MAX_NOTE_HASH_READ_REQUESTS_PER_TX,
|
|
7
|
-
type MAX_NULLIFIERS_PER_TX,
|
|
8
|
-
type MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX,
|
|
9
|
-
MAX_NULLIFIER_READ_REQUESTS_PER_TX,
|
|
10
|
-
type MAX_PUBLIC_DATA_READS_PER_TX,
|
|
11
|
-
type MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
12
|
-
MembershipWitness,
|
|
13
|
-
NOTE_HASH_TREE_HEIGHT,
|
|
14
|
-
NULLIFIER_TREE_HEIGHT,
|
|
15
|
-
type Nullifier,
|
|
16
|
-
type NullifierLeafPreimage,
|
|
17
|
-
PUBLIC_DATA_TREE_HEIGHT,
|
|
18
|
-
type PublicDataRead,
|
|
19
|
-
type PublicDataTreeLeafPreimage,
|
|
20
|
-
type PublicDataUpdateRequest,
|
|
21
|
-
type ScopedReadRequest,
|
|
22
|
-
type TreeLeafReadRequest,
|
|
23
|
-
TreeLeafReadRequestHint,
|
|
24
|
-
buildNullifierNonExistentReadRequestHints,
|
|
25
|
-
buildPublicDataHint,
|
|
26
|
-
buildPublicDataHints,
|
|
27
|
-
buildSiloedNullifierReadRequestHints,
|
|
28
|
-
} from '@aztec/circuits.js';
|
|
29
|
-
import { makeTuple } from '@aztec/foundation/array';
|
|
30
|
-
import { type Tuple } from '@aztec/foundation/serialize';
|
|
31
|
-
import { type IndexedTreeLeafPreimage } from '@aztec/foundation/trees';
|
|
32
|
-
import { type MerkleTreeReadOperations } from '@aztec/world-state';
|
|
33
|
-
|
|
34
|
-
export class HintsBuilder {
|
|
35
|
-
constructor(private db: MerkleTreeReadOperations) {}
|
|
36
|
-
|
|
37
|
-
async getNoteHashReadRequestsHints(
|
|
38
|
-
readRequests: Tuple<TreeLeafReadRequest, typeof MAX_NOTE_HASH_READ_REQUESTS_PER_TX>,
|
|
39
|
-
) {
|
|
40
|
-
return await this.getTreeLeafReadRequestsHints(
|
|
41
|
-
readRequests,
|
|
42
|
-
MAX_NOTE_HASH_READ_REQUESTS_PER_TX,
|
|
43
|
-
NOTE_HASH_TREE_HEIGHT,
|
|
44
|
-
MerkleTreeId.NOTE_HASH_TREE,
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async getNullifierReadRequestHints(
|
|
49
|
-
nullifierReadRequests: Tuple<ScopedReadRequest, typeof MAX_NULLIFIER_READ_REQUESTS_PER_TX>,
|
|
50
|
-
pendingNullifiers: Tuple<Nullifier, typeof MAX_NULLIFIERS_PER_TX>,
|
|
51
|
-
) {
|
|
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
|
-
}
|
|
60
|
-
|
|
61
|
-
getNullifierNonExistentReadRequestHints(
|
|
62
|
-
nullifierNonExistentReadRequests: Tuple<ScopedReadRequest, typeof MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX>,
|
|
63
|
-
pendingNullifiers: Tuple<Nullifier, typeof MAX_NULLIFIERS_PER_TX>,
|
|
64
|
-
) {
|
|
65
|
-
return buildNullifierNonExistentReadRequestHints(this, nullifierNonExistentReadRequests, pendingNullifiers);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async getL1ToL2MsgReadRequestsHints(
|
|
69
|
-
readRequests: Tuple<TreeLeafReadRequest, typeof MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_TX>,
|
|
70
|
-
) {
|
|
71
|
-
return await this.getTreeLeafReadRequestsHints(
|
|
72
|
-
readRequests,
|
|
73
|
-
MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_TX,
|
|
74
|
-
L1_TO_L2_MSG_TREE_HEIGHT,
|
|
75
|
-
MerkleTreeId.L1_TO_L2_MESSAGE_TREE,
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
getPublicDataHints(
|
|
80
|
-
publicDataReads: Tuple<PublicDataRead, typeof MAX_PUBLIC_DATA_READS_PER_TX>,
|
|
81
|
-
publicDataUpdateRequests: Tuple<PublicDataUpdateRequest, typeof MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX>,
|
|
82
|
-
) {
|
|
83
|
-
return buildPublicDataHints(this, publicDataReads, publicDataUpdateRequests);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
getPublicDataHint(dataAction: PublicDataRead | PublicDataUpdateRequest | bigint) {
|
|
87
|
-
const slot = typeof dataAction === 'bigint' ? dataAction : dataAction.leafSlot.toBigInt();
|
|
88
|
-
return buildPublicDataHint(this, slot);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async getNullifierMembershipWitness(nullifier: Fr) {
|
|
92
|
-
const index = await this.db.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBuffer());
|
|
93
|
-
if (index === undefined) {
|
|
94
|
-
throw new Error(`Cannot find the leaf for nullifier ${nullifier.toBigInt()}.`);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return this.getMembershipWitnessWithPreimage<typeof NULLIFIER_TREE_HEIGHT>(
|
|
98
|
-
MerkleTreeId.NULLIFIER_TREE,
|
|
99
|
-
NULLIFIER_TREE_HEIGHT,
|
|
100
|
-
index,
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
async getLowNullifierMembershipWitness(nullifier: Fr) {
|
|
105
|
-
const res = await this.db.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
106
|
-
if (!res) {
|
|
107
|
-
throw new Error(`Cannot find the low leaf for nullifier ${nullifier.toBigInt()}.`);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const { index, alreadyPresent } = res;
|
|
111
|
-
if (alreadyPresent) {
|
|
112
|
-
throw new Error(`Nullifier ${nullifier.toBigInt()} already exists in the tree.`);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Should find a way to stop casting IndexedTreeLeafPreimage as NullifierLeafPreimage
|
|
116
|
-
return this.getMembershipWitnessWithPreimage<typeof NULLIFIER_TREE_HEIGHT, NullifierLeafPreimage>(
|
|
117
|
-
MerkleTreeId.NULLIFIER_TREE,
|
|
118
|
-
NULLIFIER_TREE_HEIGHT,
|
|
119
|
-
index,
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
async getMatchOrLowPublicDataMembershipWitness(leafSlot: bigint) {
|
|
124
|
-
const res = await this.db.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot);
|
|
125
|
-
if (!res) {
|
|
126
|
-
throw new Error(`Cannot find the previous value index for public data ${leafSlot}.`);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Should find a way to stop casting IndexedTreeLeafPreimage as PublicDataTreeLeafPreimage everywhere.
|
|
130
|
-
return this.getMembershipWitnessWithPreimage<typeof PUBLIC_DATA_TREE_HEIGHT, PublicDataTreeLeafPreimage>(
|
|
131
|
-
MerkleTreeId.PUBLIC_DATA_TREE,
|
|
132
|
-
PUBLIC_DATA_TREE_HEIGHT,
|
|
133
|
-
res.index,
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
private async getMembershipWitnessWithPreimage<
|
|
138
|
-
TREE_HEIGHT extends number,
|
|
139
|
-
LEAF_PREIMAGE extends IndexedTreeLeafPreimage = IndexedTreeLeafPreimage,
|
|
140
|
-
>(treeId: IndexedTreeId, treeHeight: TREE_HEIGHT, index: bigint) {
|
|
141
|
-
const siblingPath = await this.db.getSiblingPath<TREE_HEIGHT>(treeId, index);
|
|
142
|
-
const membershipWitness = new MembershipWitness(treeHeight, index, siblingPath.toTuple());
|
|
143
|
-
|
|
144
|
-
const leafPreimage = (await this.db.getLeafPreimage(treeId, index)) as LEAF_PREIMAGE;
|
|
145
|
-
if (!leafPreimage) {
|
|
146
|
-
throw new Error(`Cannot find the leaf preimage for tree ${treeId} at index ${index}.`);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return { membershipWitness, leafPreimage };
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
private async getTreeLeafReadRequestsHints<N extends number, TREE_HEIGHT extends number>(
|
|
153
|
-
readRequests: Tuple<TreeLeafReadRequest, N>,
|
|
154
|
-
size: N,
|
|
155
|
-
treeHeight: TREE_HEIGHT,
|
|
156
|
-
treeId: MerkleTreeId,
|
|
157
|
-
): Promise<Tuple<TreeLeafReadRequestHint<TREE_HEIGHT>, N>> {
|
|
158
|
-
const hints = makeTuple(size, () => TreeLeafReadRequestHint.empty(treeHeight));
|
|
159
|
-
for (let i = 0; i < readRequests.length; i++) {
|
|
160
|
-
const request = readRequests[i];
|
|
161
|
-
if (!request.isEmpty()) {
|
|
162
|
-
const siblingPath = await this.db.getSiblingPath<typeof treeHeight>(treeId, request.leafIndex.toBigInt());
|
|
163
|
-
hints[i] = new TreeLeafReadRequestHint(treeHeight, siblingPath.toTuple());
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return hints;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type KernelCircuitPublicInputs,
|
|
3
|
-
type PublicKernelCircuitPrivateInputs,
|
|
4
|
-
type PublicKernelCircuitPublicInputs,
|
|
5
|
-
type PublicKernelInnerCircuitPrivateInputs,
|
|
6
|
-
type PublicKernelTailCircuitPrivateInputs,
|
|
7
|
-
type VMCircuitPublicInputs,
|
|
8
|
-
} from '@aztec/circuits.js';
|
|
9
|
-
import { createDebugLogger } from '@aztec/foundation/log';
|
|
10
|
-
import { elapsed } from '@aztec/foundation/timer';
|
|
11
|
-
import {
|
|
12
|
-
SimulatedPublicKernelInnerArtifact,
|
|
13
|
-
SimulatedPublicKernelMergeArtifact,
|
|
14
|
-
SimulatedPublicKernelTailArtifact,
|
|
15
|
-
convertSimulatedPublicInnerInputsToWitnessMap,
|
|
16
|
-
convertSimulatedPublicInnerOutputFromWitnessMap,
|
|
17
|
-
convertSimulatedPublicMergeInputsToWitnessMap,
|
|
18
|
-
convertSimulatedPublicMergeOutputFromWitnessMap,
|
|
19
|
-
convertSimulatedPublicTailInputsToWitnessMap,
|
|
20
|
-
convertSimulatedPublicTailOutputFromWitnessMap,
|
|
21
|
-
} from '@aztec/noir-protocol-circuits-types';
|
|
22
|
-
|
|
23
|
-
import { type SimulationProvider } from '../providers/simulation_provider.js';
|
|
24
|
-
import { type PublicKernelCircuitSimulator } from './public_kernel_circuit_simulator.js';
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Implements the PublicKernelCircuitSimulator.
|
|
28
|
-
*/
|
|
29
|
-
export class RealPublicKernelCircuitSimulator implements PublicKernelCircuitSimulator {
|
|
30
|
-
private log = createDebugLogger('aztec:public-kernel-simulator');
|
|
31
|
-
|
|
32
|
-
constructor(private simulator: SimulationProvider) {}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Simulates the public kernel setup circuit from its inputs.
|
|
36
|
-
* @param input - Inputs to the circuit.
|
|
37
|
-
* @returns The public inputs as outputs of the simulation.
|
|
38
|
-
*/
|
|
39
|
-
public async publicKernelCircuitInner(input: PublicKernelInnerCircuitPrivateInputs): Promise<VMCircuitPublicInputs> {
|
|
40
|
-
const inputWitness = convertSimulatedPublicInnerInputsToWitnessMap(input);
|
|
41
|
-
const [duration, witness] = await elapsed(() =>
|
|
42
|
-
this.simulator.simulateCircuit(inputWitness, SimulatedPublicKernelInnerArtifact),
|
|
43
|
-
);
|
|
44
|
-
const result = convertSimulatedPublicInnerOutputFromWitnessMap(witness);
|
|
45
|
-
this.log.debug(`Simulated public kernel inner circuit`, {
|
|
46
|
-
eventName: 'circuit-simulation',
|
|
47
|
-
circuitName: 'public-kernel-inner',
|
|
48
|
-
duration,
|
|
49
|
-
inputSize: input.toBuffer().length,
|
|
50
|
-
outputSize: result.toBuffer().length,
|
|
51
|
-
});
|
|
52
|
-
return result;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Simulates the public kernel app logic circuit from its inputs.
|
|
57
|
-
* @param input - Inputs to the circuit.
|
|
58
|
-
* @returns The public inputs as outputs of the simulation.
|
|
59
|
-
*/
|
|
60
|
-
public async publicKernelCircuitMerge(
|
|
61
|
-
input: PublicKernelCircuitPrivateInputs,
|
|
62
|
-
): Promise<PublicKernelCircuitPublicInputs> {
|
|
63
|
-
const inputWitness = convertSimulatedPublicMergeInputsToWitnessMap(input);
|
|
64
|
-
const [duration, witness] = await elapsed(() =>
|
|
65
|
-
this.simulator.simulateCircuit(inputWitness, SimulatedPublicKernelMergeArtifact),
|
|
66
|
-
);
|
|
67
|
-
const result = convertSimulatedPublicMergeOutputFromWitnessMap(witness);
|
|
68
|
-
this.log.debug(`Simulated public kernel merge circuit`, {
|
|
69
|
-
eventName: 'circuit-simulation',
|
|
70
|
-
circuitName: 'public-kernel-merge',
|
|
71
|
-
duration,
|
|
72
|
-
inputSize: input.toBuffer().length,
|
|
73
|
-
outputSize: result.toBuffer().length,
|
|
74
|
-
});
|
|
75
|
-
return result;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Simulates the public kernel tail circuit from its inputs.
|
|
80
|
-
* @param input - Inputs to the circuit.
|
|
81
|
-
* @returns The public inputs as outputs of the simulation.
|
|
82
|
-
*/
|
|
83
|
-
public async publicKernelCircuitTail(
|
|
84
|
-
input: PublicKernelTailCircuitPrivateInputs,
|
|
85
|
-
): Promise<KernelCircuitPublicInputs> {
|
|
86
|
-
const inputWitness = convertSimulatedPublicTailInputsToWitnessMap(input);
|
|
87
|
-
const [duration, witness] = await elapsed(() =>
|
|
88
|
-
this.simulator.simulateCircuit(inputWitness, SimulatedPublicKernelTailArtifact),
|
|
89
|
-
);
|
|
90
|
-
const result = convertSimulatedPublicTailOutputFromWitnessMap(witness);
|
|
91
|
-
this.log.debug(`Simulated public kernel tail circuit`, {
|
|
92
|
-
eventName: 'circuit-simulation',
|
|
93
|
-
circuitName: 'public-kernel-tail',
|
|
94
|
-
duration,
|
|
95
|
-
inputSize: input.toBuffer().length,
|
|
96
|
-
outputSize: result.toBuffer().length,
|
|
97
|
-
});
|
|
98
|
-
return result;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type KernelCircuitPublicInputs,
|
|
3
|
-
type PublicKernelCircuitPrivateInputs,
|
|
4
|
-
type PublicKernelCircuitPublicInputs,
|
|
5
|
-
type PublicKernelInnerCircuitPrivateInputs,
|
|
6
|
-
type PublicKernelTailCircuitPrivateInputs,
|
|
7
|
-
type VMCircuitPublicInputs,
|
|
8
|
-
} from '@aztec/circuits.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Circuit simulator for the public kernel circuits.
|
|
12
|
-
*/
|
|
13
|
-
export interface PublicKernelCircuitSimulator {
|
|
14
|
-
/**
|
|
15
|
-
* Simulates the public kernel inner circuit from its inputs.
|
|
16
|
-
* @param inputs - Inputs to the circuit.
|
|
17
|
-
* @returns The public inputs as outputs of the simulation.
|
|
18
|
-
*/
|
|
19
|
-
publicKernelCircuitInner(inputs: PublicKernelInnerCircuitPrivateInputs): Promise<VMCircuitPublicInputs>;
|
|
20
|
-
/**
|
|
21
|
-
* Simulates the public kernel merge circuit from its inputs.
|
|
22
|
-
* @param inputs - Inputs to the circuit.
|
|
23
|
-
* @returns The public inputs as outputs of the simulation.
|
|
24
|
-
*/
|
|
25
|
-
publicKernelCircuitMerge(inputs: PublicKernelCircuitPrivateInputs): Promise<PublicKernelCircuitPublicInputs>;
|
|
26
|
-
/**
|
|
27
|
-
* Simulates the public kernel tail circuit from its inputs.
|
|
28
|
-
* @param inputs - Inputs to the circuit.
|
|
29
|
-
* @returns The public inputs as outputs of the simulation.
|
|
30
|
-
*/
|
|
31
|
-
publicKernelCircuitTail(inputs: PublicKernelTailCircuitPrivateInputs): Promise<KernelCircuitPublicInputs>;
|
|
32
|
-
}
|