Skip to content

Commit

Permalink
fix: address issues when using wall-time
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Sep 2, 2024
1 parent fd61e44 commit 2577c56
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 83 deletions.
16 changes: 6 additions & 10 deletions l1-contracts/src/core/Rollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,6 @@ contract Rollup is Leonidas, IRollup, ITestRollup {
*
* @dev TODO(#7346): Verify root proofs rather than block root when batch rollups are integrated.
*
* @dev Will call `_progressState` to update the proven chain. Notice this have potentially
* unbounded gas consumption.
*
* @dev Will emit `L2ProofVerified` if the proof is valid
*
* @dev Will throw if:
Expand Down Expand Up @@ -368,16 +365,15 @@ contract Rollup is Leonidas, IRollup, ITestRollup {
}

/**
* @notice Check if a proposer can propose at a given time
* @notice Check if msg.sender can propose at a given time
*
* @param _ts - The timestamp to check
* @param _proposer - The proposer to check
* @param _archive - The archive to check (should be the latest archive)
*
* @return uint256 - The slot at the given timestamp
* @return uint256 - The block number at the given timestamp
*/
function canProposeAtTime(uint256 _ts, address _proposer, bytes32 _archive)
function canProposeAtTime(uint256 _ts, bytes32 _archive)
external
view
override(IRollup)
Expand All @@ -395,10 +391,10 @@ contract Rollup is Leonidas, IRollup, ITestRollup {
revert Errors.Rollup__InvalidArchive(tipArchive, _archive);
}

address proposer = getProposerAt(_ts);
if (proposer != address(0) && proposer != _proposer) {
revert Errors.Leonidas__InvalidProposer(proposer, _proposer);
}
SignatureLib.Signature[] memory sigs = new SignatureLib.Signature[](0);
DataStructures.ExecutionFlags memory flags =
DataStructures.ExecutionFlags({ignoreDA: true, ignoreSignatures: true});
_proposePendingBlock(slot, sigs, _archive, flags);

return (slot, pendingBlockCount);
}
Expand Down
5 changes: 1 addition & 4 deletions l1-contracts/src/core/interfaces/IRollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ interface IRollup {
event L2ProofVerified(uint256 indexed blockNumber, bytes32 indexed proverId);
event PrunedPending(uint256 provenBlockCount, uint256 pendingBlockCount);

function canProposeAtTime(uint256 _ts, address _proposer, bytes32 _archive)
external
view
returns (uint256, uint256);
function canProposeAtTime(uint256 _ts, bytes32 _archive) external view returns (uint256, uint256);
function validateHeader(
bytes calldata _header,
SignatureLib.Signature[] memory _signatures,
Expand Down
1 change: 1 addition & 0 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ library Constants {
uint256 internal constant ETHEREUM_SLOT_DURATION = 12;
uint256 internal constant AZTEC_SLOT_DURATION = 12;
uint256 internal constant AZTEC_EPOCH_DURATION = 48;
uint256 internal constant AZTEC_TARGET_COMMITTEE_SIZE = 48;
uint256 internal constant GENESIS_ARCHIVE_ROOT =
8142738430000951296386584486068033372964809139261822027365426310856631083550;
uint256 internal constant FEE_JUICE_INITIAL_MINT = 20000000000;
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/src/core/sequencer_selection/Leonidas.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ contract Leonidas is Ownable, ILeonidas {

// The target number of validators in a committee
// @todo #8021
uint256 public constant TARGET_COMMITTEE_SIZE = EPOCH_DURATION;
uint256 public constant TARGET_COMMITTEE_SIZE = Constants.AZTEC_TARGET_COMMITTEE_SIZE;

// The time that the contract was deployed
uint256 public immutable GENESIS_TIME;
Expand Down
14 changes: 7 additions & 7 deletions l1-contracts/test/fixtures/empty_block_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"l2ToL1Messages": []
},
"block": {
"archive": "0x0f24dbb7e2a507326574582c3f44c08266eb441e926f2d68ca112f358585669f",
"archive": "0x198e609aba94457e08a5455179385cea12980be1a6a385f7ad407a3b9dffe28f",
"body": "0x00000000",
"txsEffectsHash": "0x00e994e16b3763fd5039413cf99c2b3c378e2bab939e7992a77bd201b28160d6",
"decodedHeader": {
Expand All @@ -20,12 +20,12 @@
},
"globalVariables": {
"blockNumber": 1,
"slotNumber": "0x0000000000000000000000000000000000000000000000000000000000000033",
"slotNumber": "0x0000000000000000000000000000000000000000000000000000000000000034",
"chainId": 31337,
"timestamp": 1724861610,
"timestamp": 1725290863,
"version": 1,
"coinbase": "0x872bd7c2a38898f9fc254b86f0fd95475f7eec20",
"feeRecipient": "0x2d78818b03bcaf7034fca9d658f1212c6b2aecd6839e03cc21e2846fc061202d",
"coinbase": "0xd61df3e4042652255bcff1b95c26983ac090c183",
"feeRecipient": "0x214dd9f41792d8a11a3027e4481477cb1a8e1c92488ef23252f9a72c8d371e31",
"gasFees": {
"feePerDaGas": 0,
"feePerL2Gas": 0
Expand Down Expand Up @@ -56,8 +56,8 @@
}
}
},
"header": "0x1200a06aae1368abe36530b585bd7a4d2ba4de5037b82076412691a187d7621e00000001000000000000000000000000000000000000000000000000000000000000000200e994e16b3763fd5039413cf99c2b3c378e2bab939e7992a77bd201b28160d600089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c00f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb14f44d672eb357739e42463497f9fdac46623af863eea4d947ca00a497dcdeb3000000100b59baa35b9dc267744f0ccb4e3b0255c1fc512460d91130c6bc19fb2668568d0000008019a8c197c12bb33da6314c4ef4f8f6fcb9e25250c085df8672adf67c8f1e3dbc0000010023c08a6b1297210c5e24c76b9a936250a1ce2721576c26ea797c7ec35f9e46a9000001000000000000000000000000000000000000000000000000000000000000007a690000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000330000000000000000000000000000000000000000000000000000000066cf4caa872bd7c2a38898f9fc254b86f0fd95475f7eec202d78818b03bcaf7034fca9d658f1212c6b2aecd6839e03cc21e2846fc061202d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"publicInputsHash": "0x00a46e722d885c3bf479f8cf2a786adfde7a8c43740214163f7f9846914cbe6f",
"header": "0x1200a06aae1368abe36530b585bd7a4d2ba4de5037b82076412691a187d7621e00000001000000000000000000000000000000000000000000000000000000000000000200e994e16b3763fd5039413cf99c2b3c378e2bab939e7992a77bd201b28160d600089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c00f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb14f44d672eb357739e42463497f9fdac46623af863eea4d947ca00a497dcdeb3000000100b59baa35b9dc267744f0ccb4e3b0255c1fc512460d91130c6bc19fb2668568d0000008019a8c197c12bb33da6314c4ef4f8f6fcb9e25250c085df8672adf67c8f1e3dbc0000010023c08a6b1297210c5e24c76b9a936250a1ce2721576c26ea797c7ec35f9e46a9000001000000000000000000000000000000000000000000000000000000000000007a690000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000340000000000000000000000000000000000000000000000000000000066d5d96fd61df3e4042652255bcff1b95c26983ac090c183214dd9f41792d8a11a3027e4481477cb1a8e1c92488ef23252f9a72c8d371e31000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"publicInputsHash": "0x00e7e22b5bb3e3c093964849b01b3418a9747859475eb268735716e1a995bed8",
"numTxs": 0
}
}
16 changes: 8 additions & 8 deletions l1-contracts/test/fixtures/empty_block_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"l2ToL1Messages": []
},
"block": {
"archive": "0x25126f40ad58d24006e6db629c2efb1e0868a50d5c21aa342894137b2b08bc0b",
"archive": "0x07784eb4f62bed7c6426667736a270b119cc529f20b1c2143f9f9666b8c9db72",
"body": "0x00000000",
"txsEffectsHash": "0x00e994e16b3763fd5039413cf99c2b3c378e2bab939e7992a77bd201b28160d6",
"decodedHeader": {
Expand All @@ -20,20 +20,20 @@
},
"globalVariables": {
"blockNumber": 2,
"slotNumber": "0x0000000000000000000000000000000000000000000000000000000000000035",
"slotNumber": "0x0000000000000000000000000000000000000000000000000000000000000036",
"chainId": 31337,
"timestamp": 1724861634,
"timestamp": 1725290887,
"version": 1,
"coinbase": "0x872bd7c2a38898f9fc254b86f0fd95475f7eec20",
"feeRecipient": "0x2d78818b03bcaf7034fca9d658f1212c6b2aecd6839e03cc21e2846fc061202d",
"coinbase": "0xd61df3e4042652255bcff1b95c26983ac090c183",
"feeRecipient": "0x214dd9f41792d8a11a3027e4481477cb1a8e1c92488ef23252f9a72c8d371e31",
"gasFees": {
"feePerDaGas": 0,
"feePerL2Gas": 0
}
},
"lastArchive": {
"nextAvailableLeafIndex": 2,
"root": "0x0f24dbb7e2a507326574582c3f44c08266eb441e926f2d68ca112f358585669f"
"root": "0x198e609aba94457e08a5455179385cea12980be1a6a385f7ad407a3b9dffe28f"
},
"stateReference": {
"l1ToL2MessageTree": {
Expand All @@ -56,8 +56,8 @@
}
}
},
"header": "0x0f24dbb7e2a507326574582c3f44c08266eb441e926f2d68ca112f358585669f00000002000000000000000000000000000000000000000000000000000000000000000200e994e16b3763fd5039413cf99c2b3c378e2bab939e7992a77bd201b28160d600089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c00f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb14f44d672eb357739e42463497f9fdac46623af863eea4d947ca00a497dcdeb3000000200b59baa35b9dc267744f0ccb4e3b0255c1fc512460d91130c6bc19fb2668568d0000010019a8c197c12bb33da6314c4ef4f8f6fcb9e25250c085df8672adf67c8f1e3dbc0000018023c08a6b1297210c5e24c76b9a936250a1ce2721576c26ea797c7ec35f9e46a9000001800000000000000000000000000000000000000000000000000000000000007a690000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000350000000000000000000000000000000000000000000000000000000066cf4cc2872bd7c2a38898f9fc254b86f0fd95475f7eec202d78818b03bcaf7034fca9d658f1212c6b2aecd6839e03cc21e2846fc061202d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"publicInputsHash": "0x00de3870b035eca1a73e8adf24b738db855a034548805b300d8dbecfd2a6e66b",
"header": "0x198e609aba94457e08a5455179385cea12980be1a6a385f7ad407a3b9dffe28f00000002000000000000000000000000000000000000000000000000000000000000000200e994e16b3763fd5039413cf99c2b3c378e2bab939e7992a77bd201b28160d600089a9d421a82c4a25f7acbebe69e638d5b064fa8a60e018793dcb0be53752c00f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb14f44d672eb357739e42463497f9fdac46623af863eea4d947ca00a497dcdeb3000000200b59baa35b9dc267744f0ccb4e3b0255c1fc512460d91130c6bc19fb2668568d0000010019a8c197c12bb33da6314c4ef4f8f6fcb9e25250c085df8672adf67c8f1e3dbc0000018023c08a6b1297210c5e24c76b9a936250a1ce2721576c26ea797c7ec35f9e46a9000001800000000000000000000000000000000000000000000000000000000000007a690000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000360000000000000000000000000000000000000000000000000000000066d5d987d61df3e4042652255bcff1b95c26983ac090c183214dd9f41792d8a11a3027e4481477cb1a8e1c92488ef23252f9a72c8d371e31000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"publicInputsHash": "0x002843ab5ba88605f06bf9b4c845a29e9bad5aca822e5bd39aec5245fe8a3132",
"numTxs": 0
}
}
14 changes: 7 additions & 7 deletions l1-contracts/test/fixtures/mixed_block_1.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions l1-contracts/test/fixtures/mixed_block_2.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ global ETHEREUM_SLOT_DURATION: u32 = 12;
// AZTEC_SLOT_DURATION should be a multiple of ETHEREUM_SLOT_DURATION
global AZTEC_SLOT_DURATION: u32 = ETHEREUM_SLOT_DURATION * 1;
global AZTEC_EPOCH_DURATION: u32 = 48;
global AZTEC_TARGET_COMMITTEE_SIZE: u32 = 48;
// The following is taken from building a block and looking at the `lastArchive` value in it.
// You can run the `integration_l1_publisher.test.ts` and look at the first blocks in the fixtures.
global GENESIS_ARCHIVE_ROOT: Field = 0x1200a06aae1368abe36530b585bd7a4d2ba4de5037b82076412691a187d7621e;
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/circuits.js/src/constants.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const BLOB_SIZE_IN_BYTES = 126976;
export const ETHEREUM_SLOT_DURATION = 12;
export const AZTEC_SLOT_DURATION = 12;
export const AZTEC_EPOCH_DURATION = 48;
export const AZTEC_TARGET_COMMITTEE_SIZE = 48;
export const GENESIS_ARCHIVE_ROOT = 8142738430000951296386584486068033372964809139261822027365426310856631083550n;
export const FEE_JUICE_INITIAL_MINT = 20000000000;
export const MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS = 20000;
Expand Down Expand Up @@ -395,6 +396,7 @@ export enum GeneratorIndex {
SIDE_EFFECT = 29,
FEE_PAYLOAD = 30,
COMBINED_PAYLOAD = 31,
TX_NULLIFIER = 32,
TX_REQUEST = 33,
SIGNATURE_PAYLOAD = 34,
VK = 41,
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_l1_with_wall_time.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('e2e_l1_with_wall_time', () => {
const account = privateKeyToAccount(`0x${getPrivateKeyFromIndex(0)!.toString('hex')}`);
const initialValidators = [EthAddress.fromString(account.address)];

({ teardown, logger, pxe } = await setup(0, { initialValidators, l1BlockTime: 12 }));
({ teardown, logger, pxe } = await setup(0, { initialValidators, l1BlockTime: 12, salt: 420 }));
});

afterEach(() => teardown());
Expand Down
25 changes: 23 additions & 2 deletions yarn-project/end-to-end/src/e2e_p2p_network.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ describe('e2e_p2p_network', () => {

const initialValidators = [EthAddress.fromString(account.address)];

({ teardown, config, logger, deployL1ContractsValues } = await setup(0, { initialValidators, ...options }));
({ teardown, config, logger, deployL1ContractsValues } = await setup(0, {
initialValidators,
l1BlockTime: 12,
salt: 420,
...options,
}));

bootstrapNode = await createBootstrapNode(BOOT_NODE_UDP_PORT);
bootstrapNodeEnr = bootstrapNode.getENR().encodeTxt();
Expand All @@ -77,15 +82,31 @@ describe('e2e_p2p_network', () => {
for (let i = 0; i < NUM_NODES; i++) {
const account = privateKeyToAccount(`0x${getPrivateKeyFromIndex(i + 1)!.toString('hex')}`);
await rollup.write.addValidator([account.address]);
logger.debug(`Adding ${account.address} as validator`);
}

// Remove the initial sequencer from the set!
logger.debug(`Removing ${account.address} as validator`);
const txHash = await rollup.write.removeValidator([account.address]);

await deployL1ContractsValues.publicClient.waitForTransactionReceipt({ hash: txHash });

//@note Now we jump ahead to the next epoch such that the validator committee is picked
// INTERVAL MINING: If we are using anvil interval mining this will NOT progress the time!
// Which means that the validator set will still be empty! So anyone can propose.
const slotsInEpoch = await rollup.read.EPOCH_DURATION();
const timestamp = await rollup.read.getTimestampForSlot([slotsInEpoch]);
const cheatCodes = new EthCheatCodes(config.l1RpcUrl);
await cheatCodes.warp(Number(timestamp));
try {
await cheatCodes.warp(Number(timestamp));
} catch (err) {
logger.debug('Warp failed, time already satisfied');
}

// Send and await a tx to make sure we mine a block for the warp to correctly progress.
await deployL1ContractsValues.publicClient.waitForTransactionReceipt({
hash: await deployL1ContractsValues.walletClient.sendTransaction({ to: account.address, value: 1n, account }),
});
});

afterEach(() => teardown());
Expand Down
5 changes: 4 additions & 1 deletion yarn-project/end-to-end/src/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,10 @@ export async function setup(
deployL1ContractsValues.l1ContractAddresses.rollupAddress,
deployL1ContractsValues.publicClient,
);
watcher.start();

if (!opts.l1BlockTime) {
watcher.start();
}

const wallets = numberOfAccounts > 0 ? await createAccounts(pxe, numberOfAccounts) : [];
const cheatCodes = CheatCodes.create(config.l1RpcUrl, pxe!);
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/fixtures/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class Watcher {
this.logger.info(`Slot ${currentSlot} was filled, jumped to next slot`);
}
} catch (err) {
this.logger.error('mineIfSlotFilled failed', err);
this.logger.error('mineIfSlotFilled failed');
}
}
}
33 changes: 1 addition & 32 deletions yarn-project/sequencer-client/src/publisher/l1-publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,6 @@ export type L1SubmitProofArgs = {
aggregationObject: Buffer;
};

