@aztec/sequencer-client 0.32.0 → 0.33.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/client/sequencer-client.d.ts +8 -8
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +1 -1
- package/dest/config.d.ts +3 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +1 -1
- package/dest/global_variable_builder/config.d.ts +1 -1
- package/dest/global_variable_builder/config.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.d.ts +1 -1
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +1 -1
- package/dest/global_variable_builder/index.d.ts +2 -2
- package/dest/global_variable_builder/index.d.ts.map +1 -1
- package/dest/global_variable_builder/index.js +1 -1
- package/dest/global_variable_builder/viem-reader.d.ts +2 -2
- package/dest/global_variable_builder/viem-reader.d.ts.map +1 -1
- package/dest/publisher/config.d.ts +1 -1
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/index.d.ts +1 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/l1-publisher.d.ts +3 -3
- package/dest/publisher/l1-publisher.d.ts.map +1 -1
- package/dest/publisher/viem-tx-sender.d.ts +3 -3
- package/dest/publisher/viem-tx-sender.d.ts.map +1 -1
- package/dest/publisher/viem-tx-sender.js +1 -1
- package/dest/receiver.d.ts +1 -1
- package/dest/receiver.d.ts.map +1 -1
- package/dest/sequencer/abstract_phase_manager.d.ts +21 -9
- package/dest/sequencer/abstract_phase_manager.d.ts.map +1 -1
- package/dest/sequencer/abstract_phase_manager.js +38 -39
- package/dest/sequencer/app_logic_phase_manager.d.ts +7 -6
- package/dest/sequencer/app_logic_phase_manager.d.ts.map +1 -1
- package/dest/sequencer/app_logic_phase_manager.js +3 -3
- package/dest/sequencer/hints_builder.d.ts +9 -5
- package/dest/sequencer/hints_builder.d.ts.map +1 -1
- package/dest/sequencer/hints_builder.js +24 -4
- package/dest/sequencer/phase_manager_factory.d.ts +7 -7
- package/dest/sequencer/phase_manager_factory.d.ts.map +1 -1
- package/dest/sequencer/phase_manager_factory.js +5 -4
- package/dest/sequencer/public_processor.d.ts +10 -7
- package/dest/sequencer/public_processor.d.ts.map +1 -1
- package/dest/sequencer/public_processor.js +65 -27
- package/dest/sequencer/sequencer.d.ts +11 -21
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +33 -38
- package/dest/sequencer/setup_phase_manager.d.ts +7 -6
- package/dest/sequencer/setup_phase_manager.d.ts.map +1 -1
- package/dest/sequencer/setup_phase_manager.js +2 -2
- package/dest/sequencer/tail_phase_manager.d.ts +11 -6
- package/dest/sequencer/tail_phase_manager.d.ts.map +1 -1
- package/dest/sequencer/tail_phase_manager.js +28 -3
- package/dest/sequencer/teardown_phase_manager.d.ts +7 -6
- package/dest/sequencer/teardown_phase_manager.d.ts.map +1 -1
- package/dest/sequencer/teardown_phase_manager.js +2 -2
- package/dest/sequencer/tx_validator.d.ts +3 -3
- package/dest/sequencer/tx_validator.d.ts.map +1 -1
- package/dest/sequencer/tx_validator.js +9 -8
- package/dest/sequencer/tx_validator_factory.d.ts +3 -3
- package/dest/sequencer/tx_validator_factory.d.ts.map +1 -1
- package/dest/sequencer/utils.d.ts +1 -1
- package/dest/sequencer/utils.d.ts.map +1 -1
- package/dest/sequencer/utils.js +8 -7
- package/dest/simulator/index.d.ts +2 -2
- package/dest/simulator/index.d.ts.map +1 -1
- package/dest/simulator/public_executor.d.ts +5 -5
- package/dest/simulator/public_executor.d.ts.map +1 -1
- package/dest/simulator/public_executor.js +2 -2
- package/dest/simulator/public_kernel.d.ts +4 -4
- package/dest/simulator/public_kernel.d.ts.map +1 -1
- package/dest/simulator/public_kernel.js +1 -1
- package/package.json +32 -15
- package/src/client/sequencer-client.ts +8 -8
- package/src/config.ts +5 -5
- package/src/global_variable_builder/config.ts +1 -1
- package/src/global_variable_builder/global_builder.ts +1 -1
- package/src/global_variable_builder/index.ts +2 -2
- package/src/global_variable_builder/viem-reader.ts +6 -6
- package/src/publisher/config.ts +1 -1
- package/src/publisher/index.ts +1 -1
- package/src/publisher/l1-publisher.ts +4 -4
- package/src/publisher/viem-tx-sender.ts +12 -12
- package/src/receiver.ts +1 -1
- package/src/sequencer/abstract_phase_manager.ts +88 -77
- package/src/sequencer/app_logic_phase_manager.ts +13 -8
- package/src/sequencer/hints_builder.ts +49 -16
- package/src/sequencer/phase_manager_factory.ts +11 -10
- package/src/sequencer/public_processor.ts +105 -59
- package/src/sequencer/sequencer.ts +52 -61
- package/src/sequencer/setup_phase_manager.ts +12 -7
- package/src/sequencer/tail_phase_manager.ts +77 -8
- package/src/sequencer/teardown_phase_manager.ts +12 -7
- package/src/sequencer/tx_validator.ts +18 -10
- package/src/sequencer/tx_validator_factory.ts +3 -3
- package/src/sequencer/utils.ts +8 -7
- package/src/simulator/index.ts +5 -4
- package/src/simulator/public_executor.ts +20 -11
- package/src/simulator/public_kernel.ts +8 -7
- package/dest/utils.d.ts +0 -12
- package/dest/utils.d.ts.map +0 -1
- package/dest/utils.js +0 -16
- package/src/utils.ts +0 -16
|
@@ -1,37 +1,36 @@
|
|
|
1
|
-
import { MerkleTreeId, SimulationError, Tx, UnencryptedFunctionL2Logs } from '@aztec/circuit-types';
|
|
1
|
+
import { MerkleTreeId, type SimulationError, type Tx, type UnencryptedFunctionL2Logs } from '@aztec/circuit-types';
|
|
2
2
|
import {
|
|
3
3
|
AztecAddress,
|
|
4
4
|
CallRequest,
|
|
5
5
|
ContractStorageRead,
|
|
6
6
|
ContractStorageUpdateRequest,
|
|
7
7
|
Fr,
|
|
8
|
-
GlobalVariables,
|
|
9
|
-
Header,
|
|
8
|
+
type GlobalVariables,
|
|
9
|
+
type Header,
|
|
10
|
+
type KernelCircuitPublicInputs,
|
|
10
11
|
L2ToL1Message,
|
|
11
12
|
MAX_NEW_L2_TO_L1_MSGS_PER_CALL,
|
|
12
13
|
MAX_NEW_NOTE_HASHES_PER_CALL,
|
|
13
14
|
MAX_NEW_NULLIFIERS_PER_CALL,
|
|
14
|
-
MAX_NON_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
15
15
|
MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL,
|
|
16
16
|
MAX_NULLIFIER_READ_REQUESTS_PER_CALL,
|
|
17
17
|
MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL,
|
|
18
18
|
MAX_PUBLIC_DATA_READS_PER_CALL,
|
|
19
19
|
MAX_PUBLIC_DATA_READS_PER_TX,
|
|
20
20
|
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,
|
|
21
|
-
|
|
21
|
+
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
22
22
|
MembershipWitness,
|
|
23
|
-
PrivateKernelTailCircuitPublicInputs,
|
|
24
|
-
Proof,
|
|
23
|
+
type PrivateKernelTailCircuitPublicInputs,
|
|
24
|
+
type Proof,
|
|
25
25
|
PublicCallData,
|
|
26
|
-
PublicCallRequest,
|
|
26
|
+
type PublicCallRequest,
|
|
27
27
|
PublicCallStackItem,
|
|
28
28
|
PublicCircuitPublicInputs,
|
|
29
29
|
PublicDataRead,
|
|
30
30
|
PublicDataUpdateRequest,
|
|
31
31
|
PublicKernelCircuitPrivateInputs,
|
|
32
|
-
PublicKernelCircuitPublicInputs,
|
|
32
|
+
type PublicKernelCircuitPublicInputs,
|
|
33
33
|
PublicKernelData,
|
|
34
|
-
PublicKernelTailCircuitPrivateInputs,
|
|
35
34
|
RETURN_VALUES_LENGTH,
|
|
36
35
|
ReadRequest,
|
|
37
36
|
RevertCode,
|
|
@@ -42,20 +41,27 @@ import {
|
|
|
42
41
|
makeEmptyProof,
|
|
43
42
|
} from '@aztec/circuits.js';
|
|
44
43
|
import { computeVarArgsHash } from '@aztec/circuits.js/hash';
|
|
44
|
+
import {
|
|
45
|
+
type AbiType,
|
|
46
|
+
type DecodedReturn,
|
|
47
|
+
type FunctionArtifact,
|
|
48
|
+
type ProcessReturnValues,
|
|
49
|
+
decodeReturnValues,
|
|
50
|
+
} from '@aztec/foundation/abi';
|
|
45
51
|
import { arrayNonEmptyLength, padArrayEnd } from '@aztec/foundation/collection';
|
|
46
|
-
import { DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
47
|
-
import { Tuple } from '@aztec/foundation/serialize';
|
|
52
|
+
import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
|
|
53
|
+
import { type Tuple } from '@aztec/foundation/serialize';
|
|
48
54
|
import {
|
|
49
|
-
PublicExecution,
|
|
50
|
-
PublicExecutionResult,
|
|
51
|
-
PublicExecutor,
|
|
55
|
+
type PublicExecution,
|
|
56
|
+
type PublicExecutionResult,
|
|
57
|
+
type PublicExecutor,
|
|
52
58
|
collectPublicDataReads,
|
|
53
59
|
collectPublicDataUpdateRequests,
|
|
54
60
|
isPublicExecutionResult,
|
|
55
61
|
} from '@aztec/simulator';
|
|
56
|
-
import { MerkleTreeOperations } from '@aztec/world-state';
|
|
62
|
+
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
57
63
|
|
|
58
|
-
import { PublicKernelCircuitSimulator } from '../simulator/index.js';
|
|
64
|
+
import { type PublicKernelCircuitSimulator } from '../simulator/index.js';
|
|
59
65
|
import { HintsBuilder } from './hints_builder.js';
|
|
60
66
|
import { lastSideEffectCounter } from './utils.js';
|
|
61
67
|
|
|
@@ -102,6 +108,10 @@ export abstract class AbstractPhaseManager {
|
|
|
102
108
|
* the output of the public kernel circuit for this phase
|
|
103
109
|
*/
|
|
104
110
|
publicKernelOutput: PublicKernelCircuitPublicInputs;
|
|
111
|
+
/**
|
|
112
|
+
* the final output of the public kernel circuit for this phase
|
|
113
|
+
*/
|
|
114
|
+
finalKernelOutput?: KernelCircuitPublicInputs;
|
|
105
115
|
/**
|
|
106
116
|
* the proof of the public kernel circuit for this phase
|
|
107
117
|
*/
|
|
@@ -110,6 +120,7 @@ export abstract class AbstractPhaseManager {
|
|
|
110
120
|
* revert reason, if any
|
|
111
121
|
*/
|
|
112
122
|
revertReason: SimulationError | undefined;
|
|
123
|
+
returnValues: ProcessReturnValues;
|
|
113
124
|
}>;
|
|
114
125
|
|
|
115
126
|
public static extractEnqueuedPublicCallsByPhase(
|
|
@@ -117,8 +128,10 @@ export abstract class AbstractPhaseManager {
|
|
|
117
128
|
enqueuedPublicFunctionCalls: PublicCallRequest[],
|
|
118
129
|
): Record<PublicKernelPhase, PublicCallRequest[]> {
|
|
119
130
|
const publicCallsStack = enqueuedPublicFunctionCalls.slice().reverse();
|
|
120
|
-
const nonRevertibleCallStack = publicInputs.endNonRevertibleData.publicCallStack.filter(
|
|
121
|
-
|
|
131
|
+
const nonRevertibleCallStack = publicInputs.forPublic!.endNonRevertibleData.publicCallStack.filter(
|
|
132
|
+
i => !i.isEmpty(),
|
|
133
|
+
);
|
|
134
|
+
const revertibleCallStack = publicInputs.forPublic!.end.publicCallStack.filter(i => !i.isEmpty());
|
|
122
135
|
|
|
123
136
|
const callRequestsStack = publicCallsStack
|
|
124
137
|
.map(call => call.toCallRequest())
|
|
@@ -180,14 +193,22 @@ export abstract class AbstractPhaseManager {
|
|
|
180
193
|
tx: Tx,
|
|
181
194
|
previousPublicKernelOutput: PublicKernelCircuitPublicInputs,
|
|
182
195
|
previousPublicKernelProof: Proof,
|
|
183
|
-
): Promise<
|
|
196
|
+
): Promise<
|
|
197
|
+
[
|
|
198
|
+
PublicKernelCircuitPublicInputs,
|
|
199
|
+
Proof,
|
|
200
|
+
UnencryptedFunctionL2Logs[],
|
|
201
|
+
SimulationError | undefined,
|
|
202
|
+
ProcessReturnValues,
|
|
203
|
+
]
|
|
204
|
+
> {
|
|
184
205
|
let kernelOutput = previousPublicKernelOutput;
|
|
185
206
|
let kernelProof = previousPublicKernelProof;
|
|
186
207
|
|
|
187
208
|
const enqueuedCalls = this.extractEnqueuedPublicCalls(tx);
|
|
188
209
|
|
|
189
210
|
if (!enqueuedCalls || !enqueuedCalls.length) {
|
|
190
|
-
return [kernelOutput, kernelProof, [], undefined];
|
|
211
|
+
return [kernelOutput, kernelProof, [], undefined, undefined];
|
|
191
212
|
}
|
|
192
213
|
|
|
193
214
|
const newUnencryptedFunctionLogs: UnencryptedFunctionL2Logs[] = [];
|
|
@@ -196,9 +217,13 @@ export abstract class AbstractPhaseManager {
|
|
|
196
217
|
// separate public callstacks to be proven by separate public kernel sequences
|
|
197
218
|
// and submitted separately to the base rollup?
|
|
198
219
|
|
|
220
|
+
const returns = [];
|
|
221
|
+
|
|
199
222
|
for (const enqueuedCall of enqueuedCalls) {
|
|
200
223
|
const executionStack: (PublicExecution | PublicExecutionResult)[] = [enqueuedCall];
|
|
201
224
|
|
|
225
|
+
let currentReturn: DecodedReturn | undefined = undefined;
|
|
226
|
+
|
|
202
227
|
// Keep track of which result is for the top/enqueued call
|
|
203
228
|
let enqueuedExecutionResult: PublicExecutionResult | undefined;
|
|
204
229
|
|
|
@@ -207,13 +232,9 @@ export abstract class AbstractPhaseManager {
|
|
|
207
232
|
const isExecutionRequest = !isPublicExecutionResult(current);
|
|
208
233
|
|
|
209
234
|
const sideEffectCounter = lastSideEffectCounter(tx) + 1;
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
? this.publicExecutor.simulateAvm(execution, globalVariables, sideEffectCounter)
|
|
214
|
-
: this.publicExecutor.simulate(execution, globalVariables, sideEffectCounter);
|
|
215
|
-
|
|
216
|
-
const result = isExecutionRequest ? await simulator(current, this.globalVariables) : current;
|
|
235
|
+
const result = isExecutionRequest
|
|
236
|
+
? await this.publicExecutor.simulate(current, this.globalVariables, sideEffectCounter)
|
|
237
|
+
: current;
|
|
217
238
|
|
|
218
239
|
const functionSelector = result.execution.functionData.selector.toString();
|
|
219
240
|
if (result.reverted && !PhaseIsRevertible[this.phase]) {
|
|
@@ -238,7 +259,7 @@ export abstract class AbstractPhaseManager {
|
|
|
238
259
|
// sanity check. Note we can't expect them to just be equal, because e.g.
|
|
239
260
|
// if the simulator reverts in app logic, it "resets" and result.reverted will be false when we run teardown,
|
|
240
261
|
// but the kernel carries the reverted flag forward. But if the simulator reverts, so should the kernel.
|
|
241
|
-
if (result.reverted && kernelOutput.
|
|
262
|
+
if (result.reverted && kernelOutput.revertCode.isOK()) {
|
|
242
263
|
throw new Error(
|
|
243
264
|
`Public kernel circuit did not revert on ${result.execution.contractAddress.toString()}:${functionSelector}, but simulator did.`,
|
|
244
265
|
);
|
|
@@ -252,64 +273,52 @@ export abstract class AbstractPhaseManager {
|
|
|
252
273
|
result.revertReason
|
|
253
274
|
}`,
|
|
254
275
|
);
|
|
255
|
-
return [kernelOutput, kernelProof, [], result.revertReason];
|
|
276
|
+
return [kernelOutput, kernelProof, [], result.revertReason, undefined];
|
|
256
277
|
}
|
|
257
278
|
|
|
258
279
|
if (!enqueuedExecutionResult) {
|
|
259
280
|
enqueuedExecutionResult = result;
|
|
281
|
+
|
|
282
|
+
// Padding as the AVM is not always returning the expected return size (4)
|
|
283
|
+
// which is expected by the kernel.
|
|
284
|
+
const paddedReturn = padArrayEnd(result.returnValues, Fr.ZERO, RETURN_VALUES_LENGTH);
|
|
285
|
+
|
|
286
|
+
// TODO(#5450) Need to use the proper return values here
|
|
287
|
+
const returnTypes: AbiType[] = [{ kind: 'array', length: 4, type: { kind: 'field' } }];
|
|
288
|
+
const mockArtifact = { returnTypes } as any as FunctionArtifact;
|
|
289
|
+
|
|
290
|
+
currentReturn = decodeReturnValues(mockArtifact, paddedReturn);
|
|
260
291
|
}
|
|
261
292
|
}
|
|
262
293
|
// HACK(#1622): Manually patches the ordering of public state actions
|
|
263
294
|
// TODO(#757): Enforce proper ordering of public state actions
|
|
264
295
|
patchPublicStorageActionOrdering(kernelOutput, enqueuedExecutionResult!, this.phase);
|
|
296
|
+
|
|
297
|
+
returns.push(currentReturn);
|
|
265
298
|
}
|
|
266
299
|
|
|
267
300
|
// TODO(#3675): This should be done in a public kernel circuit
|
|
268
|
-
removeRedundantPublicDataWrites(kernelOutput);
|
|
301
|
+
removeRedundantPublicDataWrites(kernelOutput, this.phase);
|
|
269
302
|
|
|
270
|
-
return [kernelOutput, kernelProof, newUnencryptedFunctionLogs, undefined];
|
|
303
|
+
return [kernelOutput, kernelProof, newUnencryptedFunctionLogs, undefined, returns];
|
|
271
304
|
}
|
|
272
305
|
|
|
273
306
|
protected async runKernelCircuit(
|
|
274
307
|
previousOutput: PublicKernelCircuitPublicInputs,
|
|
275
308
|
previousProof: Proof,
|
|
276
|
-
callData
|
|
309
|
+
callData: PublicCallData,
|
|
277
310
|
): Promise<[PublicKernelCircuitPublicInputs, Proof]> {
|
|
278
311
|
const output = await this.getKernelCircuitOutput(previousOutput, previousProof, callData);
|
|
279
312
|
return [output, makeEmptyProof()];
|
|
280
313
|
}
|
|
281
314
|
|
|
282
|
-
protected
|
|
315
|
+
protected getKernelCircuitOutput(
|
|
283
316
|
previousOutput: PublicKernelCircuitPublicInputs,
|
|
284
317
|
previousProof: Proof,
|
|
285
|
-
callData
|
|
318
|
+
callData: PublicCallData,
|
|
286
319
|
): Promise<PublicKernelCircuitPublicInputs> {
|
|
287
320
|
const previousKernel = this.getPreviousKernelData(previousOutput, previousProof);
|
|
288
321
|
|
|
289
|
-
if (this.phase === PublicKernelPhase.TAIL) {
|
|
290
|
-
const { validationRequests, endNonRevertibleData, end } = previousOutput;
|
|
291
|
-
const nullifierReadRequestHints = await this.hintsBuilder.getNullifierReadRequestHints(
|
|
292
|
-
validationRequests.nullifierReadRequests,
|
|
293
|
-
endNonRevertibleData.newNullifiers,
|
|
294
|
-
end.newNullifiers,
|
|
295
|
-
);
|
|
296
|
-
const nullifierNonExistentReadRequestHints = await this.hintsBuilder.getNullifierNonExistentReadRequestHints(
|
|
297
|
-
validationRequests.nullifierNonExistentReadRequests,
|
|
298
|
-
endNonRevertibleData.newNullifiers,
|
|
299
|
-
end.newNullifiers,
|
|
300
|
-
);
|
|
301
|
-
const inputs = new PublicKernelTailCircuitPrivateInputs(
|
|
302
|
-
previousKernel,
|
|
303
|
-
nullifierReadRequestHints,
|
|
304
|
-
nullifierNonExistentReadRequestHints,
|
|
305
|
-
);
|
|
306
|
-
return this.publicKernel.publicKernelCircuitTail(inputs);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
if (!callData) {
|
|
310
|
-
throw new Error(`Cannot run public kernel circuit without call data for phase '${this.phase}'.`);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
322
|
const inputs = new PublicKernelCircuitPrivateInputs(previousKernel, callData);
|
|
314
323
|
switch (this.phase) {
|
|
315
324
|
case PublicKernelPhase.SETUP:
|
|
@@ -435,26 +444,30 @@ export abstract class AbstractPhaseManager {
|
|
|
435
444
|
}
|
|
436
445
|
}
|
|
437
446
|
|
|
438
|
-
function removeRedundantPublicDataWrites(publicInputs: PublicKernelCircuitPublicInputs) {
|
|
439
|
-
const
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
const
|
|
443
|
-
lastWritesMap.
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
+
function removeRedundantPublicDataWrites(publicInputs: PublicKernelCircuitPublicInputs, phase: PublicKernelPhase) {
|
|
448
|
+
const lastWritesMap = new Map<string, boolean>();
|
|
449
|
+
const patch = <N extends number>(requests: Tuple<PublicDataUpdateRequest, N>) =>
|
|
450
|
+
requests.filter(write => {
|
|
451
|
+
const leafSlot = write.leafSlot.toString();
|
|
452
|
+
const exists = lastWritesMap.get(leafSlot);
|
|
453
|
+
lastWritesMap.set(leafSlot, true);
|
|
454
|
+
return !exists;
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
const [prev, curr] = PhaseIsRevertible[phase]
|
|
458
|
+
? [publicInputs.endNonRevertibleData, publicInputs.end]
|
|
459
|
+
: [publicInputs.end, publicInputs.endNonRevertibleData];
|
|
447
460
|
|
|
448
|
-
|
|
449
|
-
patch(
|
|
461
|
+
curr.publicDataUpdateRequests = padArrayEnd(
|
|
462
|
+
patch(curr.publicDataUpdateRequests.reverse()).reverse(),
|
|
450
463
|
PublicDataUpdateRequest.empty(),
|
|
451
|
-
|
|
464
|
+
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
452
465
|
);
|
|
453
466
|
|
|
454
|
-
|
|
455
|
-
patch(
|
|
467
|
+
prev.publicDataUpdateRequests = padArrayEnd(
|
|
468
|
+
patch(prev.publicDataUpdateRequests.reverse()),
|
|
456
469
|
PublicDataUpdateRequest.empty(),
|
|
457
|
-
|
|
470
|
+
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
458
471
|
);
|
|
459
472
|
}
|
|
460
473
|
|
|
@@ -531,8 +544,6 @@ function patchPublicStorageActionOrdering(
|
|
|
531
544
|
...simPublicDataUpdateRequests,
|
|
532
545
|
],
|
|
533
546
|
PublicDataUpdateRequest.empty(),
|
|
534
|
-
|
|
535
|
-
? MAX_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX
|
|
536
|
-
: MAX_NON_REVERTIBLE_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
547
|
+
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
537
548
|
);
|
|
538
549
|
}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import { Tx } from '@aztec/circuit-types';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { type Tx } from '@aztec/circuit-types';
|
|
2
|
+
import {
|
|
3
|
+
type GlobalVariables,
|
|
4
|
+
type Header,
|
|
5
|
+
type Proof,
|
|
6
|
+
type PublicKernelCircuitPublicInputs,
|
|
7
|
+
} from '@aztec/circuits.js';
|
|
8
|
+
import { type PublicExecutor, type PublicStateDB } from '@aztec/simulator';
|
|
9
|
+
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
5
10
|
|
|
6
|
-
import { PublicKernelCircuitSimulator } from '../simulator/index.js';
|
|
7
|
-
import { ContractsDataSourcePublicDB } from '../simulator/public_executor.js';
|
|
11
|
+
import { type PublicKernelCircuitSimulator } from '../simulator/index.js';
|
|
12
|
+
import { type ContractsDataSourcePublicDB } from '../simulator/public_executor.js';
|
|
8
13
|
import { AbstractPhaseManager, PublicKernelPhase } from './abstract_phase_manager.js';
|
|
9
14
|
|
|
10
15
|
/**
|
|
@@ -35,7 +40,7 @@ export class AppLogicPhaseManager extends AbstractPhaseManager {
|
|
|
35
40
|
// TODO(@spalladino): Should we allow emitting contracts in the fee preparation phase?
|
|
36
41
|
this.log(`Processing tx ${tx.getTxHash()}`);
|
|
37
42
|
await this.publicContractsDB.addNewContracts(tx);
|
|
38
|
-
const [publicKernelOutput, publicKernelProof, newUnencryptedFunctionLogs, revertReason] =
|
|
43
|
+
const [publicKernelOutput, publicKernelProof, newUnencryptedFunctionLogs, revertReason, returnValues] =
|
|
39
44
|
await this.processEnqueuedPublicCalls(tx, previousPublicKernelOutput, previousPublicKernelProof).catch(
|
|
40
45
|
// if we throw for any reason other than simulation, we need to rollback and drop the TX
|
|
41
46
|
async err => {
|
|
@@ -52,6 +57,6 @@ export class AppLogicPhaseManager extends AbstractPhaseManager {
|
|
|
52
57
|
await this.publicStateDB.checkpoint();
|
|
53
58
|
}
|
|
54
59
|
|
|
55
|
-
return { publicKernelOutput, publicKernelProof, revertReason };
|
|
60
|
+
return { publicKernelOutput, publicKernelProof, revertReason, returnValues };
|
|
56
61
|
}
|
|
57
62
|
}
|
|
@@ -1,43 +1,46 @@
|
|
|
1
1
|
import { MerkleTreeId } from '@aztec/circuit-types';
|
|
2
2
|
import {
|
|
3
|
-
Fr,
|
|
3
|
+
type Fr,
|
|
4
4
|
MAX_NEW_NULLIFIERS_PER_TX,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
MAX_REVERTIBLE_NULLIFIERS_PER_TX,
|
|
5
|
+
type MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX,
|
|
6
|
+
type MAX_NULLIFIER_READ_REQUESTS_PER_TX,
|
|
7
|
+
MAX_PUBLIC_DATA_READS_PER_TX,
|
|
9
8
|
MembershipWitness,
|
|
10
9
|
NULLIFIER_TREE_HEIGHT,
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
PUBLIC_DATA_TREE_HEIGHT,
|
|
11
|
+
type PublicDataRead,
|
|
12
|
+
PublicDataTreeLeafPreimage,
|
|
13
|
+
type ReadRequestContext,
|
|
14
|
+
type SideEffectLinkedToNoteHash,
|
|
13
15
|
buildNullifierNonExistentReadRequestHints,
|
|
14
16
|
buildNullifierReadRequestHints,
|
|
15
|
-
|
|
17
|
+
mergeAccumulatedData,
|
|
16
18
|
} from '@aztec/circuits.js';
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
+
import { makeTuple } from '@aztec/foundation/array';
|
|
20
|
+
import { type Tuple } from '@aztec/foundation/serialize';
|
|
21
|
+
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
19
22
|
|
|
20
23
|
export class HintsBuilder {
|
|
21
24
|
constructor(private db: MerkleTreeOperations) {}
|
|
22
25
|
|
|
23
26
|
getNullifierReadRequestHints(
|
|
24
27
|
nullifierReadRequests: Tuple<ReadRequestContext, typeof MAX_NULLIFIER_READ_REQUESTS_PER_TX>,
|
|
25
|
-
nullifiersNonRevertible: Tuple<SideEffectLinkedToNoteHash, typeof
|
|
26
|
-
nullifiersRevertible: Tuple<SideEffectLinkedToNoteHash, typeof
|
|
28
|
+
nullifiersNonRevertible: Tuple<SideEffectLinkedToNoteHash, typeof MAX_NEW_NULLIFIERS_PER_TX>,
|
|
29
|
+
nullifiersRevertible: Tuple<SideEffectLinkedToNoteHash, typeof MAX_NEW_NULLIFIERS_PER_TX>,
|
|
27
30
|
) {
|
|
28
31
|
return buildNullifierReadRequestHints(
|
|
29
32
|
this,
|
|
30
33
|
nullifierReadRequests,
|
|
31
|
-
|
|
34
|
+
mergeAccumulatedData(MAX_NEW_NULLIFIERS_PER_TX, nullifiersNonRevertible, nullifiersRevertible),
|
|
32
35
|
);
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
getNullifierNonExistentReadRequestHints(
|
|
36
39
|
nullifierNonExistentReadRequests: Tuple<ReadRequestContext, typeof MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX>,
|
|
37
|
-
nullifiersNonRevertible: Tuple<SideEffectLinkedToNoteHash, typeof
|
|
38
|
-
nullifiersRevertible: Tuple<SideEffectLinkedToNoteHash, typeof
|
|
40
|
+
nullifiersNonRevertible: Tuple<SideEffectLinkedToNoteHash, typeof MAX_NEW_NULLIFIERS_PER_TX>,
|
|
41
|
+
nullifiersRevertible: Tuple<SideEffectLinkedToNoteHash, typeof MAX_NEW_NULLIFIERS_PER_TX>,
|
|
39
42
|
) {
|
|
40
|
-
const pendingNullifiers =
|
|
43
|
+
const pendingNullifiers = mergeAccumulatedData(
|
|
41
44
|
MAX_NEW_NULLIFIERS_PER_TX,
|
|
42
45
|
nullifiersNonRevertible,
|
|
43
46
|
nullifiersRevertible,
|
|
@@ -83,4 +86,34 @@ export class HintsBuilder {
|
|
|
83
86
|
|
|
84
87
|
return { membershipWitness, leafPreimage };
|
|
85
88
|
}
|
|
89
|
+
|
|
90
|
+
async getPublicDataReadsInfo(publicDataReads: PublicDataRead[]) {
|
|
91
|
+
const newPublicDataReadsWitnesses: Tuple<
|
|
92
|
+
MembershipWitness<typeof PUBLIC_DATA_TREE_HEIGHT>,
|
|
93
|
+
typeof MAX_PUBLIC_DATA_READS_PER_TX
|
|
94
|
+
> = makeTuple(MAX_PUBLIC_DATA_READS_PER_TX, () => MembershipWitness.empty(PUBLIC_DATA_TREE_HEIGHT, 0n));
|
|
95
|
+
|
|
96
|
+
const newPublicDataReadsPreimages: Tuple<PublicDataTreeLeafPreimage, typeof MAX_PUBLIC_DATA_READS_PER_TX> =
|
|
97
|
+
makeTuple(MAX_PUBLIC_DATA_READS_PER_TX, () => PublicDataTreeLeafPreimage.empty());
|
|
98
|
+
|
|
99
|
+
for (const i in publicDataReads) {
|
|
100
|
+
const leafSlot = publicDataReads[i].leafSlot.value;
|
|
101
|
+
const lowLeafResult = await this.db.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot);
|
|
102
|
+
if (!lowLeafResult) {
|
|
103
|
+
throw new Error(`Public data tree should have one initial leaf`);
|
|
104
|
+
}
|
|
105
|
+
const preimage = await this.db.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
106
|
+
const path = await this.db.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
107
|
+
newPublicDataReadsWitnesses[i] = new MembershipWitness(
|
|
108
|
+
PUBLIC_DATA_TREE_HEIGHT,
|
|
109
|
+
BigInt(lowLeafResult.index),
|
|
110
|
+
path.toTuple<typeof PUBLIC_DATA_TREE_HEIGHT>(),
|
|
111
|
+
);
|
|
112
|
+
newPublicDataReadsPreimages[i] = preimage! as PublicDataTreeLeafPreimage;
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
newPublicDataReadsWitnesses,
|
|
116
|
+
newPublicDataReadsPreimages,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
86
119
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Tx } from '@aztec/circuit-types';
|
|
2
|
-
import { GlobalVariables, Header, PublicKernelCircuitPublicInputs } from '@aztec/circuits.js';
|
|
3
|
-
import { PublicExecutor, PublicStateDB } from '@aztec/simulator';
|
|
4
|
-
import { MerkleTreeOperations } from '@aztec/world-state';
|
|
1
|
+
import { type Tx } from '@aztec/circuit-types';
|
|
2
|
+
import { type GlobalVariables, type Header, type PublicKernelCircuitPublicInputs } from '@aztec/circuits.js';
|
|
3
|
+
import { type PublicExecutor, type PublicStateDB } from '@aztec/simulator';
|
|
4
|
+
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
5
5
|
|
|
6
|
-
import { PublicKernelCircuitSimulator } from '../simulator/index.js';
|
|
7
|
-
import { ContractsDataSourcePublicDB } from '../simulator/public_executor.js';
|
|
8
|
-
import { AbstractPhaseManager, PublicKernelPhase } from './abstract_phase_manager.js';
|
|
6
|
+
import { type PublicKernelCircuitSimulator } from '../simulator/index.js';
|
|
7
|
+
import { type ContractsDataSourcePublicDB } from '../simulator/public_executor.js';
|
|
8
|
+
import { type AbstractPhaseManager, PublicKernelPhase } from './abstract_phase_manager.js';
|
|
9
9
|
import { AppLogicPhaseManager } from './app_logic_phase_manager.js';
|
|
10
10
|
import { SetupPhaseManager } from './setup_phase_manager.js';
|
|
11
11
|
import { TailPhaseManager } from './tail_phase_manager.js';
|
|
@@ -34,7 +34,8 @@ export class PhaseManagerFactory {
|
|
|
34
34
|
publicContractsDB: ContractsDataSourcePublicDB,
|
|
35
35
|
publicStateDB: PublicStateDB,
|
|
36
36
|
): AbstractPhaseManager | undefined {
|
|
37
|
-
|
|
37
|
+
const data = tx.data.forPublic!;
|
|
38
|
+
if (data.needsSetup) {
|
|
38
39
|
return new SetupPhaseManager(
|
|
39
40
|
db,
|
|
40
41
|
publicExecutor,
|
|
@@ -44,7 +45,7 @@ export class PhaseManagerFactory {
|
|
|
44
45
|
publicContractsDB,
|
|
45
46
|
publicStateDB,
|
|
46
47
|
);
|
|
47
|
-
} else if (
|
|
48
|
+
} else if (data.needsAppLogic) {
|
|
48
49
|
return new AppLogicPhaseManager(
|
|
49
50
|
db,
|
|
50
51
|
publicExecutor,
|
|
@@ -54,7 +55,7 @@ export class PhaseManagerFactory {
|
|
|
54
55
|
publicContractsDB,
|
|
55
56
|
publicStateDB,
|
|
56
57
|
);
|
|
57
|
-
} else if (
|
|
58
|
+
} else if (data.needsTeardown) {
|
|
58
59
|
return new TeardownPhaseManager(
|
|
59
60
|
db,
|
|
60
61
|
publicExecutor,
|