Skip to content

Commit df524d2

Browse files
chore: Fix merge-train conflicts (#23173)
After the multi app PR landed, there were conflicts in the private kernel execution prover. This PR resolves them. The conflicts came from this PR: 66d7308
1 parent ef61c7c commit df524d2

2 files changed

Lines changed: 58 additions & 8 deletions

File tree

yarn-project/pxe/src/private_kernel/private_kernel_execution_prover.test.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,20 @@ describe('Private Kernel Sequencer', () => {
6565
{
6666
publicInputs,
6767
childPublicInputs = [],
68+
address = contractAddress,
69+
nestedResults,
6870
}: {
6971
publicInputs?: PrivateCircuitPublicInputs;
7072
childPublicInputs?: PrivateCircuitPublicInputs[];
73+
address?: AztecAddress;
74+
nestedResults?: PrivateCallExecutionResult[];
7175
} = {},
7276
): PrivateCallExecutionResult => {
7377
if (!publicInputs) {
7478
publicInputs = PrivateCircuitPublicInputs.empty();
7579
}
7680
publicInputs.callContext.functionSelector = new FunctionSelector(fnName.charCodeAt(0));
77-
publicInputs.callContext.contractAddress = contractAddress;
81+
publicInputs.callContext.contractAddress = address;
7882

7983
return new PrivateCallExecutionResult(
8084
Buffer.alloc(0),
@@ -86,9 +90,10 @@ describe('Private Kernel Sequencer', () => {
8690
[],
8791
[],
8892
[],
89-
(dependencies[fnName] || []).map((name, i) =>
90-
createCallExecutionResult(name, { publicInputs: childPublicInputs[i] }),
91-
),
93+
nestedResults ??
94+
(dependencies[fnName] || []).map((name, i) =>
95+
createCallExecutionResult(name, { publicInputs: childPublicInputs[i] }),
96+
),
9297
[],
9398
);
9499
};
@@ -406,4 +411,22 @@ describe('Private Kernel Sequencer', () => {
406411
expect(proofCreator.simulateReset).toHaveBeenCalledTimes(3);
407412
expect(proofCreator.simulateTail).toHaveBeenCalledTimes(1);
408413
});
414+
415+
it('fetches updated class id hints once per unique contract address', async () => {
416+
const contractAddressB = AztecAddress.fromBigInt(111111n);
417+
418+
// a { b {} c {} }
419+
// a and c use contractAddress, b uses contractAddressB → 2 unique contracts, 3 executions.
420+
dependencies = {};
421+
const bExec = createCallExecutionResult('b', { address: contractAddressB });
422+
const cExec = createCallExecutionResult('c');
423+
const aExec = createCallExecutionResult('a', { nestedResults: [bExec, cExec] });
424+
425+
const executionResult = new PrivateExecutionResult(aExec, Fr.zero(), []);
426+
await prove(executionResult);
427+
428+
expect(oracle.getUpdatedClassIdHints).toHaveBeenCalledTimes(2);
429+
expect(oracle.getUpdatedClassIdHints).toHaveBeenCalledWith(contractAddress);
430+
expect(oracle.getUpdatedClassIdHints).toHaveBeenCalledWith(contractAddressB);
431+
});
409432
});

yarn-project/pxe/src/private_kernel/private_kernel_execution_prover.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { MAX_APPS_PER_KERNEL } from '@aztec/constants';
2+
import { uniqueBy } from '@aztec/foundation/collection';
23
import { vkAsFieldsMegaHonk } from '@aztec/foundation/crypto/keys';
34
import { Fr } from '@aztec/foundation/curves/bn254';
45
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
@@ -27,12 +28,14 @@ import {
2728
PrivateKernelTailCircuitPrivateInputs,
2829
type PrivateKernelTailCircuitPublicInputs,
2930
PrivateVerificationKeyHints,
31+
type UpdatedClassIdHints,
3032
} from '@aztec/stdlib/kernel';
3133
import { ChonkProof, ChonkProofWithPublicInputs } from '@aztec/stdlib/proofs';
3234
import {
3335
type PrivateCallExecutionResult,
3436
type PrivateExecutionResult,
3537
TxRequest,
38+
collectNested,
3639
collectNoteHashNullifierCounterMap,
3740
getFinalMinRevertibleSideEffectCounter,
3841
} from '@aztec/stdlib/tx';
@@ -120,6 +123,8 @@ export class PrivateKernelExecutionProver {
120123
// reusing the existing single-app `needsReset()` check.
121124
const planner = new BatchPlanner(noteHashNullifierCounterMap, splitCounter, this.maxBatchSize);
122125

126+
const updatedClassIdHintsMap = await this.prefetchUpdatedClassIdHints(executionResult);
127+
123128
while (executionStack.length) {
124129
if (!firstIteration) {
125130
let resetBuilder = new PrivateKernelResetPrivateInputsBuilder(
@@ -156,7 +161,7 @@ export class PrivateKernelExecutionProver {
156161
const batchSize = planner.decideBatchSize(output.publicInputs, executionStack);
157162
const apps: PrivateCallData[] = [];
158163
for (let i = 0; i < batchSize; i++) {
159-
apps.push(await this.consumeNextApp(executionStack, executionSteps));
164+
apps.push(await this.consumeNextApp(executionStack, executionSteps, updatedClassIdHintsMap));
160165
}
161166

162167
output = await this.runBatchedKernel({
@@ -365,6 +370,7 @@ export class PrivateKernelExecutionProver {
365370
private async consumeNextApp(
366371
executionStack: PrivateCallExecutionResult[],
367372
executionSteps: PrivateExecutionStep[],
373+
updatedClassIdHintsMap: Map<string, UpdatedClassIdHints>,
368374
): Promise<PrivateCallData> {
369375
const next = executionStack.pop()!;
370376
executionStack.push(...[...next.nestedExecutionResults].reverse());
@@ -385,10 +391,31 @@ export class PrivateKernelExecutionProver {
385391
},
386392
});
387393

388-
return await this.createPrivateCallData(next);
394+
return await this.createPrivateCallData(next, updatedClassIdHintsMap);
395+
}
396+
397+
/** Prefetches updated class id hints for all unique contracts in the execution tree in parallel. */
398+
private async prefetchUpdatedClassIdHints(
399+
executionResult: PrivateExecutionResult,
400+
): Promise<Map<string, UpdatedClassIdHints>> {
401+
const allAddresses = collectNested([executionResult.entrypoint], exec => [
402+
exec.publicInputs.callContext.contractAddress,
403+
]);
404+
const uniqueAddresses = uniqueBy(allAddresses, a => a.toString());
405+
return new Map<string, UpdatedClassIdHints>(
406+
await Promise.all(
407+
uniqueAddresses.map(
408+
async addr =>
409+
[addr.toString(), await this.oracle.getUpdatedClassIdHints(addr)] as [string, UpdatedClassIdHints],
410+
),
411+
),
412+
);
389413
}
390414

391-
private async createPrivateCallData({ publicInputs, vk: vkAsBuffer }: PrivateCallExecutionResult) {
415+
private async createPrivateCallData(
416+
{ publicInputs, vk: vkAsBuffer }: PrivateCallExecutionResult,
417+
updatedClassIdHintsMap: Map<string, UpdatedClassIdHints>,
418+
) {
392419
const { contractAddress, functionSelector } = publicInputs.callContext;
393420

394421
const vkAsFields = await vkAsFieldsMegaHonk(vkAsBuffer);
@@ -404,7 +431,7 @@ export class PrivateKernelExecutionProver {
404431
const { artifactHash: contractClassArtifactHash, publicBytecodeCommitment: contractClassPublicBytecodeCommitment } =
405432
await this.oracle.getContractClassIdPreimage(currentContractClassId);
406433

407-
const updatedClassIdHints = await this.oracle.getUpdatedClassIdHints(contractAddress);
434+
const updatedClassIdHints = updatedClassIdHintsMap.get(contractAddress.toString())!;
408435

409436
return PrivateCallData.from({
410437
publicInputs,

0 commit comments

Comments
 (0)