Skip to content

Commit

Permalink
fix(protocol): make _curTimestamp a parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
YoGhurt111 committed Jan 1, 2025
1 parent 26c5fb3 commit b0583fc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/protocol/contracts/layer2/based/TaikoL2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ contract TaikoL2 is EssentialContract, IBlockHash, TaikoL2Deprecated {
/// @return newGasExcess_ The new gas excess value.
function getBasefeeV2(
uint32 _parentGasUsed,
uint64 _curTimestamp,
LibSharedData.BaseFeeConfig calldata _baseFeeConfig
)
public
Expand All @@ -200,8 +201,7 @@ contract TaikoL2 is EssentialContract, IBlockHash, TaikoL2Deprecated {
(newGasTarget_, newGasExcess_) =
LibEIP1559.adjustExcess(parentGasTarget, newGasTarget, parentGasExcess);

uint64 gasIssuance =
uint64(block.timestamp - parentTimestamp) * _baseFeeConfig.gasIssuancePerSecond;
uint64 gasIssuance = (_curTimestamp - parentTimestamp) * _baseFeeConfig.gasIssuancePerSecond;

if (
_baseFeeConfig.maxGasIssuancePerBlock != 0
Expand Down Expand Up @@ -292,7 +292,7 @@ contract TaikoL2 is EssentialContract, IBlockHash, TaikoL2Deprecated {
private
{
(uint256 basefee, uint64 newGasTarget, uint64 newGasExcess) =
getBasefeeV2(_parentGasUsed, _baseFeeConfig);
getBasefeeV2(_parentGasUsed, uint64(block.timestamp), _baseFeeConfig);

require(block.basefee == basefee || skipFeeCheck(), L2_BASEFEE_MISMATCH());

Expand Down
9 changes: 6 additions & 3 deletions packages/protocol/test/layer2/TaikoL2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ contract TaikoL2Tests is TaikoL2Test {
maxGasIssuancePerBlock: _maxGasIssuancePerBlock
});

(uint256 basefee_,,) = L2.getBasefeeV2(_parentGasUsed, baseFeeConfig);
(uint256 basefee_,,) =
L2.getBasefeeV2(_parentGasUsed, uint64(block.timestamp), baseFeeConfig);
assertTrue(basefee_ != 0, "basefee is 0");
}

Expand Down Expand Up @@ -156,15 +157,17 @@ contract TaikoL2Tests is TaikoL2Test {
vm.prank(L2.GOLDEN_TOUCH_ADDRESS());
L2.anchorV2(++anchorBlockId, anchorStateRoot, _parentGasUsed, baseFeeConfig);

(uint256 basefee, uint64 newGasTarget,) = L2.getBasefeeV2(_parentGasUsed, baseFeeConfig);
(uint256 basefee, uint64 newGasTarget,) =
L2.getBasefeeV2(_parentGasUsed, uint64(block.timestamp), baseFeeConfig);

assertTrue(basefee != 0, "basefee is 0");
assertEq(newGasTarget, L2.parentGasTarget());

// change the gas issuance to change the gas target
baseFeeConfig.gasIssuancePerSecond += 1;

(basefee, newGasTarget,) = L2.getBasefeeV2(_parentGasUsed, baseFeeConfig);
(basefee, newGasTarget,) =
L2.getBasefeeV2(_parentGasUsed, uint64(block.timestamp), baseFeeConfig);

assertTrue(basefee != 0, "basefee is 0");
assertTrue(newGasTarget != L2.parentGasTarget());
Expand Down

0 comments on commit b0583fc

Please sign in to comment.