Skip to content

Commit

Permalink
refactor(protocol): delete duplicate event and error definition from …
Browse files Browse the repository at this point in the history
…TaikoL1 (#17722)
  • Loading branch information
dantaik committed Jul 4, 2024
1 parent 936bb95 commit 0607b14
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 196 deletions.
38 changes: 0 additions & 38 deletions packages/protocol/contracts/L1/TaikoErrors.sol

This file was deleted.

91 changes: 0 additions & 91 deletions packages/protocol/contracts/L1/TaikoEvents.sol

This file was deleted.

13 changes: 9 additions & 4 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import "./libs/LibProposing.sol";
import "./libs/LibProving.sol";
import "./libs/LibVerifying.sol";
import "./ITaikoL1.sol";
import "./TaikoErrors.sol";
import "./TaikoEvents.sol";

/// @title TaikoL1
/// @notice This contract serves as the "base layer contract" of the Taiko protocol, providing
Expand All @@ -18,14 +16,21 @@ import "./TaikoEvents.sol";
/// by the Bridge contract.
/// @dev Labeled in AddressResolver as "taiko"
/// @custom:security-contact [email protected]
contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents, TaikoErrors {
contract TaikoL1 is EssentialContract, ITaikoL1 {
/// @notice The TaikoL1 state.
TaikoData.State public state;

uint256[50] private __gap;

/// @notice Emitted when some state variable values changed.
/// @dev This event is currently used by Taiko node/client for block proposal/proving.
/// @param slotB The SlotB data structure.
event StateVariablesUpdated(TaikoData.SlotB slotB);

error L1_RECEIVE_DISABLED();

modifier whenProvingNotPaused() {
if (state.slotB.provingPaused) revert L1_PROVING_PAUSED();
if (state.slotB.provingPaused) revert LibProving.L1_PROVING_PAUSED();
_;
}

Expand Down
2 changes: 0 additions & 2 deletions packages/protocol/contracts/L1/libs/LibProposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ library LibProposing {
bytes32 parentMetaHash;
}

// 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.
/// @param assignedProver The address of the assigned prover.
Expand All @@ -44,7 +43,6 @@ library LibProposing {
/// @param txList The txList.
event CalldataTxList(uint256 indexed blockId, bytes txList);

// Warning: Any errors defined here must also be defined in TaikoErrors.sol.
error L1_BLOB_NOT_AVAILABLE();
error L1_BLOB_NOT_FOUND();
error L1_INVALID_SIG();
Expand Down
11 changes: 4 additions & 7 deletions packages/protocol/contracts/L1/libs/LibProving.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ library LibProving {
bool sameTransition;
}

// Warning: Any events defined here must also be defined in TaikoEvents.sol.
/// @notice Emitted when a transition is proved.
/// @param blockId The block ID.
/// @param tran The transition data.
Expand Down Expand Up @@ -63,16 +62,14 @@ library LibProving {
/// @param paused The pause status.
event ProvingPaused(bool paused);

// Warning: Any errors defined here must also be defined in TaikoErrors.sol.
error L1_ALREADY_CONTESTED();
error L1_ALREADY_PROVED();
error L1_BLOCK_MISMATCH();
error L1_CANNOT_CONTEST();
error L1_INVALID_BLOCK_ID();
error L1_INVALID_PAUSE_STATUS();
error L1_INVALID_TIER();
error L1_INVALID_TRANSITION();
error L1_NOT_ASSIGNED_PROVER();
error L1_PROVING_PAUSED();

/// @notice Pauses or unpauses the proving process.
/// @param _state Current TaikoData.State.
Expand Down Expand Up @@ -110,7 +107,7 @@ library LibProving {
TaikoData.TierProof memory proof
) = abi.decode(_input, (TaikoData.BlockMetadata, TaikoData.Transition, TaikoData.TierProof));

if (_blockId != meta.id) revert L1_INVALID_BLOCK_ID();
if (_blockId != meta.id) revert LibUtils.L1_INVALID_BLOCK_ID();

// Make sure parentHash is not zero
// To contest an existing transition, simply use any non-zero value as
Expand All @@ -124,7 +121,7 @@ library LibProving {

// Check that the block has been proposed but has not yet been verified.
if (meta.id <= local.b.lastVerifiedBlockId || meta.id >= local.b.numBlocks) {
revert L1_INVALID_BLOCK_ID();
revert LibUtils.L1_INVALID_BLOCK_ID();
}

local.slot = meta.id % _config.blockRingBufferSize;
Expand All @@ -148,7 +145,7 @@ library LibProving {
// theory, this check may be skipped, but it's included for added
// caution.
if (local.blockId != meta.id || local.metaHash != LibUtils.hashMetadata(meta)) {
revert L1_BLOCK_MISMATCH();
revert LibUtils.L1_BLOCK_MISMATCH();
}

// Each transition is uniquely identified by the parentHash, with the
Expand Down
1 change: 0 additions & 1 deletion packages/protocol/contracts/L1/libs/LibUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ library LibUtils {
uint16 tier
);

// Warning: Any errors defined here must also be defined in TaikoErrors.sol.
error L1_BLOCK_MISMATCH();
error L1_INVALID_BLOCK_ID();
error L1_INVALID_GENESIS_HASH();
Expand Down
3 changes: 1 addition & 2 deletions packages/protocol/contracts/L1/libs/LibVerifying.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
pragma solidity 0.8.24;

import "../../signal/ISignalService.sol";
import "./LibUtils.sol";
import "./LibBonds.sol";
import "./LibUtils.sol";

/// @title LibVerifying
/// @notice A library for handling block verification in the Taiko protocol.
Expand All @@ -27,7 +27,6 @@ library LibVerifying {
ITierRouter tierRouter;
}

// Warning: Any errors defined here must also be defined in TaikoErrors.sol.
error L1_BLOCK_MISMATCH();
error L1_INVALID_CONFIG();
error L1_TRANSITION_ID_ZERO();
Expand Down
24 changes: 0 additions & 24 deletions packages/protocol/contracts/tko/TaikoToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,4 @@ contract TaikoToken is TaikoTokenBase {
// Mint 1 billion tokens
_mint(_recipient, 1_000_000_000 ether);
}

/// @notice Batch transfers tokens
/// @param recipients The list of addresses to transfer tokens to.
/// @param amounts The list of amounts for transfer.
/// @return true if the transfer is successful.
function batchTransfer(
address[] calldata recipients,
uint256[] calldata amounts
)
external
returns (bool)
{
if (recipients.length != amounts.length) revert TT_INVALID_PARAM();
for (uint256 i; i < recipients.length; ++i) {
_transfer(msg.sender, recipients[i], amounts[i]);
}
return true;
}

function delegates(address account) public view virtual override returns (address) {
// Special checks to avoid reading from storage slots
if (account == _TAIKO_L1 || account == _ERC20_VAULT) return address(0);
else return super.delegates(account);
}
}
4 changes: 2 additions & 2 deletions packages/protocol/test/L1/TaikoL1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ contract TaikoL1Test is TaikoL1TestBase {
secondTransitionHash,
stateRoot,
meta.minTier,
TaikoErrors.L1_NOT_ASSIGNED_PROVER.selector
LibProving.L1_NOT_ASSIGNED_PROVER.selector
);

// Only guardian or assigned prover is allowed
Expand Down Expand Up @@ -205,7 +205,7 @@ contract TaikoL1Test is TaikoL1TestBase {
bytes32("01"),
bytes32("02"),
meta.minTier,
TaikoErrors.L1_PROVING_PAUSED.selector
LibProving.L1_PROVING_PAUSED.selector
);
}

Expand Down
18 changes: 9 additions & 9 deletions packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase {
blockHash,
stateRoot,
meta.minTier,
TaikoErrors.L1_ALREADY_PROVED.selector
LibProving.L1_ALREADY_PROVED.selector
);

vm.roll(block.number + 15 * 12);
Expand Down Expand Up @@ -265,7 +265,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase {
0,
stateRoot,
LibTiers.TIER_GUARDIAN,
TaikoErrors.L1_INVALID_TRANSITION.selector
LibProving.L1_INVALID_TRANSITION.selector
);
}

Expand Down Expand Up @@ -305,7 +305,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase {
blockHash,
stateRoot,
meta.minTier,
TaikoErrors.L1_NOT_ASSIGNED_PROVER.selector
LibProving.L1_NOT_ASSIGNED_PROVER.selector
);
vm.roll(block.number + 15 * 12);

Expand Down Expand Up @@ -398,7 +398,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase {
0,
stateRoot,
LibTiers.TIER_GUARDIAN,
TaikoErrors.L1_INVALID_TRANSITION.selector
LibProving.L1_INVALID_TRANSITION.selector
);

vm.roll(block.number + 15 * 12);
Expand Down Expand Up @@ -452,7 +452,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase {
blockHash,
stateRoot,
LibTiers.TIER_GUARDIAN,
TaikoErrors.L1_ALREADY_PROVED.selector
LibProving.L1_ALREADY_PROVED.selector
);
}
blockHash = bytes32(1_000_000 + blockId + 200);
Expand Down Expand Up @@ -495,7 +495,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase {
blockHash,
stateRoot,
LibTiers.TIER_SGX,
TaikoErrors.L1_INVALID_BLOCK_ID.selector
LibUtils.L1_INVALID_BLOCK_ID.selector
);

parentHash = blockHash;
Expand Down Expand Up @@ -532,7 +532,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase {
blockHash,
stateRoot,
LibTiers.TIER_SGX,
TaikoErrors.L1_BLOCK_MISMATCH.selector
LibUtils.L1_BLOCK_MISMATCH.selector
);

parentHash = blockHash;
Expand Down Expand Up @@ -569,7 +569,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase {
stateRoot,
stateRoot,
LibTiers.TIER_SGX,
TaikoErrors.L1_INVALID_TIER.selector
LibProving.L1_INVALID_TIER.selector
);

vm.roll(block.number + 15 * 12);
Expand Down Expand Up @@ -607,7 +607,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase {
blockHash,
stateRoot,
LibTiers.TIER_SGX,
TaikoErrors.L1_INVALID_TIER.selector
LibProving.L1_INVALID_TIER.selector
);

printVariables("");
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/test/L1/TaikoL1TestGroup1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ contract TaikoL1TestGroup1 is TaikoL1TestGroupBase {
blockHash,
stateRoot,
meta.minTier,
TaikoErrors.L1_NOT_ASSIGNED_PROVER.selector
LibProving.L1_NOT_ASSIGNED_PROVER.selector
);

console2.log("====== Alice proves the block");
Expand Down
Loading

0 comments on commit 0607b14

Please sign in to comment.