diff --git a/packages/protocol/.eslintrc.js b/packages/protocol/.eslintrc.js index 6d4c06dc472..4c6326c83b5 100644 --- a/packages/protocol/.eslintrc.js +++ b/packages/protocol/.eslintrc.js @@ -25,5 +25,6 @@ module.exports = { "node/no-missing-import": "off", "node/no-missing-require": "off", "no-unused-expressions": "off", + "no-global-import": "off", }, }; diff --git a/packages/protocol/.solhint.json b/packages/protocol/.solhint.json index 268d2d3391d..0a49c1fe1a0 100644 --- a/packages/protocol/.solhint.json +++ b/packages/protocol/.solhint.json @@ -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" } } diff --git a/packages/protocol/contracts/L1/TaikoData.sol b/packages/protocol/contracts/L1/TaikoData.sol index fde37dd4e6c..8a50cd168f7 100644 --- a/packages/protocol/contracts/L1/TaikoData.sol +++ b/packages/protocol/contracts/L1/TaikoData.sol @@ -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 diff --git a/packages/protocol/contracts/L1/TaikoEvents.sol b/packages/protocol/contracts/L1/TaikoEvents.sol index 637ed5416ce..fa2a7e5818e 100644 --- a/packages/protocol/contracts/L1/TaikoEvents.sol +++ b/packages/protocol/contracts/L1/TaikoEvents.sol @@ -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 diff --git a/packages/protocol/contracts/L1/TaikoL1.sol b/packages/protocol/contracts/L1/TaikoL1.sol index 461125ce768..1438e580b3b 100644 --- a/packages/protocol/contracts/L1/TaikoL1.sol +++ b/packages/protocol/contracts/L1/TaikoL1.sol @@ -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" @@ -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; @@ -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); } @@ -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 ); } } @@ -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. @@ -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. @@ -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); } @@ -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) diff --git a/packages/protocol/contracts/L1/TaikoToken.sol b/packages/protocol/contracts/L1/TaikoToken.sol index dd7bd2ffa43..0a13aacdb16 100644 --- a/packages/protocol/contracts/L1/TaikoToken.sol +++ b/packages/protocol/contracts/L1/TaikoToken.sol @@ -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(); @@ -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); } diff --git a/packages/protocol/contracts/L1/gov/TaikoGovernor.sol b/packages/protocol/contracts/L1/gov/TaikoGovernor.sol index 00fc4228e2c..b4e80e9939b 100644 --- a/packages/protocol/contracts/L1/gov/TaikoGovernor.sol +++ b/packages/protocol/contracts/L1/gov/TaikoGovernor.sol @@ -1,15 +1,12 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.2; +pragma solidity ^0.8.20; import "lib/openzeppelin-contracts/contracts/governance/Governor.sol"; import "lib/openzeppelin-contracts/contracts/governance/compatibility/GovernorCompatibilityBravo.sol"; -import - "lib/openzeppelin-contracts/contracts/governance/extensions/GovernorVotes.sol"; -import - "lib/openzeppelin-contracts/contracts/governance/extensions/GovernorVotesQuorumFraction.sol"; -import - "lib/openzeppelin-contracts/contracts/governance/extensions/GovernorTimelockControl.sol"; +import "lib/openzeppelin-contracts/contracts/governance/extensions/GovernorVotes.sol"; +import "lib/openzeppelin-contracts/contracts/governance/extensions/GovernorVotesQuorumFraction.sol"; +import "lib/openzeppelin-contracts/contracts/governance/extensions/GovernorTimelockControl.sol"; contract TaikoGovernor is Governor, @@ -28,6 +25,37 @@ contract TaikoGovernor is GovernorTimelockControl(_timelock) { } + function propose( + address[] memory targets, + uint256[] memory values, + bytes[] memory calldatas, + string memory description + ) + public + override(Governor, IGovernor, GovernorCompatibilityBravo) + returns (uint256) + { + return super.propose(targets, values, calldatas, description); + } + + function supportsInterface(bytes4 interfaceId) + public + view + override(Governor, IERC165, GovernorTimelockControl) + returns (bool) + { + return super.supportsInterface(interfaceId); + } + + function state(uint256 proposalId) + public + view + override(Governor, IGovernor, GovernorTimelockControl) + returns (ProposalState) + { + return super.state(proposalId); + } + // How long after a proposal is created should voting power be fixed. A // large voting delay gives users time to unstake tokens if necessary. function votingDelay() public pure override returns (uint256) { @@ -44,29 +72,6 @@ contract TaikoGovernor is return 1_000_000_000 ether / 10_000; // 0.01% of Taiko Token } - // The functions below are overrides required by Solidity. - function state(uint256 proposalId) - public - view - override(Governor, IGovernor, GovernorTimelockControl) - returns (ProposalState) - { - return super.state(proposalId); - } - - function propose( - address[] memory targets, - uint256[] memory values, - bytes[] memory calldatas, - string memory description - ) - public - override(Governor, IGovernor, GovernorCompatibilityBravo) - returns (uint256) - { - return super.propose(targets, values, calldatas, description); - } - function _execute( uint256 proposalId, address[] memory targets, @@ -101,13 +106,4 @@ contract TaikoGovernor is { return super._executor(); } - - function supportsInterface(bytes4 interfaceId) - public - view - override(Governor, IERC165, GovernorTimelockControl) - returns (bool) - { - return super.supportsInterface(interfaceId); - } } diff --git a/packages/protocol/contracts/L1/libs/LibDepositing.sol b/packages/protocol/contracts/L1/libs/LibDepositing.sol index 8a1e282b3f9..487fb9b9c01 100644 --- a/packages/protocol/contracts/L1/libs/LibDepositing.sol +++ b/packages/protocol/contracts/L1/libs/LibDepositing.sol @@ -6,11 +6,11 @@ pragma solidity ^0.8.20; -import { AddressResolver } from "../../common/AddressResolver.sol"; -import { LibAddress } from "../../libs/LibAddress.sol"; -import { LibMath } from "../../libs/LibMath.sol"; +import "../../common/AddressResolver.sol"; +import "../../libs/LibAddress.sol"; +import "../../libs/LibMath.sol"; -import { TaikoData } from "../TaikoData.sol"; +import "../TaikoData.sol"; /// @title LibDepositing /// @notice A library for handling Ether deposits in the Taiko protocol. @@ -42,8 +42,7 @@ library LibDepositing { // Append the deposit to the queue. address _recipient = recipient == address(0) ? msg.sender : recipient; - uint256 slot = - state.slotA.numEthDeposits % config.ethDepositRingBufferSize; + uint256 slot = state.slotA.numEthDeposits % config.ethDepositRingBufferSize; // range of msg.value is checked by next line. state.ethDeposits[slot] = _encodeEthDeposit(_recipient, msg.value); @@ -74,8 +73,7 @@ library LibDepositing { returns (TaikoData.EthDeposit[] memory deposits) { // Calculate the number of pending deposits. - uint256 numPending = - state.slotA.numEthDeposits - state.slotA.nextEthDepositToProcess; + uint256 numPending = state.slotA.numEthDeposits - state.slotA.nextEthDepositToProcess; if (numPending < config.ethDepositMinCountPerBlock) { deposits = new TaikoData.EthDeposit[](0); @@ -83,23 +81,17 @@ library LibDepositing { deposits = new TaikoData.EthDeposit[]( numPending.min(config.ethDepositMaxCountPerBlock) ); - uint96 fee = uint96( - config.ethDepositMaxFee.min( - block.basefee * config.ethDepositGas - ) - ); + uint96 fee = uint96(config.ethDepositMaxFee.min(block.basefee * config.ethDepositGas)); uint64 j = state.slotA.nextEthDepositToProcess; uint96 totalFee; for (uint256 i; i < deposits.length;) { - uint256 data = - state.ethDeposits[j % config.ethDepositRingBufferSize]; + uint256 data = state.ethDeposits[j % config.ethDepositRingBufferSize]; deposits[i] = TaikoData.EthDeposit({ recipient: address(uint160(data >> 96)), amount: uint96(data), id: j }); - uint96 _fee = - deposits[i].amount > fee ? fee : deposits[i].amount; + uint96 _fee = deposits[i].amount > fee ? fee : deposits[i].amount; // Unchecked is safe: // - _fee cannot be bigger than deposits[i].amount @@ -115,8 +107,7 @@ library LibDepositing { } state.slotA.nextEthDepositToProcess = j; // This is the fee deposit - state.ethDeposits[state.slotA.numEthDeposits - % config.ethDepositRingBufferSize] = + state.ethDeposits[state.slotA.numEthDeposits % config.ethDepositRingBufferSize] = _encodeEthDeposit(feeRecipient, totalFee); // Unchecked is safe: @@ -146,8 +137,7 @@ library LibDepositing { // - ethDepositRingBufferSize cannot be 0 by default (validity checked // in LibVerifying) unchecked { - return amount >= config.ethDepositMinAmount - && amount <= config.ethDepositMaxAmount + return amount >= config.ethDepositMinAmount && amount <= config.ethDepositMaxAmount && state.slotA.numEthDeposits - state.slotA.nextEthDepositToProcess < config.ethDepositRingBufferSize - 1; } @@ -157,14 +147,7 @@ library LibDepositing { /// @param addr The address of the deposit recipient. /// @param amount The amount of the deposit. /// @return The encoded deposit. - function _encodeEthDeposit( - address addr, - uint256 amount - ) - private - pure - returns (uint256) - { + function _encodeEthDeposit(address addr, uint256 amount) private pure returns (uint256) { if (amount >= type(uint96).max) revert L1_INVALID_ETH_DEPOSIT(); return (uint256(uint160(addr)) << 96) | amount; } diff --git a/packages/protocol/contracts/L1/libs/LibProposing.sol b/packages/protocol/contracts/L1/libs/LibProposing.sol index 4af52c7b236..8875f29fda0 100644 --- a/packages/protocol/contracts/L1/libs/LibProposing.sol +++ b/packages/protocol/contracts/L1/libs/LibProposing.sol @@ -6,18 +6,14 @@ pragma solidity ^0.8.20; -import { ERC20Upgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol"; - -import { AddressResolver } from "../../common/AddressResolver.sol"; -import { IBlobHashReader } from "../../4844/IBlobHashReader.sol"; -import { LibAddress } from "../../libs/LibAddress.sol"; - -import { ITierProvider } from "../tiers/ITierProvider.sol"; -import { TaikoData } from "../TaikoData.sol"; - -import { LibDepositing } from "./LibDepositing.sol"; -import { LibTaikoToken } from "./LibTaikoToken.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol"; +import "../../common/AddressResolver.sol"; +import "../../4844/IBlobHashReader.sol"; +import "../../libs/LibAddress.sol"; +import "../tiers/ITierProvider.sol"; +import "../TaikoData.sol"; +import "./LibDepositing.sol"; +import "./LibTaikoToken.sol"; /// @title LibProposing /// @notice A library for handling block proposals in the Taiko protocol. @@ -76,8 +72,7 @@ library LibProposing { TaikoData.EthDeposit[] memory depositsProcessed ) { - TaikoData.BlockParams memory params = - abi.decode(data, (TaikoData.BlockParams)); + TaikoData.BlockParams memory params = abi.decode(data, (TaikoData.BlockParams)); // Taiko, as a Based Rollup, enables permissionless block proposals. // However, if the "proposer" address is set to a non-zero value, we @@ -89,8 +84,7 @@ library LibProposing { // It's essential to ensure that the ring buffer for proposed blocks // still has space for at least one more block. - if (b.numBlocks >= b.lastVerifiedBlockId + config.blockMaxProposals + 1) - { + if (b.numBlocks >= b.lastVerifiedBlockId + config.blockMaxProposals + 1) { revert L1_TOO_MANY_BLOCKS(); } @@ -98,17 +92,13 @@ library LibProposing { state.blocks[(b.numBlocks - 1) % config.blockRingBufferSize]; // Check if parent block has the right meta hash - if ( - params.parentMetaHash != 0 - && parent.metaHash != params.parentMetaHash - ) { + if (params.parentMetaHash != 0 && parent.metaHash != params.parentMetaHash) { revert L1_UNEXPECTED_PARENT(); } // Each transaction must handle a specific quantity of L1-to-L2 // Ether deposits. - depositsProcessed = - LibDepositing.processDeposits(state, config, msg.sender); + depositsProcessed = LibDepositing.processDeposits(state, config, msg.sender); // Initialize metadata to compute a metaHash, which forms a part of // the block data to be stored on-chain for future integrity checks. @@ -149,9 +139,8 @@ library LibProposing { // proposeBlock functions are called more than once in the same // L1 transaction, these multiple L2 blocks will share the same // blob. - meta.blobHash = IBlobHashReader( - resolver.resolve("blob_hash_reader", false) - ).getFirstBlobHash(); + meta.blobHash = + IBlobHashReader(resolver.resolve("blob_hash_reader", false)).getFirstBlobHash(); if (meta.blobHash == 0) revert L1_BLOB_NOT_FOUND(); @@ -164,17 +153,13 @@ library LibProposing { } } - if ( - uint256(params.txListByteOffset) + params.txListByteSize - > MAX_BYTES_PER_BLOB - ) { + if (uint256(params.txListByteOffset) + params.txListByteSize > MAX_BYTES_PER_BLOB) { revert L1_TXLIST_OFFSET(); } - if ( - params.txListByteSize == 0 - || params.txListByteSize > config.blockMaxTxListBytes - ) revert L1_TXLIST_SIZE(); + if (params.txListByteSize == 0 || params.txListByteSize > config.blockMaxTxListBytes) { + revert L1_TXLIST_SIZE(); + } meta.txListByteOffset = params.txListByteOffset; meta.txListByteSize = params.txListByteSize; @@ -205,20 +190,19 @@ library LibProposing { // Ethereum block, we must introduce a salt to this random // number as the L2 mixHash. unchecked { - meta.difficulty = meta.blobHash - ^ bytes32(block.prevrandao * b.numBlocks * block.number); + meta.difficulty = meta.blobHash ^ bytes32(block.prevrandao * b.numBlocks * block.number); } // Use the difficulty as a random number - meta.minTier = ITierProvider(resolver.resolve("tier_provider", false)) - .getMinTier(uint256(meta.difficulty)); + meta.minTier = ITierProvider(resolver.resolve("tier_provider", false)).getMinTier( + uint256(meta.difficulty) + ); // Now, it's essential to initialize the block that will be stored // on L1. We should aim to utilize as few storage slots as possible, // alghouth using a ring buffer can minimize storage writes once // the buffer reaches its capacity. - TaikoData.Block storage blk = - state.blocks[b.numBlocks % config.blockRingBufferSize]; + TaikoData.Block storage blk = state.blocks[b.numBlocks % config.blockRingBufferSize]; // Please note that all fields must be re-initialized since we are // utilizing an existing ring buffer slot, not creating a new storage @@ -253,9 +237,7 @@ library LibProposing { // transition is not the initial one or if it was generated and // validated by different provers. Instead, a portion of the assignment // bond serves as a reward for the actual prover. - LibTaikoToken.debitTaikoToken( - state, resolver, blk.assignedProver, config.livenessBond - ); + LibTaikoToken.debitTaikoToken(state, resolver, blk.assignedProver, config.livenessBond); // Increment the counter (cursor) by 1. unchecked { @@ -265,11 +247,7 @@ library LibProposing { // Validate the prover assignment, then charge Ether or ERC20 as the // prover fee based on the block's minTier. uint256 proverFee = _payProverFeeAndTip( - meta.minTier, - meta.blobHash, - blk.blockId, - blk.metaHash, - params.assignment + meta.minTier, meta.blobHash, blk.blockId, blk.metaHash, params.assignment ); emit BlockProposed({ @@ -291,8 +269,7 @@ library LibProposing { view returns (bool) { - return - state.reusableBlobs[blobHash] + config.blobExpiry > block.timestamp; + return state.reusableBlobs[blobHash] + config.blobExpiry > block.timestamp; } function hashAssignment( @@ -337,8 +314,7 @@ library LibProposing { block.timestamp > assignment.expiry || assignment.metaHash != 0 && metaHash != assignment.metaHash || assignment.maxBlockId != 0 && blockId > assignment.maxBlockId - || assignment.maxProposedIn != 0 - && block.number > assignment.maxProposedIn + || assignment.maxProposedIn != 0 && block.number > assignment.maxProposedIn ) { revert L1_ASSIGNMENT_EXPIRED(); } diff --git a/packages/protocol/contracts/L1/libs/LibProving.sol b/packages/protocol/contracts/L1/libs/LibProving.sol index 0dac9d82858..5e3ad4d23e6 100644 --- a/packages/protocol/contracts/L1/libs/LibProving.sol +++ b/packages/protocol/contracts/L1/libs/LibProving.sol @@ -6,21 +6,18 @@ pragma solidity ^0.8.20; -import { AddressResolver } from "../../common/AddressResolver.sol"; - -import { ITierProvider } from "../tiers/ITierProvider.sol"; -import { IVerifier } from "../verifiers/IVerifier.sol"; -import { TaikoData } from "../TaikoData.sol"; - -import { LibTaikoToken } from "./LibTaikoToken.sol"; -import { LibUtils } from "./LibUtils.sol"; +import "../../common/AddressResolver.sol"; +import "../tiers/ITierProvider.sol"; +import "../verifiers/IVerifier.sol"; +import "../TaikoData.sol"; +import "./LibTaikoToken.sol"; +import "./LibUtils.sol"; /// @title LibProving /// @notice A library for handling block contestation and proving in the Taiko /// protocol. library LibProving { - bytes32 public constant RETURN_LIVENESS_BOND = - keccak256("RETURN_LIVENESS_BOND"); + bytes32 public constant RETURN_LIVENESS_BOND = keccak256("RETURN_LIVENESS_BOND"); // Warning: Any events defined here must also be defined in TaikoEvents.sol. event TransitionProved( @@ -81,10 +78,7 @@ library LibProving { // Check the integrity of the block data. It's worth noting that in // theory, this check may be skipped, but it's included for added // caution. - if ( - blk.blockId != meta.id - || blk.metaHash != keccak256(abi.encode(meta)) - ) { + if (blk.blockId != meta.id || blk.metaHash != keccak256(abi.encode(meta))) { revert L1_BLOCK_MISMATCH(); } @@ -166,17 +160,14 @@ library LibProving { // The new proof must meet or exceed the minimum tier required by the // block or the previous proof; it cannot be on a lower tier. - if ( - proof.tier == 0 || proof.tier < meta.minTier || proof.tier < ts.tier - ) { + if (proof.tier == 0 || proof.tier < meta.minTier || proof.tier < ts.tier) { revert L1_INVALID_TIER(); } // Retrieve the tier configurations. If the tier is not supported, the // subsequent action will result in a revert. - ITierProvider.Tier memory tier = ITierProvider( - resolver.resolve("tier_provider", false) - ).getTier(proof.tier); + ITierProvider.Tier memory tier = + ITierProvider(resolver.resolve("tier_provider", false)).getTier(proof.tier); maxBlocksToVerify = tier.maxBlocksToVerify; @@ -200,8 +191,7 @@ library LibProving { // proof checks for the tier. In practice, this only applies to // optimistic proofs. if (verifier != address(0)) { - bool isContesting = - proof.tier == ts.tier && tier.contestBond != 0; + bool isContesting = proof.tier == ts.tier && tier.contestBond != 0; IVerifier.Context memory ctx = IVerifier.Context({ metaHash: blk.metaHash, @@ -221,10 +211,7 @@ library LibProving { // When contestBond is zero for the current tier, it signifies // it's the top tier. In this case, it can overwrite existing // transitions without contestation. - if ( - tran.blockHash == ts.blockHash - && tran.signalRoot == ts.signalRoot - ) { + if (tran.blockHash == ts.blockHash && tran.signalRoot == ts.signalRoot) { revert L1_ALREADY_PROVED(); } // We should outright prohibit the use of zero values for both @@ -240,9 +227,7 @@ library LibProving { blk.livenessBond > 0 && proof.data.length == 32 && bytes32(proof.data) == RETURN_LIVENESS_BOND ) { - LibTaikoToken.creditTaikoToken( - state, blk.assignedProver, blk.livenessBond - ); + LibTaikoToken.creditTaikoToken(state, blk.assignedProver, blk.livenessBond); blk.livenessBond = 0; } @@ -275,10 +260,7 @@ library LibProving { // because this `proveBlock` transaction might aim to prove a // transition but could potentially be front-run by another prover // attempting to prove the same transition. - if ( - tran.blockHash == ts.blockHash - && tran.signalRoot == ts.signalRoot - ) { + if (tran.blockHash == ts.blockHash && tran.signalRoot == ts.signalRoot) { revert L1_ALREADY_PROVED(); } @@ -296,9 +278,7 @@ library LibProving { if (ts.contester != address(0)) revert L1_ALREADY_CONTESTED(); // Burn the contest bond from the prover. - LibTaikoToken.debitTaikoToken( - state, resolver, msg.sender, tier.contestBond - ); + LibTaikoToken.debitTaikoToken(state, resolver, msg.sender, tier.contestBond); // We retain the contest bond within the transition, just in // case this configuration is altered to a different value @@ -377,10 +357,7 @@ library LibProving { // This is the amount of Taiko tokens to send to the new prover // and the winner of the contest (same amount to both parties). uint256 reward; - if ( - ts.blockHash == tran.blockHash - && ts.signalRoot == tran.signalRoot - ) { + if (ts.blockHash == tran.blockHash && ts.signalRoot == tran.signalRoot) { assert(ts.contester != address(0)); // In the event that the previous prover emerges as the // winner, half of the contest bond is designated as the @@ -390,9 +367,7 @@ library LibProving { // Mint the reward and the validity bond and return it to // the previous prover. - LibTaikoToken.creditTaikoToken( - state, ts.prover, reward + ts.validityBond - ); + LibTaikoToken.creditTaikoToken(state, ts.prover, reward + ts.validityBond); } else { // In the event that the contester is the winner, half of // the validity bond is designated as the reward, to be @@ -403,15 +378,11 @@ library LibProving { // for the tier-0 transition. Consequently, we only grant a // reward to the contester if it is not a zero-address. if (ts.contester != address(0)) { - LibTaikoToken.creditTaikoToken( - state, ts.contester, reward + ts.contestBond - ); + LibTaikoToken.creditTaikoToken(state, ts.contester, reward + ts.contestBond); } else { // The prover is also the contester, so the reward is // sent to him. - LibTaikoToken.creditTaikoToken( - state, msg.sender, reward - ); + LibTaikoToken.creditTaikoToken(state, msg.sender, reward); } // Given that the contester emerges as the winner, the @@ -429,9 +400,7 @@ library LibProving { } // Burn the validity bond from the prover. - LibTaikoToken.debitTaikoToken( - state, resolver, msg.sender, tier.validityBond - ); + LibTaikoToken.debitTaikoToken(state, resolver, msg.sender, tier.validityBond); // Regardless of whether the previous prover or the contester // emerges as the winner, we consistently erase the contest history diff --git a/packages/protocol/contracts/L1/libs/LibTaikoToken.sol b/packages/protocol/contracts/L1/libs/LibTaikoToken.sol index 60ebd22297f..1bc96856664 100644 --- a/packages/protocol/contracts/L1/libs/LibTaikoToken.sol +++ b/packages/protocol/contracts/L1/libs/LibTaikoToken.sol @@ -6,10 +6,9 @@ pragma solidity ^0.8.20; -import { AddressResolver } from "../../common/AddressResolver.sol"; - -import { TaikoData } from "../TaikoData.sol"; -import { TaikoToken } from "../TaikoToken.sol"; +import "../../common/AddressResolver.sol"; +import "../TaikoData.sol"; +import "../TaikoToken.sol"; library LibTaikoToken { event TokenDeposited(uint256 amount); @@ -54,20 +53,12 @@ library LibTaikoToken { state.tokenBalances[msg.sender] -= amount; } - TaikoToken(resolver.resolve("taiko_token", false)).transfer( - msg.sender, amount - ); + TaikoToken(resolver.resolve("taiko_token", false)).transfer(msg.sender, amount); emit TokenWithdrawn(amount); } - function creditTaikoToken( - TaikoData.State storage state, - address to, - uint256 amount - ) - internal - { + function creditTaikoToken(TaikoData.State storage state, address to, uint256 amount) internal { if (amount == 0 || to == address(0)) return; unchecked { state.tokenBalances[to] += amount; diff --git a/packages/protocol/contracts/L1/libs/LibUtils.sol b/packages/protocol/contracts/L1/libs/LibUtils.sol index b4a04786d4e..3a1c031c21f 100644 --- a/packages/protocol/contracts/L1/libs/LibUtils.sol +++ b/packages/protocol/contracts/L1/libs/LibUtils.sol @@ -6,9 +6,8 @@ pragma solidity ^0.8.20; -import { ICrossChainSync } from "../../common/ICrossChainSync.sol"; - -import { TaikoData } from "../TaikoData.sol"; +import "../../common/ICrossChainSync.sol"; +import "../TaikoData.sol"; /// @title LibUtils /// @notice A library that offers helper functions. @@ -55,8 +54,7 @@ library LibUtils { view returns (ICrossChainSync.Snippet memory) { - uint64 _blockId = - blockId == 0 ? state.slotB.lastVerifiedBlockId : blockId; + uint64 _blockId = blockId == 0 ? state.slotB.lastVerifiedBlockId : blockId; uint64 slot = _blockId % config.blockRingBufferSize; TaikoData.Block storage blk = state.blocks[slot]; diff --git a/packages/protocol/contracts/L1/libs/LibVerifying.sol b/packages/protocol/contracts/L1/libs/LibVerifying.sol index 717d1fd7363..97769f3db21 100644 --- a/packages/protocol/contracts/L1/libs/LibVerifying.sol +++ b/packages/protocol/contracts/L1/libs/LibVerifying.sol @@ -6,14 +6,12 @@ pragma solidity ^0.8.20; -import { AddressResolver } from "../../common/AddressResolver.sol"; -import { ISignalService } from "../../signal/ISignalService.sol"; - -import { ITierProvider } from "../tiers/ITierProvider.sol"; -import { TaikoData } from "../TaikoData.sol"; - -import { LibTaikoToken } from "./LibTaikoToken.sol"; -import { LibUtils } from "./LibUtils.sol"; +import "../../common/AddressResolver.sol"; +import "../../signal/ISignalService.sol"; +import "../tiers/ITierProvider.sol"; +import "../TaikoData.sol"; +import "./LibTaikoToken.sol"; +import "./LibUtils.sol"; /// @title LibVerifying /// @notice A library for handling block verification in the Taiko protocol. @@ -30,10 +28,7 @@ library LibVerifying { ); event CrossChainSynced( - uint64 indexed syncedInBlock, - uint64 indexed blockId, - bytes32 blockHash, - bytes32 signalRoot + uint64 indexed syncedInBlock, uint64 indexed blockId, bytes32 blockHash, bytes32 signalRoot ); // Warning: Any errors defined here must also be defined in TaikoErrors.sol. @@ -78,11 +73,7 @@ library LibVerifying { }); } - function isConfigValid(TaikoData.Config memory config) - public - pure - returns (bool isValid) - { + function isConfigValid(TaikoData.Config memory config) public pure returns (bool isValid) { if ( config.chainId <= 1 // || config.blockMaxProposals == 1 @@ -91,15 +82,12 @@ library LibVerifying { || config.blockMaxTxListBytes > 128 * 1024 // calldata up to 128K || config.livenessBond == 0 || config.ethDepositRingBufferSize <= 1 || config.ethDepositMinCountPerBlock == 0 - || config.ethDepositMaxCountPerBlock - < config.ethDepositMinCountPerBlock + || config.ethDepositMaxCountPerBlock < config.ethDepositMinCountPerBlock || config.ethDepositMinAmount == 0 || config.ethDepositMaxAmount <= config.ethDepositMinAmount - || config.ethDepositMaxAmount >= type(uint96).max - || config.ethDepositGas == 0 || config.ethDepositMaxFee == 0 - || config.ethDepositMaxFee >= type(uint96).max - || config.ethDepositMaxFee - >= type(uint96).max / config.ethDepositMaxCountPerBlock + || config.ethDepositMaxAmount >= type(uint96).max || config.ethDepositGas == 0 + || config.ethDepositMaxFee == 0 || config.ethDepositMaxFee >= type(uint96).max + || config.ethDepositMaxFee >= type(uint96).max / config.ethDepositMaxCountPerBlock ) return false; return true; @@ -159,8 +147,7 @@ library LibVerifying { if (tid == 0) break; // A transition with the correct `parentHash` has been located. - TaikoData.TransitionState storage ts = - state.transitions[slot][tid]; + TaikoData.TransitionState storage ts = state.transitions[slot][tid]; // It's not possible to verify this block if either the // transition is contested and awaiting higher-tier proof or if @@ -172,10 +159,8 @@ library LibVerifying { tierProvider = resolver.resolve("tier_provider", false); } if ( - uint256( - ITierProvider(tierProvider).getTier(ts.tier) - .cooldownWindow - ) + ts.timestamp > block.timestamp + uint256(ITierProvider(tierProvider).getTier(ts.tier).cooldownWindow) + + ts.timestamp > block.timestamp ) { // If cooldownWindow is 0, the block can theoretically // be proved and verified within the same L1 block. @@ -200,8 +185,7 @@ library LibVerifying { // reward to the actual prover, while the assigned prover // forfeits his liveness bond due to failure to fulfill their // commitment. - uint256 bondToReturn = - uint256(ts.validityBond) + blk.livenessBond; + uint256 bondToReturn = uint256(ts.validityBond) + blk.livenessBond; // Nevertheless, it's possible for the actual prover to be the // same individual or entity as the block's assigned prover. @@ -243,14 +227,10 @@ library LibVerifying { // Store the L2's signal root as a signal to the local signal // service to allow for multi-hop bridging. - ISignalService(resolver.resolve("signal_service", false)) - .sendSignal(signalRoot); + ISignalService(resolver.resolve("signal_service", false)).sendSignal(signalRoot); emit CrossChainSynced( - uint64(block.number), - lastVerifiedBlockId, - blockHash, - signalRoot + uint64(block.number), lastVerifiedBlockId, blockHash, signalRoot ); } } diff --git a/packages/protocol/contracts/L1/provers/GuardianProver.sol b/packages/protocol/contracts/L1/provers/GuardianProver.sol index 47977683469..9d55317fb75 100644 --- a/packages/protocol/contracts/L1/provers/GuardianProver.sol +++ b/packages/protocol/contracts/L1/provers/GuardianProver.sol @@ -6,11 +6,10 @@ pragma solidity ^0.8.20; -import { EssentialContract } from "../../common/EssentialContract.sol"; -import { Proxied } from "../../common/Proxied.sol"; - -import { LibTiers } from "../tiers/ITierProvider.sol"; -import { TaikoData } from "../TaikoData.sol"; +import "../../common/EssentialContract.sol"; +import "../../common/Proxied.sol"; +import "../tiers/ITierProvider.sol"; +import "../TaikoData.sol"; /// @title GuardianProver /// @dev Labeled in AddressResolver as "guardian_prover" @@ -26,9 +25,7 @@ contract GuardianProver is EssentialContract { // Cannot use NUM_GUARDIANS below in event directly otherwise hardhat will // fail event GuardiansUpdated(address[5]); - event Approved( - uint64 indexed blockId, uint256 approvalBits, bool proofSubmitted - ); + event Approved(uint64 indexed blockId, uint256 approvalBits, bool proofSubmitted); error INVALID_GUARDIAN(); error INVALID_GUARDIAN_SET(); @@ -91,9 +88,7 @@ contract GuardianProver is EssentialContract { if (_isApproved(approvalBits)) { bytes memory data = abi.encodeWithSignature( - "proveBlock(uint64,bytes)", - meta.id, - abi.encode(meta, tran, proof) + "proveBlock(uint64,bytes)", meta.id, abi.encode(meta, tran, proof) ); (bool success,) = resolve("taiko", false).call(data); diff --git a/packages/protocol/contracts/L1/tiers/TaikoA6TierProvider.sol b/packages/protocol/contracts/L1/tiers/TaikoA6TierProvider.sol index 4b2ee81dc50..0a264bb3447 100644 --- a/packages/protocol/contracts/L1/tiers/TaikoA6TierProvider.sol +++ b/packages/protocol/contracts/L1/tiers/TaikoA6TierProvider.sol @@ -6,7 +6,7 @@ pragma solidity ^0.8.20; -import { ITierProvider, LibTiers } from "./ITierProvider.sol"; +import "./ITierProvider.sol"; /// @title TaikoA6TierProvider /// @dev Labeled in AddressResolver as "tier_provider" @@ -19,12 +19,7 @@ import { ITierProvider, LibTiers } from "./ITierProvider.sol"; contract TaikoA6TierProvider is ITierProvider { error TIER_NOT_FOUND(); - function getTier(uint16 tierId) - public - pure - override - returns (ITierProvider.Tier memory) - { + function getTier(uint16 tierId) public pure override returns (ITierProvider.Tier memory) { if (tierId == LibTiers.TIER_OPTIMISTIC) { return ITierProvider.Tier({ verifierName: "tier_optimistic", @@ -72,12 +67,7 @@ contract TaikoA6TierProvider is ITierProvider { revert TIER_NOT_FOUND(); } - function getTierIds() - public - pure - override - returns (uint16[] memory tiers) - { + function getTierIds() public pure override returns (uint16[] memory tiers) { tiers = new uint16[](4); tiers[0] = LibTiers.TIER_OPTIMISTIC; tiers[1] = LibTiers.TIER_SGX; diff --git a/packages/protocol/contracts/L1/verifiers/GuardianVerifier.sol b/packages/protocol/contracts/L1/verifiers/GuardianVerifier.sol index 5b4a8100114..7e5370e474b 100644 --- a/packages/protocol/contracts/L1/verifiers/GuardianVerifier.sol +++ b/packages/protocol/contracts/L1/verifiers/GuardianVerifier.sol @@ -6,12 +6,10 @@ pragma solidity ^0.8.20; -import { EssentialContract } from "../../common/EssentialContract.sol"; -import { Proxied } from "../../common/Proxied.sol"; - -import { TaikoData } from "../TaikoData.sol"; - -import { IVerifier } from "./IVerifier.sol"; +import "../../common/EssentialContract.sol"; +import "../../common/Proxied.sol"; +import "../TaikoData.sol"; +import "./IVerifier.sol"; /// @title GuardianVerifier contract GuardianVerifier is EssentialContract, IVerifier { diff --git a/packages/protocol/contracts/L1/verifiers/IVerifier.sol b/packages/protocol/contracts/L1/verifiers/IVerifier.sol index e32b399878e..81cfa57b710 100644 --- a/packages/protocol/contracts/L1/verifiers/IVerifier.sol +++ b/packages/protocol/contracts/L1/verifiers/IVerifier.sol @@ -6,7 +6,7 @@ pragma solidity ^0.8.20; -import { TaikoData } from "../TaikoData.sol"; +import "../TaikoData.sol"; /// @title IVerifier Interface /// @notice Defines the function that handles proof verification. diff --git a/packages/protocol/contracts/L1/verifiers/PseZkVerifier.sol b/packages/protocol/contracts/L1/verifiers/PseZkVerifier.sol index ba5f97d3874..bf92c784c79 100644 --- a/packages/protocol/contracts/L1/verifiers/PseZkVerifier.sol +++ b/packages/protocol/contracts/L1/verifiers/PseZkVerifier.sol @@ -6,15 +6,13 @@ pragma solidity ^0.8.20; -import { EssentialContract } from "../../common/EssentialContract.sol"; -import { Lib4844 } from "../../4844/Lib4844.sol"; -import { Proxied } from "../../common/Proxied.sol"; -import { Proxied } from "../../common/Proxied.sol"; -import { LibBytesUtils } from "../../thirdparty/LibBytesUtils.sol"; - -import { TaikoData } from "../TaikoData.sol"; - -import { IVerifier } from "./IVerifier.sol"; +import "../../common/EssentialContract.sol"; +import "../../4844/Lib4844.sol"; +import "../../common/Proxied.sol"; +import "../../common/Proxied.sol"; +import "../../thirdparty/LibBytesUtils.sol"; +import "../TaikoData.sol"; +import "./IVerifier.sol"; /// @title PseZkVerifier /// @notice See the documentation in {IVerifier}. @@ -88,8 +86,7 @@ contract PseZkVerifier is EssentialContract, IVerifier { // Validate the instance using bytes utilities. bool verified = LibBytesUtils.equal( - LibBytesUtils.slice(zkProof.zkp, 0, 32), - bytes.concat(bytes16(0), bytes16(instance)) + LibBytesUtils.slice(zkProof.zkp, 0, 32), bytes.concat(bytes16(0), bytes16(instance)) ); if (!verified) revert L1_INVALID_PROOF(); @@ -102,8 +99,7 @@ contract PseZkVerifier is EssentialContract, IVerifier { // Delegate to the ZKP verifier library to validate the proof. // Resolve the verifier's name and obtain its address. - address verifierAddress = - resolve(getVerifierName(zkProof.verifierId), false); + address verifierAddress = resolve(getVerifierName(zkProof.verifierId), false); // Call the verifier contract with the provided proof. bytes memory ret; @@ -123,8 +119,7 @@ contract PseZkVerifier is EssentialContract, IVerifier { pure returns (uint256) { - return uint256(keccak256(abi.encodePacked(blobHash, txListHash))) - % Lib4844.BLS_MODULUS; + return uint256(keccak256(abi.encodePacked(blobHash, txListHash))) % Lib4844.BLS_MODULUS; } function calcInstance( @@ -138,9 +133,7 @@ contract PseZkVerifier is EssentialContract, IVerifier { pure returns (bytes32 instance) { - return keccak256( - abi.encode(tran, prover, metaHash, txListHash, pointValue) - ); + return keccak256(abi.encode(tran, prover, metaHash, txListHash, pointValue)); } function getVerifierName(uint16 id) public pure returns (bytes32) { diff --git a/packages/protocol/contracts/L1/verifiers/SgxAndZkVerifier.sol b/packages/protocol/contracts/L1/verifiers/SgxAndZkVerifier.sol index b4a3388b4d9..3a1c6f16e3b 100644 --- a/packages/protocol/contracts/L1/verifiers/SgxAndZkVerifier.sol +++ b/packages/protocol/contracts/L1/verifiers/SgxAndZkVerifier.sol @@ -6,13 +6,11 @@ pragma solidity ^0.8.20; -import { EssentialContract } from "../../common/EssentialContract.sol"; -import { LibBytesUtils } from "../../thirdparty/LibBytesUtils.sol"; -import { Proxied } from "../../common/Proxied.sol"; - -import { TaikoData } from "../TaikoData.sol"; - -import { IVerifier } from "./IVerifier.sol"; +import "../../common/EssentialContract.sol"; +import "../../thirdparty/LibBytesUtils.sol"; +import "../../common/Proxied.sol"; +import "../TaikoData.sol"; +import "./IVerifier.sol"; /// @title SgxAndZkVerifier /// @notice See the documentation in {IVerifier}. @@ -42,12 +40,9 @@ contract SgxAndZkVerifier is EssentialContract, IVerifier { IVerifier(resolve("tier_sgx", false)).verifyProof(ctx, tran, _proof); // Verify the ZK part - _proof.data = LibBytesUtils.slice( - proof.data, SGX_PROOF_SIZE, (proof.data.length - SGX_PROOF_SIZE) - ); - IVerifier(resolve("tier_pse_zkevm", false)).verifyProof( - ctx, tran, _proof - ); + _proof.data = + LibBytesUtils.slice(proof.data, SGX_PROOF_SIZE, (proof.data.length - SGX_PROOF_SIZE)); + IVerifier(resolve("tier_pse_zkevm", false)).verifyProof(ctx, tran, _proof); } } diff --git a/packages/protocol/contracts/L1/verifiers/SgxVerifier.sol b/packages/protocol/contracts/L1/verifiers/SgxVerifier.sol index c6364d8d939..a47afbf9fee 100644 --- a/packages/protocol/contracts/L1/verifiers/SgxVerifier.sol +++ b/packages/protocol/contracts/L1/verifiers/SgxVerifier.sol @@ -6,16 +6,12 @@ pragma solidity ^0.8.20; -import { ECDSAUpgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/utils/cryptography/ECDSAUpgradeable.sol"; - -import { EssentialContract } from "../../common/EssentialContract.sol"; -import { Proxied } from "../../common/Proxied.sol"; -import { LibBytesUtils } from "../../thirdparty/LibBytesUtils.sol"; - -import { TaikoData } from "../TaikoData.sol"; - -import { IVerifier } from "./IVerifier.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/utils/cryptography/ECDSAUpgradeable.sol"; +import "../../common/EssentialContract.sol"; +import "../../common/Proxied.sol"; +import "../../thirdparty/LibBytesUtils.sol"; +import "../TaikoData.sol"; +import "./IVerifier.sol"; /// @title SgxVerifier /// @notice This contract is the implementation of verifying SGX signature @@ -49,10 +45,7 @@ contract SgxVerifier is EssentialContract, IVerifier { uint256[48] private __gap; event InstanceAdded( - uint256 indexed id, - address indexed instance, - address replaced, - uint256 timstamp + uint256 indexed id, address indexed instance, address replaced, uint256 timstamp ); error SGX_INVALID_INSTANCE(); @@ -92,8 +85,7 @@ contract SgxVerifier is EssentialContract, IVerifier { external returns (uint256[] memory ids) { - bytes32 signedHash = - keccak256(abi.encode("ADD_INSTANCES", extraInstances)); + bytes32 signedHash = keccak256(abi.encode("ADD_INSTANCES", extraInstances)); address oldInstance = ECDSAUpgradeable.recover(signedHash, signature); if (!_isInstanceValid(id, oldInstance)) revert SGX_INVALID_INSTANCE(); @@ -118,13 +110,11 @@ contract SgxVerifier is EssentialContract, IVerifier { if (proof.data.length != 89) revert SGX_INVALID_PROOF(); uint32 id = uint32(bytes4(LibBytesUtils.slice(proof.data, 0, 4))); - address newInstance = - address(bytes20(LibBytesUtils.slice(proof.data, 4, 20))); + address newInstance = address(bytes20(LibBytesUtils.slice(proof.data, 4, 20))); bytes memory signature = LibBytesUtils.slice(proof.data, 24); address oldInstance = ECDSAUpgradeable.recover( - getSignedHash(tran, newInstance, ctx.prover, ctx.metaHash), - signature + getSignedHash(tran, newInstance, ctx.prover, ctx.metaHash), signature ); if (!_isInstanceValid(id, oldInstance)) revert SGX_INVALID_INSTANCE(); @@ -144,46 +134,27 @@ contract SgxVerifier is EssentialContract, IVerifier { return keccak256(abi.encode(tran, newInstance, prover, metaHash)); } - function _addInstances(address[] calldata _instances) - private - returns (uint256[] memory ids) - { + function _addInstances(address[] calldata _instances) private returns (uint256[] memory ids) { ids = new uint256[](_instances.length); for (uint256 i; i < _instances.length; ++i) { if (_instances[i] == address(0)) revert SGX_INVALID_INSTANCE(); - instances[nextInstanceId] = - Instance(_instances[i], uint64(block.timestamp)); + instances[nextInstanceId] = Instance(_instances[i], uint64(block.timestamp)); ids[i] = nextInstanceId; - emit InstanceAdded( - nextInstanceId, _instances[i], address(0), block.timestamp - ); + emit InstanceAdded(nextInstanceId, _instances[i], address(0), block.timestamp); nextInstanceId++; } } - function _replaceInstance( - uint256 id, - address oldInstance, - address newInstance - ) - private - { + function _replaceInstance(uint256 id, address oldInstance, address newInstance) private { instances[id] = Instance(newInstance, uint64(block.timestamp)); emit InstanceAdded(id, newInstance, oldInstance, block.timestamp); } - function _isInstanceValid( - uint256 id, - address instance - ) - private - view - returns (bool) - { + function _isInstanceValid(uint256 id, address instance) private view returns (bool) { if (instance == address(0)) return false; if (instance != instances[id].addr) return false; return instances[id].addedAt + INSTANCE_EXPIRY > block.timestamp; diff --git a/packages/protocol/contracts/L2/Lib1559Math.sol b/packages/protocol/contracts/L2/Lib1559Math.sol index db485843a88..71595c8173e 100644 --- a/packages/protocol/contracts/L2/Lib1559Math.sol +++ b/packages/protocol/contracts/L2/Lib1559Math.sol @@ -6,7 +6,7 @@ pragma solidity ^0.8.20; -import { LibFixedPointMath } from "../thirdparty/LibFixedPointMath.sol"; +import "../thirdparty/LibFixedPointMath.sol"; /// @title Lib1559Math /// @dev Implementation of e^(x) based bonding curve for EIP-1559 @@ -16,33 +16,18 @@ library Lib1559Math { /// @dev eth_qty(excess_gas_issued) / (TARGET * ADJUSTMENT_QUOTIENT) /// @param adjustmentFactor The product of gasTarget and adjustmentQuotient - function basefee( - uint256 gasExcess, - uint256 adjustmentFactor - ) - internal - pure - returns (uint256) - { + function basefee(uint256 gasExcess, uint256 adjustmentFactor) internal pure returns (uint256) { if (adjustmentFactor == 0) { revert EIP1559_INVALID_PARAMS(); } - return _ethQty(gasExcess, adjustmentFactor) - / LibFixedPointMath.SCALING_FACTOR / adjustmentFactor; + return _ethQty(gasExcess, adjustmentFactor) / LibFixedPointMath.SCALING_FACTOR + / adjustmentFactor; } /// @dev exp(gas_qty / TARGET / ADJUSTMENT_QUOTIENT) - function _ethQty( - uint256 gasExcess, - uint256 adjustmentFactor - ) - private - pure - returns (uint256) - { - uint256 input = - gasExcess * LibFixedPointMath.SCALING_FACTOR / adjustmentFactor; + function _ethQty(uint256 gasExcess, uint256 adjustmentFactor) private pure returns (uint256) { + uint256 input = gasExcess * LibFixedPointMath.SCALING_FACTOR / adjustmentFactor; if (input > LibFixedPointMath.MAX_EXP_INPUT) { input = LibFixedPointMath.MAX_EXP_INPUT; } diff --git a/packages/protocol/contracts/L2/TaikoL2.sol b/packages/protocol/contracts/L2/TaikoL2.sol index facafa388f2..d4536463b5d 100644 --- a/packages/protocol/contracts/L2/TaikoL2.sol +++ b/packages/protocol/contracts/L2/TaikoL2.sol @@ -6,16 +6,13 @@ pragma solidity ^0.8.20; -import { Ownable2StepUpgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/access/Ownable2StepUpgradeable.sol"; - -import { ICrossChainSync } from "../common/ICrossChainSync.sol"; -import { ISignalService } from "../signal/ISignalService.sol"; -import { Proxied } from "../common/Proxied.sol"; -import { LibMath } from "../libs/LibMath.sol"; - -import { Lib1559Math } from "./Lib1559Math.sol"; -import { TaikoL2Signer } from "./TaikoL2Signer.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/access/Ownable2StepUpgradeable.sol"; +import "../common/ICrossChainSync.sol"; +import "../signal/ISignalService.sol"; +import "../common/Proxied.sol"; +import "../libs/LibMath.sol"; +import "./Lib1559Math.sol"; +import "./TaikoL2Signer.sol"; /// @title TaikoL2 /// @notice Taiko L2 is a smart contract that handles cross-layer message @@ -57,13 +54,7 @@ contract TaikoL2 is Ownable2StepUpgradeable, TaikoL2Signer, ICrossChainSync { /// @notice Initializes the TaikoL2 contract. /// @param _signalService Address of the {ISignalService} contract. /// @param _gasExcess The initial gasExcess. - function init( - address _signalService, - uint64 _gasExcess - ) - external - initializer - { + function init(address _signalService, uint64 _gasExcess) external initializer { Ownable2StepUpgradeable.__Ownable2Step_init(); if (_signalService == address(0)) revert L2_INVALID_PARAM(); @@ -115,8 +106,7 @@ contract TaikoL2 is Ownable2StepUpgradeable, TaikoL2Signer, ICrossChainSync { } // Verify ancestor hashes - (bytes32 publicInputHashOld, bytes32 publicInputHashNew) = - _calcPublicInputHash(parentId); + (bytes32 publicInputHashOld, bytes32 publicInputHashNew) = _calcPublicInputHash(parentId); if (publicInputHash != publicInputHashOld) { revert L2_PUBLIC_INPUT_HASH_MISMATCH(); } @@ -133,9 +123,7 @@ contract TaikoL2 is Ownable2StepUpgradeable, TaikoL2Signer, ICrossChainSync { // Store the L1's signal root as a signal to the local signal service to // allow for multi-hop bridging. ISignalService(signalService).sendSignal(l1SignalRoot); - emit CrossChainSynced( - uint64(block.number), l1Height, l1BlockHash, l1SignalRoot - ); + emit CrossChainSynced(uint64(block.number), l1Height, l1BlockHash, l1SignalRoot); // Update state variables l2Hashes[parentId] = blockhash(parentId); @@ -267,9 +255,7 @@ contract TaikoL2 is Ownable2StepUpgradeable, TaikoL2Signer, ICrossChainSync { // block, however, the this block's gas used will affect the next // block's base fee. _basefee = Lib1559Math.basefee( - _gasExcess, - uint256(config.basefeeAdjustmentQuotient) - * config.gasTargetPerL1Block + _gasExcess, uint256(config.basefeeAdjustmentQuotient) * config.gasTargetPerL1Block ); } diff --git a/packages/protocol/contracts/L2/TaikoL2EIP1559Configurable.sol b/packages/protocol/contracts/L2/TaikoL2EIP1559Configurable.sol index 9b82c39c7a4..b9b7ae6c2db 100644 --- a/packages/protocol/contracts/L2/TaikoL2EIP1559Configurable.sol +++ b/packages/protocol/contracts/L2/TaikoL2EIP1559Configurable.sol @@ -6,8 +6,8 @@ pragma solidity ^0.8.20; -import { TaikoL2 } from "./TaikoL2.sol"; -import { Proxied } from "../common/Proxied.sol"; +import "./TaikoL2.sol"; +import "../common/Proxied.sol"; /// @title TaikoL2EIP1559Configurable /// @notice Taiko L2 with a setter to change EIP-1559 configurations and states. @@ -46,7 +46,4 @@ contract TaikoL2EIP1559Configurable is TaikoL2 { /// @title ProxiedTaikoL2EIP1559Configurable /// @notice Proxied version of the TaikoL2EIP1559Configurable contract. -contract ProxiedTaikoL2EIP1559Configurable is - Proxied, - TaikoL2EIP1559Configurable -{ } +contract ProxiedTaikoL2EIP1559Configurable is Proxied, TaikoL2EIP1559Configurable { } diff --git a/packages/protocol/contracts/L2/TaikoL2Signer.sol b/packages/protocol/contracts/L2/TaikoL2Signer.sol index 5b8d6f83341..29b449a3a50 100644 --- a/packages/protocol/contracts/L2/TaikoL2Signer.sol +++ b/packages/protocol/contracts/L2/TaikoL2Signer.sol @@ -6,31 +6,27 @@ pragma solidity ^0.8.20; -import { LibUint512Math } from "../thirdparty/LibUint512Math.sol"; +import "../thirdparty/LibUint512Math.sol"; /// @title TaikoL2Signer /// @notice This contract allows for signing operations required on Taiko L2. /// @dev It uses precomputed values for optimized signature creation. abstract contract TaikoL2Signer { // Constants related to the golden touch signature. - address public constant GOLDEN_TOUCH_ADDRESS = - 0x0000777735367b36bC9B61C50022d9D0700dB4Ec; + address public constant GOLDEN_TOUCH_ADDRESS = 0x0000777735367b36bC9B61C50022d9D0700dB4Ec; uint256 public constant GOLDEN_TOUCH_PRIVATEKEY = 0x92954368afd3caa1f3ce3ead0069c1af414054aefe1ef9aeacc1bf426222ce38; // Precomputed curve constants. - uint256 private constant GX = - 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798; - uint256 private constant GY = - 0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8; + uint256 private constant GX = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798; + uint256 private constant GY = 0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8; uint256 private constant GX2 = 0xc6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5; uint256 private constant GY2 = 0x1ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a; // Curve order. - uint256 private constant N = - 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141; + uint256 private constant N = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141; // Precomputed multiplication results for optimization. uint256 private constant GX_MUL_GOLDEN_TOUCH_PRIVATEKEY_LOW = @@ -66,21 +62,17 @@ abstract contract TaikoL2Signer { r = k == 1 ? GX : GX2; - uint256 low256 = k == 1 - ? GX_MUL_GOLDEN_TOUCH_PRIVATEKEY_LOW - : GX2_MUL_GOLDEN_TOUCH_PRIVATEKEY_LOW; - uint256 high256 = k == 1 - ? GX_MUL_GOLDEN_TOUCH_PRIVATEKEY_HIGH - : GX2_MUL_GOLDEN_TOUCH_PRIVATEKEY_HIGH; + uint256 low256 = + k == 1 ? GX_MUL_GOLDEN_TOUCH_PRIVATEKEY_LOW : GX2_MUL_GOLDEN_TOUCH_PRIVATEKEY_LOW; + uint256 high256 = + k == 1 ? GX_MUL_GOLDEN_TOUCH_PRIVATEKEY_HIGH : GX2_MUL_GOLDEN_TOUCH_PRIVATEKEY_HIGH; - (low256, high256) = - LibUint512Math.add(low256, high256, uint256(digest), 0); + (low256, high256) = LibUint512Math.add(low256, high256, uint256(digest), 0); if (k == 1) { s = _expmod(low256, high256, 1, N); } else { - (low256, high256) = - LibUint512Math.mul(K_2_INVM_N, _expmod(low256, high256, 1, N)); + (low256, high256) = LibUint512Math.mul(K_2_INVM_N, _expmod(low256, high256, 1, N)); s = _expmod(low256, high256, 1, N); } @@ -118,9 +110,7 @@ abstract contract TaikoL2Signer { mstore(add(p, 0xa0), e) // Exponent mstore(add(p, 0xc0), m) // Modulus - if iszero(staticcall(sub(gas(), 2000), 0x05, p, 0xe0, p, 0x20)) { - revert(0, 0) - } + if iszero(staticcall(sub(gas(), 2000), 0x05, p, 0xe0, p, 0x20)) { revert(0, 0) } o := mload(p) } } diff --git a/packages/protocol/contracts/bridge/Bridge.sol b/packages/protocol/contracts/bridge/Bridge.sol index f4a3fb98374..2b933ec3f88 100644 --- a/packages/protocol/contracts/bridge/Bridge.sol +++ b/packages/protocol/contracts/bridge/Bridge.sol @@ -5,12 +5,11 @@ // |_|\__,_|_|_\_\___/ |____\__,_|_.__/__/ pragma solidity ^0.8.20; -import { EssentialContract } from "../common/EssentialContract.sol"; -import { Proxied } from "../common/Proxied.sol"; -import { ISignalService } from "../signal/ISignalService.sol"; -import { LibAddress } from "../libs/LibAddress.sol"; - -import { IBridge, IRecallableSender } from "./IBridge.sol"; +import "../common/EssentialContract.sol"; +import "../common/Proxied.sol"; +import "../signal/ISignalService.sol"; +import "../libs/LibAddress.sol"; +import "./IBridge.sol"; /// @title Bridge /// @dev Labeled in AddressResolver as "bridge" @@ -126,28 +125,23 @@ contract Bridge is EssentialContract, IBridge { bytes32 msgHash = hashMessage(message); if (isMessageRecalled[msgHash]) revert B_RECALLED_ALREADY(); - bool received = _proveSignalReceived( - _signalForFailedMessage(msgHash), message.destChainId, proof - ); + bool received = + _proveSignalReceived(_signalForFailedMessage(msgHash), message.destChainId, proof); if (!received) revert B_NOT_FAILED(); isMessageRecalled[msgHash] = true; // Execute the recall logic based on the contract's support for the // IRecallableSender interface - bool support = - message.from.supportsInterface(type(IRecallableSender).interfaceId); + bool support = message.from.supportsInterface(type(IRecallableSender).interfaceId); if (support) { - _ctx = Context({ - msgHash: msgHash, - from: address(this), - srcChainId: message.srcChainId - }); + _ctx = + Context({ msgHash: msgHash, from: address(this), srcChainId: message.srcChainId }); // Perform recall - IRecallableSender(message.from).onMessageRecalled{ - value: message.value - }(message, msgHash); + IRecallableSender(message.from).onMessageRecalled{ value: message.value }( + message, msgHash + ); // Reset the context after the message call _ctx = Context({ @@ -204,8 +198,7 @@ contract Bridge is EssentialContract, IBridge { } else { // Use the specified message gas limit if called by the owner, else // use remaining gas - uint256 gasLimit = - msg.sender == message.owner ? gasleft() : message.gasLimit; + uint256 gasLimit = msg.sender == message.owner ? gasleft() : message.gasLimit; if (_invokeMessageCall(message, msgHash, gasLimit)) { status = Status.DONE; @@ -218,8 +211,7 @@ contract Bridge is EssentialContract, IBridge { _updateMessageStatus(msgHash, status); // Determine the refund recipient - address refundTo = - message.refundTo == address(0) ? message.owner : message.refundTo; + address refundTo = message.refundTo == address(0) ? message.owner : message.refundTo; // Refund the processing fee if (msg.sender == refundTo) { @@ -273,11 +265,7 @@ contract Bridge is EssentialContract, IBridge { /// @notice Checks if the message was sent. /// @param message The message. /// @return True if the message was sent. - function isMessageSent(Message calldata message) - public - view - returns (bool) - { + function isMessageSent(Message calldata message) public view returns (bool) { if (message.srcChainId != block.chainid) return false; return ISignalService(resolve("signal_service", false)).isSignalSent({ app: address(this), @@ -299,9 +287,7 @@ contract Bridge is EssentialContract, IBridge { { if (message.srcChainId != block.chainid) return false; return _proveSignalReceived( - _signalForFailedMessage(hashMessage(message)), - message.destChainId, - proof + _signalForFailedMessage(hashMessage(message)), message.destChainId, proof ); } @@ -318,9 +304,7 @@ contract Bridge is EssentialContract, IBridge { returns (bool) { if (message.destChainId != block.chainid) return false; - return _proveSignalReceived( - hashMessage(message), message.srcChainId, proof - ); + return _proveSignalReceived(hashMessage(message), message.srcChainId, proof); } /// @notice Checks if the destination chain is enabled. @@ -346,11 +330,7 @@ contract Bridge is EssentialContract, IBridge { } /// @notice Hash the message - function hashMessage(Message memory message) - public - pure - returns (bytes32) - { + function hashMessage(Message memory message) public pure returns (bytes32) { return keccak256(abi.encode("TAIKO_MESSAGE", message)); } @@ -373,15 +353,10 @@ contract Bridge is EssentialContract, IBridge { if (gasLimit == 0) revert B_INVALID_GAS_LIMIT(); assert(message.from != address(this)); - _ctx = Context({ - msgHash: msgHash, - from: message.from, - srcChainId: message.srcChainId - }); + _ctx = Context({ msgHash: msgHash, from: message.from, srcChainId: message.srcChainId }); // Perform the message call and capture the success value - (success,) = - message.to.call{ value: message.value, gas: gasLimit }(message.data); + (success,) = message.to.call{ value: message.value, gas: gasLimit }(message.data); // Reset the context after the message call _ctx = Context({ @@ -423,8 +398,7 @@ contract Bridge is EssentialContract, IBridge { view returns (bool) { - return ISignalService(resolve("signal_service", false)) - .proveSignalReceived({ + return ISignalService(resolve("signal_service", false)).proveSignalReceived({ srcChainId: srcChainId, app: resolve(srcChainId, "bridge", false), signal: signal, @@ -432,11 +406,7 @@ contract Bridge is EssentialContract, IBridge { }); } - function _signalForFailedMessage(bytes32 msgHash) - private - pure - returns (bytes32) - { + function _signalForFailedMessage(bytes32 msgHash) private pure returns (bytes32) { return msgHash ^ bytes32(uint256(Status.FAILED)); } } diff --git a/packages/protocol/contracts/common/AddressManager.sol b/packages/protocol/contracts/common/AddressManager.sol index 0cb649773a8..0601489d4ae 100644 --- a/packages/protocol/contracts/common/AddressManager.sol +++ b/packages/protocol/contracts/common/AddressManager.sol @@ -6,10 +6,8 @@ pragma solidity ^0.8.20; -import { Ownable2StepUpgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/access/Ownable2StepUpgradeable.sol"; - -import { Proxied } from "./Proxied.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/access/Ownable2StepUpgradeable.sol"; +import "./Proxied.sol"; /// @title IAddressManager /// @notice Specifies methods to manage address mappings for given chainId-name @@ -21,13 +19,7 @@ interface IAddressManager { /// @param chainId The chainId for which the address needs to be fetched. /// @param name The name for which the address needs to be fetched. /// @return Address associated with the chainId-name pair. - function getAddress( - uint64 chainId, - bytes32 name - ) - external - view - returns (address); + function getAddress(uint64 chainId, bytes32 name) external view returns (address); } /// @title AddressManager @@ -37,10 +29,7 @@ contract AddressManager is Ownable2StepUpgradeable, IAddressManager { uint256[49] private __gap; event AddressSet( - uint64 indexed chainId, - bytes32 indexed name, - address newAddress, - address oldAddress + uint64 indexed chainId, bytes32 indexed name, address newAddress, address oldAddress ); /// @notice Initializes the owner for the upgradable contract. @@ -67,15 +56,7 @@ contract AddressManager is Ownable2StepUpgradeable, IAddressManager { } /// @inheritdoc IAddressManager - function getAddress( - uint64 chainId, - bytes32 name - ) - public - view - override - returns (address) - { + function getAddress(uint64 chainId, bytes32 name) public view override returns (address) { return addresses[chainId][name]; } } diff --git a/packages/protocol/contracts/common/AddressResolver.sol b/packages/protocol/contracts/common/AddressResolver.sol index c8c8d733f54..2fb319e9eda 100644 --- a/packages/protocol/contracts/common/AddressResolver.sol +++ b/packages/protocol/contracts/common/AddressResolver.sol @@ -6,9 +6,8 @@ pragma solidity ^0.8.20; -import { StringsUpgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/utils/StringsUpgradeable.sol"; -import { IAddressManager } from "./AddressManager.sol"; +import "lib/openzeppelin-contracts/contracts/utils/Strings.sol"; +import "./AddressManager.sol"; /// @title AddressResolver /// @notice This contract acts as a bridge for name-to-address resolution. @@ -20,7 +19,7 @@ import { IAddressManager } from "./AddressManager.sol"; /// is no setAddressManager() function go guarantee atomicness across all /// contracts that are resolvers. abstract contract AddressResolver { - using StringsUpgradeable for uint256; + using Strings for uint256; address public addressManager; uint256[49] private __gap; @@ -102,8 +101,7 @@ abstract contract AddressResolver { { if (addressManager == address(0)) revert RESOLVER_INVALID_MANAGER(); - addr = - payable(IAddressManager(addressManager).getAddress(chainId, name)); + addr = payable(IAddressManager(addressManager).getAddress(chainId, name)); if (!allowZeroAddress && addr == address(0)) { revert RESOLVER_ZERO_ADDR(chainId, uint256(name).toString()); diff --git a/packages/protocol/contracts/common/AuthorizableContract.sol b/packages/protocol/contracts/common/AuthorizableContract.sol index 4a5532e2746..4c83bbf0e8b 100644 --- a/packages/protocol/contracts/common/AuthorizableContract.sol +++ b/packages/protocol/contracts/common/AuthorizableContract.sol @@ -6,7 +6,7 @@ pragma solidity ^0.8.20; -import { EssentialContract } from "../common/EssentialContract.sol"; +import "../common/EssentialContract.sol"; /// @title AuthorizableContract abstract contract AuthorizableContract is EssentialContract { @@ -38,14 +38,7 @@ abstract contract AuthorizableContract is EssentialContract { return authorizedAddresses[addr] != 0; } - function isAuthorizedAs( - address addr, - bytes32 label - ) - public - view - returns (bool) - { + function isAuthorizedAs(address addr, bytes32 label) public view returns (bool) { return label != 0 && authorizedAddresses[addr] == label; } diff --git a/packages/protocol/contracts/common/EssentialContract.sol b/packages/protocol/contracts/common/EssentialContract.sol index 101d596b6d9..42199349b9c 100644 --- a/packages/protocol/contracts/common/EssentialContract.sol +++ b/packages/protocol/contracts/common/EssentialContract.sol @@ -6,19 +6,14 @@ pragma solidity ^0.8.20; -import { Ownable2StepUpgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/access/Ownable2StepUpgradeable.sol"; - -import { AddressResolver } from "./AddressResolver.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/access/Ownable2StepUpgradeable.sol"; +import "./AddressResolver.sol"; /// @title EssentialContract /// @notice This contract serves as the base contract for many core components. /// @dev We didn't use OpenZeppelin's PausableUpgradeable and /// ReentrancyGuardUpgradeable contract to optimize storage reads. -abstract contract EssentialContract is - Ownable2StepUpgradeable, - AddressResolver -{ +abstract contract EssentialContract is Ownable2StepUpgradeable, AddressResolver { uint8 private constant _FALSE = 1; uint8 private constant _TRUE = 2; diff --git a/packages/protocol/contracts/common/ICrossChainSync.sol b/packages/protocol/contracts/common/ICrossChainSync.sol index f491e15cf73..87fdf59cf70 100644 --- a/packages/protocol/contracts/common/ICrossChainSync.sol +++ b/packages/protocol/contracts/common/ICrossChainSync.sol @@ -28,18 +28,12 @@ interface ICrossChainSync { /// @param blockHash The hash of the synced block. /// @param signalRoot The root hash representing cross-chain signals. event CrossChainSynced( - uint64 indexed syncedInBlock, - uint64 indexed blockId, - bytes32 blockHash, - bytes32 signalRoot + uint64 indexed syncedInBlock, uint64 indexed blockId, bytes32 blockHash, bytes32 signalRoot ); /// @notice Fetches the hash of a block from the opposite chain. /// @param blockId The target block id. Specifying 0 retrieves the hash /// of the latest block. /// @return snippet The block hash and signal root synced. - function getSyncedSnippet(uint64 blockId) - external - view - returns (Snippet memory snippet); + function getSyncedSnippet(uint64 blockId) external view returns (Snippet memory snippet); } diff --git a/packages/protocol/contracts/common/Proxied.sol b/packages/protocol/contracts/common/Proxied.sol index fe66d15abaf..a09d3ea5e0c 100644 --- a/packages/protocol/contracts/common/Proxied.sol +++ b/packages/protocol/contracts/common/Proxied.sol @@ -6,8 +6,7 @@ pragma solidity ^0.8.20; -import { Initializable } from - "lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol"; /// @title Proxied /// @dev Extends OpenZeppelin's Initializable for upgradeable contracts. diff --git a/packages/protocol/contracts/libs/LibAddress.sol b/packages/protocol/contracts/libs/LibAddress.sol index 0402013a0b5..e71e1e9946c 100644 --- a/packages/protocol/contracts/libs/LibAddress.sol +++ b/packages/protocol/contracts/libs/LibAddress.sol @@ -6,14 +6,10 @@ pragma solidity ^0.8.20; -import { AddressUpgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/utils/AddressUpgradeable.sol"; -import { ECDSAUpgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/utils/cryptography/ECDSAUpgradeable.sol"; -import { IERC165Upgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/utils/introspection/IERC165Upgradeable.sol"; -import { IERC1271Upgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/interfaces/IERC1271Upgradeable.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/utils/AddressUpgradeable.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/utils/cryptography/ECDSAUpgradeable.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/utils/introspection/IERC165Upgradeable.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/interfaces/IERC1271Upgradeable.sol"; /// @title LibAddress /// @dev Provides utilities for address-related operations. @@ -57,9 +53,7 @@ library LibAddress { { if (!AddressUpgradeable.isContract(addr)) return false; - try IERC165Upgradeable(addr).supportsInterface(interfaceId) returns ( - bool _result - ) { + try IERC165Upgradeable(addr).supportsInterface(interfaceId) returns (bool _result) { result = _result; } catch { } } @@ -74,8 +68,7 @@ library LibAddress { returns (bool valid) { if (AddressUpgradeable.isContract(addr)) { - return IERC1271Upgradeable(addr).isValidSignature(hash, sig) - == EIP1271_MAGICVALUE; + return IERC1271Upgradeable(addr).isValidSignature(hash, sig) == EIP1271_MAGICVALUE; } else { return ECDSAUpgradeable.recover(hash, sig) == addr; } diff --git a/packages/protocol/contracts/signal/ISignalService.sol b/packages/protocol/contracts/signal/ISignalService.sol index db1e96da882..8b7b54a4229 100644 --- a/packages/protocol/contracts/signal/ISignalService.sol +++ b/packages/protocol/contracts/signal/ISignalService.sol @@ -20,21 +20,13 @@ interface ISignalService { /// of 1. /// @param signal The signal (message) to send. /// @return storageSlot The location in storage where this signal is stored. - function sendSignal(bytes32 signal) - external - returns (bytes32 storageSlot); + function sendSignal(bytes32 signal) external returns (bytes32 storageSlot); /// @notice Verifies if a particular signal has already been sent. /// @param app The address that initiated the signal. /// @param signal The signal (message) to send. /// @return True if the signal has been sent, otherwise false. - function isSignalSent( - address app, - bytes32 signal - ) - external - view - returns (bool); + function isSignalSent(address app, bytes32 signal) external view returns (bool); /// @notice Verifies if a signal has been received on the target chain. /// @param srcChainId The identifier for the source chain from which the diff --git a/packages/protocol/contracts/signal/SignalService.sol b/packages/protocol/contracts/signal/SignalService.sol index bca95a2bf81..5750bbf5e66 100644 --- a/packages/protocol/contracts/signal/SignalService.sol +++ b/packages/protocol/contracts/signal/SignalService.sol @@ -6,15 +6,14 @@ pragma solidity ^0.8.20; -import { SafeCastUpgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/utils/math/SafeCastUpgradeable.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/utils/math/SafeCastUpgradeable.sol"; -import { AuthorizableContract } from "../common/AuthorizableContract.sol"; -import { ICrossChainSync } from "../common/ICrossChainSync.sol"; -import { Proxied } from "../common/Proxied.sol"; -import { LibSecureMerkleTrie } from "../thirdparty/LibSecureMerkleTrie.sol"; +import "../common/AuthorizableContract.sol"; +import "../common/ICrossChainSync.sol"; +import "../common/Proxied.sol"; +import "../thirdparty/LibSecureMerkleTrie.sol"; -import { ISignalService } from "./ISignalService.sol"; +import "./ISignalService.sol"; /// @title SignalService /// @dev Labeled in AddressResolver as "signal_service" @@ -62,14 +61,7 @@ contract SignalService is AuthorizableContract, ISignalService { } /// @inheritdoc ISignalService - function isSignalSent( - address app, - bytes32 signal - ) - public - view - returns (bool) - { + function isSignalSent(address app, bytes32 signal) public view returns (bool) { if (signal == 0) revert SS_INVALID_SIGNAL(); if (app == address(0)) revert SS_INVALID_APP(); bytes32 slot = getSignalSlot(uint64(block.chainid), app, signal); @@ -93,10 +85,7 @@ contract SignalService is AuthorizableContract, ISignalService { { if (skipProofCheck()) return true; - if ( - app == address(0) || signal == 0 || srcChainId == 0 - || srcChainId == block.chainid - ) { + if (app == address(0) || signal == 0 || srcChainId == 0 || srcChainId == block.chainid) { return false; } @@ -120,9 +109,7 @@ contract SignalService is AuthorizableContract, ISignalService { return false; } - bytes32 signalRoot = ICrossChainSync(p.crossChainSync).getSyncedSnippet( - p.height - ).signalRoot; + bytes32 signalRoot = ICrossChainSync(p.crossChainSync).getSyncedSnippet(p.height).signalRoot; if (signalRoot == 0) return false; diff --git a/packages/protocol/contracts/team/TimeLockTokenPool.sol b/packages/protocol/contracts/team/TimeLockTokenPool.sol index 57ad948f56f..0e30f41a5a3 100644 --- a/packages/protocol/contracts/team/TimeLockTokenPool.sol +++ b/packages/protocol/contracts/team/TimeLockTokenPool.sol @@ -6,16 +6,12 @@ pragma solidity ^0.8.20; -import { Ownable2StepUpgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/access/Ownable2StepUpgradeable.sol"; -import { ERC20Upgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol"; -import { SafeERC20Upgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/utils/SafeERC20Upgradeable.sol"; -import { ECDSAUpgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/utils/cryptography/ECDSAUpgradeable.sol"; - -import { Proxied } from "../common/Proxied.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/access/Ownable2StepUpgradeable.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/utils/SafeERC20Upgradeable.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/utils/cryptography/ECDSAUpgradeable.sol"; +import "../common/Proxied.sol"; + /// @title TimeLockTokenPool /// Contract for managing Taiko tokens allocated to different roles and /// individuals. @@ -31,7 +27,6 @@ import { Proxied } from "../common/Proxied.sol"; /// - investors /// - team members, advisors, etc. /// - grant program grantees - contract TimeLockTokenPool is Ownable2StepUpgradeable { using SafeERC20Upgradeable for ERC20Upgradeable; @@ -82,13 +77,7 @@ contract TimeLockTokenPool is Ownable2StepUpgradeable { error NOTHING_TO_WITHDRAW(); error TOO_MANY(); - function init( - address _taikoToken, - address _sharedVault - ) - external - initializer - { + function init(address _taikoToken, address _sharedVault) external initializer { Ownable2StepUpgradeable.__Ownable2Step_init(); if (_taikoToken == address(0)) revert INVALID_PARAM(); @@ -139,9 +128,7 @@ contract TimeLockTokenPool is Ownable2StepUpgradeable { /// @notice Withdraws all withdrawable tokens. function withdraw(address to, bytes memory sig) external { if (to == address(0)) revert INVALID_PARAM(); - bytes32 hash = keccak256( - abi.encodePacked("Withdraw unlocked Taiko token to: ", to) - ); + bytes32 hash = keccak256(abi.encodePacked("Withdraw unlocked Taiko token to: ", to)); address recipient = ECDSAUpgradeable.recover(hash, sig); _withdraw(recipient, to); } @@ -166,11 +153,7 @@ contract TimeLockTokenPool is Ownable2StepUpgradeable { amountWithdrawable = amountUnlocked - amountWithdrawn; } - function getMyGrants(address recipient) - public - view - returns (Grant[] memory) - { + function getMyGrants(address recipient) public view returns (Grant[] memory) { return recipients[recipient].grants; } @@ -192,10 +175,7 @@ contract TimeLockTokenPool is Ownable2StepUpgradeable { emit Withdrawn(recipient, to, amount); } - function _voidGrant(Grant storage g) - private - returns (uint128 amountVoided) - { + function _voidGrant(Grant storage g) private returns (uint128 amountVoided) { uint128 amountOwned = _getAmountOwned(g); amountVoided = g.amount - amountOwned; @@ -209,14 +189,8 @@ contract TimeLockTokenPool is Ownable2StepUpgradeable { return _calcAmount(g.amount, g.grantStart, g.grantCliff, g.grantPeriod); } - function _getAmountUnlocked(Grant memory g) - private - view - returns (uint128) - { - return _calcAmount( - _getAmountOwned(g), g.unlockStart, g.unlockCliff, g.unlockPeriod - ); + function _getAmountUnlocked(Grant memory g) private view returns (uint128) { + return _calcAmount(_getAmountOwned(g), g.unlockStart, g.unlockCliff, g.unlockPeriod); } function _calcAmount( @@ -247,14 +221,7 @@ contract TimeLockTokenPool is Ownable2StepUpgradeable { _validateCliff(g.unlockStart, g.unlockCliff, g.unlockPeriod); } - function _validateCliff( - uint64 start, - uint64 cliff, - uint32 period - ) - private - pure - { + function _validateCliff(uint64 start, uint64 cliff, uint32 period) private pure { if (start == 0 || period == 0) { if (cliff > 0) revert INVALID_GRANT(); } else { diff --git a/packages/protocol/contracts/test/erc20/FreeMintERC20.sol b/packages/protocol/contracts/test/erc20/FreeMintERC20.sol index 9c4adf75eea..90c09e74208 100644 --- a/packages/protocol/contracts/test/erc20/FreeMintERC20.sol +++ b/packages/protocol/contracts/test/erc20/FreeMintERC20.sol @@ -6,8 +6,7 @@ pragma solidity ^0.8.20; -import { ERC20 } from - "lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol"; +import "lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol"; // An ERC20 Token with a mint function anyone can call, for free, to receive // 5 tokens. diff --git a/packages/protocol/contracts/test/erc20/MayFailFreeMintERC20.sol b/packages/protocol/contracts/test/erc20/MayFailFreeMintERC20.sol index 103d3ae21dc..3883d0bd01c 100644 --- a/packages/protocol/contracts/test/erc20/MayFailFreeMintERC20.sol +++ b/packages/protocol/contracts/test/erc20/MayFailFreeMintERC20.sol @@ -6,8 +6,7 @@ pragma solidity ^0.8.20; -import { ERC20 } from - "lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol"; +import "lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol"; // An ERC20 token for testing the Taiko Bridge on testnets. // This token has 50% of failure on transfers so we can @@ -29,14 +28,7 @@ contract MayFailFreeMintERC20 is ERC20 { _mint(to, 50 * (10 ** decimals())); } - function transfer( - address to, - uint256 amount - ) - public - override - returns (bool) - { + function transfer(address to, uint256 amount) public override returns (bool) { _mayFail(); return ERC20.transfer(to, amount); } diff --git a/packages/protocol/contracts/test/erc20/RegularERC20.sol b/packages/protocol/contracts/test/erc20/RegularERC20.sol index 588e6fe92c4..086a787512c 100644 --- a/packages/protocol/contracts/test/erc20/RegularERC20.sol +++ b/packages/protocol/contracts/test/erc20/RegularERC20.sol @@ -2,8 +2,7 @@ pragma solidity ^0.8.20; -import { ERC20 } from - "lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol"; +import "lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol"; contract RegularERC20 is ERC20 { constructor(uint256 initialSupply) ERC20("RegularERC20", "RGL") { diff --git a/packages/protocol/contracts/thirdparty/LibBytesUtils.sol b/packages/protocol/contracts/thirdparty/LibBytesUtils.sol index dd411386bfe..24210d7c8fb 100644 --- a/packages/protocol/contracts/thirdparty/LibBytesUtils.sol +++ b/packages/protocol/contracts/thirdparty/LibBytesUtils.sol @@ -68,21 +68,14 @@ library LibBytesUtils { // because when slicing multiples of 32 bytes (lengthmod == 0) // the following copy loop was copying the origin's length // and then ending prematurely not copying everything it should. - let mc := - add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod))) + let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod))) let end := add(mc, _length) for { // The multiplication in the next line has the same exact // purpose // as the one above. - let cc := - add( - add( - add(_bytes, lengthmod), mul(0x20, iszero(lengthmod)) - ), - _start - ) + let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start) } lt(mc, end) { mc := add(mc, 0x20) cc := add(cc, 0x20) @@ -110,14 +103,7 @@ library LibBytesUtils { return tempBytes; } - function slice( - bytes memory _bytes, - uint256 _start - ) - internal - pure - returns (bytes memory) - { + function slice(bytes memory _bytes, uint256 _start) internal pure returns (bytes memory) { if (_start >= _bytes.length) { return bytes(""); } @@ -138,11 +124,7 @@ library LibBytesUtils { // 32 bytes } - function toNibbles(bytes memory _bytes) - internal - pure - returns (bytes memory) - { + function toNibbles(bytes memory _bytes) internal pure returns (bytes memory) { bytes memory nibbles = new bytes(_bytes.length * 2); for (uint256 i; i < _bytes.length; ++i) { @@ -153,14 +135,7 @@ library LibBytesUtils { return nibbles; } - function equal( - bytes memory _bytes, - bytes memory _other - ) - internal - pure - returns (bool) - { + function equal(bytes memory _bytes, bytes memory _other) internal pure returns (bool) { return keccak256(_bytes) == keccak256(_other); } } diff --git a/packages/protocol/contracts/thirdparty/LibFixedPointMath.sol b/packages/protocol/contracts/thirdparty/LibFixedPointMath.sol index 1f2d33f5ad0..f9862f5151b 100644 --- a/packages/protocol/contracts/thirdparty/LibFixedPointMath.sol +++ b/packages/protocol/contracts/thirdparty/LibFixedPointMath.sol @@ -37,9 +37,7 @@ library LibFixedPointMath { // powers of two // such that exp(x) = exp(x') * 2**k, where k is an integer. // Solving this gives k = round(x / log(2)) and x' = x - k * log(2). - int256 k = ( - (x << 96) / 54_916_777_467_707_473_351_141_471_128 + 2 ** 95 - ) >> 96; + int256 k = ((x << 96) / 54_916_777_467_707_473_351_141_471_128 + 2 ** 95) >> 96; x = x - k * 54_916_777_467_707_473_351_141_471_128; // k is in the range [-61, 195]. @@ -77,11 +75,8 @@ library LibFixedPointMath { // basis // so the final right shift is always by a positive amount. r = int256( - ( - uint256(r) - * - 3_822_833_074_963_236_453_042_738_258_902_158_003_155_416_615_667 - ) >> uint256(195 - k) + (uint256(r) * 3_822_833_074_963_236_453_042_738_258_902_158_003_155_416_615_667) + >> uint256(195 - k) ); } } diff --git a/packages/protocol/contracts/thirdparty/LibMerkleTrie.sol b/packages/protocol/contracts/thirdparty/LibMerkleTrie.sol index 4332b42da6d..77cb64d991d 100644 --- a/packages/protocol/contracts/thirdparty/LibMerkleTrie.sol +++ b/packages/protocol/contracts/thirdparty/LibMerkleTrie.sol @@ -28,8 +28,8 @@ pragma solidity ^0.8.20; /* Library Imports */ -import { LibBytesUtils } from "./LibBytesUtils.sol"; -import { LibRLPReader } from "./LibRLPReader.sol"; +import "./LibBytesUtils.sol"; +import "./LibRLPReader.sol"; /** * @title LibMerkleTrie @@ -120,8 +120,7 @@ library LibMerkleTrie { require(exists || isFinalNode, "Provided proof is invalid."); - bytes memory value = - exists ? _getNodeValue(proof[pathLength - 1]) : bytes(""); + bytes memory value = exists ? _getNodeValue(proof[pathLength - 1]) : bytes(""); return (exists, value); } @@ -142,11 +141,7 @@ library LibMerkleTrie { ) private pure - returns ( - uint256 _pathLength, - bytes memory _keyRemainder, - bool _isFinalNode - ) + returns (uint256 _pathLength, bytes memory _keyRemainder, bool _isFinalNode) { uint256 pathLength; bytes memory key = LibBytesUtils.toNibbles(_key); @@ -168,21 +163,16 @@ library LibMerkleTrie { if (currentKeyIndex == 0) { // First proof element is always the root node. - require( - keccak256(currentNode.encoded) == currentNodeID, - "Invalid root hash" - ); + require(keccak256(currentNode.encoded) == currentNodeID, "Invalid root hash"); } else if (currentNode.encoded.length >= 32) { // Nodes 32 bytes or larger are hashed inside branch nodes. require( - keccak256(currentNode.encoded) == currentNodeID, - "Invalid large internal hash" + keccak256(currentNode.encoded) == currentNodeID, "Invalid large internal hash" ); } else { // Nodes smaller than 31 bytes aren't hashed. require( - LibBytesUtils.toBytes32(currentNode.encoded) - == currentNodeID, + LibBytesUtils.toBytes32(currentNode.encoded) == currentNodeID, "Invalid internal node hash" ); } @@ -196,23 +186,18 @@ library LibMerkleTrie { // We're not at the end of the key yet. // Figure out what the next node ID should be and continue. uint8 branchKey = uint8(key[currentKeyIndex]); - LibRLPReader.RLPItem memory nextNode = - currentNode.decoded[branchKey]; + LibRLPReader.RLPItem memory nextNode = currentNode.decoded[branchKey]; currentNodeID = _getNodeID(nextNode); currentKeyIncrement = 1; continue; } - } else if ( - currentNode.decoded.length == LEAF_OR_EXTENSION_NODE_LENGTH - ) { + } else if (currentNode.decoded.length == LEAF_OR_EXTENSION_NODE_LENGTH) { bytes memory path = _getNodePath(currentNode); uint8 prefix = uint8(path[0]); uint8 offset = 2 - (prefix % 2); bytes memory pathRemainder = LibBytesUtils.slice(path, offset); - bytes memory keyRemainder = - LibBytesUtils.slice(key, currentKeyIndex); - uint256 sharedNibbleLength = - _getSharedNibbleLength(pathRemainder, keyRemainder); + bytes memory keyRemainder = LibBytesUtils.slice(key, currentKeyIndex); + uint256 sharedNibbleLength = _getSharedNibbleLength(pathRemainder, keyRemainder); if (prefix == PREFIX_LEAF_EVEN || prefix == PREFIX_LEAF_ODD) { if ( @@ -228,10 +213,7 @@ library LibMerkleTrie { // We've hit a leaf node, so our next node should be NULL. currentNodeID = bytes32(RLP_NULL); break; - } else if ( - prefix == PREFIX_EXTENSION_EVEN - || prefix == PREFIX_EXTENSION_ODD - ) { + } else if (prefix == PREFIX_EXTENSION_EVEN || prefix == PREFIX_EXTENSION_ODD) { if (sharedNibbleLength != pathRemainder.length) { // Our extension node is not identical to the remainder. // We've hit the end of this path @@ -255,8 +237,7 @@ library LibMerkleTrie { // If our node ID is NULL, then we're at a dead end. bool isFinalNode = currentNodeID == bytes32(RLP_NULL); - return - (pathLength, LibBytesUtils.slice(key, currentKeyIndex), isFinalNode); + return (pathLength, LibBytesUtils.slice(key, currentKeyIndex), isFinalNode); } /** @@ -264,20 +245,13 @@ library LibMerkleTrie { * @param _proof RLP-encoded proof to parse. * @return _parsed Proof parsed into easily accessible structs. */ - function _parseProof(bytes memory _proof) - private - pure - returns (TrieNode[] memory _parsed) - { + function _parseProof(bytes memory _proof) private pure returns (TrieNode[] memory _parsed) { LibRLPReader.RLPItem[] memory nodes = LibRLPReader.readList(_proof); TrieNode[] memory proof = new TrieNode[](nodes.length); for (uint256 i; i < nodes.length; ++i) { bytes memory encoded = LibRLPReader.readBytes(nodes[i]); - proof[i] = TrieNode({ - encoded: encoded, - decoded: LibRLPReader.readList(encoded) - }); + proof[i] = TrieNode({ encoded: encoded, decoded: LibRLPReader.readList(encoded) }); } return proof; @@ -290,11 +264,7 @@ library LibMerkleTrie { * @param _node Node to pull an ID for. * @return _nodeID ID for the node, depending on the size of its contents. */ - function _getNodeID(LibRLPReader.RLPItem memory _node) - private - pure - returns (bytes32 _nodeID) - { + function _getNodeID(LibRLPReader.RLPItem memory _node) private pure returns (bytes32 _nodeID) { bytes memory nodeID; if (_node.length < 32) { @@ -313,11 +283,7 @@ library LibMerkleTrie { * @param _node Node to get a path for. * @return _path Node path, converted to an array of nibbles. */ - function _getNodePath(TrieNode memory _node) - private - pure - returns (bytes memory _path) - { + function _getNodePath(TrieNode memory _node) private pure returns (bytes memory _path) { return LibBytesUtils.toNibbles(LibRLPReader.readBytes(_node.decoded[0])); } @@ -326,11 +292,7 @@ library LibMerkleTrie { * @param _node Node to get a value for. * @return _value Node value, as hex bytes. */ - function _getNodeValue(TrieNode memory _node) - private - pure - returns (bytes memory _value) - { + function _getNodeValue(TrieNode memory _node) private pure returns (bytes memory _value) { return LibRLPReader.readBytes(_node.decoded[_node.decoded.length - 1]); } diff --git a/packages/protocol/contracts/thirdparty/LibRLPReader.sol b/packages/protocol/contracts/thirdparty/LibRLPReader.sol index 7f354acbf36..e1c367fb159 100644 --- a/packages/protocol/contracts/thirdparty/LibRLPReader.sol +++ b/packages/protocol/contracts/thirdparty/LibRLPReader.sol @@ -49,11 +49,7 @@ library LibRLPReader { * @param _in Input bytes to convert. * @return Output memory reference. */ - function toRLPItem(bytes memory _in) - internal - pure - returns (RLPItem memory) - { + function toRLPItem(bytes memory _in) internal pure returns (RLPItem memory) { uint256 ptr; assembly { ptr := add(_in, 32) @@ -67,11 +63,7 @@ library LibRLPReader { * @param _in RLP list value. * @return Decoded RLP list items. */ - function readList(RLPItem memory _in) - internal - pure - returns (RLPItem[] memory) - { + function readList(RLPItem memory _in) internal pure returns (RLPItem[] memory) { (uint256 listOffset,, RLPItemType itemType) = _decodeLength(_in); require(itemType == RLPItemType.LIST_ITEM, "Invalid RLP list value."); @@ -89,19 +81,12 @@ library LibRLPReader { uint256 itemCount; uint256 offset = listOffset; while (offset < _in.length) { - require( - itemCount < MAX_LIST_LENGTH, - "Provided RLP list exceeds max list length." - ); + require(itemCount < MAX_LIST_LENGTH, "Provided RLP list exceeds max list length."); - (uint256 itemOffset, uint256 itemLength,) = _decodeLength( - RLPItem({ length: _in.length - offset, ptr: _in.ptr + offset }) - ); + (uint256 itemOffset, uint256 itemLength,) = + _decodeLength(RLPItem({ length: _in.length - offset, ptr: _in.ptr + offset })); - out[itemCount] = RLPItem({ - length: itemLength + itemOffset, - ptr: _in.ptr + offset - }); + out[itemCount] = RLPItem({ length: itemLength + itemOffset, ptr: _in.ptr + offset }); itemCount += 1; offset += itemOffset + itemLength; @@ -120,11 +105,7 @@ library LibRLPReader { * @param _in RLP list value. * @return Decoded RLP list items. */ - function readList(bytes memory _in) - internal - pure - returns (RLPItem[] memory) - { + function readList(bytes memory _in) internal pure returns (RLPItem[] memory) { return readList(toRLPItem(_in)); } @@ -133,13 +114,8 @@ library LibRLPReader { * @param _in RLP bytes value. * @return Decoded bytes. */ - function readBytes(RLPItem memory _in) - internal - pure - returns (bytes memory) - { - (uint256 itemOffset, uint256 itemLength, RLPItemType itemType) = - _decodeLength(_in); + function readBytes(RLPItem memory _in) internal pure returns (bytes memory) { + (uint256 itemOffset, uint256 itemLength, RLPItemType itemType) = _decodeLength(_in); require(itemType == RLPItemType.DATA_ITEM, "Invalid RLP bytes value."); @@ -160,11 +136,7 @@ library LibRLPReader { * @param _in RLP string value. * @return Decoded string. */ - function readString(RLPItem memory _in) - internal - pure - returns (string memory) - { + function readString(RLPItem memory _in) internal pure returns (string memory) { return string(readBytes(_in)); } @@ -173,11 +145,7 @@ library LibRLPReader { * @param _in RLP string value. * @return Decoded string. */ - function readString(bytes memory _in) - internal - pure - returns (string memory) - { + function readString(bytes memory _in) internal pure returns (string memory) { return readString(toRLPItem(_in)); } @@ -189,8 +157,7 @@ library LibRLPReader { function readBytes32(RLPItem memory _in) internal pure returns (bytes32) { require(_in.length <= 33, "Invalid RLP bytes32 value."); - (uint256 itemOffset, uint256 itemLength, RLPItemType itemType) = - _decodeLength(_in); + (uint256 itemOffset, uint256 itemLength, RLPItemType itemType) = _decodeLength(_in); require(itemType == RLPItemType.DATA_ITEM, "Invalid RLP bytes32 value."); @@ -200,9 +167,7 @@ library LibRLPReader { out := mload(ptr) // Shift the bytes over to match the item size. - if lt(itemLength, 32) { - out := div(out, exp(256, sub(32, itemLength))) - } + if lt(itemLength, 32) { out := div(out, exp(256, sub(32, itemLength))) } } return out; @@ -249,10 +214,7 @@ library LibRLPReader { out := byte(0, mload(ptr)) } - require( - out == 0 || out == 1, - "LibRLPReader: Invalid RLP boolean value, must be 0 or 1" - ); + require(out == 0 || out == 1, "LibRLPReader: Invalid RLP boolean value, must be 0 or 1"); return out != 0; } @@ -295,11 +257,7 @@ library LibRLPReader { * @param _in RLP item to read. * @return Raw RLP bytes. */ - function readRawBytes(RLPItem memory _in) - internal - pure - returns (bytes memory) - { + function readRawBytes(RLPItem memory _in) internal pure returns (bytes memory) { return _copy(_in); } @@ -345,13 +303,10 @@ library LibRLPReader { uint256 strLen; assembly { // Pick out the string length. - strLen := - div(mload(add(ptr, 1)), exp(256, sub(32, lenOfStrLen))) + strLen := div(mload(add(ptr, 1)), exp(256, sub(32, lenOfStrLen))) } - require( - _in.length > lenOfStrLen + strLen, "Invalid RLP long string." - ); + require(_in.length > lenOfStrLen + strLen, "Invalid RLP long string."); return (1 + lenOfStrLen, strLen, RLPItemType.DATA_ITEM); } else if (prefix <= 0xf7) { @@ -371,13 +326,10 @@ library LibRLPReader { uint256 listLen; assembly { // Pick out the list length. - listLen := - div(mload(add(ptr, 1)), exp(256, sub(32, lenOfListLen))) + listLen := div(mload(add(ptr, 1)), exp(256, sub(32, lenOfListLen))) } - require( - _in.length > lenOfListLen + listLen, "Invalid RLP long list." - ); + require(_in.length > lenOfListLen + listLen, "Invalid RLP long list."); return (1 + lenOfListLen, listLen, RLPItemType.LIST_ITEM); } diff --git a/packages/protocol/contracts/thirdparty/LibSecureMerkleTrie.sol b/packages/protocol/contracts/thirdparty/LibSecureMerkleTrie.sol index 7cc18a129a4..bfefe125f0b 100644 --- a/packages/protocol/contracts/thirdparty/LibSecureMerkleTrie.sol +++ b/packages/protocol/contracts/thirdparty/LibSecureMerkleTrie.sol @@ -28,7 +28,7 @@ pragma solidity ^0.8.20; /* Library Imports */ -import { LibMerkleTrie } from "./LibMerkleTrie.sol"; +import "./LibMerkleTrie.sol"; /** * @title LibSecureMerkleTrie @@ -95,11 +95,7 @@ library LibSecureMerkleTrie { * @param _key Key to get a secure key from. * @return _secureKey Secure version of the key. */ - function _getSecureKey(bytes memory _key) - private - pure - returns (bytes memory _secureKey) - { + function _getSecureKey(bytes memory _key) private pure returns (bytes memory _secureKey) { return bytes.concat(keccak256(_key)); } } diff --git a/packages/protocol/contracts/thirdparty/LibUint512Math.sol b/packages/protocol/contracts/thirdparty/LibUint512Math.sol index baf623c39e8..60eef4bc0a6 100644 --- a/packages/protocol/contracts/thirdparty/LibUint512Math.sol +++ b/packages/protocol/contracts/thirdparty/LibUint512Math.sol @@ -33,14 +33,7 @@ library LibUint512Math { /// @param b The second uint256 operand. /// @return r0 The lower 256 bits of the result. /// @return r1 The higher 256 bits of the result. - function mul( - uint256 a, - uint256 b - ) - internal - pure - returns (uint256 r0, uint256 r1) - { + function mul(uint256 a, uint256 b) internal pure returns (uint256 r0, uint256 r1) { assembly { // Calculate modulo of the multiplication by the largest 256-bit // number. diff --git a/packages/protocol/contracts/tokenvault/BaseNFTVault.sol b/packages/protocol/contracts/tokenvault/BaseNFTVault.sol index 41ef9e39a42..357a304e55e 100644 --- a/packages/protocol/contracts/tokenvault/BaseNFTVault.sol +++ b/packages/protocol/contracts/tokenvault/BaseNFTVault.sol @@ -6,7 +6,7 @@ pragma solidity ^0.8.20; -import { BaseVault } from "./BaseVault.sol"; +import "./BaseVault.sol"; /// @title BaseNFTVault /// @notice Abstract contract for bridging NFTs across different chains. diff --git a/packages/protocol/contracts/tokenvault/BaseVault.sol b/packages/protocol/contracts/tokenvault/BaseVault.sol index e615c35b383..eb7486d95b1 100644 --- a/packages/protocol/contracts/tokenvault/BaseVault.sol +++ b/packages/protocol/contracts/tokenvault/BaseVault.sol @@ -5,17 +5,11 @@ // |_|\__,_|_|_\_\___/ |____\__,_|_.__/__/ pragma solidity ^0.8.20; -import { IERC165Upgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/utils/introspection/IERC165Upgradeable.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/utils/introspection/IERC165Upgradeable.sol"; +import "../bridge/IBridge.sol"; +import "../common/EssentialContract.sol"; -import { IBridge, IRecallableSender } from "../bridge/IBridge.sol"; -import { EssentialContract } from "../common/EssentialContract.sol"; - -abstract contract BaseVault is - EssentialContract, - IRecallableSender, - IERC165Upgradeable -{ +abstract contract BaseVault is EssentialContract, IRecallableSender, IERC165Upgradeable { error VAULT_PERMISSION_DENIED(); modifier onlyFromBridge() { @@ -34,13 +28,7 @@ abstract contract BaseVault is /// @notice Checks if the contract supports the given interface. /// @param interfaceId The interface identifier. /// @return true if the contract supports the interface, false otherwise. - function supportsInterface(bytes4 interfaceId) - public - view - virtual - override - returns (bool) - { + function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IRecallableSender).interfaceId; } diff --git a/packages/protocol/contracts/tokenvault/BridgedERC1155.sol b/packages/protocol/contracts/tokenvault/BridgedERC1155.sol index ce24db306cd..0ba5f55d229 100644 --- a/packages/protocol/contracts/tokenvault/BridgedERC1155.sol +++ b/packages/protocol/contracts/tokenvault/BridgedERC1155.sol @@ -6,17 +6,13 @@ pragma solidity ^0.8.20; -import { ERC1155Upgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC1155/ERC1155Upgradeable.sol"; -import { IERC1155MetadataURIUpgradeable } from +import "lib/openzeppelin-contracts/contracts/utils/Strings.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC1155/ERC1155Upgradeable.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC1155/extensions/IERC1155MetadataURIUpgradeable.sol"; -import { IERC1155Upgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC1155/IERC1155Upgradeable.sol"; -import { StringsUpgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/utils/StringsUpgradeable.sol"; - -import { EssentialContract } from "../common/EssentialContract.sol"; -import { Proxied } from "../common/Proxied.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC1155/IERC1155Upgradeable.sol"; +import "../common/EssentialContract.sol"; +import "../common/Proxied.sol"; /// @title BridgedERC1155 /// @notice Contract for bridging ERC1155 tokens across different chains. @@ -34,12 +30,7 @@ contract BridgedERC1155 is uint256[46] private __gap; // Event triggered upon token transfer. - event Transfer( - address indexed from, - address indexed to, - uint256 tokenId, - uint256 amount - ); + event Transfer(address indexed from, address indexed to, uint256 tokenId, uint256 amount); error BRIDGED_TOKEN_CANNOT_RECEIVE(); error BRIDGED_TOKEN_INVALID_PARAMS(); @@ -60,10 +51,7 @@ contract BridgedERC1155 is external initializer { - if ( - _srcToken == address(0) || _srcChainId == 0 - || _srcChainId == block.chainid - ) { + if (_srcToken == address(0) || _srcChainId == 0 || _srcChainId == block.chainid) { revert BRIDGED_TOKEN_INVALID_PARAMS(); } EssentialContract._init(_addressManager); @@ -127,16 +115,13 @@ contract BridgedERC1155 is if (to == address(this)) { revert BRIDGED_TOKEN_CANNOT_RECEIVE(); } - return - ERC1155Upgradeable.safeTransferFrom(from, to, tokenId, amount, data); + return ERC1155Upgradeable.safeTransferFrom(from, to, tokenId, amount, data); } /// @notice Gets the concatenated name of the bridged token. /// @return The concatenated name. function name() public view returns (string memory) { - return string.concat( - name_, unicode" â­€", StringsUpgradeable.toString(srcChainId) - ); + return string.concat(name_, unicode" â­€", Strings.toString(srcChainId)); } } diff --git a/packages/protocol/contracts/tokenvault/BridgedERC20.sol b/packages/protocol/contracts/tokenvault/BridgedERC20.sol index 94ce327f0f3..c692bbe1745 100644 --- a/packages/protocol/contracts/tokenvault/BridgedERC20.sol +++ b/packages/protocol/contracts/tokenvault/BridgedERC20.sol @@ -6,20 +6,13 @@ pragma solidity ^0.8.20; -import { - ERC20Upgradeable, - IERC20Upgradeable -} from - "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol"; -import { IERC20MetadataUpgradeable } from +import "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/extensions/IERC20MetadataUpgradeable.sol"; -import { StringsUpgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/utils/StringsUpgradeable.sol"; - -import { EssentialContract } from "../common/EssentialContract.sol"; -import { Proxied } from "../common/Proxied.sol"; - -import { IMintableERC20 } from "./IMintableERC20.sol"; +import "lib/openzeppelin-contracts/contracts/utils/Strings.sol"; +import "../common/EssentialContract.sol"; +import "../common/Proxied.sol"; +import "./IMintableERC20.sol"; /// @title BridgedERC20 /// @notice An upgradeable ERC20 contract that represents tokens bridged from @@ -61,9 +54,8 @@ contract BridgedERC20 is { // Check if provided parameters are valid if ( - _srcToken == address(0) || _srcChainId == 0 - || _srcChainId == block.chainid || bytes(_symbol).length == 0 - || bytes(_name).length == 0 + _srcToken == address(0) || _srcChainId == 0 || _srcChainId == block.chainid + || bytes(_symbol).length == 0 || bytes(_name).length == 0 ) { revert BRIDGED_TOKEN_INVALID_PARAMS(); } @@ -82,13 +74,7 @@ contract BridgedERC20 is /// @dev Only an ERC20Vault can call this function. /// @param account The account to mint tokens to. /// @param amount The amount of tokens to mint. - function mint( - address account, - uint256 amount - ) - public - onlyFromNamed("erc20_vault") - { + function mint(address account, uint256 amount) public onlyFromNamed("erc20_vault") { _mint(account, amount); emit Transfer(address(0), account, amount); } @@ -97,13 +83,7 @@ contract BridgedERC20 is /// @dev Only an ERC20Vault can call this function. /// @param account The account to burn tokens from. /// @param amount The amount of tokens to burn. - function burn( - address account, - uint256 amount - ) - public - onlyFromNamed("erc20_vault") - { + function burn(address account, uint256 amount) public onlyFromNamed("erc20_vault") { _burn(account, amount); emit Transfer(account, address(0), amount); } @@ -156,9 +136,7 @@ contract BridgedERC20 is override(ERC20Upgradeable, IERC20MetadataUpgradeable) returns (string memory) { - return string.concat( - super.name(), unicode" â­€", StringsUpgradeable.toString(srcChainId) - ); + return string.concat(super.name(), unicode" â­€", Strings.toString(srcChainId)); } /// @notice Gets the number of decimal places of the token. diff --git a/packages/protocol/contracts/tokenvault/BridgedERC721.sol b/packages/protocol/contracts/tokenvault/BridgedERC721.sol index 1b638d21b3d..20287b97c6d 100644 --- a/packages/protocol/contracts/tokenvault/BridgedERC721.sol +++ b/packages/protocol/contracts/tokenvault/BridgedERC721.sol @@ -6,13 +6,10 @@ pragma solidity ^0.8.20; -import { ERC721Upgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC721/ERC721Upgradeable.sol"; -import { StringsUpgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/utils/StringsUpgradeable.sol"; - -import { EssentialContract } from "../common/EssentialContract.sol"; -import { Proxied } from "../common/Proxied.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC721/ERC721Upgradeable.sol"; +import "lib/openzeppelin-contracts/contracts/utils/Strings.sol"; +import "../common/EssentialContract.sol"; +import "../common/Proxied.sol"; /// @title BridgedERC721 /// @notice Contract for bridging ERC721 tokens across different chains. @@ -43,9 +40,8 @@ contract BridgedERC721 is EssentialContract, ERC721Upgradeable { initializer { if ( - _srcToken == address(0) || _srcChainId == 0 - || _srcChainId == block.chainid || bytes(_symbol).length == 0 - || bytes(_name).length == 0 + _srcToken == address(0) || _srcChainId == 0 || _srcChainId == block.chainid + || bytes(_symbol).length == 0 || bytes(_name).length == 0 ) { revert BRIDGED_TOKEN_INVALID_PARAMS(); } @@ -58,13 +54,7 @@ contract BridgedERC721 is EssentialContract, ERC721Upgradeable { /// @dev Mints tokens. /// @param account Address to receive the minted token. /// @param tokenId ID of the token to mint. - function mint( - address account, - uint256 tokenId - ) - public - onlyFromNamed("erc721_vault") - { + function mint(address account, uint256 tokenId) public onlyFromNamed("erc721_vault") { _mint(account, tokenId); emit Transfer(address(0), account, tokenId); } @@ -72,13 +62,7 @@ contract BridgedERC721 is EssentialContract, ERC721Upgradeable { /// @dev Burns tokens. /// @param account Address from which the token is burned. /// @param tokenId ID of the token to burn. - function burn( - address account, - uint256 tokenId - ) - public - onlyFromNamed("erc721_vault") - { + function burn(address account, uint256 tokenId) public onlyFromNamed("erc721_vault") { // Check if the caller is the owner of the token. if (ownerOf(tokenId) != account) { revert BRIDGED_TOKEN_INVALID_BURN(); @@ -108,15 +92,8 @@ contract BridgedERC721 is EssentialContract, ERC721Upgradeable { /// @notice Gets the concatenated name of the bridged token. /// @return The concatenated name. - function name() - public - view - override(ERC721Upgradeable) - returns (string memory) - { - return string.concat( - super.name(), unicode" â­€", StringsUpgradeable.toString(srcChainId) - ); + function name() public view override(ERC721Upgradeable) returns (string memory) { + return string.concat(super.name(), unicode" â­€", Strings.toString(srcChainId)); } /// @notice Gets the source token and source chain ID being bridged. @@ -126,13 +103,7 @@ contract BridgedERC721 is EssentialContract, ERC721Upgradeable { } /// @notice Returns an empty token URI. - function tokenURI(uint256) - public - pure - virtual - override - returns (string memory) - { + function tokenURI(uint256) public pure virtual override returns (string memory) { return ""; } } diff --git a/packages/protocol/contracts/tokenvault/ERC1155Vault.sol b/packages/protocol/contracts/tokenvault/ERC1155Vault.sol index 5e420a1da02..3bb71c3922f 100644 --- a/packages/protocol/contracts/tokenvault/ERC1155Vault.sol +++ b/packages/protocol/contracts/tokenvault/ERC1155Vault.sol @@ -6,23 +6,18 @@ pragma solidity ^0.8.20; -import { TransparentUpgradeableProxy } from - "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; +import "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; -import { - ERC1155ReceiverUpgradeable, - IERC1155ReceiverUpgradeable -} from +import "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC1155/utils/ERC1155ReceiverUpgradeable.sol"; -import { ERC1155Upgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC1155/ERC1155Upgradeable.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC1155/ERC1155Upgradeable.sol"; -import { Proxied } from "../common/Proxied.sol"; -import { IBridge, IRecallableSender } from "../bridge/IBridge.sol"; -import { LibAddress } from "../libs/LibAddress.sol"; +import "../common/Proxied.sol"; +import "../bridge/IBridge.sol"; +import "../libs/LibAddress.sol"; -import { BaseVault, BaseNFTVault } from "./BaseNFTVault.sol"; -import { BridgedERC1155 } from "./BridgedERC1155.sol"; +import "./BaseNFTVault.sol"; +import "./BridgedERC1155.sol"; /// @title ERC1155NameAndSymbol /// @notice Interface for ERC1155 contracts that provide name() and symbol() @@ -83,9 +78,8 @@ contract ERC1155Vault is BaseNFTVault, ERC1155ReceiverUpgradeable { // Send the message and obtain the message hash bytes32 msgHash; - (msgHash, _message) = IBridge(resolve("bridge", false)).sendMessage{ - value: msg.value - }(message); + (msgHash, _message) = + IBridge(resolve("bridge", false)).sendMessage{ value: msg.value }(message); // Emit TokenSent event emit TokenSent({ @@ -174,25 +168,15 @@ contract ERC1155Vault is BaseNFTVault, ERC1155ReceiverUpgradeable { { checkRecallMessageContext(); - ( - CanonicalNFT memory nft, - , - , - uint256[] memory tokenIds, - uint256[] memory amounts - ) = abi.decode( - message.data[4:], - (CanonicalNFT, address, address, uint256[], uint256[]) - ); + (CanonicalNFT memory nft,,, uint256[] memory tokenIds, uint256[] memory amounts) = + abi.decode(message.data[4:], (CanonicalNFT, address, address, uint256[], uint256[])); if (nft.addr == address(0)) revert VAULT_INVALID_TOKEN(); unchecked { if (bridgedToCanonical[nft.addr].addr != address(0)) { for (uint256 i; i < tokenIds.length; ++i) { - BridgedERC1155(nft.addr).mint( - message.owner, tokenIds[i], amounts[i] - ); + BridgedERC1155(nft.addr).mint(message.owner, tokenIds[i], amounts[i]); } } else { for (uint256 i; i < tokenIds.length; ++i) { @@ -281,9 +265,7 @@ contract ERC1155Vault is BaseNFTVault, ERC1155ReceiverUpgradeable { if (bridgedToCanonical[op.token].addr != address(0)) { nft = bridgedToCanonical[op.token]; for (uint256 i; i < op.tokenIds.length; ++i) { - BridgedERC1155(op.token).burn( - user, op.tokenIds[i], op.amounts[i] - ); + BridgedERC1155(op.token).burn(user, op.tokenIds[i], op.amounts[i]); } } else { // is a ctoken token, meaning, it lives on this chain @@ -312,12 +294,7 @@ contract ERC1155Vault is BaseNFTVault, ERC1155ReceiverUpgradeable { } } msgData = abi.encodeWithSelector( - this.receiveToken.selector, - nft, - user, - op.to, - op.tokenIds, - op.amounts + this.receiveToken.selector, nft, user, op.to, op.tokenIds, op.amounts ); } @@ -339,19 +316,10 @@ contract ERC1155Vault is BaseNFTVault, ERC1155ReceiverUpgradeable { /// this chain. /// @param ctoken CanonicalNFT data. /// @return btoken Address of the deployed bridged token contract. - function _deployBridgedToken(CanonicalNFT memory ctoken) - private - returns (address btoken) - { + function _deployBridgedToken(CanonicalNFT memory ctoken) private returns (address btoken) { bytes memory data = bytes.concat( BridgedERC1155.init.selector, - abi.encode( - addressManager, - ctoken.addr, - ctoken.chainId, - ctoken.symbol, - ctoken.name - ) + abi.encode(addressManager, ctoken.addr, ctoken.chainId, ctoken.symbol, ctoken.name) ); btoken = address( new TransparentUpgradeableProxy( diff --git a/packages/protocol/contracts/tokenvault/ERC20Vault.sol b/packages/protocol/contracts/tokenvault/ERC20Vault.sol index 7a849a624fb..e05958504c3 100644 --- a/packages/protocol/contracts/tokenvault/ERC20Vault.sol +++ b/packages/protocol/contracts/tokenvault/ERC20Vault.sol @@ -6,21 +6,16 @@ pragma solidity ^0.8.20; -import { TransparentUpgradeableProxy } from - "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; +import "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; -import { ERC20Upgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol"; -import { SafeERC20Upgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/utils/SafeERC20Upgradeable.sol"; - -import { Proxied } from "../common/Proxied.sol"; -import { IBridge } from "../bridge/IBridge.sol"; -import { LibAddress } from "../libs/LibAddress.sol"; - -import { BridgedERC20 } from "./BridgedERC20.sol"; -import { IMintableERC20 } from "./IMintableERC20.sol"; -import { BaseVault } from "./BaseVault.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/ERC20Upgradeable.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/utils/SafeERC20Upgradeable.sol"; +import "../common/Proxied.sol"; +import "../bridge/IBridge.sol"; +import "../libs/LibAddress.sol"; +import "./BridgedERC20.sol"; +import "./IMintableERC20.sol"; +import "./BaseVault.sol"; /// @title ERC20Vault /// @dev Labeled in AddressResolver as "erc20_vault" @@ -77,10 +72,7 @@ contract ERC20Vault is BaseVault { uint256 amount ); event TokenReleased( - bytes32 indexed msgHash, - address indexed from, - address token, - uint256 amount + bytes32 indexed msgHash, address indexed from, address token, uint256 amount ); event TokenReceived( bytes32 indexed msgHash, @@ -116,12 +108,8 @@ contract ERC20Vault is BaseVault { uint256 _amount; IBridge.Message memory message; - (message.data, _amount) = _handleMessage({ - user: msg.sender, - token: op.token, - amount: op.amount, - to: op.to - }); + (message.data, _amount) = + _handleMessage({ user: msg.sender, token: op.token, amount: op.amount, to: op.to }); message.destChainId = op.destChainId; message.owner = msg.sender; @@ -133,9 +121,8 @@ contract ERC20Vault is BaseVault { message.memo = op.memo; bytes32 msgHash; - (msgHash, _message) = IBridge(resolve("bridge", false)).sendMessage{ - value: msg.value - }(message); + (msgHash, _message) = + IBridge(resolve("bridge", false)).sendMessage{ value: msg.value }(message); emit TokenSent({ msgHash: msgHash, @@ -199,9 +186,8 @@ contract ERC20Vault is BaseVault { { checkRecallMessageContext(); - (, address token,, uint256 amount) = abi.decode( - message.data[4:], (CanonicalERC20, address, address, uint256) - ); + (, address token,, uint256 amount) = + abi.decode(message.data[4:], (CanonicalERC20, address, address, uint256)); if (token == address(0)) revert VAULT_INVALID_TOKEN(); @@ -215,12 +201,7 @@ contract ERC20Vault is BaseVault { message.owner.sendEther(message.value); - emit TokenReleased({ - msgHash: msgHash, - from: message.owner, - token: token, - amount: amount - }); + emit TokenReleased({ msgHash: msgHash, from: message.owner, token: token, amount: amount }); } function name() public pure override returns (bytes32) { @@ -269,17 +250,12 @@ contract ERC20Vault is BaseVault { // simply using `amount` -- some contract may deduct a fee from the // transferred amount. uint256 _balance = t.balanceOf(address(this)); - t.transferFrom({ - from: msg.sender, - to: address(this), - amount: amount - }); + t.transferFrom({ from: msg.sender, to: address(this), amount: amount }); _balanceChange = t.balanceOf(address(this)) - _balance; } - msgData = abi.encodeWithSelector( - this.receiveToken.selector, ctoken, user, to, _balanceChange - ); + msgData = + abi.encodeWithSelector(this.receiveToken.selector, ctoken, user, to, _balanceChange); } /// @dev Retrieve or deploy a bridged ERC20 token contract. @@ -301,10 +277,7 @@ contract ERC20Vault is BaseVault { /// this chain. /// @param ctoken CanonicalERC20 data. /// @return btoken Address of the deployed bridged token contract. - function _deployBridgedToken(CanonicalERC20 calldata ctoken) - private - returns (address btoken) - { + function _deployBridgedToken(CanonicalERC20 calldata ctoken) private returns (address btoken) { bytes memory data = bytes.concat( BridgedERC20.init.selector, abi.encode( diff --git a/packages/protocol/contracts/tokenvault/ERC721Vault.sol b/packages/protocol/contracts/tokenvault/ERC721Vault.sol index afdaaa0de7e..07f326f4f5b 100644 --- a/packages/protocol/contracts/tokenvault/ERC721Vault.sol +++ b/packages/protocol/contracts/tokenvault/ERC721Vault.sol @@ -6,20 +6,16 @@ pragma solidity ^0.8.20; -import { TransparentUpgradeableProxy } from - "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; +import "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; -import { ERC721Upgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC721/ERC721Upgradeable.sol"; -import { IERC721ReceiverUpgradeable } from +import "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC721/ERC721Upgradeable.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC721/IERC721ReceiverUpgradeable.sol"; - -import { IBridge } from "../bridge/IBridge.sol"; -import { LibAddress } from "../libs/LibAddress.sol"; -import { Proxied } from "../common/Proxied.sol"; - -import { BaseNFTVault } from "./BaseNFTVault.sol"; -import { BridgedERC721 } from "./BridgedERC721.sol"; +import "../bridge/IBridge.sol"; +import "../libs/LibAddress.sol"; +import "../common/Proxied.sol"; +import "./BaseNFTVault.sol"; +import "./BridgedERC721.sol"; /// @title ERC721Vault /// @dev Labeled in AddressResolver as "erc721_vault" @@ -69,9 +65,8 @@ contract ERC721Vault is BaseNFTVault, IERC721ReceiverUpgradeable { message.memo = op.memo; bytes32 msgHash; - (msgHash, _message) = IBridge(resolve("bridge", false)).sendMessage{ - value: msg.value - }(message); + (msgHash, _message) = + IBridge(resolve("bridge", false)).sendMessage{ value: msg.value }(message); emit TokenSent({ msgHash: msgHash, @@ -153,9 +148,8 @@ contract ERC721Vault is BaseNFTVault, IERC721ReceiverUpgradeable { revert VAULT_INVALID_SRC_CHAIN_ID(); } - (CanonicalNFT memory nft,,, uint256[] memory tokenIds) = abi.decode( - message.data[4:], (CanonicalNFT, address, address, uint256[]) - ); + (CanonicalNFT memory nft,,, uint256[] memory tokenIds) = + abi.decode(message.data[4:], (CanonicalNFT, address, address, uint256[])); if (nft.addr == address(0)) revert VAULT_INVALID_TOKEN(); @@ -241,9 +235,7 @@ contract ERC721Vault is BaseNFTVault, IERC721ReceiverUpgradeable { } } - msgData = abi.encodeWithSelector( - this.receiveToken.selector, nft, user, op.to, op.tokenIds - ); + msgData = abi.encodeWithSelector(this.receiveToken.selector, nft, user, op.to, op.tokenIds); } /// @dev Retrieve or deploy a bridged ERC721 token contract. @@ -265,19 +257,10 @@ contract ERC721Vault is BaseNFTVault, IERC721ReceiverUpgradeable { /// this chain. /// @param ctoken CanonicalNFT data. /// @return btoken Address of the deployed bridged token contract. - function _deployBridgedToken(CanonicalNFT memory ctoken) - private - returns (address btoken) - { + function _deployBridgedToken(CanonicalNFT memory ctoken) private returns (address btoken) { bytes memory data = bytes.concat( BridgedERC721.init.selector, - abi.encode( - addressManager, - ctoken.addr, - ctoken.chainId, - ctoken.symbol, - ctoken.name - ) + abi.encode(addressManager, ctoken.addr, ctoken.chainId, ctoken.symbol, ctoken.name) ); btoken = address( new TransparentUpgradeableProxy( diff --git a/packages/protocol/contracts/tokenvault/IMintableERC20.sol b/packages/protocol/contracts/tokenvault/IMintableERC20.sol index d2d93274082..80b2bb96acd 100644 --- a/packages/protocol/contracts/tokenvault/IMintableERC20.sol +++ b/packages/protocol/contracts/tokenvault/IMintableERC20.sol @@ -6,8 +6,7 @@ pragma solidity ^0.8.20; -import { IERC20Upgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/IERC20Upgradeable.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/token/ERC20/IERC20Upgradeable.sol"; /// @title IMintableERC20 /// @notice Interface for ERC20 tokens with mint and burn functionality. diff --git a/packages/protocol/foundry.toml b/packages/protocol/foundry.toml index 45373b1f387..38c1e4552d9 100644 --- a/packages/protocol/foundry.toml +++ b/packages/protocol/foundry.toml @@ -35,7 +35,7 @@ seed = 13623721389213 [fmt] bracket_spacing = true -line_length = 80 +line_length = 100 multiline_func_header = 'all' number_underscore = 'thousands' wrap_comments = true diff --git a/packages/protocol/genesis/GenerateGenesis.g.sol b/packages/protocol/genesis/GenerateGenesis.g.sol index b10391d2b5c..49aed95bde1 100644 --- a/packages/protocol/genesis/GenerateGenesis.g.sol +++ b/packages/protocol/genesis/GenerateGenesis.g.sol @@ -1,24 +1,23 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.20; -import { console2 } from "forge-std/console2.sol"; -import { stdJson } from "forge-std/StdJson.sol"; -import { Test } from "forge-std/Test.sol"; - -import { TransparentUpgradeableProxy } from "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; - -import { AddressManager } from "../contracts/common/AddressManager.sol"; -import { AddressResolver } from "../contracts/common/AddressResolver.sol"; -import { EssentialContract } from "../contracts/common/EssentialContract.sol"; -import { Bridge } from "../contracts/bridge/Bridge.sol"; -import { ERC1155Vault } from "../contracts/tokenvault/ERC1155Vault.sol"; -import { ERC20Vault } from "../contracts/tokenvault/ERC20Vault.sol"; -import { ERC721Vault } from "../contracts/tokenvault/ERC721Vault.sol"; -import { IBridge } from "../contracts/bridge/IBridge.sol"; -import { RegularERC20 } from "../contracts/test/erc20/RegularERC20.sol"; -import { SignalService } from "../contracts/signal/SignalService.sol"; -import { TaikoL2 } from "../contracts/L2/TaikoL2.sol"; - +import "forge-std/console2.sol"; +import "forge-std/StdJson.sol"; +import "forge-std/Test.sol"; + +import "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + +import "../contracts/common/AddressManager.sol"; +import "../contracts/common/AddressResolver.sol"; +import "../contracts/common/EssentialContract.sol"; +import "../contracts/bridge/Bridge.sol"; +import "../contracts/tokenvault/ERC1155Vault.sol"; +import "../contracts/tokenvault/ERC20Vault.sol"; +import "../contracts/tokenvault/ERC721Vault.sol"; +import "../contracts/bridge/IBridge.sol"; +import "../contracts/test/erc20/RegularERC20.sol"; +import "../contracts/signal/SignalService.sol"; +import "../contracts/L2/TaikoL2.sol"; contract TestGenerateGenesis is Test, AddressResolver { using stdJson for string; diff --git a/packages/protocol/script/AuthorizeRemoteTaikoProtocols.s.sol b/packages/protocol/script/AuthorizeRemoteTaikoProtocols.s.sol index 9435831f4af..1fa3b22f508 100644 --- a/packages/protocol/script/AuthorizeRemoteTaikoProtocols.s.sol +++ b/packages/protocol/script/AuthorizeRemoteTaikoProtocols.s.sol @@ -6,21 +6,16 @@ pragma solidity ^0.8.20; +import "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; import "forge-std/Script.sol"; import "forge-std/console2.sol"; - import "../contracts/signal/SignalService.sol"; -import - "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; - contract AuthorizeRemoteTaikoProtocols is Script { uint256 public privateKey = vm.envUint("PRIVATE_KEY"); - address public signalServiceAddress = - vm.envAddress("SIGNAL_SERVICE_ADDRESS"); + address public signalServiceAddress = vm.envAddress("SIGNAL_SERVICE_ADDRESS"); uint256[] public remoteChainIDs = vm.envUint("REMOTE_CHAIN_IDS", ","); - address[] public remoteTaikoProtocols = - vm.envAddress("REMOTE_TAIKO_PROTOCOLS", ","); + address[] public remoteTaikoProtocols = vm.envAddress("REMOTE_TAIKO_PROTOCOLS", ","); function run() external { require( @@ -34,9 +29,7 @@ contract AuthorizeRemoteTaikoProtocols is Script { ProxiedSingletonSignalService(payable(signalServiceAddress)); for (uint256 i; i < remoteChainIDs.length; ++i) { console2.log(remoteTaikoProtocols[i], "--->", remoteChainIDs[i]); - signalService.authorize( - remoteTaikoProtocols[i], bytes32(remoteChainIDs[i]) - ); + signalService.authorize(remoteTaikoProtocols[i], bytes32(remoteChainIDs[i])); } vm.stopBroadcast(); diff --git a/packages/protocol/script/DeployOnL1.s.sol b/packages/protocol/script/DeployOnL1.s.sol index bcfe5eda9db..cf1c67dda45 100644 --- a/packages/protocol/script/DeployOnL1.s.sol +++ b/packages/protocol/script/DeployOnL1.s.sol @@ -6,11 +6,12 @@ pragma solidity ^0.8.20; +import "lib/openzeppelin-contracts/contracts/utils/Strings.sol"; +import "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + import "forge-std/Script.sol"; import "forge-std/console2.sol"; -import - "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; -import "lib/openzeppelin-contracts/contracts/utils/Strings.sol"; + import "../contracts/L1/TaikoToken.sol"; import "../contracts/L1/TaikoL1.sol"; import "../contracts/L1/provers/GuardianProver.sol"; @@ -57,13 +58,11 @@ contract DeployOnL1 is Script { address public singletonBridge = vm.envAddress("SINGLETON_BRIDGE"); - address public singletonSignalService = - vm.envAddress("SINGLETON_SIGNAL_SERVICE"); + address public singletonSignalService = vm.envAddress("SINGLETON_SIGNAL_SERVICE"); uint256 public tierProvider = vm.envUint("TIER_PROVIDER"); - address public taikoTokenPremintRecipient = - vm.envAddress("TAIKO_TOKEN_PREMINT_RECIPIENT"); + address public taikoTokenPremintRecipient = vm.envAddress("TAIKO_TOKEN_PREMINT_RECIPIENT"); TaikoL1 taikoL1; address public addressManagerProxy; @@ -76,29 +75,20 @@ contract DeployOnL1 is Script { require(owner != address(0), "owner is zero"); require(taikoL2Address != address(0), "taikoL2Address is zero"); require(l2SignalService != address(0), "l2SignalService is zero"); - require( - guardianProvers.length == NUM_GUARDIANS, - "invalid guardian provers number" - ); + require(guardianProvers.length == NUM_GUARDIANS, "invalid guardian provers number"); if (singletonBridge == address(0)) { require( - singletonSignalService == address(0), - "non-empty singleton signal service address" + singletonSignalService == address(0), "non-empty singleton signal service address" ); } else { - require( - singletonSignalService != address(0), - "empty singleton signal service address" - ); + require(singletonSignalService != address(0), "empty singleton signal service address"); } vm.startBroadcast(deployerPrivateKey); // AddressManager AddressManager addressManager = new ProxiedAddressManager(); addressManagerProxy = deployProxy( - "address_manager", - address(addressManager), - bytes.concat(addressManager.init.selector) + "address_manager", address(addressManager), bytes.concat(addressManager.init.selector) ); // TaikoL1 @@ -124,10 +114,7 @@ contract DeployOnL1 is Script { bytes.concat( taikoToken.init.selector, abi.encode( - addressManagerProxy, - "Taiko Token Katla", - "TTKOk", - taikoTokenPremintRecipient + addressManagerProxy, "Taiko Token Katla", "TTKOk", taikoTokenPremintRecipient ) ) ); @@ -139,10 +126,7 @@ contract DeployOnL1 is Script { address taikoL1Proxy = deployProxy( "taiko", address(taikoL1), - bytes.concat( - taikoL1.init.selector, - abi.encode(addressManagerProxy, genesisHash) - ) + bytes.concat(taikoL1.init.selector, abi.encode(addressManagerProxy, genesisHash)) ); setAddress("taiko", taikoL1Proxy); @@ -166,9 +150,7 @@ contract DeployOnL1 is Script { address guardianProverProxy = deployProxy( "guardian_prover", address(guardianProver), - bytes.concat( - guardianProver.init.selector, abi.encode(addressManagerProxy) - ) + bytes.concat(guardianProver.init.selector, abi.encode(addressManagerProxy)) ); address[NUM_GUARDIANS] memory guardians; for (uint256 i = 0; i < NUM_GUARDIANS; ++i) { @@ -177,20 +159,14 @@ contract DeployOnL1 is Script { ProxiedGuardianProver(guardianProverProxy).setGuardians(guardians); // Config provider - deployProxy( - "tier_provider", - deployTierProvider(uint256(TierProviders.TAIKO_ALPHA6)), - "" - ); + deployProxy("tier_provider", deployTierProvider(uint256(TierProviders.TAIKO_ALPHA6)), ""); // GuardianVerifier GuardianVerifier guardianVerifier = new ProxiedGuardianVerifier(); deployProxy( "tier_guardian", address(guardianVerifier), - bytes.concat( - guardianVerifier.init.selector, abi.encode(addressManagerProxy) - ) + bytes.concat(guardianVerifier.init.selector, abi.encode(addressManagerProxy)) ); // SgxVerifier @@ -198,9 +174,7 @@ contract DeployOnL1 is Script { deployProxy( "tier_sgx", address(sgxVerifier), - bytes.concat( - sgxVerifier.init.selector, abi.encode(addressManagerProxy) - ) + bytes.concat(sgxVerifier.init.selector, abi.encode(addressManagerProxy)) ); // SgxAndZkVerifier @@ -208,9 +182,7 @@ contract DeployOnL1 is Script { deployProxy( "tier_sgx_and_pse_zkevm", address(sgxAndZkVerifier), - bytes.concat( - sgxVerifier.init.selector, abi.encode(addressManagerProxy) - ) + bytes.concat(sgxVerifier.init.selector, abi.encode(addressManagerProxy)) ); // PseZkVerifier @@ -218,9 +190,7 @@ contract DeployOnL1 is Script { deployProxy( "tier_pse_zkevm", address(pseZkVerifier), - bytes.concat( - pseZkVerifier.init.selector, abi.encode(addressManagerProxy) - ) + bytes.concat(pseZkVerifier.init.selector, abi.encode(addressManagerProxy)) ); // PlonkVerifier @@ -231,18 +201,14 @@ contract DeployOnL1 is Script { function deployPlonkVerifiers(PseZkVerifier pseZkVerifier) private { address[] memory plonkVerifiers = new address[](1); - plonkVerifiers[0] = - deployYulContract("contracts/L1/verifiers/PlonkVerifier.yulp"); + plonkVerifiers[0] = deployYulContract("contracts/L1/verifiers/PlonkVerifier.yulp"); for (uint16 i = 0; i < plonkVerifiers.length; ++i) { setAddress(pseZkVerifier.getVerifierName(i), plonkVerifiers[i]); } } - function deployYulContract(string memory contractPath) - private - returns (address) - { + function deployYulContract(string memory contractPath) private returns (address) { string[] memory cmds = new string[](3); cmds[0] = "bash"; cmds[1] = "-c"; @@ -269,10 +235,7 @@ contract DeployOnL1 is Script { return deployedAddress; } - function deployTierProvider(uint256 tier) - private - returns (address providerAddress) - { + function deployTierProvider(uint256 tier) private returns (address providerAddress) { if (tier == uint256(TierProviders.TAIKO_ALPHA6)) { return address(new TaikoA6TierProvider()); } @@ -296,10 +259,7 @@ contract DeployOnL1 is Script { addressManagerForSingletonsProxy, "bridge", address(bridge), - bytes.concat( - bridge.init.selector, - abi.encode(addressManagerForSingletonsProxy) - ) + bytes.concat(bridge.init.selector, abi.encode(addressManagerForSingletonsProxy)) ); // ERC20Vault @@ -308,10 +268,7 @@ contract DeployOnL1 is Script { addressManagerForSingletonsProxy, "erc20_vault", address(erc20Vault), - bytes.concat( - erc20Vault.init.selector, - abi.encode(addressManagerForSingletonsProxy) - ) + bytes.concat(erc20Vault.init.selector, abi.encode(addressManagerForSingletonsProxy)) ); // ERC721Vault @@ -320,10 +277,7 @@ contract DeployOnL1 is Script { addressManagerForSingletonsProxy, "erc721_vault", address(erc721Vault), - bytes.concat( - erc721Vault.init.selector, - abi.encode(addressManagerForSingletonsProxy) - ) + bytes.concat(erc721Vault.init.selector, abi.encode(addressManagerForSingletonsProxy)) ); // ERC1155Vault @@ -332,10 +286,7 @@ contract DeployOnL1 is Script { addressManagerForSingletonsProxy, "erc1155_vault", address(erc1155Vault), - bytes.concat( - erc1155Vault.init.selector, - abi.encode(addressManagerForSingletonsProxy) - ) + bytes.concat(erc1155Vault.init.selector, abi.encode(addressManagerForSingletonsProxy)) ); // SignalService @@ -344,10 +295,7 @@ contract DeployOnL1 is Script { addressManagerForSingletonsProxy, "signal_service", address(signalService), - bytes.concat( - signalService.init.selector, - abi.encode(addressManagerForSingletonsProxy) - ) + bytes.concat(signalService.init.selector, abi.encode(addressManagerForSingletonsProxy)) ); // Deploy ProxiedBridged token contracts @@ -391,16 +339,12 @@ contract DeployOnL1 is Script { private returns (address proxy) { - proxy = address( - new TransparentUpgradeableProxy(implementation, owner, data) - ); + proxy = address(new TransparentUpgradeableProxy(implementation, owner, data)); console2.log(name, "(impl) ->", implementation); console2.log(name, "(proxy) ->", proxy); - setAddress( - addressManager, uint64(block.chainid), bytes32(bytes(name)), proxy - ); + setAddress(addressManager, uint64(block.chainid), bytes32(bytes(name)), proxy); vm.writeJson( vm.serializeAddress("deployment", name, proxy), diff --git a/packages/protocol/script/SetAddress.s.sol b/packages/protocol/script/SetAddress.s.sol index dae9b396a1b..781b7d7fc2c 100644 --- a/packages/protocol/script/SetAddress.s.sol +++ b/packages/protocol/script/SetAddress.s.sol @@ -11,8 +11,7 @@ import "forge-std/console2.sol"; import "../contracts/common/AddressManager.sol"; -import - "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; +import "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; contract SetAddress is Script { uint256 public adminPrivateKey = vm.envUint("PRIVATE_KEY"); diff --git a/packages/protocol/script/SetRemoteBridgeSuites.s.sol b/packages/protocol/script/SetRemoteBridgeSuites.s.sol index dbba251ef59..540657e25d1 100644 --- a/packages/protocol/script/SetRemoteBridgeSuites.s.sol +++ b/packages/protocol/script/SetRemoteBridgeSuites.s.sol @@ -6,31 +6,25 @@ pragma solidity ^0.8.20; +import "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + import "forge-std/Script.sol"; import "forge-std/console2.sol"; import "../contracts/common/AddressManager.sol"; -import - "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; - contract SetRemoteBridgeSuites is Script { uint256 public privateKey = vm.envUint("PRIVATE_KEY"); - address public addressManagerAddress = - vm.envAddress("ADDRESS_MANAGER_ADDRESS"); + address public addressManagerAddress = vm.envAddress("ADDRESS_MANAGER_ADDRESS"); uint256[] public remoteChainIDs = vm.envUint("REMOTE_CHAIN_IDS", ","); address[] public remoteBridges = vm.envAddress("REMOTE_BRIDGES", ","); - address[] public remoteERC20Vaults = - vm.envAddress("REMOTE_ERC20_VAULTS", ","); - address[] public remoteERC721Vaults = - vm.envAddress("REMOTE_ERC721_VAULTS", ","); - address[] public remoteERC1155Vaults = - vm.envAddress("REMOTE_ERC1155_VAULTS", ","); + address[] public remoteERC20Vaults = vm.envAddress("REMOTE_ERC20_VAULTS", ","); + address[] public remoteERC721Vaults = vm.envAddress("REMOTE_ERC721_VAULTS", ","); + address[] public remoteERC1155Vaults = vm.envAddress("REMOTE_ERC1155_VAULTS", ","); function run() external { require( - remoteChainIDs.length == remoteBridges.length, - "invalid remote bridge addresses length" + remoteChainIDs.length == remoteBridges.length, "invalid remote bridge addresses length" ); require( remoteChainIDs.length == remoteERC20Vaults.length, @@ -48,12 +42,7 @@ contract SetRemoteBridgeSuites is Script { vm.startBroadcast(privateKey); for (uint256 i; i < remoteChainIDs.length; ++i) { - setAddress( - addressManagerAddress, - uint64(remoteChainIDs[i]), - "bridge", - remoteBridges[i] - ); + setAddress(addressManagerAddress, uint64(remoteChainIDs[i]), "bridge", remoteBridges[i]); setAddress( addressManagerAddress, uint64(remoteChainIDs[i]), diff --git a/packages/protocol/script/upgrade/TransferOwnership.s.sol b/packages/protocol/script/upgrade/TransferOwnership.s.sol index e3e14c5e60a..625d448355c 100644 --- a/packages/protocol/script/upgrade/TransferOwnership.s.sol +++ b/packages/protocol/script/upgrade/TransferOwnership.s.sol @@ -27,18 +27,8 @@ interface IOwnable { /// forge script TransferOwnership --sig "run(address,address)"
///
contract TransferOwnership is UpgradeScript { - function run( - address contractAddr, - address timeLockContract - ) - external - setUp - { + function run(address contractAddr, address timeLockContract) external setUp { IOwnable(contractAddr).transferOwnership(timeLockContract); - console2.log( - contractAddr, - " contract has a new owner:", - address(timeLockContract) - ); + console2.log(contractAddr, " contract has a new owner:", address(timeLockContract)); } } diff --git a/packages/protocol/script/upgrade/UpgradeAddressManager.s.sol b/packages/protocol/script/upgrade/UpgradeAddressManager.s.sol index d68bc7f555f..82d596e0093 100644 --- a/packages/protocol/script/upgrade/UpgradeAddressManager.s.sol +++ b/packages/protocol/script/upgrade/UpgradeAddressManager.s.sol @@ -15,9 +15,6 @@ contract UpgradeAddressManager is UpgradeScript { function run() external setUp { AddressManager newAddressManager = new ProxiedAddressManager(); proxy.upgradeTo(address(newAddressManager)); - console2.log( - "proxy upgraded AddressManager implementation to", - address(newAddressManager) - ); + console2.log("proxy upgraded AddressManager implementation to", address(newAddressManager)); } } diff --git a/packages/protocol/script/upgrade/UpgradeBridge.s.sol b/packages/protocol/script/upgrade/UpgradeBridge.s.sol index 9261e01bed0..067bfd16c4d 100644 --- a/packages/protocol/script/upgrade/UpgradeBridge.s.sol +++ b/packages/protocol/script/upgrade/UpgradeBridge.s.sol @@ -15,8 +15,6 @@ contract UpgradeBridge is UpgradeScript { function run() external setUp { Bridge newBridge = new ProxiedSingletonBridge(); proxy.upgradeTo(address(newBridge)); - console2.log( - "proxy upgraded Bridge implementation to", address(newBridge) - ); + console2.log("proxy upgraded Bridge implementation to", address(newBridge)); } } diff --git a/packages/protocol/script/upgrade/UpgradeERC1155Vault.s.sol b/packages/protocol/script/upgrade/UpgradeERC1155Vault.s.sol index b2931ae2f9e..3d4db5d9062 100644 --- a/packages/protocol/script/upgrade/UpgradeERC1155Vault.s.sol +++ b/packages/protocol/script/upgrade/UpgradeERC1155Vault.s.sol @@ -15,9 +15,6 @@ contract UpgradeERC1155Vault is UpgradeScript { function run() external setUp { ERC1155Vault newERC1155Vault = new ProxiedSingletonERC1155Vault(); proxy.upgradeTo(address(newERC1155Vault)); - console2.log( - "proxy upgraded ERC1155Vault implementation to", - address(newERC1155Vault) - ); + console2.log("proxy upgraded ERC1155Vault implementation to", address(newERC1155Vault)); } } diff --git a/packages/protocol/script/upgrade/UpgradeERC20Vault.s.sol b/packages/protocol/script/upgrade/UpgradeERC20Vault.s.sol index 03873dc19c6..819c8db5d07 100644 --- a/packages/protocol/script/upgrade/UpgradeERC20Vault.s.sol +++ b/packages/protocol/script/upgrade/UpgradeERC20Vault.s.sol @@ -15,9 +15,6 @@ contract UpgradeERC20Vault is UpgradeScript { function run() external setUp { ERC20Vault newERC20Vault = new ProxiedSingletonERC20Vault(); proxy.upgradeTo(address(newERC20Vault)); - console2.log( - "proxy upgraded ERC20Vault implementation to", - address(newERC20Vault) - ); + console2.log("proxy upgraded ERC20Vault implementation to", address(newERC20Vault)); } } diff --git a/packages/protocol/script/upgrade/UpgradeERC721Vault.s.sol b/packages/protocol/script/upgrade/UpgradeERC721Vault.s.sol index f29686db9d2..17bd0743ceb 100644 --- a/packages/protocol/script/upgrade/UpgradeERC721Vault.s.sol +++ b/packages/protocol/script/upgrade/UpgradeERC721Vault.s.sol @@ -15,9 +15,6 @@ contract UpgradeERC721Vault is UpgradeScript { function run() external setUp { ERC721Vault newERC721Vault = new ProxiedSingletonERC721Vault(); proxy.upgradeTo(address(newERC721Vault)); - console2.log( - "proxy upgraded ERC721Vault implementation to", - address(newERC721Vault) - ); + console2.log("proxy upgraded ERC721Vault implementation to", address(newERC721Vault)); } } diff --git a/packages/protocol/script/upgrade/UpgradeScript.s.sol b/packages/protocol/script/upgrade/UpgradeScript.s.sol index 4b6275e19eb..4683e995150 100644 --- a/packages/protocol/script/upgrade/UpgradeScript.s.sol +++ b/packages/protocol/script/upgrade/UpgradeScript.s.sol @@ -8,8 +8,7 @@ pragma solidity ^0.8.20; import "forge-std/Script.sol"; import "forge-std/console2.sol"; -import - "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; +import "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; contract UpgradeScript is Script { uint256 public deployerPrivateKey = vm.envUint("PRIVATE_KEY"); diff --git a/packages/protocol/script/upgrade/UpgradeSignalService.sol b/packages/protocol/script/upgrade/UpgradeSignalService.sol index a8d1592715d..e813cc1d7ed 100644 --- a/packages/protocol/script/upgrade/UpgradeSignalService.sol +++ b/packages/protocol/script/upgrade/UpgradeSignalService.sol @@ -15,9 +15,6 @@ contract UpgradeSignalService is UpgradeScript { function run() external setUp { SignalService newSignalService = new ProxiedSingletonSignalService(); proxy.upgradeTo(address(newSignalService)); - console2.log( - "proxy upgraded SignalService implementation to", - address(newSignalService) - ); + console2.log("proxy upgraded SignalService implementation to", address(newSignalService)); } } diff --git a/packages/protocol/script/upgrade/UpgradeTaikoL1.s.sol b/packages/protocol/script/upgrade/UpgradeTaikoL1.s.sol index 7eccfcea3d7..412cf8c4063 100644 --- a/packages/protocol/script/upgrade/UpgradeTaikoL1.s.sol +++ b/packages/protocol/script/upgrade/UpgradeTaikoL1.s.sol @@ -15,8 +15,6 @@ contract UpgradeTaikoL1 is UpgradeScript { function run() external setUp { TaikoL1 newTaikoL1 = new ProxiedTaikoL1(); proxy.upgradeTo(address(newTaikoL1)); - console2.log( - "proxy upgraded taiko L1 implementation to", address(newTaikoL1) - ); + console2.log("proxy upgraded taiko L1 implementation to", address(newTaikoL1)); } } diff --git a/packages/protocol/script/upgrade/UpgradeTaikoL2.s.sol b/packages/protocol/script/upgrade/UpgradeTaikoL2.s.sol index f2286c644c2..c7189b3700a 100644 --- a/packages/protocol/script/upgrade/UpgradeTaikoL2.s.sol +++ b/packages/protocol/script/upgrade/UpgradeTaikoL2.s.sol @@ -15,8 +15,6 @@ contract UpgradeTaikoL2 is UpgradeScript { function run() external setUp { TaikoL2 newTaikoL2 = new ProxiedSingletonTaikoL2(); proxy.upgradeTo(address(newTaikoL2)); - console2.log( - "proxy upgraded TaikoL2 implementation to", address(newTaikoL2) - ); + console2.log("proxy upgraded TaikoL2 implementation to", address(newTaikoL2)); } } diff --git a/packages/protocol/script/upgrade/UpgradeTaikoToken.s.sol b/packages/protocol/script/upgrade/UpgradeTaikoToken.s.sol index e901190abbe..8baa2a52e06 100644 --- a/packages/protocol/script/upgrade/UpgradeTaikoToken.s.sol +++ b/packages/protocol/script/upgrade/UpgradeTaikoToken.s.sol @@ -15,9 +15,6 @@ contract UpgradeTaikoToken is UpgradeScript { function run() external setUp { TaikoToken newTaikoToken = new ProxiedTaikoToken(); proxy.upgradeTo(address(newTaikoToken)); - console2.log( - "proxy upgraded TaikoToken implementation to", - address(newTaikoToken) - ); + console2.log("proxy upgraded TaikoToken implementation to", address(newTaikoToken)); } } diff --git a/packages/protocol/test/L1/SgxVerifier.t.sol b/packages/protocol/test/L1/SgxVerifier.t.sol index 73a9efedfe0..cc55090ea65 100644 --- a/packages/protocol/test/L1/SgxVerifier.t.sol +++ b/packages/protocol/test/L1/SgxVerifier.t.sol @@ -1,11 +1,11 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.20; -import { Test } from "forge-std/Test.sol"; -import { console2 } from "forge-std/console2.sol"; -import { TaikoL1 } from "../../contracts/L1/TaikoL1.sol"; -import { SgxVerifier } from "../../contracts/L1/verifiers/SgxVerifier.sol"; -import { TaikoL1TestBase } from "./TaikoL1TestBase.sol"; +import "forge-std/Test.sol"; +import "forge-std/console2.sol"; +import "../../contracts/L1/TaikoL1.sol"; +import "../../contracts/L1/verifiers/SgxVerifier.sol"; +import "./TaikoL1TestBase.sol"; contract TestSgxVerifier is TaikoL1TestBase { function deployTaikoL1() internal override returns (TaikoL1 taikoL1) { diff --git a/packages/protocol/test/L1/TaikoL1.t.sol b/packages/protocol/test/L1/TaikoL1.t.sol index d84101f7ae9..5ed61840f6c 100644 --- a/packages/protocol/test/L1/TaikoL1.t.sol +++ b/packages/protocol/test/L1/TaikoL1.t.sol @@ -1,24 +1,19 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.20; -import { Test } from "forge-std/Test.sol"; -import { console2 } from "forge-std/console2.sol"; -import { AddressManager } from "../../contracts/common/AddressManager.sol"; -import { LibUtils } from "../../contracts/L1/libs/LibUtils.sol"; -import { TaikoData } from "../../contracts/L1/TaikoData.sol"; -import { TaikoErrors } from "../../contracts/L1/TaikoErrors.sol"; -import { TaikoL1 } from "../../contracts/L1/TaikoL1.sol"; -import { TaikoToken } from "../../contracts/L1/TaikoToken.sol"; -import { SignalService } from "../../contracts/signal/SignalService.sol"; -import { TaikoL1TestBase } from "./TaikoL1TestBase.sol"; +import "forge-std/Test.sol"; +import "forge-std/console2.sol"; +import "../../contracts/common/AddressManager.sol"; +import "../../contracts/L1/libs/LibUtils.sol"; +import "../../contracts/L1/TaikoData.sol"; +import "../../contracts/L1/TaikoErrors.sol"; +import "../../contracts/L1/TaikoL1.sol"; +import "../../contracts/L1/TaikoToken.sol"; +import "../../contracts/signal/SignalService.sol"; +import "./TaikoL1TestBase.sol"; contract TaikoL1_NoCooldown is TaikoL1 { - function getConfig() - public - view - override - returns (TaikoData.Config memory config) - { + function getConfig() public view override returns (TaikoData.Config memory config) { config = TaikoL1.getConfig(); // over-write the following config.maxBlocksToVerifyPerProposal = 0; @@ -59,27 +54,15 @@ contract TaikoL1Test is TaikoL1TestBase { bytes32 parentHash = GENESIS_BLOCK_HASH; - for ( - uint256 blockId = 1; blockId < conf.blockMaxProposals * 3; blockId++ - ) { + for (uint256 blockId = 1; blockId < conf.blockMaxProposals * 3; blockId++) { //printVariables("before propose"); - (TaikoData.BlockMetadata memory meta,) = - proposeBlock(Alice, Bob, 1_000_000, 1024); + (TaikoData.BlockMetadata memory meta,) = proposeBlock(Alice, Bob, 1_000_000, 1024); //printVariables("after propose"); mine(1); bytes32 blockHash = bytes32(1e10 + blockId); bytes32 signalRoot = bytes32(1e9 + blockId); - proveBlock( - Bob, - Bob, - meta, - parentHash, - blockHash, - signalRoot, - meta.minTier, - "" - ); + proveBlock(Bob, Bob, meta, parentHash, blockHash, signalRoot, meta.minTier, ""); vm.roll(block.number + 15 * 12); uint16 minTier = meta.minTier; @@ -106,23 +89,13 @@ contract TaikoL1Test is TaikoL1TestBase { for (uint256 blockId = 1; blockId <= 20; ++blockId) { printVariables("before propose"); - (TaikoData.BlockMetadata memory meta,) = - proposeBlock(Alice, Bob, 1_000_000, 1024); + (TaikoData.BlockMetadata memory meta,) = proposeBlock(Alice, Bob, 1_000_000, 1024); printVariables("after propose"); bytes32 blockHash = bytes32(1e10 + blockId); bytes32 signalRoot = bytes32(1e9 + blockId); - proveBlock( - Bob, - Bob, - meta, - parentHash, - blockHash, - signalRoot, - meta.minTier, - "" - ); + proveBlock(Bob, Bob, meta, parentHash, blockHash, signalRoot, meta.minTier, ""); vm.roll(block.number + 15 * 12); uint16 minTier = meta.minTier; vm.warp(block.timestamp + L1.getTier(minTier).cooldownWindow + 1); @@ -145,26 +118,15 @@ contract TaikoL1Test is TaikoL1TestBase { bytes32 parentHash = GENESIS_BLOCK_HASH; - for (uint256 blockId = 1; blockId <= conf.blockMaxProposals; blockId++) - { + for (uint256 blockId = 1; blockId <= conf.blockMaxProposals; blockId++) { printVariables("before propose"); - (TaikoData.BlockMetadata memory meta,) = - proposeBlock(Alice, Bob, 1_000_000, 1024); + (TaikoData.BlockMetadata memory meta,) = proposeBlock(Alice, Bob, 1_000_000, 1024); printVariables("after propose"); bytes32 blockHash = bytes32(1e10 + blockId); bytes32 signalRoot = bytes32(1e9 + blockId); - proveBlock( - Bob, - Bob, - meta, - parentHash, - blockHash, - signalRoot, - meta.minTier, - "" - ); + proveBlock(Bob, Bob, meta, parentHash, blockHash, signalRoot, meta.minTier, ""); parentHash = blockHash; } @@ -223,9 +185,7 @@ contract TaikoL1Test is TaikoL1TestBase { console2.log("gas used with eth deposits:", gasUsedWithDeposits); printVariables("after processing send-ethers"); - assertTrue( - keccak256(abi.encode(depositsProcessed)) != emptyDepositsRoot - ); + assertTrue(keccak256(abi.encode(depositsProcessed)) != emptyDepositsRoot); assertEq(depositsProcessed.length, count); gas = gasleft(); @@ -234,8 +194,7 @@ contract TaikoL1Test is TaikoL1TestBase { console2.log("gas used without eth deposits:", gasUsedWithoutDeposits); - uint256 gasPerEthDeposit = - (gasUsedWithDeposits - gasUsedWithoutDeposits) / count; + uint256 gasPerEthDeposit = (gasUsedWithDeposits - gasUsedWithoutDeposits) / count; console2.log("gas per eth deposit:", gasPerEthDeposit); console2.log("ethDepositMaxCountPerBlock:", count); @@ -276,14 +235,7 @@ contract TaikoL1Test is TaikoL1TestBase { signalRoot = bytes32(1e9 + uint256(blockId)); proveBlock( - Bob, - Bob, - meta, - parentHashes[blockId - 1], - blockHash, - signalRoot, - meta.minTier, - "" + Bob, Bob, meta, parentHashes[blockId - 1], blockHash, signalRoot, meta.minTier, "" ); vm.roll(block.number + 15 * 12); diff --git a/packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol b/packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol index 46311ca933f..fa562e73375 100644 --- a/packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol +++ b/packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol @@ -1,30 +1,23 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.20; -import { Test } from "forge-std/Test.sol"; -import { console2 } from "forge-std/console2.sol"; - -import { AddressManager } from "../../contracts/common/AddressManager.sol"; -import { LibUtils } from "../../contracts/L1/libs/LibUtils.sol"; -import { LibProposing } from "../../contracts/L1/libs/LibProposing.sol"; -import { GuardianVerifier } from - "../../contracts/L1/verifiers/GuardianVerifier.sol"; -import { TaikoData } from "../../contracts/L1/TaikoData.sol"; -import { TaikoErrors } from "../../contracts/L1/TaikoErrors.sol"; -import { TaikoL1 } from "../../contracts/L1/TaikoL1.sol"; -import { TaikoToken } from "../../contracts/L1/TaikoToken.sol"; -import { SignalService } from "../../contracts/signal/SignalService.sol"; - -import { TaikoL1TestBase } from "./TaikoL1TestBase.sol"; -import { LibTiers } from "../../contracts/L1/tiers/ITierProvider.sol"; +import "forge-std/Test.sol"; +import "forge-std/console2.sol"; + +import "../../contracts/common/AddressManager.sol"; +import "../../contracts/L1/libs/LibUtils.sol"; +import "../../contracts/L1/libs/LibProposing.sol"; +import "../../contracts/L1/verifiers/GuardianVerifier.sol"; +import "../../contracts/L1/TaikoData.sol"; +import "../../contracts/L1/TaikoErrors.sol"; +import "../../contracts/L1/TaikoL1.sol"; +import "../../contracts/L1/TaikoToken.sol"; +import "../../contracts/L1/tiers/ITierProvider.sol"; +import "../../contracts/signal/SignalService.sol"; +import "./TaikoL1TestBase.sol"; contract TaikoL1Tiers is TaikoL1 { - function getConfig() - public - view - override - returns (TaikoData.Config memory config) - { + function getConfig() public view override returns (TaikoData.Config memory config) { config = TaikoL1.getConfig(); config.maxBlocksToVerifyPerProposal = 0; @@ -66,16 +59,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { } else if (minTier == LibTiers.TIER_SGX_AND_PSE_ZKEVM) { tierToProveWith = LibTiers.TIER_GUARDIAN; } - proveBlock( - Carol, - Carol, - meta, - parentHash, - blockHash, - signalRoot, - tierToProveWith, - "" - ); + proveBlock(Carol, Carol, meta, parentHash, blockHash, signalRoot, tierToProveWith, ""); } function test_L1_ContestingWithSameProof() external { @@ -92,12 +76,9 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { vm.prank(Bob, Bob); bytes32 parentHash = GENESIS_BLOCK_HASH; - for ( - uint256 blockId = 1; blockId < conf.blockMaxProposals * 3; blockId++ - ) { + for (uint256 blockId = 1; blockId < conf.blockMaxProposals * 3; blockId++) { printVariables("before propose"); - (TaikoData.BlockMetadata memory meta,) = - proposeBlock(Alice, Bob, 1_000_000, 1024); + (TaikoData.BlockMetadata memory meta,) = proposeBlock(Alice, Bob, 1_000_000, 1024); //printVariables("after propose"); mine(1); @@ -105,16 +86,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { bytes32 signalRoot = bytes32(1e9 + blockId); // This proof cannot be verified obviously because of // blockhash:blockId - proveBlock( - Bob, - Bob, - meta, - parentHash, - blockHash, - signalRoot, - meta.minTier, - "" - ); + proveBlock(Bob, Bob, meta, parentHash, blockHash, signalRoot, meta.minTier, ""); // Try to contest - but should revert with L1_ALREADY_PROVED proveBlock( @@ -154,12 +126,9 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { vm.prank(Bob, Bob); bytes32 parentHash = GENESIS_BLOCK_HASH; - for ( - uint256 blockId = 1; blockId < conf.blockMaxProposals * 3; blockId++ - ) { + for (uint256 blockId = 1; blockId < conf.blockMaxProposals * 3; blockId++) { printVariables("before propose"); - (TaikoData.BlockMetadata memory meta,) = - proposeBlock(Alice, Bob, 1_000_000, 1024); + (TaikoData.BlockMetadata memory meta,) = proposeBlock(Alice, Bob, 1_000_000, 1024); //printVariables("after propose"); mine(1); @@ -169,21 +138,10 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { // signalRoot instead of blockHash uint16 minTier = meta.minTier; - proveBlock( - Bob, Bob, meta, parentHash, signalRoot, signalRoot, minTier, "" - ); + proveBlock(Bob, Bob, meta, parentHash, signalRoot, signalRoot, minTier, ""); // Try to contest - proveBlock( - Carol, - Carol, - meta, - parentHash, - blockHash, - signalRoot, - minTier, - "" - ); + proveBlock(Carol, Carol, meta, parentHash, blockHash, signalRoot, minTier, ""); vm.roll(block.number + 15 * 12); @@ -192,14 +150,9 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { // Cannot verify block because it is contested.. verifyBlock(Carol, 1); - proveHigherTierProof( - meta, parentHash, signalRoot, blockHash, minTier - ); + proveHigherTierProof(meta, parentHash, signalRoot, blockHash, minTier); - vm.warp( - block.timestamp - + L1.getTier(LibTiers.TIER_GUARDIAN).cooldownWindow + 1 - ); + vm.warp(block.timestamp + L1.getTier(LibTiers.TIER_GUARDIAN).cooldownWindow + 1); // Now can verify console2.log("Probalom verify-olni"); verifyBlock(Carol, 1); @@ -223,12 +176,9 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { vm.prank(Bob, Bob); bytes32 parentHash = GENESIS_BLOCK_HASH; - for ( - uint256 blockId = 1; blockId < conf.blockMaxProposals * 3; blockId++ - ) { + for (uint256 blockId = 1; blockId < conf.blockMaxProposals * 3; blockId++) { printVariables("before propose"); - (TaikoData.BlockMetadata memory meta,) = - proposeBlock(Alice, Bob, 1_000_000, 1024); + (TaikoData.BlockMetadata memory meta,) = proposeBlock(Alice, Bob, 1_000_000, 1024); //printVariables("after propose"); mine(1); @@ -237,21 +187,10 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { // This proof cannot be verified obviously because of // signalRoot instead of blockHash uint16 minTier = meta.minTier; - proveBlock( - Bob, Bob, meta, parentHash, signalRoot, signalRoot, minTier, "" - ); + proveBlock(Bob, Bob, meta, parentHash, signalRoot, signalRoot, minTier, ""); // Try to contest - proveBlock( - Carol, - Carol, - meta, - parentHash, - blockHash, - signalRoot, - minTier, - "" - ); + proveBlock(Carol, Carol, meta, parentHash, blockHash, signalRoot, minTier, ""); vm.roll(block.number + 15 * 12); @@ -260,15 +199,10 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { // Cannot verify block because it is contested.. verifyBlock(Carol, 1); - proveHigherTierProof( - meta, parentHash, signalRoot, blockHash, minTier - ); + proveHigherTierProof(meta, parentHash, signalRoot, blockHash, minTier); // Otherwise just not contest - vm.warp( - block.timestamp - + L1.getTier(LibTiers.TIER_GUARDIAN).cooldownWindow + 1 - ); + vm.warp(block.timestamp + L1.getTier(LibTiers.TIER_GUARDIAN).cooldownWindow + 1); // Now can verify verifyBlock(Carol, 1); @@ -291,12 +225,9 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { vm.prank(Bob, Bob); bytes32 parentHash = GENESIS_BLOCK_HASH; - for ( - uint256 blockId = 1; blockId < conf.blockMaxProposals * 3; blockId++ - ) { + for (uint256 blockId = 1; blockId < conf.blockMaxProposals * 3; blockId++) { printVariables("before propose"); - (TaikoData.BlockMetadata memory meta,) = - proposeBlock(Alice, Bob, 1_000_000, 1024); + (TaikoData.BlockMetadata memory meta,) = proposeBlock(Alice, Bob, 1_000_000, 1024); //printVariables("after propose"); mine(1); @@ -306,28 +237,15 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { // signalRoot instead of blockHash uint16 minTier = meta.minTier; - proveBlock( - Bob, Bob, meta, parentHash, blockHash, signalRoot, minTier, "" - ); + proveBlock(Bob, Bob, meta, parentHash, blockHash, signalRoot, minTier, ""); if (minTier == LibTiers.TIER_OPTIMISTIC) { // Try to contest - proveBlock( - Carol, - Carol, - meta, - parentHash, - signalRoot, - signalRoot, - minTier, - "" - ); + proveBlock(Carol, Carol, meta, parentHash, signalRoot, signalRoot, minTier, ""); vm.roll(block.number + 15 * 12); - vm.warp( - block.timestamp + L1.getTier(minTier).cooldownWindow + 1 - ); + vm.warp(block.timestamp + L1.getTier(minTier).cooldownWindow + 1); // Cannot verify block because it is contested.. verifyBlock(Carol, 1); @@ -345,10 +263,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { } // Otherwise just not contest - vm.warp( - block.timestamp - + L1.getTier(LibTiers.TIER_GUARDIAN).cooldownWindow + 1 - ); + vm.warp(block.timestamp + L1.getTier(LibTiers.TIER_GUARDIAN).cooldownWindow + 1); // Now can verify verifyBlock(Carol, 1); @@ -373,8 +288,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { bytes32 parentHash = GENESIS_BLOCK_HASH; for (uint256 blockId = 1; blockId < 10; blockId++) { printVariables("before propose"); - (TaikoData.BlockMetadata memory meta,) = - proposeBlock(Alice, Bob, 1_000_000, 1024); + (TaikoData.BlockMetadata memory meta,) = proposeBlock(Alice, Bob, 1_000_000, 1024); //printVariables("after propose"); mine(1); @@ -383,29 +297,15 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { // This proof cannot be verified obviously because of // signalRoot instead of blockHash uint16 minTier = meta.minTier; - proveBlock( - Bob, Bob, meta, parentHash, signalRoot, signalRoot, minTier, "" - ); + proveBlock(Bob, Bob, meta, parentHash, signalRoot, signalRoot, minTier, ""); if (minTier == LibTiers.TIER_OPTIMISTIC) { // Try to contest - proveBlock( - Carol, - Carol, - meta, - parentHash, - blockHash, - signalRoot, - minTier, - "" - ); + proveBlock(Carol, Carol, meta, parentHash, blockHash, signalRoot, minTier, ""); vm.roll(block.number + 15 * 12); - vm.warp( - block.timestamp - + L1.getTier(LibTiers.TIER_GUARDIAN).cooldownWindow + 1 - ); + vm.warp(block.timestamp + L1.getTier(LibTiers.TIER_GUARDIAN).cooldownWindow + 1); // Cannot verify block because it is contested.. verifyBlock(Carol, 1); @@ -423,10 +323,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { } // Otherwise just not contest - vm.warp( - block.timestamp - + L1.getTier(LibTiers.TIER_GUARDIAN).cooldownWindow + 1 - ); + vm.warp(block.timestamp + L1.getTier(LibTiers.TIER_GUARDIAN).cooldownWindow + 1); // Now can verify verifyBlock(Carol, 1); @@ -435,9 +332,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { printVariables(""); } - function test_L1_NonAsignedProverCannotBeFirstInProofWindowTime() - external - { + function test_L1_NonAsignedProverCannotBeFirstInProofWindowTime() external { giveEthAndTko(Alice, 1e8 ether, 100 ether); // This is a very weird test (code?) issue here. // If this line (or Bob's query balance) is uncommented, @@ -453,8 +348,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { for (uint256 blockId = 1; blockId < 10; blockId++) { //printVariables("before propose"); - (TaikoData.BlockMetadata memory meta,) = - proposeBlock(Alice, Bob, 1_000_000, 1024); + (TaikoData.BlockMetadata memory meta,) = proposeBlock(Alice, Bob, 1_000_000, 1024); //printVariables("after propose"); mine(1); @@ -497,8 +391,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { for (uint256 blockId = 1; blockId < 10; blockId++) { //printVariables("before propose"); - (TaikoData.BlockMetadata memory meta,) = - proposeBlock(Alice, Bob, 1_000_000, 1024); + (TaikoData.BlockMetadata memory meta,) = proposeBlock(Alice, Bob, 1_000_000, 1024); //printVariables("after propose"); mine(1); @@ -541,12 +434,9 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { vm.prank(Bob, Bob); bytes32 parentHash = GENESIS_BLOCK_HASH; - for ( - uint256 blockId = 1; blockId < conf.blockMaxProposals * 3; blockId++ - ) { + for (uint256 blockId = 1; blockId < conf.blockMaxProposals * 3; blockId++) { printVariables("before propose"); - (TaikoData.BlockMetadata memory meta,) = - proposeBlock(Alice, Bob, 1_000_000, 1024); + (TaikoData.BlockMetadata memory meta,) = proposeBlock(Alice, Bob, 1_000_000, 1024); //printVariables("after propose"); mine(1); @@ -554,16 +444,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { bytes32 signalRoot = bytes32(1e9 + blockId); // This proof cannot be verified obviously because of // blockhash:blockId - proveBlock( - Bob, - Bob, - meta, - parentHash, - blockHash, - signalRoot, - meta.minTier, - "" - ); + proveBlock(Bob, Bob, meta, parentHash, blockHash, signalRoot, meta.minTier, ""); // Try to contest - but should revert with L1_ALREADY_PROVED proveBlock( @@ -603,12 +484,9 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { vm.prank(Bob, Bob); bytes32 parentHash = GENESIS_BLOCK_HASH; - for ( - uint256 blockId = 1; blockId < conf.blockMaxProposals * 3; blockId++ - ) { + for (uint256 blockId = 1; blockId < conf.blockMaxProposals * 3; blockId++) { printVariables("before propose"); - (TaikoData.BlockMetadata memory meta,) = - proposeBlock(Alice, Bob, 1_000_000, 1024); + (TaikoData.BlockMetadata memory meta,) = proposeBlock(Alice, Bob, 1_000_000, 1024); //printVariables("after propose"); mine(1); @@ -616,16 +494,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { bytes32 signalRoot = bytes32(1e9 + blockId); // This proof cannot be verified obviously because of // blockhash:blockId - proveBlock( - Bob, - Bob, - meta, - parentHash, - blockHash, - signalRoot, - meta.minTier, - "" - ); + proveBlock(Bob, Bob, meta, parentHash, blockHash, signalRoot, meta.minTier, ""); // Try to contest - but should revert with L1_ALREADY_PROVED proveBlock( @@ -665,12 +534,9 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { vm.prank(Bob, Bob); bytes32 parentHash = GENESIS_BLOCK_HASH; - for ( - uint256 blockId = 1; blockId < conf.blockMaxProposals * 3; blockId++ - ) { + for (uint256 blockId = 1; blockId < conf.blockMaxProposals * 3; blockId++) { printVariables("before propose"); - (TaikoData.BlockMetadata memory meta,) = - proposeBlock(Alice, Bob, 1_000_000, 1024); + (TaikoData.BlockMetadata memory meta,) = proposeBlock(Alice, Bob, 1_000_000, 1024); //printVariables("after propose"); mine(1); @@ -678,27 +544,11 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { bytes32 signalRoot = bytes32(1e9 + blockId); // This proof cannot be verified obviously because of // blockhash:blockId - proveBlock( - Bob, - Bob, - meta, - parentHash, - signalRoot, - signalRoot, - meta.minTier, - "" - ); + proveBlock(Bob, Bob, meta, parentHash, signalRoot, signalRoot, meta.minTier, ""); // Prove as guardian proveBlock( - Carol, - Carol, - meta, - parentHash, - blockHash, - signalRoot, - LibTiers.TIER_GUARDIAN, - "" + Carol, Carol, meta, parentHash, blockHash, signalRoot, LibTiers.TIER_GUARDIAN, "" ); vm.roll(block.number + 15 * 12); @@ -731,8 +581,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { bytes32 parentHash = GENESIS_BLOCK_HASH; for (uint256 blockId = 1; blockId < 10; blockId++) { printVariables("before propose"); - (TaikoData.BlockMetadata memory meta,) = - proposeBlock(Alice, Bob, 1_000_000, 1024); + (TaikoData.BlockMetadata memory meta,) = proposeBlock(Alice, Bob, 1_000_000, 1024); //printVariables("after propose"); mine(1); @@ -740,16 +589,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { bytes32 signalRoot = bytes32(1e9 + blockId); // This proof cannot be verified obviously because of // blockhash:blockId - proveBlock( - Bob, - Bob, - meta, - parentHash, - signalRoot, - signalRoot, - meta.minTier, - "" - ); + proveBlock(Bob, Bob, meta, parentHash, signalRoot, signalRoot, meta.minTier, ""); // Prove as guardian but in reality not a guardian proveBlock( @@ -793,8 +633,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { bytes32 parentHash = GENESIS_BLOCK_HASH; for (uint256 blockId = 1; blockId < 10; blockId++) { printVariables("before propose"); - (TaikoData.BlockMetadata memory meta,) = - proposeBlock(Alice, Bob, 1_000_000, 1024); + (TaikoData.BlockMetadata memory meta,) = proposeBlock(Alice, Bob, 1_000_000, 1024); //printVariables("after propose"); mine(1); @@ -836,8 +675,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { bytes32 parentHash = GENESIS_BLOCK_HASH; for (uint256 blockId = 1; blockId < 10; blockId++) { printVariables("before propose"); - (TaikoData.BlockMetadata memory meta,) = - proposeBlock(Alice, Bob, 1_000_000, 1024); + (TaikoData.BlockMetadata memory meta,) = proposeBlock(Alice, Bob, 1_000_000, 1024); //printVariables("after propose"); mine(1); @@ -876,12 +714,9 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { vm.prank(Bob, Bob); bytes32 parentHash = GENESIS_BLOCK_HASH; - for ( - uint256 blockId = 1; blockId < conf.blockMaxProposals * 3; blockId++ - ) { + for (uint256 blockId = 1; blockId < conf.blockMaxProposals * 3; blockId++) { printVariables("before propose"); - (TaikoData.BlockMetadata memory meta,) = - proposeBlock(Alice, Bob, 1_000_000, 1024); + (TaikoData.BlockMetadata memory meta,) = proposeBlock(Alice, Bob, 1_000_000, 1024); //printVariables("after propose"); mine(1); @@ -889,27 +724,11 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { bytes32 signalRoot = bytes32(1e9 + blockId); // This proof cannot be verified obviously because of blockhash is // exchanged with signalRoot - proveBlock( - Bob, - Bob, - meta, - parentHash, - signalRoot, - signalRoot, - meta.minTier, - "" - ); + proveBlock(Bob, Bob, meta, parentHash, signalRoot, signalRoot, meta.minTier, ""); // Prove as guardian proveBlock( - Carol, - Carol, - meta, - parentHash, - blockHash, - signalRoot, - LibTiers.TIER_GUARDIAN, - "" + Carol, Carol, meta, parentHash, blockHash, signalRoot, LibTiers.TIER_GUARDIAN, "" ); // Try to re-prove but reverts @@ -950,12 +769,9 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { vm.prank(Bob, Bob); bytes32 parentHash = GENESIS_BLOCK_HASH; - for ( - uint256 blockId = 1; blockId < conf.blockMaxProposals * 3; blockId++ - ) { + for (uint256 blockId = 1; blockId < conf.blockMaxProposals * 3; blockId++) { printVariables("before propose"); - (TaikoData.BlockMetadata memory meta,) = - proposeBlock(Alice, Bob, 1_000_000, 1024); + (TaikoData.BlockMetadata memory meta,) = proposeBlock(Alice, Bob, 1_000_000, 1024); //printVariables("after propose"); mine(1); @@ -963,16 +779,7 @@ contract TaikoL1LibProvingWithTiers is TaikoL1TestBase { bytes32 signalRoot = bytes32(1e9 + blockId); // This proof cannot be verified obviously because of blockhash is // exchanged with signalRoot - proveBlock( - Bob, - Bob, - meta, - parentHash, - signalRoot, - signalRoot, - meta.minTier, - "" - ); + proveBlock(Bob, Bob, meta, parentHash, signalRoot, signalRoot, meta.minTier, ""); // Let's say the 10th block is unprovable so prove accordingly if (blockId == 10) { diff --git a/packages/protocol/test/L1/TaikoL1TestBase.sol b/packages/protocol/test/L1/TaikoL1TestBase.sol index 4cc3731bc37..0cd05baae6b 100644 --- a/packages/protocol/test/L1/TaikoL1TestBase.sol +++ b/packages/protocol/test/L1/TaikoL1TestBase.sol @@ -1,30 +1,26 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.20; -import { TestBase } from "../TestBase.sol"; -import { console2 } from "forge-std/console2.sol"; -import { AddressManager } from "../../contracts/common/AddressManager.sol"; -import { Bridge } from "../../contracts/bridge/Bridge.sol"; -import { LibProving } from "../../contracts/L1/libs/LibProving.sol"; -import { LibProposing } from "../../contracts/L1/libs/LibProposing.sol"; -import { LibUtils } from "../../contracts/L1/libs/LibUtils.sol"; -import { TaikoData } from "../../contracts/L1/TaikoData.sol"; -import { TaikoL1 } from "../../contracts/L1/TaikoL1.sol"; -import { TaikoToken } from "../../contracts/L1/TaikoToken.sol"; -import { GuardianVerifier } from - "../../contracts/L1/verifiers/GuardianVerifier.sol"; -import { TaikoA6TierProvider } from - "../../contracts/L1/tiers/TaikoA6TierProvider.sol"; -import { PseZkVerifier } from "../../contracts/L1/verifiers/PseZkVerifier.sol"; -import { SgxVerifier } from "../../contracts/L1/verifiers/SgxVerifier.sol"; -import { SgxAndZkVerifier } from - "../../contracts/L1/verifiers/SgxAndZkVerifier.sol"; -import { GuardianProver } from "../../contracts/L1/provers/GuardianProver.sol"; -import { SignalService } from "../../contracts/signal/SignalService.sol"; -import { StringsUpgradeable as Strings } from - "lib/openzeppelin-contracts-upgradeable/contracts/utils/StringsUpgradeable.sol"; -import { AddressResolver } from "../../contracts/common/AddressResolver.sol"; -import { LibTiers } from "../../contracts/L1/tiers/ITierProvider.sol"; +import "lib/openzeppelin-contracts/contracts/utils/Strings.sol"; +import "forge-std/console2.sol"; +import "../TestBase.sol"; +import "../../contracts/common/AddressManager.sol"; +import "../../contracts/bridge/Bridge.sol"; +import "../../contracts/L1/libs/LibProving.sol"; +import "../../contracts/L1/libs/LibProposing.sol"; +import "../../contracts/L1/libs/LibUtils.sol"; +import "../../contracts/L1/TaikoData.sol"; +import "../../contracts/L1/TaikoL1.sol"; +import "../../contracts/L1/TaikoToken.sol"; +import "../../contracts/L1/verifiers/GuardianVerifier.sol"; +import "../../contracts/L1/tiers/TaikoA6TierProvider.sol"; +import "../../contracts/L1/verifiers/PseZkVerifier.sol"; +import "../../contracts/L1/verifiers/SgxVerifier.sol"; +import "../../contracts/L1/verifiers/SgxAndZkVerifier.sol"; +import "../../contracts/L1/provers/GuardianProver.sol"; +import "../../contracts/signal/SignalService.sol"; +import "../../contracts/common/AddressResolver.sol"; +import "../../contracts/L1/tiers/ITierProvider.sol"; contract MockVerifier { fallback(bytes calldata) external returns (bytes memory) { @@ -34,7 +30,7 @@ contract MockVerifier { // TODO (dani): remove some code to sub-contracts, this one shall only contain // shared logics and data. -abstract contract TaikoL1TestBase is TestBase { +abstract contract TaikoL1TestBase is TaikoTest { AddressManager public addressManager; TaikoToken public tko; SignalService public ss; @@ -137,16 +133,14 @@ abstract contract TaikoL1TestBase is TestBase { tierFees[0] = TaikoData.TierFee(LibTiers.TIER_OPTIMISTIC, 1 ether); tierFees[1] = TaikoData.TierFee(LibTiers.TIER_SGX, 1 ether); tierFees[2] = TaikoData.TierFee(LibTiers.TIER_PSE_ZKEVM, 2 ether); - tierFees[3] = - TaikoData.TierFee(LibTiers.TIER_SGX_AND_PSE_ZKEVM, 2 ether); + tierFees[3] = TaikoData.TierFee(LibTiers.TIER_SGX_AND_PSE_ZKEVM, 2 ether); tierFees[4] = TaikoData.TierFee(LibTiers.TIER_GUARDIAN, 0 ether); // For the test not to fail, set the message.value to the highest, the // rest will be returned // anyways uint256 msgValue = 2 ether; - TaikoData.ProverAssignment memory assignment = TaikoData - .ProverAssignment({ + TaikoData.ProverAssignment memory assignment = TaikoData.ProverAssignment({ prover: prover, feeToken: address(0), tierFees: tierFees, @@ -159,8 +153,7 @@ abstract contract TaikoL1TestBase is TestBase { bytes memory txList = new bytes(txListSize); - assignment.signature = - _signAssignment(prover, assignment, address(L1), keccak256(txList)); + assignment.signature = _signAssignment(prover, assignment, address(L1), keccak256(txList)); (, TaikoData.SlotB memory b) = L1.getStateVariables(); @@ -177,8 +170,7 @@ abstract contract TaikoL1TestBase is TestBase { vm.prank(proposer, proposer); (meta, depositsProcessed) = L1.proposeBlock{ value: msgValue }( - abi.encode(TaikoData.BlockParams(assignment, 0, 0, 0, 0, false, 0)), - txList + abi.encode(TaikoData.BlockParams(assignment, 0, 0, 0, 0, false, 0)), txList ); } @@ -201,9 +193,8 @@ abstract contract TaikoL1TestBase is TestBase { graffiti: 0x0 }); - bytes32 instance = pv.calcInstance( - tran, prover, keccak256(abi.encode(meta)), meta.blobHash, 0 - ); + bytes32 instance = + pv.calcInstance(tran, prover, keccak256(abi.encode(meta)), meta.blobHash, 0); TaikoData.TierProof memory proof; proof.tier = tier; @@ -233,21 +224,17 @@ abstract contract TaikoL1TestBase is TestBase { } if (tier == LibTiers.TIER_SGX) { - bytes memory signature = createSgxSignatureProof( - tran, newInstance, prover, keccak256(abi.encode(meta)) - ); + bytes memory signature = + createSgxSignatureProof(tran, newInstance, prover, keccak256(abi.encode(meta))); - proof.data = - bytes.concat(bytes4(0), bytes20(newInstance), signature); + proof.data = bytes.concat(bytes4(0), bytes20(newInstance), signature); } if (tier == LibTiers.TIER_SGX_AND_PSE_ZKEVM) { - bytes memory signature = createSgxSignatureProof( - tran, newInstance, prover, keccak256(abi.encode(meta)) - ); + bytes memory signature = + createSgxSignatureProof(tran, newInstance, prover, keccak256(abi.encode(meta))); - bytes memory sgxProof = - bytes.concat(bytes4(0), bytes20(newInstance), signature); + bytes memory sgxProof = bytes.concat(bytes4(0), bytes20(newInstance), signature); // Concatenate SGX and ZK (in this order) proof.data = bytes.concat(sgxProof, proof.data); } @@ -303,9 +290,7 @@ abstract contract TaikoL1TestBase is TestBase { function registerL2Address(bytes32 nameHash, address addr) internal { addressManager.setAddress(conf.chainId, nameHash, addr); - console2.log( - conf.chainId, string(abi.encodePacked(nameHash)), unicode"→", addr - ); + console2.log(conf.chainId, string(abi.encodePacked(nameHash)), unicode"→", addr); } function _signAssignment( @@ -318,8 +303,7 @@ abstract contract TaikoL1TestBase is TestBase { view returns (bytes memory signature) { - bytes32 digest = - LibProposing.hashAssignment(assignment, taikoAddr, blobHash); + bytes32 digest = LibProposing.hashAssignment(assignment, taikoAddr, blobHash); uint256 signerPrivateKey; // In the test suite these are the 3 which acts as provers @@ -360,13 +344,7 @@ abstract contract TaikoL1TestBase is TestBase { signature = abi.encodePacked(r, s, v); } - function giveEthAndTko( - address to, - uint256 amountTko, - uint256 amountEth - ) - internal - { + function giveEthAndTko(address to, uint256 amountTko, uint256 amountEth) internal { vm.deal(to, amountEth); console2.log("TKO balance this:", tko.balanceOf(address(this))); console2.log(amountTko); @@ -380,8 +358,7 @@ abstract contract TaikoL1TestBase is TestBase { } function printVariables(string memory comment) internal { - (TaikoData.SlotA memory a, TaikoData.SlotB memory b) = - L1.getStateVariables(); + (TaikoData.SlotA memory a, TaikoData.SlotB memory b) = L1.getStateVariables(); string memory str = string.concat( Strings.toString(logCount++), diff --git a/packages/protocol/test/L1/TaikoToken.t.sol b/packages/protocol/test/L1/TaikoToken.t.sol index 00aebbe263f..c76f83d270c 100644 --- a/packages/protocol/test/L1/TaikoToken.t.sol +++ b/packages/protocol/test/L1/TaikoToken.t.sol @@ -1,14 +1,13 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.20; -import { TestBase } from "../TestBase.sol"; -import { AddressManager } from "../../contracts/common/AddressManager.sol"; -import { AddressResolver } from "../../contracts/common/AddressResolver.sol"; -import { TaikoToken } from "../../contracts/L1/TaikoToken.sol"; -import { TransparentUpgradeableProxy } from - "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; - -contract TaikoTokenTest is TestBase { +import "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; +import "../TestBase.sol"; +import "../../contracts/common/AddressManager.sol"; +import "../../contracts/common/AddressResolver.sol"; +import "../../contracts/L1/TaikoToken.sol"; + +contract TaikoTokenTest is TaikoTest { bytes32 GENESIS_BLOCK_HASH; address public tokenOwner; @@ -31,9 +30,7 @@ contract TaikoTokenTest is TestBase { address(tko), bytes.concat( tko.init.selector, - abi.encode( - address(addressManager), "Taiko Token", "TKO", address(this) - ) + abi.encode(address(addressManager), "Taiko Token", "TKO", address(this)) ) ); diff --git a/packages/protocol/test/L2/Lib1559Math.t.sol b/packages/protocol/test/L2/Lib1559Math.t.sol index 17b1ba4a39b..6bd46238f77 100644 --- a/packages/protocol/test/L2/Lib1559Math.t.sol +++ b/packages/protocol/test/L2/Lib1559Math.t.sol @@ -1,16 +1,15 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.20; -import { console2 } from "forge-std/console2.sol"; +import "forge-std/console2.sol"; -import { Lib1559Math } from "../../contracts/L2/Lib1559Math.sol"; -import { LibFixedPointMath } from - "../../contracts/thirdparty/LibFixedPointMath.sol"; -import { LibMath } from "../../contracts/libs/LibMath.sol"; +import "../../contracts/L2/Lib1559Math.sol"; +import "../../contracts/thirdparty/LibFixedPointMath.sol"; +import "../../contracts/libs/LibMath.sol"; -import { TestBase } from "../TestBase.sol"; +import "../TestBase.sol"; -contract TestLib1559Math is TestBase { +contract TestLib1559Math is TaikoTest { using LibMath for uint256; function test_eip1559_math() external { @@ -20,10 +19,7 @@ contract TestLib1559Math is TestBase { // The expected values are calculated in eip1559_util.py _assertAmostEq( 999_999_916, - Lib1559Math.basefee({ - gasExcess: 49_954_623_777, - adjustmentFactor: adjustmentFactor - }) + Lib1559Math.basefee({ gasExcess: 49_954_623_777, adjustmentFactor: adjustmentFactor }) ); _assertAmostEq( diff --git a/packages/protocol/test/L2/TaikoL2.t.sol b/packages/protocol/test/L2/TaikoL2.t.sol index 64bdd9232e0..145683f5c29 100644 --- a/packages/protocol/test/L2/TaikoL2.t.sol +++ b/packages/protocol/test/L2/TaikoL2.t.sol @@ -1,16 +1,14 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.20; -import { console2 } from "forge-std/console2.sol"; -import { Strings } from "lib/openzeppelin-contracts/contracts/utils/Strings.sol"; -import { SafeCastUpgradeable } from - "lib/openzeppelin-contracts-upgradeable/contracts/utils/math/SafeCastUpgradeable.sol"; -import { AddressManager } from "../../contracts/common/AddressManager.sol"; -import { SignalService } from "../../contracts/signal/SignalService.sol"; -import { TaikoL2EIP1559Configurable } from - "../../contracts/L2/TaikoL2EIP1559Configurable.sol"; -import { TaikoL2 } from "../../contracts/L2/TaikoL2.sol"; -import { TestBase } from "../TestBase.sol"; +import "lib/openzeppelin-contracts/contracts/utils/Strings.sol"; +import "lib/openzeppelin-contracts-upgradeable/contracts/utils/math/SafeCastUpgradeable.sol"; +import "forge-std/console2.sol"; +import "../../contracts/common/AddressManager.sol"; +import "../../contracts/signal/SignalService.sol"; +import "../../contracts/L2/TaikoL2EIP1559Configurable.sol"; +import "../../contracts/L2/TaikoL2.sol"; +import "../TestBase.sol"; contract SkipBasefeeCheckL2 is TaikoL2EIP1559Configurable { function skipFeeCheck() public pure override returns (bool) { @@ -18,7 +16,7 @@ contract SkipBasefeeCheckL2 is TaikoL2EIP1559Configurable { } } -contract TestTaikoL2 is TestBase { +contract TestTaikoL2 is TaikoTest { using SafeCastUpgradeable for uint256; // Initial salt for semi-random generation @@ -51,9 +49,7 @@ contract TestTaikoL2 is TestBase { gasExcess = 195_420_300_100; L2FeeSimulation.init(address(ss), gasExcess); - L2FeeSimulation.setConfigAndExcess( - TaikoL2.Config(gasTarget, quotient), gasExcess - ); + L2FeeSimulation.setConfigAndExcess(TaikoL2.Config(gasTarget, quotient), gasExcess); vm.roll(block.number + 1); vm.warp(block.timestamp + 30); @@ -146,12 +142,7 @@ contract TestTaikoL2 is TestBase { newRandomWithoutSalt = uint256( keccak256( abi.encodePacked( - block.prevrandao, - msg.sender, - block.timestamp, - i, - newRandomWithoutSalt, - salt + block.prevrandao, msg.sender, block.timestamp, i, newRandomWithoutSalt, salt ) ) ); @@ -160,11 +151,8 @@ contract TestTaikoL2 is TestBase { if (maxDiffToMinGas == 0) { currentGasUsed = uint32(minGas); } else { - currentGasUsed = uint32( - pickRandomNumber( - newRandomWithoutSalt, minGas, maxDiffToMinGas - ) - ); + currentGasUsed = + uint32(pickRandomNumber(newRandomWithoutSalt, minGas, maxDiffToMinGas)); } salt = uint256(keccak256(abi.encodePacked(currentGasUsed, salt))); accumulated_parent_gas_per_l1_block += currentGasUsed; @@ -174,20 +162,14 @@ contract TestTaikoL2 is TestBase { if (maxDiffToQuickest == 0) { currentTimeAhead = uint8(quickest); } else { - currentTimeAhead = uint8( - pickRandomNumber( - newRandomWithoutSalt, quickest, maxDiffToQuickest - ) - ); + currentTimeAhead = + uint8(pickRandomNumber(newRandomWithoutSalt, quickest, maxDiffToQuickest)); } accumulated_seconds += currentTimeAhead; if (accumulated_seconds >= 12) { console2.log( - "Gas used per L1 block:", - l1Height, - ":", - accumulated_parent_gas_per_l1_block + "Gas used per L1 block:", l1Height, ":", accumulated_parent_gas_per_l1_block ); l1Height++; l1BlockCounter++; @@ -197,8 +179,7 @@ contract TestTaikoL2 is TestBase { vm.prank(L2.GOLDEN_TOUCH_ADDRESS()); _anchorSimulation(currentGasUsed, l1Height); - uint256 currentBaseFee = - L2FeeSimulation.getBasefee(l1Height, currentGasUsed); + uint256 currentBaseFee = L2FeeSimulation.getBasefee(l1Height, currentGasUsed); allBaseFee += currentBaseFee; console2.log("Actual gas in L2 block is:", currentGasUsed); console2.log("L2block to baseFee is:", i, ":", currentBaseFee); @@ -207,13 +188,8 @@ contract TestTaikoL2 is TestBase { vm.warp(block.timestamp + currentTimeAhead); } - console2.log( - "Average wei gas price per L2 block is:", - (allBaseFee / maxL2BlockCount) - ); - console2.log( - "Average gasUsed per L1 block:", (allGasUsed / l1BlockCounter) - ); + console2.log("Average wei gas price per L2 block is:", (allBaseFee / maxL2BlockCount)); + console2.log("Average gasUsed per L1 block:", (allGasUsed / l1BlockCounter)); } // calling anchor in the same block more than once should fail @@ -257,12 +233,7 @@ contract TestTaikoL2 is TestBase { L2.anchor(l1Hash, l1SignalRoot, 12_345, parentGasLimit); } - function _anchorSimulation( - uint32 parentGasLimit, - uint64 l1Height - ) - private - { + function _anchorSimulation(uint32 parentGasLimit, uint64 l1Height) private { bytes32 l1Hash = getRandomBytes32(); bytes32 l1SignalRoot = getRandomBytes32(); L2FeeSimulation.anchor(l1Hash, l1SignalRoot, l1Height, parentGasLimit); diff --git a/packages/protocol/test/TestBase.sol b/packages/protocol/test/TestBase.sol index b2c1e9873d7..88c9edd0627 100644 --- a/packages/protocol/test/TestBase.sol +++ b/packages/protocol/test/TestBase.sol @@ -1,13 +1,13 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.20; -import { Test } from "forge-std/Test.sol"; -import { Bridge } from "../contracts/bridge/Bridge.sol"; -import { SignalService } from "../contracts/signal/SignalService.sol"; -import { ICrossChainSync } from "../contracts/common/ICrossChainSync.sol"; -import { EssentialContract } from "../contracts/common/EssentialContract.sol"; +import "forge-std/Test.sol"; +import "../contracts/bridge/Bridge.sol"; +import "../contracts/signal/SignalService.sol"; +import "../contracts/common/ICrossChainSync.sol"; +import "../contracts/common/EssentialContract.sol"; -abstract contract TestBase is Test { +abstract contract TaikoTest is Test { uint256 private _seed = 0x12345678; function getRandomAddress() internal returns (address) { diff --git a/packages/protocol/test/bridge/Bridge.t.sol b/packages/protocol/test/bridge/Bridge.t.sol index 8daf48f81c6..2f6e6d676dd 100644 --- a/packages/protocol/test/bridge/Bridge.t.sol +++ b/packages/protocol/test/bridge/Bridge.t.sol @@ -1,17 +1,11 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.20; -import { AddressManager } from "../../contracts/common/AddressManager.sol"; -import { IBridge, Bridge } from "../../contracts/bridge/Bridge.sol"; -import { console2 } from "forge-std/console2.sol"; -import { SignalService } from "../../contracts/signal/SignalService.sol"; -import { - TestBase, - SkipProofCheckSignal, - DummyCrossChainSync, - GoodReceiver, - BadReceiver -} from "../TestBase.sol"; +import "forge-std/console2.sol"; +import "../../contracts/common/AddressManager.sol"; +import "../../contracts/bridge/Bridge.sol"; +import "../../contracts/signal/SignalService.sol"; +import "../TestBase.sol"; // A contract which is not our ErcXXXTokenVault // Which in such case, the sent funds are still recoverable, but not via the @@ -28,7 +22,7 @@ contract UntrustedSendMessageRelayer { } } -contract BridgeTest is TestBase { +contract BridgeTest is TaikoTest { AddressManager addressManager; BadReceiver badReceiver; GoodReceiver goodReceiver; @@ -66,24 +60,16 @@ contract BridgeTest is TestBase { vm.deal(address(untrustedSenderContract), 10 ether); addressManager.setAddress( - uint64(block.chainid), - "signal_service", - address(mockProofSignalService) + uint64(block.chainid), "signal_service", address(mockProofSignalService) ); - addressManager.setAddress( - destChainId, "signal_service", address(mockProofSignalService) - ); + addressManager.setAddress(destChainId, "signal_service", address(mockProofSignalService)); - addressManager.setAddress( - destChainId, "bridge", address(destChainBridge) - ); + addressManager.setAddress(destChainId, "bridge", address(destChainBridge)); addressManager.setAddress(destChainId, "taiko", address(uint160(123))); - addressManager.setAddress( - uint64(block.chainid), "bridge", address(bridge) - ); + addressManager.setAddress(uint64(block.chainid), "bridge", address(bridge)); vm.stopPrank(); } @@ -162,9 +148,7 @@ contract BridgeTest is TestBase { assertEq(Bob.balance, 1000); } - function test_Bridge_send_ether_to_contract_with_value_and_message_data() - public - { + function test_Bridge_send_ether_to_contract_with_value_and_message_data() public { goodReceiver = new GoodReceiver(); IBridge.Message memory message = IBridge.Message({ @@ -201,10 +185,7 @@ contract BridgeTest is TestBase { assertEq(Carol.balance, 500); } - function test_Bridge_send_message_ether_reverts_if_value_doesnt_match_expected( - ) - public - { + function test_Bridge_send_message_ether_reverts_if_value_doesnt_match_expected() public { // uint256 amount = 1 wei; IBridge.Message memory message = newMessage({ owner: Alice, @@ -219,9 +200,7 @@ contract BridgeTest is TestBase { bridge.sendMessage(message); } - function test_Bridge_send_message_ether_reverts_when_owner_is_zero_address() - public - { + function test_Bridge_send_message_ether_reverts_when_owner_is_zero_address() public { uint256 amount = 1 wei; IBridge.Message memory message = newMessage({ owner: address(0), @@ -236,10 +215,7 @@ contract BridgeTest is TestBase { bridge.sendMessage{ value: amount }(message); } - function test_Bridge_send_message_ether_reverts_when_dest_chain_is_not_enabled( - ) - public - { + function test_Bridge_send_message_ether_reverts_when_dest_chain_is_not_enabled() public { uint256 amount = 1 wei; IBridge.Message memory message = newMessage({ owner: Alice, @@ -254,8 +230,7 @@ contract BridgeTest is TestBase { bridge.sendMessage{ value: amount }(message); } - function test_Bridge_send_message_ether_reverts_when_dest_chain_same_as_block_chainid( - ) + function test_Bridge_send_message_ether_reverts_when_dest_chain_same_as_block_chainid() public { uint256 amount = 1 wei; @@ -283,8 +258,7 @@ contract BridgeTest is TestBase { destChain: destChainId }); - (, IBridge.Message memory _message) = - bridge.sendMessage{ value: amount }(message); + (, IBridge.Message memory _message) = bridge.sendMessage{ value: amount }(message); assertEq(bridge.isMessageSent(_message), true); } @@ -300,8 +274,7 @@ contract BridgeTest is TestBase { destChain: destChainId }); - (, IBridge.Message memory _message) = - bridge.sendMessage{ value: amount + fee }(message); + (, IBridge.Message memory _message) = bridge.sendMessage{ value: amount + fee }(message); assertEq(bridge.isMessageSent(_message), true); } @@ -321,8 +294,7 @@ contract BridgeTest is TestBase { uint256 starterBalanceAlice = Alice.balance; vm.prank(Alice, Alice); - (, IBridge.Message memory _message) = - bridge.sendMessage{ value: amount + fee }(message); + (, IBridge.Message memory _message) = bridge.sendMessage{ value: amount + fee }(message); assertEq(bridge.isMessageSent(_message), true); assertEq(address(bridge).balance, (starterBalanceVault + amount + fee)); @@ -333,9 +305,7 @@ contract BridgeTest is TestBase { assertEq(Alice.balance, (starterBalanceAlice - fee)); } - function test_Bridge_recall_message_but_not_supports_recall_interface() - public - { + function test_Bridge_recall_message_but_not_supports_recall_interface() public { // In this test we expect that the 'message value is still refundable, // just not via // ERCXXTokenVault (message.from) but directly from the Bridge @@ -353,9 +323,7 @@ contract BridgeTest is TestBase { uint256 starterBalanceVault = address(bridge).balance; - untrustedSenderContract.sendMessage( - address(bridge), message, amount + fee - ); + untrustedSenderContract.sendMessage(address(bridge), message, amount + fee); assertEq(address(bridge).balance, (starterBalanceVault + amount + fee)); @@ -364,9 +332,7 @@ contract BridgeTest is TestBase { assertEq(address(bridge).balance, (starterBalanceVault + fee)); } - function test_Bridge_send_message_ether_with_processing_fee_invalid_amount() - public - { + function test_Bridge_send_message_ether_with_processing_fee_invalid_amount() public { uint256 amount = 0 wei; uint256 fee = 1 wei; IBridge.Message memory message = newMessage({ @@ -451,9 +417,7 @@ contract BridgeTest is TestBase { destChainBridge.retryMessage(message, true); } - function retry_message_reverts_when_last_attempt_and_message_is_not_owner() - public - { + function retry_message_reverts_when_last_attempt_and_message_is_not_owner() public { vm.startPrank(Alice); IBridge.Message memory message = newMessage({ owner: Bob, @@ -480,17 +444,13 @@ contract BridgeTest is TestBase { uint64 dest = 1337; addressManager.setAddress(dest, "taiko", address(crossChainSync)); - addressManager.setAddress( - 1336, "bridge", 0x564540a26Fb667306b3aBdCB4ead35BEb88698ab - ); + addressManager.setAddress(1336, "bridge", 0x564540a26Fb667306b3aBdCB4ead35BEb88698ab); addressManager.setAddress(dest, "bridge", address(destChainBridge)); vm.deal(address(bridge), 100 ether); - addressManager.setAddress( - dest, "signal_service", address(mockProofSignalService) - ); + addressManager.setAddress(dest, "signal_service", address(mockProofSignalService)); crossChainSync.setSyncedData( 0xd5f5d8ac6bc37139c97389b00e9cf53e89c153ad8a5fc765ffe9f44ea9f3d31e, diff --git a/packages/protocol/test/libs/LibFixedPointMath.t.sol b/packages/protocol/test/libs/LibFixedPointMath.t.sol index 94892c68ed3..1aef9ae8e9b 100644 --- a/packages/protocol/test/libs/LibFixedPointMath.t.sol +++ b/packages/protocol/test/libs/LibFixedPointMath.t.sol @@ -3,8 +3,8 @@ // https://github.com/recmo/experiment-solexp/blob/main/src/test/FixedPointMathLib.t.sol pragma solidity 0.8.20; -import { Test } from "forge-std/Test.sol"; -import { console2 } from "forge-std/console2.sol"; +import "forge-std/Test.sol"; +import "forge-std/console2.sol"; import "../../contracts/thirdparty/LibFixedPointMath.sol"; contract LibFixedPointMathTest is Test { @@ -15,18 +15,12 @@ contract LibFixedPointMathTest is Test { function testExpSmallest() public view { int256 y = LibFixedPointMath.exp(-42_139_678_854_452_767_550); - console2.log( - "LibFixedPointMath.exp(-42139678854452767550)=", uint256(y) - ); + console2.log("LibFixedPointMath.exp(-42139678854452767550)=", uint256(y)); } function testExpLargest() public view { - int256 y = LibFixedPointMath.exp( - int256(uint256(LibFixedPointMath.MAX_EXP_INPUT)) - ); - console2.log( - "LibFixedPointMath.exp(135305999368893231588)=", uint256(y) - ); + int256 y = LibFixedPointMath.exp(int256(uint256(LibFixedPointMath.MAX_EXP_INPUT))); + console2.log("LibFixedPointMath.exp(135305999368893231588)=", uint256(y)); } function testExpSome() public view { diff --git a/packages/protocol/test/signal/SignalService.t.sol b/packages/protocol/test/signal/SignalService.t.sol index b1bf1f9426f..721b1e5f26e 100644 --- a/packages/protocol/test/signal/SignalService.t.sol +++ b/packages/protocol/test/signal/SignalService.t.sol @@ -1,18 +1,17 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.20; -import { AddressManager } from "../../contracts/common/AddressManager.sol"; -import { AddressResolver } from "../../contracts/common/AddressResolver.sol"; -import { Bridge } from "../../contracts/bridge/Bridge.sol"; -import { BridgedERC20 } from "../../contracts/tokenvault/BridgedERC20.sol"; -import { console } from "forge-std/console.sol"; -import { FreeMintERC20 } from "../../contracts/test/erc20/FreeMintERC20.sol"; -import { SignalService } from "../../contracts/signal/SignalService.sol"; -import { TestBase, DummyCrossChainSync } from "../TestBase.sol"; - -import { console2 } from "forge-std/console2.sol"; - -contract TestSignalService is TestBase { +import "forge-std/console.sol"; +import "forge-std/console2.sol"; +import "../../contracts/common/AddressManager.sol"; +import "../../contracts/common/AddressResolver.sol"; +import "../../contracts/bridge/Bridge.sol"; +import "../../contracts/tokenvault/BridgedERC20.sol"; +import "../../contracts/test/erc20/FreeMintERC20.sol"; +import "../../contracts/signal/SignalService.sol"; +import "../TestBase.sol"; + +contract TestSignalService is TaikoTest { AddressManager addressManager; SignalService signalService; @@ -37,13 +36,9 @@ contract TestSignalService is TestBase { crossChainSync = new DummyCrossChainSync(); crossChainSync.init(address(addressManager)); - addressManager.setAddress( - uint64(block.chainid), "signal_service", address(signalService) - ); + addressManager.setAddress(uint64(block.chainid), "signal_service", address(signalService)); - addressManager.setAddress( - destChainId, "signal_service", address(destSignalService) - ); + addressManager.setAddress(destChainId, "signal_service", address(destSignalService)); addressManager.setAddress(destChainId, "taiko", address(crossChainSync)); @@ -88,19 +83,15 @@ contract TestSignalService is TestBase { // contract, this is why this chainId. address app = 0x927a146e18294efb36edCacC99D9aCEA6aB16b95; // Mock app, // actually it is an EOA, but it is ok for tests! - bytes32 signal = - 0x21761f7cd1af3972774272b39a0f4602dbcd418325cddb14e156b4bb073d52a8; + bytes32 signal = 0x21761f7cd1af3972774272b39a0f4602dbcd418325cddb14e156b4bb073d52a8; bytes memory inclusionProof = hex"e5a4e3a1209749684f52b5c0717a7ca78127fb56043d637d81763c04e9d30ba4d4746d56e901"; //eth_getProof's // result RLP encoded storage proof - bytes32 signalRoot = - 0xf7916f389ccda56e3831e115238b7389b30750886785a3c21265601572698f0f; //eth_getProof + bytes32 signalRoot = 0xf7916f389ccda56e3831e115238b7389b30750886785a3c21265601572698f0f; //eth_getProof // result's storage hash vm.startPrank(Alice); - signalService.authorize( - address(crossChainSync), bytes32(uint256(block.chainid)) - ); + signalService.authorize(address(crossChainSync), bytes32(uint256(block.chainid))); crossChainSync.setSyncedData("", signalRoot); @@ -111,9 +102,8 @@ contract TestSignalService is TestBase { p.storageProof = inclusionProof; p.hops = h; - bool isSignalReceived = signalService.proveSignalReceived( - chainId, app, signal, abi.encode(p) - ); + bool isSignalReceived = + signalService.proveSignalReceived(chainId, app, signal, abi.encode(p)); assertEq(isSignalReceived, true); } @@ -171,9 +161,8 @@ contract TestSignalService is TestBase { p.hops = h; - bool isSignalReceived = signalService.proveSignalReceived( - chainId, app, signal_of_L2A_msgHash, abi.encode(p) - ); + bool isSignalReceived = + signalService.proveSignalReceived(chainId, app, signal_of_L2A_msgHash, abi.encode(p)); assertEq(isSignalReceived, true); } } diff --git a/packages/protocol/test/team/TimeLockTokenPool.t.sol b/packages/protocol/test/team/TimeLockTokenPool.t.sol index 49c6586d22d..bbd52ce1aaa 100644 --- a/packages/protocol/test/team/TimeLockTokenPool.t.sol +++ b/packages/protocol/test/team/TimeLockTokenPool.t.sol @@ -1,12 +1,10 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.20; -import { TimeLockTokenPool as Pool } from - "../../contracts/team/TimeLockTokenPool.sol"; -import { Test } from "forge-std/Test.sol"; -import { ERC20 } from - "lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol"; -import { console2 } from "forge-std/console2.sol"; +import "lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol"; +import "forge-std/Test.sol"; +import "forge-std/console2.sol"; +import "../../contracts/team/TimeLockTokenPool.sol"; contract MyERC20 is ERC20 { constructor(address owner) ERC20("Taiko Token", "TKO") { @@ -14,28 +12,28 @@ contract MyERC20 is ERC20 { } } -contract TestTimeLockTokenPool is Test { +contract TestTimeLockTokenTimeLockTokenPool is Test { address internal Vault = vm.addr(0x1); address internal Alice = vm.addr(0x2); address internal Bob = vm.addr(0x3); ERC20 tko = new MyERC20(Vault); - Pool pool = new Pool(); + TimeLockTokenPool pool = new TimeLockTokenPool(); function setUp() public { pool.init(address(tko), Vault); } function test_invalid_granting() public { - vm.expectRevert(Pool.INVALID_GRANT.selector); - pool.grant(Alice, Pool.Grant(0, 0, 0, 0, 0, 0, 0)); + vm.expectRevert(TimeLockTokenPool.INVALID_GRANT.selector); + pool.grant(Alice, TimeLockTokenPool.Grant(0, 0, 0, 0, 0, 0, 0)); - vm.expectRevert(Pool.INVALID_PARAM.selector); - pool.grant(address(0), Pool.Grant(100e18, 0, 0, 0, 0, 0, 0)); + vm.expectRevert(TimeLockTokenPool.INVALID_PARAM.selector); + pool.grant(address(0), TimeLockTokenPool.Grant(100e18, 0, 0, 0, 0, 0, 0)); } function test_single_grant_zero_grant_period_zero_unlock_period() public { - pool.grant(Alice, Pool.Grant(10_000e18, 0, 0, 0, 0, 0, 0)); + pool.grant(Alice, TimeLockTokenPool.Grant(10_000e18, 0, 0, 0, 0, 0, 0)); vm.prank(Vault); tko.approve(address(pool), 10_000e18); @@ -51,7 +49,7 @@ contract TestTimeLockTokenPool is Test { assertEq(amountWithdrawable, 10_000e18); // Try to void the grant - vm.expectRevert(Pool.NOTHING_TO_VOID.selector); + vm.expectRevert(TimeLockTokenPool.NOTHING_TO_VOID.selector); pool.void(Alice); vm.prank(Alice); @@ -73,9 +71,7 @@ contract TestTimeLockTokenPool is Test { pool.grant( Alice, - Pool.Grant( - 10_000e18, 0, 0, 0, unlockStart, unlockCliff, unlockPeriod - ) + TimeLockTokenPool.Grant(10_000e18, 0, 0, 0, unlockStart, unlockCliff, unlockPeriod) ); vm.prank(Vault); tko.approve(address(pool), 10_000e18); @@ -139,8 +135,7 @@ contract TestTimeLockTokenPool is Test { uint64 grantCliff = grantStart + grantPeriod / 2; pool.grant( - Alice, - Pool.Grant(10_000e18, grantStart, grantCliff, grantPeriod, 0, 0, 0) + Alice, TimeLockTokenPool.Grant(10_000e18, grantStart, grantCliff, grantPeriod, 0, 0, 0) ); vm.prank(Vault); tko.approve(address(pool), 10_000e18); @@ -198,9 +193,7 @@ contract TestTimeLockTokenPool is Test { assertEq(amountWithdrawable, 0); } - function test_single_grant_4year_grant_period_4year_unlock_period() - public - { + function test_single_grant_4year_grant_period_4year_unlock_period() public { uint64 grantStart = uint64(block.timestamp); uint32 grantPeriod = 4 * 365 days; uint64 grantCliff = grantStart + 90 days; @@ -211,7 +204,7 @@ contract TestTimeLockTokenPool is Test { pool.grant( Alice, - Pool.Grant( + TimeLockTokenPool.Grant( 10_000e18, grantStart, grantCliff, @@ -300,8 +293,8 @@ contract TestTimeLockTokenPool is Test { } function test_multiple_grants() public { - pool.grant(Alice, Pool.Grant(10_000e18, 0, 0, 0, 0, 0, 0)); - pool.grant(Alice, Pool.Grant(20_000e18, 0, 0, 0, 0, 0, 0)); + pool.grant(Alice, TimeLockTokenPool.Grant(10_000e18, 0, 0, 0, 0, 0, 0)); + pool.grant(Alice, TimeLockTokenPool.Grant(20_000e18, 0, 0, 0, 0, 0, 0)); vm.prank(Vault); tko.approve(address(pool), 30_000e18); @@ -320,8 +313,8 @@ contract TestTimeLockTokenPool is Test { function test_void_multiple_grants_before_granted() public { uint64 grantStart = uint64(block.timestamp) + 30 days; - pool.grant(Alice, Pool.Grant(10_000e18, grantStart, 0, 0, 0, 0, 0)); - pool.grant(Alice, Pool.Grant(20_000e18, grantStart, 0, 0, 0, 0, 0)); + pool.grant(Alice, TimeLockTokenPool.Grant(10_000e18, grantStart, 0, 0, 0, 0, 0)); + pool.grant(Alice, TimeLockTokenPool.Grant(20_000e18, grantStart, 0, 0, 0, 0, 0)); vm.prank(Vault); tko.approve(address(pool), 30_000e18); @@ -340,7 +333,7 @@ contract TestTimeLockTokenPool is Test { // Try to void the grant pool.void(Alice); - Pool.Grant[] memory grants = pool.getMyGrants(Alice); + TimeLockTokenPool.Grant[] memory grants = pool.getMyGrants(Alice); for (uint256 i; i < grants.length; ++i) { assertEq(grants[i].grantStart, 0); assertEq(grants[i].grantPeriod, 0); @@ -356,8 +349,8 @@ contract TestTimeLockTokenPool is Test { function test_void_multiple_grants_after_granted() public { uint64 grantStart = uint64(block.timestamp) + 30 days; - pool.grant(Alice, Pool.Grant(10_000e18, grantStart, 0, 0, 0, 0, 0)); - pool.grant(Alice, Pool.Grant(20_000e18, grantStart, 0, 0, 0, 0, 0)); + pool.grant(Alice, TimeLockTokenPool.Grant(10_000e18, grantStart, 0, 0, 0, 0, 0)); + pool.grant(Alice, TimeLockTokenPool.Grant(20_000e18, grantStart, 0, 0, 0, 0, 0)); vm.prank(Vault); tko.approve(address(pool), 30_000e18); @@ -378,19 +371,15 @@ contract TestTimeLockTokenPool is Test { // Try to void the grant // Try to void the grant - vm.expectRevert(Pool.NOTHING_TO_VOID.selector); + vm.expectRevert(TimeLockTokenPool.NOTHING_TO_VOID.selector); pool.void(Alice); } function test_void_multiple_grants_in_the_middle() public { uint64 grantStart = uint64(block.timestamp); uint32 grantPeriod = 100 days; - pool.grant( - Alice, Pool.Grant(10_000e18, grantStart, 0, grantPeriod, 0, 0, 0) - ); - pool.grant( - Alice, Pool.Grant(20_000e18, grantStart, 0, grantPeriod, 0, 0, 0) - ); + pool.grant(Alice, TimeLockTokenPool.Grant(10_000e18, grantStart, 0, grantPeriod, 0, 0, 0)); + pool.grant(Alice, TimeLockTokenPool.Grant(20_000e18, grantStart, 0, grantPeriod, 0, 0, 0)); vm.prank(Vault); tko.approve(address(pool), 30_000e18); diff --git a/packages/protocol/test/tokenvault/ERC1155Vault.t.sol b/packages/protocol/test/tokenvault/ERC1155Vault.t.sol index acfd0cd5609..bab7ffeaafd 100644 --- a/packages/protocol/test/tokenvault/ERC1155Vault.t.sol +++ b/packages/protocol/test/tokenvault/ERC1155Vault.t.sol @@ -1,29 +1,18 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.20; -import { console2 } from "forge-std/console2.sol"; -import { - TestBase, - SkipProofCheckSignal, - DummyCrossChainSync, - NonNftContract, - BadReceiver -} from "../TestBase.sol"; -import { AddressResolver } from "../../contracts/common/AddressResolver.sol"; -import { AddressManager } from "../../contracts/common/AddressManager.sol"; -import { IBridge, Bridge } from "../../contracts/bridge/Bridge.sol"; -import { BaseNFTVault } from "../../contracts/tokenvault/BaseNFTVault.sol"; -import { ERC1155Vault } from "../../contracts/tokenvault/ERC1155Vault.sol"; -import { - ProxiedBridgedERC1155, - BridgedERC1155 -} from "../../contracts/tokenvault/BridgedERC1155.sol"; -import { SignalService } from "../../contracts/signal/SignalService.sol"; -import { ICrossChainSync } from "../../contracts/common/ICrossChainSync.sol"; -import { ERC1155 } from - "lib/openzeppelin-contracts/contracts/token/ERC1155/ERC1155.sol"; -import { TransparentUpgradeableProxy } from - "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; +import "lib/openzeppelin-contracts/contracts/token/ERC1155/ERC1155.sol"; +import "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; +import "forge-std/console2.sol"; +import "../TestBase.sol"; +import "../../contracts/common/AddressResolver.sol"; +import "../../contracts/common/AddressManager.sol"; +import "../../contracts/bridge/Bridge.sol"; +import "../../contracts/tokenvault/BaseNFTVault.sol"; +import "../../contracts/tokenvault/ERC1155Vault.sol"; +import "../../contracts/tokenvault/BridgedERC1155.sol"; +import "../../contracts/signal/SignalService.sol"; +import "../../contracts/common/ICrossChainSync.sol"; contract TestTokenERC1155 is ERC1155 { constructor(string memory baseURI) ERC1155(baseURI) { } @@ -109,7 +98,7 @@ contract UpdatedBridgedERC1155 is BridgedERC1155 { } } -contract ERC1155VaultTest is TestBase { +contract ERC1155VaultTest is TaikoTest { AddressManager addressManager; BadReceiver badReceiver; Bridge bridge; @@ -160,62 +149,38 @@ contract ERC1155VaultTest is TestBase { crossChainSync = new DummyCrossChainSync(); addressManager.setAddress( - uint64(block.chainid), - "signal_service", - address(mockProofSignalService) + uint64(block.chainid), "signal_service", address(mockProofSignalService) ); - addressManager.setAddress( - destChainId, "signal_service", address(mockProofSignalService) - ); + addressManager.setAddress(destChainId, "signal_service", address(mockProofSignalService)); - addressManager.setAddress( - uint64(block.chainid), "bridge", address(bridge) - ); + addressManager.setAddress(uint64(block.chainid), "bridge", address(bridge)); - addressManager.setAddress( - destChainId, "bridge", address(destChainIdBridge) - ); + addressManager.setAddress(destChainId, "bridge", address(destChainIdBridge)); - addressManager.setAddress( - uint64(block.chainid), "erc1155_vault", address(erc1155Vault) - ); + addressManager.setAddress(uint64(block.chainid), "erc1155_vault", address(erc1155Vault)); - addressManager.setAddress( - destChainId, "erc1155_vault", address(destChainErc1155Vault) - ); + addressManager.setAddress(destChainId, "erc1155_vault", address(destChainErc1155Vault)); // Below 2-2 registrations (mock) are needed bc of // LibBridgeRecall.sol's // resolve address + addressManager.setAddress(destChainId, "erc721_vault", address(mockProofSignalService)); + addressManager.setAddress(destChainId, "erc20_vault", address(mockProofSignalService)); addressManager.setAddress( - destChainId, "erc721_vault", address(mockProofSignalService) - ); - addressManager.setAddress( - destChainId, "erc20_vault", address(mockProofSignalService) + uint64(block.chainid), "erc721_vault", address(mockProofSignalService) ); addressManager.setAddress( - uint64(block.chainid), - "erc721_vault", - address(mockProofSignalService) - ); - addressManager.setAddress( - uint64(block.chainid), - "erc20_vault", - address(mockProofSignalService) + uint64(block.chainid), "erc20_vault", address(mockProofSignalService) ); vm.deal(address(bridge), 100 ether); address proxiedBridgedERC1155 = address(new ProxiedBridgedERC1155()); + addressManager.setAddress(destChainId, "proxied_bridged_erc1155", proxiedBridgedERC1155); addressManager.setAddress( - destChainId, "proxied_bridged_erc1155", proxiedBridgedERC1155 - ); - addressManager.setAddress( - uint64(block.chainid), - "proxied_bridged_erc1155", - proxiedBridgedERC1155 + uint64(block.chainid), "proxied_bridged_erc1155", proxiedBridgedERC1155 ); ctoken1155 = new TestTokenERC1155("http://example.host.com/"); @@ -245,17 +210,8 @@ contract ERC1155VaultTest is TestBase { uint256[] memory amounts = new uint256[](1); amounts[0] = 2; - BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault - .BridgeTransferOp( - destChainId, - Alice, - address(ctoken1155), - tokenIds, - amounts, - 140_000, - 140_000, - Alice, - "" + BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault.BridgeTransferOp( + destChainId, Alice, address(ctoken1155), tokenIds, amounts, 140_000, 140_000, Alice, "" ); vm.prank(Alice, Alice); erc1155Vault.sendToken{ value: 140_000 }(sendOpts); @@ -264,9 +220,7 @@ contract ERC1155VaultTest is TestBase { assertEq(ctoken1155.balanceOf(address(erc1155Vault), 1), 2); } - function test_1155Vault_sendToken_with_invalid_token_address_1155() - public - { + function test_1155Vault_sendToken_with_invalid_token_address_1155() public { vm.prank(Alice, Alice); ctoken1155.setApprovalForAll(address(erc1155Vault), true); @@ -279,17 +233,8 @@ contract ERC1155VaultTest is TestBase { uint256[] memory amounts = new uint256[](1); amounts[0] = 2; - BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault - .BridgeTransferOp( - destChainId, - Alice, - address(0), - tokenIds, - amounts, - 140_000, - 140_000, - Alice, - "" + BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault.BridgeTransferOp( + destChainId, Alice, address(0), tokenIds, amounts, 140_000, 140_000, Alice, "" ); vm.prank(Alice, Alice); vm.expectRevert(BaseNFTVault.VAULT_INVALID_TOKEN.selector); @@ -309,17 +254,8 @@ contract ERC1155VaultTest is TestBase { uint256[] memory amounts = new uint256[](1); amounts[0] = 0; - BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault - .BridgeTransferOp( - destChainId, - Alice, - address(ctoken1155), - tokenIds, - amounts, - 140_000, - 140_000, - Alice, - "" + BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault.BridgeTransferOp( + destChainId, Alice, address(ctoken1155), tokenIds, amounts, 140_000, 140_000, Alice, "" ); vm.prank(Alice, Alice); vm.expectRevert(BaseNFTVault.VAULT_INVALID_AMOUNT.selector); @@ -342,17 +278,8 @@ contract ERC1155VaultTest is TestBase { uint256[] memory amounts = new uint256[](1); amounts[0] = 2; - BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault - .BridgeTransferOp( - destChainId, - Alice, - address(ctoken1155), - tokenIds, - amounts, - 140_000, - 140_000, - Alice, - "" + BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault.BridgeTransferOp( + destChainId, Alice, address(ctoken1155), tokenIds, amounts, 140_000, 140_000, Alice, "" ); vm.prank(Alice, Alice); erc1155Vault.sendToken{ value: 140_000 }(sendOpts); @@ -384,16 +311,14 @@ contract ERC1155VaultTest is TestBase { ); // Query canonicalToBridged - address deployedContract = destChainErc1155Vault.canonicalToBridged( - srcChainId, address(ctoken1155) - ); + address deployedContract = + destChainErc1155Vault.canonicalToBridged(srcChainId, address(ctoken1155)); // Alice bridged over 2 items assertEq(ERC1155(deployedContract).balanceOf(Alice, 1), 2); } - function test_1155Vault_receiveTokens_but_mint_not_deploy_if_bridged_second_time_1155( - ) + function test_1155Vault_receiveTokens_but_mint_not_deploy_if_bridged_second_time_1155() public { vm.prank(Alice, Alice); @@ -408,17 +333,8 @@ contract ERC1155VaultTest is TestBase { uint256[] memory amounts = new uint256[](1); amounts[0] = 2; - BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault - .BridgeTransferOp( - destChainId, - Alice, - address(ctoken1155), - tokenIds, - amounts, - 140_000, - 140_000, - Alice, - "" + BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault.BridgeTransferOp( + destChainId, Alice, address(ctoken1155), tokenIds, amounts, 140_000, 140_000, Alice, "" ); vm.prank(Alice, Alice); erc1155Vault.sendToken{ value: 140_000 }(sendOpts); @@ -449,9 +365,8 @@ contract ERC1155VaultTest is TestBase { ); // Query canonicalToBridged - address deployedContract = destChainErc1155Vault.canonicalToBridged( - srcChainId, address(ctoken1155) - ); + address deployedContract = + destChainErc1155Vault.canonicalToBridged(srcChainId, address(ctoken1155)); // Alice bridged over 2 items assertEq(ERC1155(deployedContract).balanceOf(Alice, 1), 2); @@ -463,15 +378,7 @@ contract ERC1155VaultTest is TestBase { amounts[0] = 1; sendOpts = BaseNFTVault.BridgeTransferOp( - destChainId, - Alice, - address(ctoken1155), - tokenIds, - amounts, - 140_000, - 140_000, - Alice, - "" + destChainId, Alice, address(ctoken1155), tokenIds, amounts, 140_000, 140_000, Alice, "" ); vm.prank(Alice, Alice); erc1155Vault.sendToken{ value: 140_000 }(sendOpts); @@ -494,9 +401,8 @@ contract ERC1155VaultTest is TestBase { ); // Query canonicalToBridged - address bridgedContract = destChainErc1155Vault.canonicalToBridged( - srcChainId, address(ctoken1155) - ); + address bridgedContract = + destChainErc1155Vault.canonicalToBridged(srcChainId, address(ctoken1155)); assertEq(bridgedContract, deployedContract); } @@ -516,17 +422,8 @@ contract ERC1155VaultTest is TestBase { uint256 etherValue = 0.1 ether; - BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault - .BridgeTransferOp( - destChainId, - David, - address(ctoken1155), - tokenIds, - amounts, - 140_000, - 140_000, - Alice, - "" + BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault.BridgeTransferOp( + destChainId, David, address(ctoken1155), tokenIds, amounts, 140_000, 140_000, Alice, "" ); vm.prank(Alice, Alice); erc1155Vault.sendToken{ value: etherValue }(sendOpts); @@ -558,9 +455,8 @@ contract ERC1155VaultTest is TestBase { ); // Query canonicalToBridged - address deployedContract = destChainErc1155Vault.canonicalToBridged( - srcChainId, address(ctoken1155) - ); + address deployedContract = + destChainErc1155Vault.canonicalToBridged(srcChainId, address(ctoken1155)); // Alice bridged over 2 items and etherValue to David assertEq(ERC1155(deployedContract).balanceOf(David, 1), 2); @@ -580,22 +476,12 @@ contract ERC1155VaultTest is TestBase { uint256[] memory amounts = new uint256[](1); amounts[0] = 2; - BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault - .BridgeTransferOp( - destChainId, - Alice, - address(ctoken1155), - tokenIds, - amounts, - 140_000, - 140_000, - Alice, - "" + BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault.BridgeTransferOp( + destChainId, Alice, address(ctoken1155), tokenIds, amounts, 140_000, 140_000, Alice, "" ); vm.prank(Alice, Alice); - IBridge.Message memory message = - erc1155Vault.sendToken{ value: 140_000 }(sendOpts); + IBridge.Message memory message = erc1155Vault.sendToken{ value: 140_000 }(sendOpts); assertEq(ctoken1155.balanceOf(Alice, 1), 8); assertEq(ctoken1155.balanceOf(address(erc1155Vault), 1), 2); @@ -625,17 +511,8 @@ contract ERC1155VaultTest is TestBase { amounts[0] = 2; amounts[1] = 5; - BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault - .BridgeTransferOp( - destChainId, - Alice, - address(ctoken1155), - tokenIds, - amounts, - 140_000, - 140_000, - Alice, - "" + BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault.BridgeTransferOp( + destChainId, Alice, address(ctoken1155), tokenIds, amounts, 140_000, 140_000, Alice, "" ); vm.prank(Alice, Alice); erc1155Vault.sendToken{ value: 140_000 }(sendOpts); @@ -669,18 +546,15 @@ contract ERC1155VaultTest is TestBase { ); // Query canonicalToBridged - address deployedContract = destChainErc1155Vault.canonicalToBridged( - srcChainId, address(ctoken1155) - ); + address deployedContract = + destChainErc1155Vault.canonicalToBridged(srcChainId, address(ctoken1155)); // Alice bridged over 2 items assertEq(ERC1155(deployedContract).balanceOf(Alice, 1), 2); assertEq(ERC1155(deployedContract).balanceOf(Alice, 2), 5); } - function test_1155Vault_bridge_back_but_owner_is_different_now_1155() - public - { + function test_1155Vault_bridge_back_but_owner_is_different_now_1155() public { vm.prank(Alice, Alice); ctoken1155.setApprovalForAll(address(erc1155Vault), true); @@ -693,17 +567,8 @@ contract ERC1155VaultTest is TestBase { uint256[] memory amounts = new uint256[](1); amounts[0] = 1; - BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault - .BridgeTransferOp( - destChainId, - Alice, - address(ctoken1155), - tokenIds, - amounts, - 140_000, - 140_000, - Alice, - "" + BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault.BridgeTransferOp( + destChainId, Alice, address(ctoken1155), tokenIds, amounts, 140_000, 140_000, Alice, "" ); vm.prank(Alice, Alice); erc1155Vault.sendToken{ value: 140_000 }(sendOpts); @@ -713,8 +578,7 @@ contract ERC1155VaultTest is TestBase { // This canonicalToken is basically need to be exact same as the // sendToken() puts together // - here is just mocking putting it together. - BaseNFTVault.CanonicalNFT memory canonicalToken = BaseNFTVault - .CanonicalNFT({ + BaseNFTVault.CanonicalNFT memory canonicalToken = BaseNFTVault.CanonicalNFT({ chainId: 31_337, addr: address(ctoken1155), symbol: "TT", @@ -736,9 +600,8 @@ contract ERC1155VaultTest is TestBase { 0 ); // Query canonicalToBridged - address deployedContract = destChainErc1155Vault.canonicalToBridged( - chainId, address(ctoken1155) - ); + address deployedContract = + destChainErc1155Vault.canonicalToBridged(chainId, address(ctoken1155)); // Alice bridged over 1 from tokenId 1 assertEq(ERC1155(deployedContract).balanceOf(Alice, 1), 1); @@ -752,20 +615,10 @@ contract ERC1155VaultTest is TestBase { assertEq(ERC1155(deployedContract).balanceOf(Alice, 1), 0); vm.prank(Bob, Bob); - ERC1155(deployedContract).setApprovalForAll( - address(destChainErc1155Vault), true - ); + ERC1155(deployedContract).setApprovalForAll(address(destChainErc1155Vault), true); sendOpts = BaseNFTVault.BridgeTransferOp( - chainId, - Bob, - address(deployedContract), - tokenIds, - amounts, - 140_000, - 140_000, - Bob, - "" + chainId, Bob, address(deployedContract), tokenIds, amounts, 140_000, 140_000, Bob, "" ); vm.prank(Bob, Bob); @@ -778,9 +631,7 @@ contract ERC1155VaultTest is TestBase { destChainIdBridge.setERC1155Vault(address(erc1155Vault)); vm.prank(Amelia, Amelia); - addressManager.setAddress( - uint64(block.chainid), "bridge", address(destChainIdBridge) - ); + addressManager.setAddress(uint64(block.chainid), "bridge", address(destChainIdBridge)); destChainIdBridge.sendReceiveERC1155ToERC1155Vault( canonicalToken, @@ -797,8 +648,7 @@ contract ERC1155VaultTest is TestBase { assertEq(ctoken1155.balanceOf(Bob, 1), 1); } - function test_1155Vault_bridge_back_but_original_owner_cannot_claim_it_anymore_if_sold_1155( - ) + function test_1155Vault_bridge_back_but_original_owner_cannot_claim_it_anymore_if_sold_1155() public { vm.prank(Alice, Alice); @@ -813,17 +663,8 @@ contract ERC1155VaultTest is TestBase { uint256[] memory amounts = new uint256[](1); amounts[0] = 1; - BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault - .BridgeTransferOp( - destChainId, - Alice, - address(ctoken1155), - tokenIds, - amounts, - 140_000, - 140_000, - Alice, - "" + BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault.BridgeTransferOp( + destChainId, Alice, address(ctoken1155), tokenIds, amounts, 140_000, 140_000, Alice, "" ); vm.prank(Alice, Alice); erc1155Vault.sendToken{ value: 140_000 }(sendOpts); @@ -833,8 +674,7 @@ contract ERC1155VaultTest is TestBase { // This canonicalToken is basically need to be exact same as the // sendToken() puts together // - here is just mocking putting it together. - BaseNFTVault.CanonicalNFT memory canonicalToken = BaseNFTVault - .CanonicalNFT({ + BaseNFTVault.CanonicalNFT memory canonicalToken = BaseNFTVault.CanonicalNFT({ chainId: 31_337, addr: address(ctoken1155), symbol: "TT", @@ -857,9 +697,8 @@ contract ERC1155VaultTest is TestBase { ); // Query canonicalToBridged - address deployedContract = destChainErc1155Vault.canonicalToBridged( - chainId, address(ctoken1155) - ); + address deployedContract = + destChainErc1155Vault.canonicalToBridged(chainId, address(ctoken1155)); // Alice bridged over 1 from tokenId 1 assertEq(ERC1155(deployedContract).balanceOf(Alice, 1), 1); @@ -872,20 +711,10 @@ contract ERC1155VaultTest is TestBase { assertEq(ERC1155(deployedContract).balanceOf(Alice, 1), 0); vm.prank(Bob, Bob); - ERC1155(deployedContract).setApprovalForAll( - address(destChainErc1155Vault), true - ); + ERC1155(deployedContract).setApprovalForAll(address(destChainErc1155Vault), true); sendOpts = BaseNFTVault.BridgeTransferOp( - chainId, - Alice, - address(deployedContract), - tokenIds, - amounts, - 140_000, - 140_000, - Bob, - "" + chainId, Alice, address(deployedContract), tokenIds, amounts, 140_000, 140_000, Bob, "" ); vm.prank(Alice, Alice); @@ -906,17 +735,8 @@ contract ERC1155VaultTest is TestBase { uint256[] memory amounts = new uint256[](1); amounts[0] = 2; - BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault - .BridgeTransferOp( - destChainId, - Alice, - address(ctoken1155), - tokenIds, - amounts, - 140_000, - 140_000, - Alice, - "" + BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault.BridgeTransferOp( + destChainId, Alice, address(ctoken1155), tokenIds, amounts, 140_000, 140_000, Alice, "" ); vm.prank(Alice, Alice); erc1155Vault.sendToken{ value: 140_000 }(sendOpts); @@ -947,9 +767,8 @@ contract ERC1155VaultTest is TestBase { ); // Query canonicalToBridged - address deployedContract = destChainErc1155Vault.canonicalToBridged( - srcChainId, address(ctoken1155) - ); + address deployedContract = + destChainErc1155Vault.canonicalToBridged(srcChainId, address(ctoken1155)); try UpdatedBridgedERC1155(deployedContract).helloWorld() { fail(); diff --git a/packages/protocol/test/tokenvault/ERC20Vault.t.sol b/packages/protocol/test/tokenvault/ERC20Vault.t.sol index 7a2cbc583eb..04b6a138aaa 100644 --- a/packages/protocol/test/tokenvault/ERC20Vault.t.sol +++ b/packages/protocol/test/tokenvault/ERC20Vault.t.sol @@ -1,29 +1,25 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.20; -import { AddressManager } from "../../contracts/common/AddressManager.sol"; -import { AddressResolver } from "../../contracts/common/AddressResolver.sol"; -import { Bridge } from "../../contracts/bridge/Bridge.sol"; -import { - ProxiedBridgedERC20, - BridgedERC20 -} from "../../contracts/tokenvault/BridgedERC20.sol"; -import { FreeMintERC20 } from "../../contracts/test/erc20/FreeMintERC20.sol"; -import { SignalService } from "../../contracts/signal/SignalService.sol"; -import { TaikoToken } from "../../contracts/L1/TaikoToken.sol"; -import { Test } from "forge-std/Test.sol"; -import { ERC20Vault } from "../../contracts/tokenvault/ERC20Vault.sol"; -import { TransparentUpgradeableProxy } from - "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; +import "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; +import "forge-std/Test.sol"; +import "../../contracts/common/AddressManager.sol"; +import "../../contracts/common/AddressResolver.sol"; +import "../../contracts/bridge/Bridge.sol"; +import "../../contracts/tokenvault/BridgedERC20.sol"; +import "../../contracts/test/erc20/FreeMintERC20.sol"; +import "../../contracts/signal/SignalService.sol"; +import "../../contracts/L1/TaikoToken.sol"; +import "../../contracts/tokenvault/ERC20Vault.sol"; // PrankDestBridge lets us simulate a transaction to the ERC20Vault // from a named Bridge, without having to test/run through the real Bridge code, // outside the scope of the unit tests in the ERC20Vault. contract PrankDestBridge { ERC20Vault destERC20Vault; - Context ctx; + TContext ctx; - struct Context { + struct TContext { bytes32 msgHash; // messageHash address sender; uint64 srcChainId; @@ -37,7 +33,7 @@ contract PrankDestBridge { destERC20Vault = ERC20Vault(addr); } - function context() public view returns (Context memory) { + function context() public view returns (TContext memory) { return ctx; } @@ -110,9 +106,7 @@ contract TestERC20Vault is Test { addressManager = new AddressManager(); addressManager.init(); - addressManager.setAddress( - uint64(block.chainid), "taiko_token", address(tko) - ); + addressManager.setAddress(uint64(block.chainid), "taiko_token", address(tko)); erc20Vault = new ERC20Vault(); erc20Vault.init(address(addressManager)); @@ -132,31 +126,19 @@ contract TestERC20Vault is Test { signalService = new SignalService(); signalService.init(); - addressManager.setAddress( - uint64(block.chainid), "bridge", address(bridge) - ); + addressManager.setAddress(uint64(block.chainid), "bridge", address(bridge)); - addressManager.setAddress( - uint64(block.chainid), "signal_service", address(signalService) - ); + addressManager.setAddress(uint64(block.chainid), "signal_service", address(signalService)); - addressManager.setAddress( - uint64(block.chainid), "erc20_vault", address(erc20Vault) - ); + addressManager.setAddress(uint64(block.chainid), "erc20_vault", address(erc20Vault)); - addressManager.setAddress( - destChainId, "erc20_vault", address(destChainIdERC20Vault) - ); + addressManager.setAddress(destChainId, "erc20_vault", address(destChainIdERC20Vault)); - addressManager.setAddress( - destChainId, "bridge", address(destChainIdBridge) - ); + addressManager.setAddress(destChainId, "bridge", address(destChainIdBridge)); address proxiedBridgedERC20 = address(new ProxiedBridgedERC20()); - addressManager.setAddress( - destChainId, "proxied_bridged_erc20", proxiedBridgedERC20 - ); + addressManager.setAddress(destChainId, "proxied_bridged_erc20", proxiedBridgedERC20); addressManager.setAddress( uint64(block.chainid), "proxied_bridged_erc20", proxiedBridgedERC20 @@ -198,10 +180,7 @@ contract TestERC20Vault is Test { assertEq(erc20VaultBalanceAfter - erc20VaultBalanceBefore, amount); } - function test_20Vault_send_erc20_processing_fee_reverts_if_msg_value_too_low( - ) - public - { + function test_20Vault_send_erc20_processing_fee_reverts_if_msg_value_too_low() public { vm.startPrank(Alice); uint256 amount = 2 wei; @@ -210,14 +189,7 @@ contract TestERC20Vault is Test { vm.expectRevert(); erc20Vault.sendToken( ERC20Vault.BridgeTransferOp( - destChainId, - Bob, - address(erc20), - amount, - 1_000_000, - amount - 1, - Bob, - "" + destChainId, Bob, address(erc20), amount, 1_000_000, amount - 1, Bob, "" ) ); } @@ -271,14 +243,11 @@ contract TestERC20Vault is Test { vm.expectRevert(ERC20Vault.VAULT_INVALID_TOKEN.selector); erc20Vault.sendToken( - ERC20Vault.BridgeTransferOp( - destChainId, Bob, address(0), amount, 1_000_000, 0, Bob, "" - ) + ERC20Vault.BridgeTransferOp(destChainId, Bob, address(0), amount, 1_000_000, 0, Bob, "") ); } - function test_20Vault_receive_erc20_canonical_to_dest_chain_transfers_from_canonical_token( - ) + function test_20Vault_receive_erc20_canonical_to_dest_chain_transfers_from_canonical_token() public { vm.startPrank(Alice); diff --git a/packages/protocol/test/tokenvault/ERC721Vault.t.sol b/packages/protocol/test/tokenvault/ERC721Vault.t.sol index 488a2062a52..df272108b8a 100644 --- a/packages/protocol/test/tokenvault/ERC721Vault.t.sol +++ b/packages/protocol/test/tokenvault/ERC721Vault.t.sol @@ -1,28 +1,17 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.20; -import { console2 } from "forge-std/console2.sol"; -import { - TestBase, - SkipProofCheckSignal, - DummyCrossChainSync, - NonNftContract, - BadReceiver -} from "../TestBase.sol"; -import { AddressManager } from "../../contracts/common/AddressManager.sol"; -import { IBridge, Bridge } from "../../contracts/bridge/Bridge.sol"; -import { BaseNFTVault } from "../../contracts/tokenvault/BaseNFTVault.sol"; -import { ERC721Vault } from "../../contracts/tokenvault/ERC721Vault.sol"; -import { - ProxiedBridgedERC721, - BridgedERC721 -} from "../../contracts/tokenvault/BridgedERC721.sol"; -import { SignalService } from "../../contracts/signal/SignalService.sol"; -import { ICrossChainSync } from "../../contracts/common/ICrossChainSync.sol"; -import { ERC721 } from - "lib/openzeppelin-contracts/contracts/token/ERC721/ERC721.sol"; -import { TransparentUpgradeableProxy } from - "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; +import "lib/openzeppelin-contracts/contracts/token/ERC721/ERC721.sol"; +import "lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; +import "forge-std/console2.sol"; +import "../TestBase.sol"; +import "../../contracts/common/AddressManager.sol"; +import "../../contracts/bridge/Bridge.sol"; +import "../../contracts/tokenvault/BaseNFTVault.sol"; +import "../../contracts/tokenvault/ERC721Vault.sol"; +import "../../contracts/tokenvault/BridgedERC721.sol"; +import "../../contracts/signal/SignalService.sol"; +import "../../contracts/common/ICrossChainSync.sol"; contract TestTokenERC721 is ERC721 { string _baseTokenURI; @@ -36,13 +25,7 @@ contract TestTokenERC721 is ERC721 { _baseTokenURI = baseURI; } - function _baseURI() - internal - view - virtual - override - returns (string memory) - { + function _baseURI() internal view virtual override returns (string memory) { return _baseTokenURI; } @@ -129,7 +112,7 @@ contract UpdatedBridgedERC721 is BridgedERC721 { } } -contract ERC721VaultTest is TestBase { +contract ERC721VaultTest is TaikoTest { AddressManager addressManager; BadReceiver badReceiver; Bridge bridge; @@ -180,55 +163,31 @@ contract ERC721VaultTest is TestBase { crossChainSync = new DummyCrossChainSync(); addressManager.setAddress( - uint64(block.chainid), - "signal_service", - address(mockProofSignalService) + uint64(block.chainid), "signal_service", address(mockProofSignalService) ); - addressManager.setAddress( - destChainId, "signal_service", address(mockProofSignalService) - ); + addressManager.setAddress(destChainId, "signal_service", address(mockProofSignalService)); - addressManager.setAddress( - uint64(block.chainid), "bridge", address(bridge) - ); + addressManager.setAddress(uint64(block.chainid), "bridge", address(bridge)); - addressManager.setAddress( - destChainId, "bridge", address(destChainIdBridge) - ); + addressManager.setAddress(destChainId, "bridge", address(destChainIdBridge)); - addressManager.setAddress( - uint64(block.chainid), "erc721_vault", address(erc721Vault) - ); + addressManager.setAddress(uint64(block.chainid), "erc721_vault", address(erc721Vault)); - addressManager.setAddress( - destChainId, "erc721_vault", address(destChainErc721Vault) - ); + addressManager.setAddress(destChainId, "erc721_vault", address(destChainErc721Vault)); // Below 2-2 registrations (mock) are needed bc of // LibBridgeRecall.sol's // resolve address - addressManager.setAddress( - destChainId, "erc1155_vault", address(erc721Vault) - ); - addressManager.setAddress( - destChainId, "erc20_vault", address(erc721Vault) - ); - addressManager.setAddress( - uint64(block.chainid), "erc1155_vault", address(erc721Vault) - ); - addressManager.setAddress( - uint64(block.chainid), "erc20_vault", address(erc721Vault) - ); + addressManager.setAddress(destChainId, "erc1155_vault", address(erc721Vault)); + addressManager.setAddress(destChainId, "erc20_vault", address(erc721Vault)); + addressManager.setAddress(uint64(block.chainid), "erc1155_vault", address(erc721Vault)); + addressManager.setAddress(uint64(block.chainid), "erc20_vault", address(erc721Vault)); address proxiedBridgedERC721 = address(new ProxiedBridgedERC721()); + addressManager.setAddress(destChainId, "proxied_bridged_erc721", proxiedBridgedERC721); addressManager.setAddress( - destChainId, "proxied_bridged_erc721", proxiedBridgedERC721 - ); - addressManager.setAddress( - uint64(block.chainid), - "proxied_bridged_erc721", - proxiedBridgedERC721 + uint64(block.chainid), "proxied_bridged_erc721", proxiedBridgedERC721 ); vm.stopPrank(); @@ -257,8 +216,7 @@ contract ERC721VaultTest is TestBase { uint256[] memory amounts = new uint256[](1); amounts[0] = 0; - BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault - .BridgeTransferOp( + BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault.BridgeTransferOp( destChainId, Alice, address(canonicalToken721), @@ -287,26 +245,15 @@ contract ERC721VaultTest is TestBase { uint256[] memory amounts = new uint256[](1); amounts[0] = 0; - BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault - .BridgeTransferOp( - destChainId, - Alice, - address(0), - tokenIds, - amounts, - 140_000, - 140_000, - Alice, - "" + BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault.BridgeTransferOp( + destChainId, Alice, address(0), tokenIds, amounts, 140_000, 140_000, Alice, "" ); vm.prank(Alice, Alice); vm.expectRevert(BaseNFTVault.VAULT_INVALID_TOKEN.selector); erc721Vault.sendToken{ value: 140_000 }(sendOpts); } - function test_721Vault_sendToken_with_1_tokens_but_erc721_amount_1_invalid() - public - { + function test_721Vault_sendToken_with_1_tokens_but_erc721_amount_1_invalid() public { vm.prank(Alice, Alice); canonicalToken721.approve(address(erc721Vault), 1); @@ -317,8 +264,7 @@ contract ERC721VaultTest is TestBase { uint256[] memory amounts = new uint256[](1); amounts[0] = 1; - BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault - .BridgeTransferOp( + BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault.BridgeTransferOp( destChainId, Alice, address(canonicalToken721), @@ -349,8 +295,7 @@ contract ERC721VaultTest is TestBase { uint256[] memory amounts = new uint256[](1); amounts[0] = 0; - BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault - .BridgeTransferOp( + BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault.BridgeTransferOp( destChainId, Alice, address(canonicalToken721), @@ -366,8 +311,7 @@ contract ERC721VaultTest is TestBase { assertEq(canonicalToken721.ownerOf(1), address(erc721Vault)); - BaseNFTVault.CanonicalNFT memory canonicalToken = BaseNFTVault - .CanonicalNFT({ + BaseNFTVault.CanonicalNFT memory canonicalToken = BaseNFTVault.CanonicalNFT({ chainId: 31_337, addr: address(canonicalToken721), symbol: "TT", @@ -378,29 +322,18 @@ contract ERC721VaultTest is TestBase { vm.chainId(destChainId); destChainIdBridge.sendReceiveERC721ToERC721Vault( - canonicalToken, - Alice, - Alice, - tokenIds, - bytes32(0), - address(erc721Vault), - chainId, - 0 + canonicalToken, Alice, Alice, tokenIds, bytes32(0), address(erc721Vault), chainId, 0 ); // Query canonicalToBridged - address deployedContract = destChainErc721Vault.canonicalToBridged( - chainId, address(canonicalToken721) - ); + address deployedContract = + destChainErc721Vault.canonicalToBridged(chainId, address(canonicalToken721)); // Alice bridged over tokenId 1 assertEq(ERC721(deployedContract).ownerOf(1), Alice); } - function test_721Vault_receiveTokens_but_mint_not_deploy_if_bridged_second_time_721( - ) - public - { + function test_721Vault_receiveTokens_but_mint_not_deploy_if_bridged_second_time_721() public { vm.prank(Alice, Alice); canonicalToken721.approve(address(erc721Vault), 1); vm.prank(Alice, Alice); @@ -414,8 +347,7 @@ contract ERC721VaultTest is TestBase { uint256[] memory amounts = new uint256[](1); amounts[0] = 0; - BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault - .BridgeTransferOp( + BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault.BridgeTransferOp( destChainId, Alice, address(canonicalToken721), @@ -434,8 +366,7 @@ contract ERC721VaultTest is TestBase { // This canonicalToken is basically need to be exact same as the // sendToken() puts together // - here is just mocking putting it together. - BaseNFTVault.CanonicalNFT memory canonicalToken = BaseNFTVault - .CanonicalNFT({ + BaseNFTVault.CanonicalNFT memory canonicalToken = BaseNFTVault.CanonicalNFT({ chainId: 31_337, addr: address(canonicalToken721), symbol: "TT", @@ -446,20 +377,12 @@ contract ERC721VaultTest is TestBase { vm.chainId(destChainId); destChainIdBridge.sendReceiveERC721ToERC721Vault( - canonicalToken, - Alice, - Alice, - tokenIds, - bytes32(0), - address(erc721Vault), - chainId, - 0 + canonicalToken, Alice, Alice, tokenIds, bytes32(0), address(erc721Vault), chainId, 0 ); // Query canonicalToBridged - address deployedContract = destChainErc721Vault.canonicalToBridged( - chainId, address(canonicalToken721) - ); + address deployedContract = + destChainErc721Vault.canonicalToBridged(chainId, address(canonicalToken721)); // Alice bridged over tokenId 1 assertEq(ERC721(deployedContract).ownerOf(1), Alice); @@ -490,20 +413,12 @@ contract ERC721VaultTest is TestBase { vm.chainId(destChainId); destChainIdBridge.sendReceiveERC721ToERC721Vault( - canonicalToken, - Alice, - Alice, - tokenIds, - bytes32(0), - address(erc721Vault), - chainId, - 0 + canonicalToken, Alice, Alice, tokenIds, bytes32(0), address(erc721Vault), chainId, 0 ); // Query canonicalToBridged - address bridgedContract = destChainErc721Vault.canonicalToBridged( - chainId, address(canonicalToken721) - ); + address bridgedContract = + destChainErc721Vault.canonicalToBridged(chainId, address(canonicalToken721)); assertEq(bridgedContract, deployedContract); } @@ -521,8 +436,7 @@ contract ERC721VaultTest is TestBase { amounts[0] = 0; uint256 etherValue = 0.1 ether; - BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault - .BridgeTransferOp( + BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault.BridgeTransferOp( destChainId, David, address(canonicalToken721), @@ -538,8 +452,7 @@ contract ERC721VaultTest is TestBase { assertEq(canonicalToken721.ownerOf(1), address(erc721Vault)); - BaseNFTVault.CanonicalNFT memory canonicalToken = BaseNFTVault - .CanonicalNFT({ + BaseNFTVault.CanonicalNFT memory canonicalToken = BaseNFTVault.CanonicalNFT({ chainId: 31_337, addr: address(canonicalToken721), symbol: "TT", @@ -561,9 +474,8 @@ contract ERC721VaultTest is TestBase { ); // Query canonicalToBridged - address deployedContract = destChainErc721Vault.canonicalToBridged( - chainId, address(canonicalToken721) - ); + address deployedContract = + destChainErc721Vault.canonicalToBridged(chainId, address(canonicalToken721)); // Alice bridged over tokenId 1 and etherValue to David assertEq(ERC721(deployedContract).ownerOf(1), David); @@ -582,8 +494,7 @@ contract ERC721VaultTest is TestBase { uint256[] memory amounts = new uint256[](1); amounts[0] = 0; - BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault - .BridgeTransferOp( + BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault.BridgeTransferOp( destChainId, Alice, address(canonicalToken721), @@ -596,8 +507,7 @@ contract ERC721VaultTest is TestBase { ); vm.prank(Alice, Alice); - IBridge.Message memory message = - erc721Vault.sendToken{ value: 140_000 }(sendOpts); + IBridge.Message memory message = erc721Vault.sendToken{ value: 140_000 }(sendOpts); assertEq(canonicalToken721.ownerOf(1), address(erc721Vault)); @@ -624,8 +534,7 @@ contract ERC721VaultTest is TestBase { amounts[0] = 0; amounts[1] = 0; - BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault - .BridgeTransferOp( + BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault.BridgeTransferOp( destChainId, Alice, address(canonicalToken721), @@ -642,8 +551,7 @@ contract ERC721VaultTest is TestBase { assertEq(canonicalToken721.ownerOf(1), address(erc721Vault)); assertEq(canonicalToken721.ownerOf(2), address(erc721Vault)); - BaseNFTVault.CanonicalNFT memory canonicalToken = BaseNFTVault - .CanonicalNFT({ + BaseNFTVault.CanonicalNFT memory canonicalToken = BaseNFTVault.CanonicalNFT({ chainId: 31_337, addr: address(canonicalToken721), symbol: "TT", @@ -654,29 +562,19 @@ contract ERC721VaultTest is TestBase { vm.chainId(destChainId); destChainIdBridge.sendReceiveERC721ToERC721Vault( - canonicalToken, - Alice, - Alice, - tokenIds, - bytes32(0), - address(erc721Vault), - srcChainId, - 0 + canonicalToken, Alice, Alice, tokenIds, bytes32(0), address(erc721Vault), srcChainId, 0 ); // Query canonicalToBridged - address deployedContract = destChainErc721Vault.canonicalToBridged( - srcChainId, address(canonicalToken721) - ); + address deployedContract = + destChainErc721Vault.canonicalToBridged(srcChainId, address(canonicalToken721)); // Alice bridged over tokenId 1 assertEq(ERC721(deployedContract).ownerOf(1), Alice); assertEq(ERC721(deployedContract).ownerOf(2), Alice); } - function test_721Vault_bridge_back_but_owner_is_different_now_721() - public - { + function test_721Vault_bridge_back_but_owner_is_different_now_721() public { vm.prank(Alice, Alice); canonicalToken721.approve(address(erc721Vault), 1); vm.prank(Alice, Alice); @@ -690,8 +588,7 @@ contract ERC721VaultTest is TestBase { uint256[] memory amounts = new uint256[](1); amounts[0] = 0; - BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault - .BridgeTransferOp( + BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault.BridgeTransferOp( destChainId, Alice, address(canonicalToken721), @@ -710,8 +607,7 @@ contract ERC721VaultTest is TestBase { // This canonicalToken is basically need to be exact same as the // sendToken() puts together // - here is just mocking putting it together. - BaseNFTVault.CanonicalNFT memory canonicalToken = BaseNFTVault - .CanonicalNFT({ + BaseNFTVault.CanonicalNFT memory canonicalToken = BaseNFTVault.CanonicalNFT({ chainId: 31_337, addr: address(canonicalToken721), symbol: "TT", @@ -722,20 +618,12 @@ contract ERC721VaultTest is TestBase { vm.chainId(destChainId); destChainIdBridge.sendReceiveERC721ToERC721Vault( - canonicalToken, - Alice, - Alice, - tokenIds, - bytes32(0), - address(erc721Vault), - chainId, - 0 + canonicalToken, Alice, Alice, tokenIds, bytes32(0), address(erc721Vault), chainId, 0 ); // Query canonicalToBridged - address deployedContract = destChainErc721Vault.canonicalToBridged( - chainId, address(canonicalToken721) - ); + address deployedContract = + destChainErc721Vault.canonicalToBridged(chainId, address(canonicalToken721)); // Alice bridged over tokenId 1 assertEq(ERC721(deployedContract).ownerOf(1), Alice); @@ -751,15 +639,7 @@ contract ERC721VaultTest is TestBase { ERC721(deployedContract).approve(address(destChainErc721Vault), 1); sendOpts = BaseNFTVault.BridgeTransferOp( - chainId, - Bob, - address(deployedContract), - tokenIds, - amounts, - 140_000, - 140_000, - Bob, - "" + chainId, Bob, address(deployedContract), tokenIds, amounts, 140_000, 140_000, Bob, "" ); vm.prank(Bob, Bob); @@ -772,26 +652,16 @@ contract ERC721VaultTest is TestBase { destChainIdBridge.setERC721Vault(address(erc721Vault)); vm.prank(Amelia, Amelia); - addressManager.setAddress( - uint64(block.chainid), "bridge", address(destChainIdBridge) - ); + addressManager.setAddress(uint64(block.chainid), "bridge", address(destChainIdBridge)); destChainIdBridge.sendReceiveERC721ToERC721Vault( - canonicalToken, - Bob, - Bob, - tokenIds, - bytes32(0), - address(erc721Vault), - chainId, - 0 + canonicalToken, Bob, Bob, tokenIds, bytes32(0), address(erc721Vault), chainId, 0 ); assertEq(canonicalToken721.ownerOf(1), Bob); } - function test_721Vault_bridge_back_but_original_owner_cannot_claim_it_anymore_if_sold_721( - ) + function test_721Vault_bridge_back_but_original_owner_cannot_claim_it_anymore_if_sold_721() public { vm.prank(Alice, Alice); @@ -807,8 +677,7 @@ contract ERC721VaultTest is TestBase { uint256[] memory amounts = new uint256[](1); amounts[0] = 0; - BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault - .BridgeTransferOp( + BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault.BridgeTransferOp( destChainId, Alice, address(canonicalToken721), @@ -827,8 +696,7 @@ contract ERC721VaultTest is TestBase { // This canonicalToken is basically need to be exact same as the // sendToken() puts together // - here is just mocking putting it together. - BaseNFTVault.CanonicalNFT memory canonicalToken = BaseNFTVault - .CanonicalNFT({ + BaseNFTVault.CanonicalNFT memory canonicalToken = BaseNFTVault.CanonicalNFT({ chainId: 31_337, addr: address(canonicalToken721), symbol: "TT", @@ -839,20 +707,12 @@ contract ERC721VaultTest is TestBase { vm.chainId(destChainId); destChainIdBridge.sendReceiveERC721ToERC721Vault( - canonicalToken, - Alice, - Alice, - tokenIds, - bytes32(0), - address(erc721Vault), - chainId, - 0 + canonicalToken, Alice, Alice, tokenIds, bytes32(0), address(erc721Vault), chainId, 0 ); // Query canonicalToBridged - address deployedContract = destChainErc721Vault.canonicalToBridged( - chainId, address(canonicalToken721) - ); + address deployedContract = + destChainErc721Vault.canonicalToBridged(chainId, address(canonicalToken721)); // Alice bridged over tokenId 1 assertEq(ERC721(deployedContract).ownerOf(1), Alice); @@ -869,15 +729,7 @@ contract ERC721VaultTest is TestBase { // Alice puts together a malicious bridging back message sendOpts = BaseNFTVault.BridgeTransferOp( - chainId, - Alice, - address(deployedContract), - tokenIds, - amounts, - 140_000, - 140_000, - Bob, - "" + chainId, Alice, address(deployedContract), tokenIds, amounts, 140_000, 140_000, Bob, "" ); vm.prank(Alice, Alice); @@ -899,8 +751,7 @@ contract ERC721VaultTest is TestBase { uint256[] memory amounts = new uint256[](1); amounts[0] = 0; - BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault - .BridgeTransferOp( + BaseNFTVault.BridgeTransferOp memory sendOpts = BaseNFTVault.BridgeTransferOp( destChainId, Alice, address(canonicalToken721), @@ -919,8 +770,7 @@ contract ERC721VaultTest is TestBase { // This canonicalToken is basically need to be exact same as the // sendToken() puts together // - here is just mocking putting it together. - BaseNFTVault.CanonicalNFT memory canonicalToken = BaseNFTVault - .CanonicalNFT({ + BaseNFTVault.CanonicalNFT memory canonicalToken = BaseNFTVault.CanonicalNFT({ chainId: 31_337, addr: address(canonicalToken721), symbol: "TT", @@ -931,20 +781,12 @@ contract ERC721VaultTest is TestBase { vm.chainId(destChainId); destChainIdBridge.sendReceiveERC721ToERC721Vault( - canonicalToken, - Alice, - Alice, - tokenIds, - bytes32(0), - address(erc721Vault), - chainId, - 0 + canonicalToken, Alice, Alice, tokenIds, bytes32(0), address(erc721Vault), chainId, 0 ); // Query canonicalToBridged - address deployedContract = destChainErc721Vault.canonicalToBridged( - chainId, address(canonicalToken721) - ); + address deployedContract = + destChainErc721Vault.canonicalToBridged(chainId, address(canonicalToken721)); try UpdatedBridgedERC721(deployedContract).helloWorld() { fail();