|
| 1 | +import { Fr } from '@aztec/foundation/curves/bn254'; |
| 2 | +import { MerkleTreeId, PublicDataTreeLeaf } from '@aztec/stdlib/trees'; |
| 3 | +import type { GenesisData } from '@aztec/stdlib/world-state'; |
| 4 | + |
| 5 | +import { jest } from '@jest/globals'; |
| 6 | + |
| 7 | +import { NativeWorldStateService } from './native/index.js'; |
| 8 | + |
| 9 | +jest.setTimeout(60_000); |
| 10 | + |
| 11 | +describe('generateGenesisValues world state backend equivalence', () => { |
| 12 | + // A genesis with both non-empty prefilled public data and a non-zero timestamp, so the |
| 13 | + // fast-return branch in generateGenesisValues is not taken and the archive root is computed |
| 14 | + // from an actual world state. |
| 15 | + const genesis: GenesisData = { |
| 16 | + prefilledPublicData: [ |
| 17 | + new PublicDataTreeLeaf(new Fr(1000), new Fr(2000)), |
| 18 | + new PublicDataTreeLeaf(new Fr(3000), new Fr(4000)), |
| 19 | + ], |
| 20 | + genesisTimestamp: 1234567890n, |
| 21 | + }; |
| 22 | + |
| 23 | + const archiveRoot = async (ws: NativeWorldStateService) => |
| 24 | + new Fr((await ws.getCommitted().getTreeInfo(MerkleTreeId.ARCHIVE)).root); |
| 25 | + |
| 26 | + // The consensus-critical guarantee behind computing genesis values on the fsync-off ephemeral |
| 27 | + // backend instead of tmp: both backends must derive the exact same on-chain genesis archive root. |
| 28 | + it('ephemeral and tmp produce identical genesis archive roots', async () => { |
| 29 | + const tmpWs = await NativeWorldStateService.tmp(undefined /* rollupAddress */, true /* cleanupTmpDir */, genesis); |
| 30 | + const ephemeralWs = await NativeWorldStateService.ephemeral(genesis); |
| 31 | + try { |
| 32 | + const tmpRoot = await archiveRoot(tmpWs); |
| 33 | + const ephemeralRoot = await archiveRoot(ephemeralWs); |
| 34 | + expect(ephemeralRoot).toEqual(tmpRoot); |
| 35 | + } finally { |
| 36 | + await tmpWs.close(); |
| 37 | + await ephemeralWs.close(); |
| 38 | + } |
| 39 | + }); |
| 40 | +}); |
0 commit comments