Skip to content

Commit

Permalink
makeHeader cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jan 29, 2024
1 parent db39d23 commit 04b39dd
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 22 deletions.
6 changes: 2 additions & 4 deletions yarn-project/circuit-types/src/l2_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
STRING_ENCODING,
} from '@aztec/circuits.js';
import { makeAppendOnlyTreeSnapshot, makeGlobalVariables, makeHeader } from '@aztec/circuits.js/factories';
import { makeAppendOnlyTreeSnapshot, makeHeader } from '@aztec/circuits.js/factories';
import { times } from '@aztec/foundation/collection';
import { keccak, sha256 } from '@aztec/foundation/crypto';
import { Fr } from '@aztec/foundation/fields';
Expand Down Expand Up @@ -139,8 +139,6 @@ export class L2Block {
numEncryptedLogsPerCall = 2,
numUnencryptedLogsPerCall = 1,
): L2Block {
const globalVariables = makeGlobalVariables(0, l2BlockNum);

const newNullifiers = times(MAX_NEW_NULLIFIERS_PER_TX * txsPerBlock, Fr.random);
const newCommitments = times(MAX_NEW_COMMITMENTS_PER_TX * txsPerBlock, Fr.random);
const newContracts = times(MAX_NEW_CONTRACTS_PER_TX * txsPerBlock, Fr.random);
Expand All @@ -164,7 +162,7 @@ export class L2Block {
return L2Block.fromFields(
{
archive: makeAppendOnlyTreeSnapshot(1),
header: makeHeader(0, globalVariables),
header: makeHeader(0, l2BlockNum),
newCommitments,
newNullifiers,
newContracts,
Expand Down
13 changes: 5 additions & 8 deletions yarn-project/circuits.js/src/tests/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -888,33 +888,30 @@ export function makeRootRollupInputs(seed = 0, globalVariables?: GlobalVariables
/**
* Makes root rollup public inputs.
* @param seed - The seed to use for generating the root rollup public inputs.
* @param blockNumber - The block number to use for generating the root rollup public inputs.
* if blockNumber is undefined, it will be set to seed + 2.
* @param blockNumber - The block number to use in the global variables of a header.
* @returns A root rollup public inputs.
*/
export function makeRootRollupPublicInputs(
seed = 0,
globalVariables: GlobalVariables | undefined = undefined,
blockNumber: number | undefined = undefined,
): RootRollupPublicInputs {
return RootRollupPublicInputs.from({
aggregationObject: makeAggregationObject(seed),
archive: makeAppendOnlyTreeSnapshot(seed + 0x100),
header: makeHeader(seed + 0x200, globalVariables),
header: makeHeader(seed + 0x200, blockNumber),
l1ToL2MessagesHash: [new Fr(3n), new Fr(4n)],
});
}

/**
* Makes header.
*/
// TODO(benesjan): is passing in global vars separately really used?
// would it be better to just allow for setting block num?
export function makeHeader(seed = 0, globalVariables: GlobalVariables | undefined): Header {
export function makeHeader(seed = 0, blockNumber: number | undefined = undefined): Header {
return new Header(
makeAppendOnlyTreeSnapshot(seed + 0x100),
toBufferBE(BigInt(seed + 0x200), NUM_BYTES_PER_SHA256),
makeStateReference(seed + 0x300),
globalVariables ?? makeGlobalVariables((seed += 0x400)),
makeGlobalVariables((seed += 0x400), blockNumber),
);
}

Expand Down
5 changes: 1 addition & 4 deletions yarn-project/pxe/src/database/pxe_database_test_suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,7 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) {

describe('block header', () => {
it('stores and retrieves the block header', async () => {
// TODO(benesjan): make this more straightforward?
const randomInt = () => Math.floor(Math.random() * 1000);
const globalVariables = makeGlobalVariables(randomInt(), INITIAL_L2_BLOCK_NUM);
const header = makeHeader(randomInt(), globalVariables);
const header = makeHeader(Math.floor(Math.random() * 1000), INITIAL_L2_BLOCK_NUM);

await database.setHeader(header);
expect(database.getHeader()).toEqual(header);
Expand Down
7 changes: 2 additions & 5 deletions yarn-project/pxe/src/synchronizer/synchronizer.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AztecNode, INITIAL_L2_BLOCK_NUM, L2Block } from '@aztec/circuit-types';
import { CompleteAddress, Fr, GrumpkinScalar, Header } from '@aztec/circuits.js';
import { Grumpkin } from '@aztec/circuits.js/barretenberg';
import { makeGlobalVariables, makeHeader } from '@aztec/circuits.js/factories';
import { makeHeader } from '@aztec/circuits.js/factories';
import { SerialQueue } from '@aztec/foundation/fifo';
import { TestKeyStore } from '@aztec/key-store';
import { AztecLmdbStore } from '@aztec/kv-store';
Expand All @@ -22,10 +22,7 @@ describe('Synchronizer', () => {
let headerBlock3: Header;

beforeEach(async () => {
// TODO(benesjan): make this more straightforward?
const randomInt = () => Math.floor(Math.random() * 1000);
const globalVariables = makeGlobalVariables(randomInt(), initialSyncBlockNumber);
headerBlock3 = makeHeader(randomInt(), globalVariables);
headerBlock3 = makeHeader(Math.floor(Math.random() * 1000), initialSyncBlockNumber);

aztecNode = mock<AztecNode>();
database = new KVPxeDatabase(await AztecLmdbStore.openTmp());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ describe('sequencer/solo_block_builder', () => {
// Create mock outputs for simulator
baseRollupOutputLeft = makeBaseOrMergeRollupPublicInputs(0, globalVariables);
baseRollupOutputRight = makeBaseOrMergeRollupPublicInputs(0, globalVariables);
rootRollupOutput = makeRootRollupPublicInputs(0, globalVariables);
rootRollupOutput = makeRootRollupPublicInputs(0);
rootRollupOutput.header.globalVariables = globalVariables;

// Set up mocks
prover.getBaseRollupProof.mockResolvedValue(emptyProof);
Expand Down

0 comments on commit 04b39dd

Please sign in to comment.