Skip to content

Commit

Permalink
Fix compile error and simplified imports
Browse files Browse the repository at this point in the history
  • Loading branch information
dong77 committed Nov 18, 2023
1 parent f4a007b commit 80dd6c4
Show file tree
Hide file tree
Showing 85 changed files with 953 additions and 2,509 deletions.
1 change: 1 addition & 0 deletions packages/protocol/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ module.exports = {
"node/no-missing-import": "off",
"node/no-missing-require": "off",
"no-unused-expressions": "off",
"no-global-import": "off",
},
};
3 changes: 2 additions & 1 deletion packages/protocol/.solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"payable-fallback": "off",
"no-console": "off",
"avoid-tx-origin": "off",
"one-contract-per-file": "off"
"one-contract-per-file": "off",
"no-global-import": "off"
}
}
7 changes: 2 additions & 5 deletions packages/protocol/contracts/L1/TaikoData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,14 @@ library TaikoData {
// Ring buffer for proposed blocks and a some recent verified blocks.
mapping(uint64 blockId_mod_blockRingBufferSize => Block) blocks;
// Indexing to transition ids (ring buffer not possible)
mapping(
uint64 blockId => mapping(bytes32 parentHash => uint32 transitionId)
) transitionIds;
mapping(uint64 blockId => mapping(bytes32 parentHash => uint32 transitionId)) transitionIds;
// Ring buffer for transitions
mapping(
uint64 blockId_mod_blockRingBufferSize
=> mapping(uint32 transitionId => TransitionState)
) transitions;
// Ring buffer for Ether deposits
mapping(uint256 depositId_mod_ethDepositRingBufferSize => uint256)
ethDeposits;
mapping(uint256 depositId_mod_ethDepositRingBufferSize => uint256) ethDeposits;
// In-protocol Taiko token balances
mapping(address account => uint256 balance) tokenBalances;
// Reusable blobs
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/TaikoEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

pragma solidity ^0.8.20;

import { TaikoData } from "./TaikoData.sol";
import "./TaikoData.sol";

/// @title TaikoEvents
/// @notice This abstract contract provides event declarations for the Taiko
Expand Down
127 changes: 32 additions & 95 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,20 @@

pragma solidity ^0.8.20;

import { AddressResolver } from "../common/AddressResolver.sol";
import { EssentialContract } from "../common/EssentialContract.sol";
import { ICrossChainSync } from "../common/ICrossChainSync.sol";
import { Proxied } from "../common/Proxied.sol";

import { LibDepositing } from "./libs/LibDepositing.sol";
import { LibProposing } from "./libs/LibProposing.sol";
import { LibProving } from "./libs/LibProving.sol";
import { LibTaikoToken } from "./libs/LibTaikoToken.sol";
import { LibUtils } from "./libs/LibUtils.sol";
import { LibVerifying } from "./libs/LibVerifying.sol";

import { TaikoData } from "./TaikoData.sol";
import { TaikoErrors } from "./TaikoErrors.sol";
import { TaikoEvents } from "./TaikoEvents.sol";
import { ITierProvider } from "./tiers/ITierProvider.sol";
import "../common/AddressResolver.sol";
import "../common/EssentialContract.sol";
import "../common/ICrossChainSync.sol";
import "../common/Proxied.sol";
import "./libs/LibDepositing.sol";
import "./libs/LibProposing.sol";
import "./libs/LibProving.sol";
import "./libs/LibTaikoToken.sol";
import "./libs/LibUtils.sol";
import "./libs/LibVerifying.sol";
import "./TaikoData.sol";
import "./TaikoErrors.sol";
import "./TaikoEvents.sol";
import "./tiers/ITierProvider.sol";

/// @title TaikoL1
/// @dev Labeled in AddressResolver as "taiko"
Expand All @@ -31,13 +29,7 @@ import { ITierProvider } from "./tiers/ITierProvider.sol";
/// deployed on L1, it can also be deployed on L2s to create L3s ("inception
/// layers"). The contract also handles the deposit and withdrawal of Taiko
/// tokens and Ether.
contract TaikoL1 is
EssentialContract,
ICrossChainSync,
ITierProvider,
TaikoEvents,
TaikoErrors
{
contract TaikoL1 is EssentialContract, ICrossChainSync, ITierProvider, TaikoEvents, TaikoErrors {
TaikoData.State public state;
uint256[100] private __gap;

Expand All @@ -51,13 +43,7 @@ contract TaikoL1 is
/// @notice Initializes the rollup.
/// @param _addressManager The {AddressManager} address.
/// @param _genesisBlockHash The block hash of the genesis block.
function init(
address _addressManager,
bytes32 _genesisBlockHash
)
external
initializer
{
function init(address _addressManager, bytes32 _genesisBlockHash) external initializer {
EssentialContract._init(_addressManager);
LibVerifying.init(state, getConfig(), _genesisBlockHash);
}
Expand All @@ -81,18 +67,11 @@ contract TaikoL1 is
)
{
TaikoData.Config memory config = getConfig();
(meta, depositsProcessed) = LibProposing.proposeBlock(
state, config, AddressResolver(this), params, txList
);
if (
!state.slotB.provingPaused
&& config.maxBlocksToVerifyPerProposal > 0
) {
(meta, depositsProcessed) =
LibProposing.proposeBlock(state, config, AddressResolver(this), params, txList);
if (!state.slotB.provingPaused && config.maxBlocksToVerifyPerProposal > 0) {
LibVerifying.verifyBlocks(
state,
config,
AddressResolver(this),
config.maxBlocksToVerifyPerProposal
state, config, AddressResolver(this), config.maxBlocksToVerifyPerProposal
);
}
}
Expand All @@ -102,49 +81,30 @@ contract TaikoL1 is
/// select the right implementation version.
/// @param input An abi-encoded (BlockMetadata, Transition, TierProof)
/// tuple.
function proveBlock(
uint64 blockId,
bytes calldata input
)
external
nonReentrant
whenNotPaused
{
function proveBlock(uint64 blockId, bytes calldata input) external nonReentrant whenNotPaused {
(
TaikoData.BlockMetadata memory meta,
TaikoData.Transition memory tran,
TaikoData.TierProof memory proof
) = abi.decode(
input,
(TaikoData.BlockMetadata, TaikoData.Transition, TaikoData.TierProof)
);
) = abi.decode(input, (TaikoData.BlockMetadata, TaikoData.Transition, TaikoData.TierProof));

if (blockId != meta.id) revert L1_INVALID_BLOCK_ID();

TaikoData.Config memory config = getConfig();
uint8 maxBlocksToVerify = LibProving.proveBlock(
state, config, AddressResolver(this), meta, tran, proof
);
uint8 maxBlocksToVerify =
LibProving.proveBlock(state, config, AddressResolver(this), meta, tran, proof);
if (maxBlocksToVerify > 0) {
LibVerifying.verifyBlocks(
state, config, AddressResolver(this), maxBlocksToVerify
);
LibVerifying.verifyBlocks(state, config, AddressResolver(this), maxBlocksToVerify);
}
}

/// @notice Verifies up to N blocks.
/// @param maxBlocksToVerify Max number of blocks to verify.
function verifyBlocks(uint64 maxBlocksToVerify)
external
nonReentrant
whenNotPaused
{
function verifyBlocks(uint64 maxBlocksToVerify) external nonReentrant whenNotPaused {
if (maxBlocksToVerify == 0) revert L1_INVALID_PARAM();
if (state.slotB.provingPaused) revert L1_PROVING_PAUSED();

LibVerifying.verifyBlocks(
state, getConfig(), AddressResolver(this), maxBlocksToVerify
);
LibVerifying.verifyBlocks(state, getConfig(), AddressResolver(this), maxBlocksToVerify);
}

/// @notice Pause block proving.
Expand All @@ -169,9 +129,7 @@ contract TaikoL1 is
/// @param recipient Address of the recipient for the deposited Ether on
/// Layer 2.
function depositEtherToL2(address recipient) public payable whenNotPaused {
LibDepositing.depositEtherToL2(
state, getConfig(), AddressResolver(this), recipient
);
LibDepositing.depositEtherToL2(state, getConfig(), AddressResolver(this), recipient);
}

/// @notice Checks if Ether deposit is allowed for Layer 2.
Expand All @@ -188,11 +146,7 @@ contract TaikoL1 is
/// @notice Gets the details of a block.
/// @param blockId Index of the block.
/// @return blk The block.
function getBlock(uint64 blockId)
public
view
returns (TaikoData.Block memory blk)
{
function getBlock(uint64 blockId) public view returns (TaikoData.Block memory blk) {
return LibUtils.getBlock(state, getConfig(), blockId);
}

Expand Down Expand Up @@ -253,36 +207,19 @@ contract TaikoL1 is
}

/// @notice Retrieves the IDs of all supported tiers.
function getTierIds()
public
view
virtual
override
returns (uint16[] memory ids)
{
function getTierIds() public view virtual override returns (uint16[] memory ids) {
ids = ITierProvider(resolve("tier_provider", false)).getTierIds();
if (ids.length >= type(uint8).max) revert L1_TOO_MANY_TIERS();
}

/// @notice Determines the minimal tier for a block based on a random input.
function getMinTier(uint256 rand)
public
view
virtual
override
returns (uint16)
{
function getMinTier(uint256 rand) public view virtual override returns (uint16) {
return ITierProvider(resolve("tier_provider", false)).getMinTier(rand);
}

/// @notice Gets the configuration of the TaikoL1 contract.
/// @return Config struct containing configuration parameters.
function getConfig()
public
view
virtual
returns (TaikoData.Config memory)
{
function getConfig() public view virtual returns (TaikoData.Config memory) {
// All hard-coded configurations:
// - treasury: 0xdf09A0afD09a63fb04ab3573922437e1e637dE8b
// - blockMaxTxs: 150 (limited by the PSE zkEVM circuits)
Expand Down
27 changes: 7 additions & 20 deletions packages/protocol/contracts/L1/TaikoToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,20 @@

pragma solidity ^0.8.20;

import { ERC20SnapshotUpgradeable } from
import
"lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/extensions/ERC20SnapshotUpgradeable.sol";
import { ERC20Upgradeable } from
"lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol";
import { ERC20VotesUpgradeable } from
import "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol";
import
"lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/extensions/ERC20VotesUpgradeable.sol";

import { EssentialContract } from "../common/EssentialContract.sol";
import { Proxied } from "../common/Proxied.sol";
import "../common/EssentialContract.sol";
import "../common/Proxied.sol";

/// @title TaikoToken
/// @dev Labeled in AddressResolver as "taiko_token"
/// @notice The TaikoToken (TKO), in the protocol is used for prover collateral
/// in the form of bonds. It is an ERC20 token with 18 decimal places of
/// precision.
contract TaikoToken is
EssentialContract,
ERC20SnapshotUpgradeable,
ERC20VotesUpgradeable
{
contract TaikoToken is EssentialContract, ERC20SnapshotUpgradeable, ERC20VotesUpgradeable {
error TKO_INVALID_ADDR();
error TKO_INVALID_PREMINT_PARAMS();

Expand Down Expand Up @@ -75,14 +69,7 @@ contract TaikoToken is
/// @param to The address to transfer tokens to.
/// @param amount The amount of tokens to transfer.
/// @return A boolean indicating whether the transfer was successful or not.
function transfer(
address to,
uint256 amount
)
public
override
returns (bool)
{
function transfer(address to, uint256 amount) public override returns (bool) {
if (to == address(this)) revert TKO_INVALID_ADDR();
return super.transfer(to, amount);
}
Expand Down
Loading

0 comments on commit 80dd6c4

Please sign in to comment.