Skip to content

Commit

Permalink
fix or uncomment not relevant tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Keszey Dániel authored and Keszey Dániel committed Jul 19, 2024
1 parent 0e9a241 commit ca4a6e6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 46 deletions.
68 changes: 35 additions & 33 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -129,44 +129,46 @@ contract TaikoL1 is EssentialContract, TaikoEvents, TaikoErrors {
// Check that the tx length is non-zero and within the supported range
require(_block.txListByteSize <= config.blockMaxTxListBytes, "invalid txlist size");

// Also since we dont write into storage this check is hard to do here + the
// parentBlock.l1StateBlockNumber too for the preconfs (checking the 4 epoch window)
// I just guess, but also during proving we can see if this condition is
// fulfilled OR not, and then resulting in an empty block (+slashing of the
// proposer/preconfer) ?
TaikoData.Block storage parentBlock = state.blocks[(state.numBlocks - 1)];

require(_block.parentMetaHash == parentBlock.metaHash, "invalid parentMetaHash");
require(_block.parentBlockHash == parentBlock.blockHash, "invalid parentHash");

// Verify the passed in L1 state block number.
// We only allow the L1 block to be 4 epochs old.
// The other constraint is that the L1 block number needs to be larger than or equal the one
// in the previous L2 block.

if (
_block.l1StateBlockNumber + 128 < block.number
|| _block.l1StateBlockNumber >= block.number
|| _block.l1StateBlockNumber < parentBlock.l1StateBlockNumber
) {
revert L1_INVALID_L1_STATE_BLOCK();
}

// Verify the passed in timestamp.
// We only allow the timestamp to be 4 epochs old.
// The other constraint is that the timestamp needs to be larger than or equal the one
// in the previous L2 block.
if (
_block.timestamp + 128 * 12 < block.timestamp || _block.timestamp > block.timestamp
|| _block.timestamp < parentBlock.timestamp
) {
revert L1_INVALID_TIMESTAMP();
}
/* NOT NEEDED ! Commenting out. When PR approved, i'll delete also. */
// // Also since we dont write into storage this check is hard to do here + the
// // parentBlock.l1StateBlockNumber too for the preconfs (checking the 4 epoch window)
// // I just guess, but also during proving we can see if this condition is
// // fulfilled OR not, and then resulting in an empty block (+slashing of the
// // proposer/preconfer) ?
// TaikoData.Block storage parentBlock = state.blocks[(state.numBlocks - 1)];

// require(_block.parentMetaHash == parentBlock.metaHash, "invalid parentMetaHash");
// require(_block.parentBlockHash == parentBlock.blockHash, "invalid parentHash");

// // Verify the passed in L1 state block number.
// // We only allow the L1 block to be 4 epochs old.
// // The other constraint is that the L1 block number needs to be larger than or equal the one
// // in the previous L2 block.

// if (
// _block.l1StateBlockNumber + 128 < block.number
// || _block.l1StateBlockNumber >= block.number
// || _block.l1StateBlockNumber < parentBlock.l1StateBlockNumber
// ) {
// revert L1_INVALID_L1_STATE_BLOCK();
// }

// // Verify the passed in timestamp.
// // We only allow the timestamp to be 4 epochs old.
// // The other constraint is that the timestamp needs to be larger than or equal the one
// // in the previous L2 block.
// if (
// _block.timestamp + 128 * 12 < block.timestamp || _block.timestamp > block.timestamp
// || _block.timestamp < parentBlock.timestamp
// ) {
// revert L1_INVALID_TIMESTAMP();
// }

emit BlockProposed({ blockId: _block.l2BlockNumber, meta: _block });
}

// These will be unknown in the smart contract
// NOT NEEDED ! Commenting out. When PR approved, i'll delete also.
// Maybe possible to extract with ChainProver, but not directly from here.
// function getBlock(uint64 blockId) {}
// function getLastVerifiedBlockId() {}
Expand Down
28 changes: 15 additions & 13 deletions packages/protocol/test/L1/TaikoL1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,25 @@ contract TaikoL1Test is TaikoL1TestBase {
}
}

function test_L1_propose_block_outside_the_4_epoch_window() external {
giveEthAndTko(Alice, 100 ether, 100 ether);
// This test does not fail anymore, because proposing is possible but validating of the preconf window violation will be done
// So for now, not needed ! Commenting out. When PR approved, i'll delete also.
// function test_L1_propose_block_outside_the_4_epoch_window() external {
// giveEthAndTko(Alice, 100 ether, 100 ether);

TaikoData.BlockMetadata memory meta;
// TaikoData.BlockMetadata memory meta;

vm.roll(block.number + 1);
vm.warp(block.timestamp + 12);
// vm.roll(block.number + 1);
// vm.warp(block.timestamp + 12);

bytes32 parentMetaHash;
bytes32 parentBlockHash = GENESIS_BLOCK_HASH;
// Create metadata and propose the block 129 blocks later only
meta = createBlockMetaData(Alice, 1, 1, true, parentMetaHash, parentBlockHash);
vm.roll(block.number + 129);
vm.warp(block.timestamp + 129 * 12);
// bytes32 parentMetaHash;
// bytes32 parentBlockHash = GENESIS_BLOCK_HASH;
// // Create metadata and propose the block 129 blocks later only
// meta = createBlockMetaData(Alice, 1, 1, true, parentMetaHash, parentBlockHash);
// vm.roll(block.number + 129);
// vm.warp(block.timestamp + 129 * 12);

proposeBlock(Alice, meta, TaikoErrors.L1_INVALID_L1_STATE_BLOCK.selector);
}
// proposeBlock(Alice, meta, TaikoErrors.L1_INVALID_L1_STATE_BLOCK.selector);
// }

function test_print_genesis_hash() external pure {
console2.logBytes32(keccak256("GENESIS_BLOCK_HASH"));
Expand Down

0 comments on commit ca4a6e6

Please sign in to comment.