-
Notifications
You must be signed in to change notification settings - Fork 310
/
Copy pathbb_prover_full_rollup.test.ts
125 lines (102 loc) · 5.32 KB
/
bb_prover_full_rollup.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import { BBNativeRollupProver, type BBProverConfig } from '@aztec/bb-prover';
import { mockTx } from '@aztec/circuit-types';
import { Fr, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/circuits.js';
import { makeTuple } from '@aztec/foundation/array';
import { times } from '@aztec/foundation/collection';
import { type Logger, createLogger } from '@aztec/foundation/log';
import { getTestData, isGenerateTestDataEnabled } from '@aztec/foundation/testing';
import { writeTestData } from '@aztec/foundation/testing/files';
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vks';
import { getTelemetryClient } from '@aztec/telemetry-client';
import { buildBlock } from '../block_builder/light.js';
import { makeGlobals } from '../mocks/fixtures.js';
import { TestContext } from '../mocks/test_context.js';
describe('prover/bb_prover/full-rollup', () => {
let context: TestContext;
let prover: BBNativeRollupProver;
let log: Logger;
beforeEach(async () => {
const buildProver = async (bbConfig: BBProverConfig) => {
prover = await BBNativeRollupProver.new(bbConfig, getTelemetryClient());
return prover;
};
log = createLogger('prover-client:test:bb-prover-full-rollup');
context = await TestContext.new(log, 1, buildProver);
});
afterEach(async () => {
await context.cleanup();
});
it.each([
[1, 1, 0, 2], // Epoch with a single block, requires one padding block proof
// [2, 2, 0, 2], // Full epoch with two blocks // TODO(#10678) disabled for time x resource usage on main runner
// [2, 3, 0, 2], // Epoch with two blocks but the block merge tree was assembled as with 3 leaves, requires one padding block proof; commented out to reduce running time
])(
'proves a private-only epoch with %i/%i blocks with %i/%i non-empty txs each',
async (blockCount, totalBlocks, nonEmptyTxs, totalTxs) => {
log.info(`Proving epoch with ${blockCount}/${totalBlocks} blocks with ${nonEmptyTxs}/${totalTxs} non-empty txs`);
const initialHeader = context.getBlockHeader(0);
context.orchestrator.startNewEpoch(1, 1, totalBlocks);
for (let blockNum = 1; blockNum <= blockCount; blockNum++) {
const globals = makeGlobals(blockNum);
const l1ToL2Messages = makeTuple(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP, Fr.random);
const txs = times(nonEmptyTxs, (i: number) => {
const txOpts = { numberOfNonRevertiblePublicCallRequests: 0, numberOfRevertiblePublicCallRequests: 0 };
const tx = mockTx(blockNum * 100_000 + 1000 * (i + 1), txOpts);
tx.data.constants.historicalHeader = initialHeader;
tx.data.constants.vkTreeRoot = getVKTreeRoot();
return tx;
});
log.info(`Starting new block #${blockNum}`);
await context.orchestrator.startNewBlock(globals, l1ToL2Messages, context.getPreviousBlockHeader(blockNum));
log.info(`Processing public functions`);
const [processed, failed] = await context.processPublicFunctions(txs, nonEmptyTxs);
expect(processed.length).toBe(nonEmptyTxs);
expect(failed.length).toBe(0);
await context.orchestrator.addTxs(processed);
log.info(`Setting block as completed`);
await context.orchestrator.setBlockCompleted(blockNum);
log.info(`Updating world state with new block`);
const block = await buildBlock(processed, globals, l1ToL2Messages, await context.worldState.fork());
await context.worldState.handleL2BlockAndMessages(block, l1ToL2Messages);
}
log.info(`Awaiting proofs`);
const epochResult = await context.orchestrator.finaliseEpoch();
await expect(prover.verifyProof('RootRollupArtifact', epochResult.proof)).resolves.not.toThrow();
// Generate test data for the 2/2 blocks epoch scenario
if (blockCount === 2 && totalBlocks === 2 && isGenerateTestDataEnabled()) {
const epochProof = getTestData('epochProofResult').at(-1);
writeTestData(
'yarn-project/end-to-end/src/fixtures/dumps/epoch_proof_result.json',
JSON.stringify(epochProof!),
);
}
},
900000,
);
// TODO(@PhilWindle): Remove public functions and re-enable once we can handle empty tx slots
it.skip('proves all circuits', async () => {
const numTransactions = 4;
const txs = times(numTransactions, (i: number) =>
mockTx(1000 * (i + 1), {
numberOfNonRevertiblePublicCallRequests: 2,
numberOfRevertiblePublicCallRequests: 1,
}),
);
for (const tx of txs) {
tx.data.constants.historicalHeader = context.getBlockHeader(0);
}
const l1ToL2Messages = makeTuple<Fr, typeof NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP>(
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
Fr.random,
);
context.orchestrator.startNewEpoch(1, 1, 1);
await context.orchestrator.startNewBlock(context.globalVariables, l1ToL2Messages, context.getPreviousBlockHeader());
const [processed, failed] = await context.processPublicFunctions(txs, numTransactions);
expect(processed.length).toBe(numTransactions);
expect(failed.length).toBe(0);
await context.orchestrator.addTxs(processed);
await context.orchestrator.setBlockCompleted(context.blockNumber);
const result = await context.orchestrator.finaliseEpoch();
await expect(prover.verifyProof('RootRollupArtifact', result.proof)).resolves.not.toThrow();
});
});