Skip to content

Commit

Permalink
fix(protocol): add timestamp as a new parameter to getBasefeeV2 (#18686)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Wang <99078276+dantaik@users.noreply.github.com>
Co-authored-by: YoGhurt111 <YoGhurt111@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 2, 2025
1 parent a0c21a3 commit 361c26a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 3 additions & 2 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 _blockTimestamp,
LibSharedData.BaseFeeConfig calldata _baseFeeConfig
)
public
Expand All @@ -201,7 +202,7 @@ contract TaikoL2 is EssentialContract, IBlockHash, TaikoL2Deprecated {
LibEIP1559.adjustExcess(parentGasTarget, newGasTarget, parentGasExcess);

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

if (
_baseFeeConfig.maxGasIssuancePerBlock != 0
Expand Down Expand Up @@ -292,7 +293,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 361c26a

Please sign in to comment.