Skip to content

Commit

Permalink
feat(protocol): remove the ETHDeposit feature completely (#16638)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik authored Apr 4, 2024
1 parent d375cc1 commit 643b4b1
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 360 deletions.
28 changes: 7 additions & 21 deletions packages/protocol/contracts/L1/TaikoData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,8 @@ library TaikoData {
// The amount of Taiko token as a prover liveness bond
uint96 livenessBond;
// ---------------------------------------------------------------------
// Group 4: ETH deposit related configs
// Group 4: Cross-chain sync
// ---------------------------------------------------------------------
// The size of the ETH deposit ring buffer.
uint256 ethDepositRingBufferSize;
// The minimum number of ETH deposits allowed per block.
uint64 ethDepositMinCountPerBlock;
// The maximum number of ETH deposits allowed per block.
uint64 ethDepositMaxCountPerBlock;
// The minimum amount of ETH required for a deposit.
uint96 ethDepositMinAmount;
// The maximum amount of ETH allowed for a deposit.
uint96 ethDepositMaxAmount;
// The gas cost for processing an ETH deposit.
uint256 ethDepositGas;
// The maximum fee allowed for an ETH deposit.
uint256 ethDepositMaxFee;
// The max number of L2 blocks that can stay unsynced on L1 (a value of zero disables
// syncing)
uint8 blockSyncThreshold;
Expand Down Expand Up @@ -148,17 +134,17 @@ library TaikoData {
struct SlotA {
uint64 genesisHeight;
uint64 genesisTimestamp;
uint64 numEthDeposits;
uint64 nextEthDepositToProcess;
uint64 __reservedA1;
uint64 __reservedA2;
}

struct SlotB {
uint64 numBlocks;
uint64 lastVerifiedBlockId;
bool provingPaused;
uint8 __reserved1;
uint16 __reserved2;
uint32 __reserved3;
uint8 __reservedB1;
uint16 __reservedB2;
uint32 __reservedB3;
uint64 lastUnpausedAt;
}

Expand All @@ -174,7 +160,7 @@ library TaikoData {
=> mapping(uint32 transitionId => TransitionState ts)
) transitions;
// Ring buffer for Ether deposits
mapping(uint256 depositId_mod_ethDepositRingBufferSize => uint256 depositAmount) ethDeposits;
bytes32 __reserve1;
SlotA slotA; // slot 5
SlotB slotB; // slot 6
uint256[44] __gap;
Expand Down
1 change: 0 additions & 1 deletion packages/protocol/contracts/L1/TaikoErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ abstract contract TaikoErrors {
error L1_BLOCK_MISMATCH();
error L1_INVALID_BLOCK_ID();
error L1_INVALID_CONFIG();
error L1_INVALID_ETH_DEPOSIT();
error L1_INVALID_HOOK();
error L1_INVALID_PARAM();
error L1_INVALID_PAUSE_STATUS();
Expand Down
35 changes: 11 additions & 24 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents, TaikoErrors {
LibVerifying.emitEventForClient(state);
}

/// @dev Fallback function to receive Ether from Hooks
/// @dev Allows for receiving Ether from Hooks
receive() external payable {
if (!_inNonReentrant()) revert L1_RECEIVE_DISABLED();
}
Expand All @@ -55,6 +55,16 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents, TaikoErrors {
LibVerifying.init(state, getConfig(), _genesisBlockHash);
}

function init2() external reinitializer(2) {
// reset some previously used slots for future reuse
state.slotA.__reservedA1 = 0;
state.slotA.__reservedA2 = 0;
state.slotB.__reservedB1 = 0;
state.slotB.__reservedB2 = 0;
state.slotB.__reservedB3 = 0;
state.__reserve1 = 0;
}

/// @inheritdoc ITaikoL1
function proposeBlock(
bytes calldata _params,
Expand All @@ -68,7 +78,6 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents, TaikoErrors {
returns (TaikoData.BlockMetadata memory meta_, TaikoData.EthDeposit[] memory deposits_)
{
TaikoData.Config memory config = getConfig();

(meta_, deposits_) = LibProposing.proposeBlock(state, config, this, _params, _txList);

if (!state.slotB.provingPaused) {
Expand Down Expand Up @@ -120,26 +129,12 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents, TaikoErrors {
LibProving.pauseProving(state, _pause);
}

/// @notice Deposits Ether to Layer 2.
/// @param _recipient Address of the recipient for the deposited Ether on
/// Layer 2.
function depositEtherToL2(address _recipient) external payable whenNotPaused nonReentrant {
LibDepositing.depositEtherToL2(state, getConfig(), this, _recipient);
}

/// @inheritdoc EssentialContract
function unpause() public override {
super.unpause(); // permission checked inside
state.slotB.lastUnpausedAt = uint64(block.timestamp);
}

/// @notice Checks if Ether deposit is allowed for Layer 2.
/// @param _amount Amount of Ether to be deposited.
/// @return true if Ether deposit is allowed, false otherwise.
function canDepositEthToL2(uint256 _amount) public view returns (bool) {
return LibDepositing.canDepositEthToL2(state, getConfig(), _amount);
}

/// @notice Gets the details of a block.
/// @param _blockId Index of the block.
/// @return blk_ The block.
Expand Down Expand Up @@ -203,14 +198,6 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents, TaikoErrors {
// Taiko blocks proposed per Ethereum block is smaller than 1.
blockMaxGasLimit: 240_000_000,
livenessBond: 250e18, // 250 Taiko token
// ETH deposit related.
ethDepositRingBufferSize: 1024,
ethDepositMinCountPerBlock: 8,
ethDepositMaxCountPerBlock: 32,
ethDepositMinAmount: 1 ether,
ethDepositMaxAmount: 10_000 ether,
ethDepositGas: 21_000,
ethDepositMaxFee: 1e17, //0.1 ether,
blockSyncThreshold: 16
});
}
Expand Down
153 changes: 0 additions & 153 deletions packages/protocol/contracts/L1/libs/LibDepositing.sol

This file was deleted.

16 changes: 8 additions & 8 deletions packages/protocol/contracts/L1/libs/LibProposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@
pragma solidity 0.8.24;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../../common/IAddressResolver.sol";
import "../../libs/LibAddress.sol";
import "../hooks/IHook.sol";
import "../tiers/ITierProvider.sol";
import "./LibDepositing.sol";

/// @title LibProposing
/// @notice A library for handling block proposals in the Taiko protocol.
/// @custom:security-contact [email protected]
library LibProposing {
using LibAddress for address;

// = keccak256(abi.encode(new TaikoData.EthDeposit[](0)))
bytes32 private constant _EMPTY_ETH_DEPOSIT_HASH =
0x569e75fc77c1a856f6daaf9e69d8a9566ca34aa47f9133711ce065a571af0cfd;

// Warning: Any events defined here must also be defined in TaikoEvents.sol.
/// @notice Emitted when a block is proposed.
/// @param blockId The ID of the proposed block.
Expand Down Expand Up @@ -46,8 +51,6 @@ library LibProposing {
/// @param _data Encoded data bytes containing the block params.
/// @param _txList Transaction list bytes (if not blob).
/// @return meta_ The constructed block's metadata.
/// @return deposits_ The EthDeposit array about processed deposits in this proposed
/// block.
function proposeBlock(
TaikoData.State storage _state,
TaikoData.Config memory _config,
Expand Down Expand Up @@ -92,10 +95,6 @@ library LibProposing {
revert L1_UNEXPECTED_PARENT();
}

// Each transaction must handle a specific quantity of L1-to-L2
// Ether deposits.
deposits_ = LibDepositing.processDeposits(_state, _config, params.coinbase);

// Initialize metadata to compute a metaHash, which forms a part of
// the block data to be stored on-chain for future integrity checks.
// If we choose to persist all data fields in the metadata, it will
Expand All @@ -106,7 +105,7 @@ library LibProposing {
difficulty: 0, // to be initialized below
blobHash: 0, // to be initialized below
extraData: params.extraData,
depositsHash: keccak256(abi.encode(deposits_)),
depositsHash: _EMPTY_ETH_DEPOSIT_HASH,
coinbase: params.coinbase,
id: b.numBlocks,
gasLimit: _config.blockMaxGasLimit,
Expand Down Expand Up @@ -213,6 +212,7 @@ library LibProposing {
}
}

deposits_ = new TaikoData.EthDeposit[](0);
emit BlockProposed({
blockId: blk.blockId,
assignedProver: blk.assignedProver,
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/libs/LibProving.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ library LibProving {
/// @notice Pauses or unpauses the proving process.
/// @param _state Current TaikoData.State.
/// @param _pause The pause status.
function pauseProving(TaikoData.State storage _state, bool _pause) external {
function pauseProving(TaikoData.State storage _state, bool _pause) internal {
if (_state.slotB.provingPaused == _pause) revert L1_INVALID_PAUSE_STATUS();
_state.slotB.provingPaused = _pause;

Expand Down
4 changes: 2 additions & 2 deletions packages/protocol/contracts/L1/libs/LibUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ library LibUtils {
uint64 _blockId,
bytes32 _parentHash
)
external
internal
view
returns (TaikoData.TransitionState storage)
{
Expand Down Expand Up @@ -57,7 +57,7 @@ library LibUtils {
TaikoData.Config memory _config,
uint64 _blockId
)
external
internal
view
returns (TaikoData.Block storage blk_, uint64 slot_)
{
Expand Down
Loading

0 comments on commit 643b4b1

Please sign in to comment.