Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(protocol): switch to default EIP1559 implementation post Ontake fork #17857

Closed
wants to merge 10 commits into from
7 changes: 1 addition & 6 deletions packages/protocol/contracts/L1/TaikoData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ library TaikoData {
// ---------------------------------------------------------------------
// Group 5: Previous configs in TaikoL2
// ---------------------------------------------------------------------
uint8 basefeeAdjustmentQuotient;
uint8 basefeeSharingPctg;
uint32 blockGasIssuance;
uint8 blockGasTargetMillion;
// ---------------------------------------------------------------------
// Group 6: Others
// ---------------------------------------------------------------------
Expand Down Expand Up @@ -72,7 +71,6 @@ library TaikoData {

struct BlockParamsV2 {
address coinbase;
bytes32 extraData;
bytes32 parentMetaHash;
uint64 anchorBlockId; // NEW
uint64 timestamp; // NEW
Expand Down Expand Up @@ -124,9 +122,6 @@ library TaikoData {
uint32 blobTxListOffset;
uint32 blobTxListLength;
uint8 blobIndex;
uint8 basefeeAdjustmentQuotient;
uint8 basefeeSharingPctg;
uint32 blockGasIssuance;
}

/// @dev Struct representing transition to be proven.
Expand Down
3 changes: 1 addition & 2 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,8 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents {
livenessBond: 125e18, // 125 Taiko token
stateRootSyncInternal: 16,
maxAnchorHeightOffset: 64,
basefeeAdjustmentQuotient: 8,
basefeeSharingPctg: 75,
blockGasIssuance: 20_000_000,
blockGasTargetMillion: 20,
ontakeForkHeight: 374_400 // = 7200 * 52
});
}
Expand Down
6 changes: 1 addition & 5 deletions packages/protocol/contracts/L1/libs/LibData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ library LibData {
{
return TaikoData.BlockParamsV2({
coinbase: _v1.coinbase,
extraData: _v1.extraData,
parentMetaHash: _v1.parentMetaHash,
anchorBlockId: 0,
timestamp: 0,
Expand Down Expand Up @@ -75,10 +74,7 @@ library LibData {
proposedIn: 0,
blobTxListOffset: 0,
blobTxListLength: 0,
blobIndex: 0,
basefeeAdjustmentQuotient: 0,
basefeeSharingPctg: 0,
blockGasIssuance: 0
blobIndex: 0
});
}
}
25 changes: 19 additions & 6 deletions packages/protocol/contracts/L1/libs/LibProposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ library LibProposing {
ITierProvider tierProvider;
bytes32 parentMetaHash;
bool postFork;
bytes32 extraData;
}

/// @notice Emitted when a block is proposed.
Expand Down Expand Up @@ -96,7 +97,9 @@ library LibProposing {
// otherwise use a default BlockParamsV2 with 0 values
}
} else {
local.params = LibData.blockParamsV1ToV2(abi.decode(_data, (TaikoData.BlockParams)));
TaikoData.BlockParams memory paramsV1 = abi.decode(_data, (TaikoData.BlockParams));
local.params = LibData.blockParamsV1ToV2(paramsV1);
local.extraData = paramsV1.extraData;
}

if (local.params.coinbase == address(0)) {
Expand Down Expand Up @@ -158,7 +161,9 @@ library LibProposing {
anchorBlockHash: blockhash(local.params.anchorBlockId),
difficulty: keccak256(abi.encode("TAIKO_DIFFICULTY", local.b.numBlocks)),
blobHash: 0, // to be initialized below
extraData: local.params.extraData,
extraData: local.postFork
? _encodeExtraBlockConfigs(_config.basefeeSharingPctg, _config.blockGasTargetMillion)
: local.extraData,
coinbase: local.params.coinbase,
id: local.b.numBlocks,
gasLimit: _config.blockMaxGasLimit,
Expand All @@ -173,10 +178,7 @@ library LibProposing {
proposedIn: uint64(block.number),
blobTxListOffset: local.params.blobTxListOffset,
blobTxListLength: local.params.blobTxListLength,
blobIndex: local.params.blobIndex,
basefeeAdjustmentQuotient: _config.basefeeAdjustmentQuotient,
basefeeSharingPctg: _config.basefeeSharingPctg,
blockGasIssuance: _config.blockGasIssuance
blobIndex: local.params.blobIndex
});
}

Expand Down Expand Up @@ -262,4 +264,15 @@ library LibProposing {
revert L1_INVALID_PROPOSER();
}
}

