Skip to content

Commit

Permalink
fix: Do not start block root rollup proof before block is built
Browse files Browse the repository at this point in the history
  • Loading branch information
spalladino committed Oct 2, 2024
1 parent 7ef1643 commit 1609437
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class BlockProvingState {
private rootParityInputs: Array<RootParityInput<typeof RECURSIVE_PROOF_LENGTH> | undefined> = [];
private finalRootParityInputs: RootParityInput<typeof NESTED_RECURSIVE_PROOF_LENGTH> | undefined;
public blockRootRollupPublicInputs: BlockRootOrBlockMergePublicInputs | undefined;
public blockRootRollupStarted: boolean = false;
public finalProof: Proof | undefined;
public block: L2Block | undefined;
private txs: TxProvingState[] = [];
Expand Down Expand Up @@ -180,6 +181,7 @@ export class BlockProvingState {
// Returns true if we have sufficient inputs to execute the block root rollup
public isReadyForBlockRootRollup() {
return !(
this.block === undefined ||
this.mergeRollupInputs[0] === undefined ||
this.finalRootParityInput === undefined ||
this.mergeRollupInputs[0].inputs.findIndex(p => !p) !== -1
Expand Down
18 changes: 15 additions & 3 deletions yarn-project/prover-client/src/orchestrator/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ export class ProvingOrchestrator implements EpochProver {
logger.verbose(`Block ${provingState.globalVariables.blockNumber} completed. Assembling header.`);
await this.buildBlock(provingState);

// If the proofs were faster than the block building, then we need to try the block root rollup again here
this.checkAndEnqueueBlockRootRollup(provingState);
return provingState.block!;
}

Expand Down Expand Up @@ -871,11 +873,17 @@ export class ProvingOrchestrator implements EpochProver {
}

// Executes the block root rollup circuit
private enqueueBlockRootRollup(provingState: BlockProvingState | undefined) {
if (!provingState?.verifyState()) {
private enqueueBlockRootRollup(provingState: BlockProvingState) {
if (!provingState.block) {
throw new Error(`Invalid proving state for block root rollup, block not available`);
}

if (!provingState.verifyState()) {
logger.debug('Not running block root rollup, state no longer valid');
return;
}

provingState.blockRootRollupStarted = true;
const mergeInputData = provingState.getMergeInputs(0);
const rootParityInput = provingState.finalRootParityInput!;

Expand Down Expand Up @@ -1063,11 +1071,15 @@ export class ProvingOrchestrator implements EpochProver {
);
}

private checkAndEnqueueBlockRootRollup(provingState: BlockProvingState | undefined) {
private checkAndEnqueueBlockRootRollup(provingState: BlockProvingState) {
if (!provingState?.isReadyForBlockRootRollup()) {
logger.debug('Not ready for root rollup');
return;
}
if (provingState.blockRootRollupStarted) {
logger.debug('Block root rollup already started');
return;
}
this.enqueueBlockRootRollup(provingState);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import { type MerkleTreeOperations, MerkleTrees } from '@aztec/world-state';

import { type MockProxy, mock } from 'jest-mock-extended';

import { makeBloatedProcessedTx } from '../mocks/fixtures.js';
import { ProvingOrchestrator } from './orchestrator.js';

describe('prover/orchestrator', () => {
describe('workflow', () => {
let orchestrator: ProvingOrchestrator;
let mockProver: MockProxy<ServerCircuitProver>;
let actualDb: MerkleTreeOperations;

beforeEach(async () => {
const telemetryClient = new NoopTelemetryClient();
actualDb = await MerkleTrees.new(openTmpStore(), telemetryClient).then(t => t.asLatest());
Expand Down Expand Up @@ -67,5 +69,22 @@ describe('prover/orchestrator', () => {

orchestrator.cancel();
});

it('waits for block to be completed before enqueueing block root proof', async () => {
orchestrator.startNewEpoch(1, 1);
await orchestrator.startNewBlock(2, makeGlobalVariables(1), []);
await orchestrator.addNewTx(makeBloatedProcessedTx(actualDb, 1));
await orchestrator.addNewTx(makeBloatedProcessedTx(actualDb, 2));

// wait for the block root proof to try to be enqueued
await sleep(10);

// now finish the block
await orchestrator.setBlockCompleted();
await sleep(1);

const result = await orchestrator.finaliseEpoch();
expect(result.proof).toBeDefined();
});
});
});

0 comments on commit 1609437

Please sign in to comment.