export type MetadataForSlot = {
proposer: EthAddress;
slot: bigint;
pendingBlockNumber: bigint;
archive: Buffer;
};

/**
* Publishes L2 blocks to L1. This implementation does *not* retry a transaction in
* the event of network congestion, but should work for local development.
Expand Down Expand Up @@ -175,11 +168,7 @@ export class L1Publisher {
*/
public async canProposeAtNextEthBlock(archive: Buffer): Promise<[bigint, bigint]> {
const ts = BigInt((await this.publicClient.getBlock()).timestamp + BigInt(ETHEREUM_SLOT_DURATION));
const [slot, blockNumber] = await this.rollupContract.read.canProposeAtTime([
ts,
this.account.address,
`0x${archive.toString('hex')}`,
]);
const [slot, blockNumber] = await this.rollupContract.read.canProposeAtTime([ts, `0x${archive.toString('hex')}`]);
return [slot, blockNumber];
}

Expand Down Expand Up @@ -226,26 +215,6 @@ export class L1Publisher {
}
}

// @note Assumes that all ethereum slots have blocks
// Using next Ethereum block so we do NOT need to wait for it being mined before seeing the effect
public async getMetadataForSlotAtNextEthBlock(): Promise<MetadataForSlot> {
const ts = BigInt((await this.publicClient.getBlock()).timestamp + BigInt(ETHEREUM_SLOT_DURATION));

const [submitter, slot, pendingBlockCount, archive] = await Promise.all([
this.rollupContract.read.getProposerAt([ts]),
this.rollupContract.read.getSlotAt([ts]),
this.rollupContract.read.pendingBlockCount(),
this.rollupContract.read.archive(),
]);

return {
proposer: EthAddress.fromString(submitter),
slot,
pendingBlockNumber: pendingBlockCount - 1n,
archive: Buffer.from(archive.replace('0x', ''), 'hex'),
};
}

public async getCurrentEpochCommittee(): Promise<EthAddress[]> {
const committee = await this.rollupContract.read.getCurrentEpochCommittee();
return committee.map(EthAddress.fromString);
Expand Down
6 changes: 5 additions & 1 deletion yarn-project/sequencer-client/src/sequencer/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,11 @@ export class Sequencer {
const revertError = err.walk(err => err instanceof ContractFunctionRevertedError);
if (revertError instanceof ContractFunctionRevertedError) {
const errorName = revertError.data?.errorName ?? '';
this.log.debug(`canProposeAtTime failed with "${errorName}"`);
const args =
revertError.metaMessages && revertError.metaMessages?.length > 1
? revertError.metaMessages[1].trimStart()
: '';
this.log.debug(`canProposeAtTime failed with "${errorName}${args}"`);
}
}
throw err;
Expand Down

0 comments on commit 2577c56

Please sign in to comment.