function _encodeExtraBlockConfigs(
uint8 _basefeeSharingPctg,
uint8 _blockGasTargetMillion
)
private
pure
returns (bytes32)
{
return bytes32(uint256(_basefeeSharingPctg) << 8 | uint256(_blockGasTargetMillion));
}
}
83 changes: 24 additions & 59 deletions packages/protocol/contracts/L2/TaikoL2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,33 +121,19 @@ contract TaikoL2 is EssentialContract {
nonReentrant
{
if (block.number >= ONTAKE_FORK_HEIGHT) revert L2_FORK_ERROR();
_anchor(
_l1BlockId,
_l1StateRoot,
_parentGasUsed,
0, // not used
0 // not used
);
_anchor(_l1BlockId, _l1StateRoot, _parentGasUsed);
}

function anchorV2(
uint64 _anchorBlockId,
bytes32 _anchorStateRoot,
uint32 _parentGasUsed,
uint32 _blockGasIssuance,
uint8 _basefeeAdjustmentQuotient
)
external
nonReentrant
{
/// @notice Anchors the latest L1 block details to L2 for cross-layer
/// message verification.
/// @dev This function can be called freely as the golden touch private key is publicly known,
/// but the Taiko node guarantees the first transaction of each block is always this anchor
/// transaction, and any subsequent calls will revert with L2_PUBLIC_INPUT_HASH_MISMATCH.
/// @param _anchorBlockId The `anchorBlockId` value in this block's metadata.
/// @param _anchorStateRoot The state root for the L1 block with id equals `_anchorBlockId`
function anchorV2(uint64 _anchorBlockId, bytes32 _anchorStateRoot) external nonReentrant {
if (block.number < ONTAKE_FORK_HEIGHT) revert L2_FORK_ERROR();
_anchor(
_anchorBlockId,
_anchorStateRoot,
_parentGasUsed,
_blockGasIssuance,
_basefeeAdjustmentQuotient
);
_anchor(_anchorBlockId, _anchorStateRoot, 0);
}

/// @notice Withdraw token or Ether from this address
Expand All @@ -172,8 +158,7 @@ contract TaikoL2 is EssentialContract {

/// @notice Gets the basefee and gas excess using EIP-1559 configuration for
/// the given parameters.
/// @dev This function will deprecate after Ontake fork, node/client shall use calculateBaseFee
/// instead for base fee prediction.
/// @dev This function will deprecate after Ontake fork.
/// @param _anchorBlockId The synced L1 height in the next Taiko block
/// @param _parentGasUsed Gas used in the parent block.
/// @return basefee_ The calculated EIP-1559 base fee per gas.
Expand Down Expand Up @@ -220,35 +205,10 @@ contract TaikoL2 is EssentialContract {
return false;
}

/// @notice Calculates the basefee and the new gas excess value based on parent gas used and gas
/// excess.
/// @param _blockGasIssuance The L2 block's gas issuance.
/// @param _adjustmentQuotient The gas adjustment quotient.
/// @param _gasExcess The current gas excess value.
/// @param _parentGasUsed Total gas used by the parent block.
/// @return basefee_ Next block's base fee.
/// @return gasExcess_ The new gas excess value.
function calculateBaseFee(
uint32 _blockGasIssuance,
uint8 _adjustmentQuotient,
uint64 _gasExcess,
uint32 _parentGasUsed
)
public
pure
returns (uint256 basefee_, uint64 gasExcess_)
{
return Lib1559Math.calc1559BaseFee(
_blockGasIssuance, _adjustmentQuotient, _gasExcess, _blockGasIssuance, _parentGasUsed
);
}

function _anchor(
uint64 _anchorBlockId,
bytes32 _anchorStateRoot,
uint32 _parentGasUsed,
uint32 _blockGasIssuance, // only used by ontake
uint8 _basefeeAdjustmentQuotient // only used by ontake
uint32 _parentGasUsed
)
private
{
Expand All @@ -273,12 +233,15 @@ contract TaikoL2 is EssentialContract {
}

// Verify the base fee per gas is correct
(uint256 _basefee, uint64 _gasExcess) = block.number < ONTAKE_FORK_HEIGHT
? getBasefee(_anchorBlockId, _parentGasUsed)
: calculateBaseFee(_blockGasIssuance, _basefeeAdjustmentQuotient, gasExcess, _parentGasUsed);

if (!skipFeeCheck() && block.basefee != _basefee) {
revert L2_BASEFEE_MISMATCH();
uint64 _gasExcess;
if (block.number < ONTAKE_FORK_HEIGHT) {
uint256 _basefee;
(_basefee, _gasExcess) = getBasefee(_anchorBlockId, _parentGasUsed);

if (!skipFeeCheck() && block.basefee != _basefee) {
revert L2_BASEFEE_MISMATCH();
}
}

if (_anchorBlockId > lastSyncedBlock) {
Expand All @@ -295,9 +258,11 @@ contract TaikoL2 is EssentialContract {
bytes32 _parentHash = blockhash(parentId);
l2Hashes[parentId] = _parentHash;
publicInputHash = publicInputHashNew;
gasExcess = _gasExcess;

emit Anchored(_parentHash, _gasExcess);
if (block.number < ONTAKE_FORK_HEIGHT) {
gasExcess = _gasExcess;
emit Anchored(_parentHash, _gasExcess);
}
}

function _calcPublicInputHash(uint256 _blockId)
Expand Down
3 changes: 1 addition & 2 deletions packages/protocol/contracts/hekla/HeklaTaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ contract HeklaTaikoL1 is TaikoL1 {
livenessBond: 125e18, // 125 Taiko token
stateRootSyncInternal: 16,
maxAnchorHeightOffset: 64,
basefeeAdjustmentQuotient: 8,
basefeeSharingPctg: 75,
blockGasIssuance: 20_000_000,
blockGasTargetMillion: 20,
ontakeForkHeight: 720_000 // = 7200 * 100
});
}
Expand Down
5 changes: 0 additions & 5 deletions packages/protocol/test/L1/TaikoL1testGroupA2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ contract TaikoL1TestGroupA2 is TaikoL1TestGroupBase {
assertEq(meta.anchorBlockHash, blockhash(block.number - 1));
assertEq(meta.livenessBond, config.livenessBond);
assertEq(meta.coinbase, Alice);
assertEq(meta.extraData, params.extraData);

TaikoData.Block memory blk = L1.getBlock(i);
assertEq(blk.blockId, i);
Expand Down Expand Up @@ -104,7 +103,6 @@ contract TaikoL1TestGroupA2 is TaikoL1TestGroupBase {
// Propose the first block with default parameters
TaikoData.BlockParamsV2 memory params = TaikoData.BlockParamsV2({
coinbase: address(0),
extraData: 0,
parentMetaHash: 0,
anchorBlockId: 0,
timestamp: 0,
Expand All @@ -125,7 +123,6 @@ contract TaikoL1TestGroupA2 is TaikoL1TestGroupBase {
assertEq(meta.livenessBond, config.livenessBond);
assertEq(meta.coinbase, Alice);
assertEq(meta.parentMetaHash, bytes32(uint256(1)));
assertEq(meta.extraData, params.extraData);

TaikoData.Block memory blk = L1.getBlock(1);
assertEq(blk.blockId, 1);
Expand All @@ -145,7 +142,6 @@ contract TaikoL1TestGroupA2 is TaikoL1TestGroupBase {

params = TaikoData.BlockParamsV2({
coinbase: Bob,
extraData: bytes32(uint256(123)),
parentMetaHash: 0,
anchorBlockId: 90,
timestamp: uint64(block.timestamp - 100),
Expand All @@ -165,7 +161,6 @@ contract TaikoL1TestGroupA2 is TaikoL1TestGroupBase {
assertEq(meta.livenessBond, config.livenessBond);
assertEq(meta.coinbase, Bob);
assertEq(meta.parentMetaHash, blk.metaHash);
assertEq(meta.extraData, params.extraData);

blk = L1.getBlock(2);
assertEq(blk.blockId, 2);
Expand Down