From 284447b369edde7b85e92da9ada5fd303c3446f7 Mon Sep 17 00:00:00 2001 From: Daniel Wang <99078276+dantaik@users.noreply.github.com> Date: Thu, 14 Mar 2024 19:36:51 +0800 Subject: [PATCH 1/2] feat(protocol)!: remove the blob-reuse feature (#16439) --- packages/protocol/contracts/L1/TaikoData.sol | 22 +---- .../protocol/contracts/L1/TaikoErrors.sol | 5 +- .../protocol/contracts/L1/TaikoEvents.sol | 4 - packages/protocol/contracts/L1/TaikoL1.sol | 12 --- .../contracts/L1/libs/LibProposing.sol | 89 ++----------------- .../contracts/L1/libs/LibVerifying.sol | 6 +- packages/protocol/test/L1/TaikoL1TestBase.sol | 2 +- 7 files changed, 16 insertions(+), 124 deletions(-) diff --git a/packages/protocol/contracts/L1/TaikoData.sol b/packages/protocol/contracts/L1/TaikoData.sol index 290fccb6174..5d08a1f4fb0 100644 --- a/packages/protocol/contracts/L1/TaikoData.sol +++ b/packages/protocol/contracts/L1/TaikoData.sol @@ -24,14 +24,6 @@ library TaikoData { uint64 maxBlocksToVerifyPerProposal; // The maximum gas limit allowed for a block. uint32 blockMaxGasLimit; - // The maximum allowed bytes for the proposed transaction list calldata. - uint24 blockMaxTxListBytes; - // The max period in seconds that a blob can be reused for DA. - uint24 blobExpiry; - // True if EIP-4844 is enabled for DA - bool blobAllowedForDA; - // True if blob can be reused - bool blobReuseEnabled; // --------------------------------------------------------------------- // Group 3: Proof related configs // --------------------------------------------------------------------- @@ -79,10 +71,6 @@ library TaikoData { address assignedProver; address coinbase; bytes32 extraData; - bytes32 blobHash; - uint24 txListByteOffset; - uint24 txListByteSize; - bool cacheBlobForReuse; bytes32 parentMetaHash; HookCall[] hookCalls; } @@ -102,8 +90,6 @@ library TaikoData { uint32 gasLimit; uint64 timestamp; uint64 l1Height; - uint24 txListByteOffset; - uint24 txListByteSize; uint16 minTier; bool blobUsed; bytes32 parentMetaHash; @@ -189,10 +175,8 @@ library TaikoData { ) transitions; // Ring buffer for Ether deposits mapping(uint256 depositId_mod_ethDepositRingBufferSize => uint256 depositAmount) ethDeposits; - // Reusable blobs - mapping(bytes32 blobHash => uint256 since) reusableBlobs; - SlotA slotA; // slot 6 - SlotB slotB; // slot 7 - uint256[43] __gap; + SlotA slotA; // slot 5 + SlotB slotB; // slot 6 + uint256[44] __gap; } } diff --git a/packages/protocol/contracts/L1/TaikoErrors.sol b/packages/protocol/contracts/L1/TaikoErrors.sol index cf9fe36955d..638b4ed0afb 100644 --- a/packages/protocol/contracts/L1/TaikoErrors.sol +++ b/packages/protocol/contracts/L1/TaikoErrors.sol @@ -12,10 +12,8 @@ abstract contract TaikoErrors { error L1_ALREADY_CONTESTED(); error L1_ALREADY_PROVED(); error L1_ASSIGNED_PROVER_NOT_ALLOWED(); - error L1_BLOB_FOR_DA_DISABLED(); + error L1_BLOB_NOT_AVAILABLE(); error L1_BLOB_NOT_FOUND(); - error L1_BLOB_NOT_REUSABLE(); - error L1_BLOB_REUSE_DISABLED(); error L1_BLOCK_MISMATCH(); error L1_INVALID_BLOCK_ID(); error L1_INVALID_CONFIG(); @@ -36,7 +34,6 @@ abstract contract TaikoErrors { error L1_TOO_MANY_TIERS(); error L1_TRANSITION_ID_ZERO(); error L1_TRANSITION_NOT_FOUND(); - error L1_TXLIST_SIZE(); error L1_UNAUTHORIZED(); error L1_UNEXPECTED_PARENT(); error L1_UNEXPECTED_TRANSITION_ID(); diff --git a/packages/protocol/contracts/L1/TaikoEvents.sol b/packages/protocol/contracts/L1/TaikoEvents.sol index cb93082104b..83912b0424e 100644 --- a/packages/protocol/contracts/L1/TaikoEvents.sol +++ b/packages/protocol/contracts/L1/TaikoEvents.sol @@ -72,10 +72,6 @@ abstract contract TaikoEvents { uint16 tier ); - /// @dev Emitted when a blob is cached for reuse. - /// @param blobHash The blobHash cached. - event BlobCached(bytes32 blobHash); - /// @dev Emitted when proving has been paused /// @param paused True if paused, false if unpaused. event ProvingPaused(bool paused); diff --git a/packages/protocol/contracts/L1/TaikoL1.sol b/packages/protocol/contracts/L1/TaikoL1.sol index 4c12105d35f..d57fcf780e1 100644 --- a/packages/protocol/contracts/L1/TaikoL1.sol +++ b/packages/protocol/contracts/L1/TaikoL1.sol @@ -133,11 +133,6 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents, TaikoErrors { return LibDepositing.canDepositEthToL2(state, getConfig(), _amount); } - /// @notice See {LibProposing-isBlobReusable}. - function isBlobReusable(bytes32 _blobHash) public view returns (bool) { - return LibProposing.isBlobReusable(state, getConfig(), _blobHash); - } - /// @notice Gets the details of a block. /// @param _blockId Index of the block. /// @return blk_ The block. @@ -197,13 +192,6 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents, TaikoErrors { // Can be overridden by the tier config. maxBlocksToVerifyPerProposal: 10, blockMaxGasLimit: 15_000_000, - // Each go-ethereum transaction has a size limit of 128KB, - // and right now txList is still saved in calldata, so we set it - // to 120KB. - blockMaxTxListBytes: 120_000, - blobExpiry: 24 hours, - blobAllowedForDA: false, - blobReuseEnabled: false, livenessBond: 250e18, // 250 Taiko token // ETH deposit related. ethDepositRingBufferSize: 1024, diff --git a/packages/protocol/contracts/L1/libs/LibProposing.sol b/packages/protocol/contracts/L1/libs/LibProposing.sol index e9813a683c9..d8395d1c2cb 100644 --- a/packages/protocol/contracts/L1/libs/LibProposing.sol +++ b/packages/protocol/contracts/L1/libs/LibProposing.sol @@ -15,11 +15,6 @@ import "./LibDepositing.sol"; library LibProposing { using LibAddress for address; - /// @notice The maximum number of bytes allowed per blob. - /// @dev According to EIP4844, each blob has up to 4096 field elements, and each - /// field element has 32 bytes. - uint256 public constant MAX_BYTES_PER_BLOB = 4096 * 32; - // Warning: Any events defined here must also be defined in TaikoEvents.sol. /// @notice Emitted when a block is proposed. /// @param blockId The ID of the proposed block. @@ -36,23 +31,15 @@ library LibProposing { TaikoData.EthDeposit[] depositsProcessed ); - /// @notice Emitted when a blob is cached. - /// @param blobHash The hash of the cached blob. - event BlobCached(bytes32 blobHash); - // Warning: Any errors defined here must also be defined in TaikoErrors.sol. - error L1_BLOB_FOR_DA_DISABLED(); + error L1_BLOB_NOT_AVAILABLE(); error L1_BLOB_NOT_FOUND(); - error L1_BLOB_NOT_REUSABLE(); - error L1_BLOB_REUSE_DISABLED(); error L1_INVALID_HOOK(); error L1_INVALID_PARAM(); error L1_INVALID_PROVER(); error L1_LIVENESS_BOND_NOT_RECEIVED(); error L1_PROPOSER_NOT_EOA(); error L1_TOO_MANY_BLOCKS(); - error L1_TXLIST_OFFSET(); - error L1_TXLIST_SIZE(); error L1_UNAUTHORIZED(); error L1_UNEXPECTED_PARENT(); @@ -129,8 +116,6 @@ library LibProposing { gasLimit: _config.blockMaxGasLimit, timestamp: uint64(block.timestamp), l1Height: uint64(block.number - 1), - txListByteOffset: 0, // to be initialized below - txListByteSize: 0, // to be initialized below minTier: 0, // to be initialized below blobUsed: _txList.length == 0, parentMetaHash: parentMetaHash, @@ -140,41 +125,14 @@ library LibProposing { // Update certain meta fields if (meta_.blobUsed) { - if (!_config.blobAllowedForDA) revert L1_BLOB_FOR_DA_DISABLED(); - - if (params.blobHash != 0) { - if (!_config.blobReuseEnabled) revert L1_BLOB_REUSE_DISABLED(); - - // We try to reuse an old blob - if (!isBlobReusable(_state, _config, params.blobHash)) { - revert L1_BLOB_NOT_REUSABLE(); - } - meta_.blobHash = params.blobHash; - } else { - // Always use the first blob in this transaction. If the - // proposeBlock functions are called more than once in the same - // L1 transaction, these multiple L2 blocks will share the same - // blob. - meta_.blobHash = blobhash(0); - - if (meta_.blobHash == 0) revert L1_BLOB_NOT_FOUND(); - - // Depends on the blob data price, it may not make sense to - // cache the blob which costs 20,000 (sstore) + 631 (event) - // extra gas. - if (_config.blobReuseEnabled && params.cacheBlobForReuse) { - _state.reusableBlobs[meta_.blobHash] = block.timestamp; - emit BlobCached(meta_.blobHash); - } - } - - // Check that the txList data range is within the max size of a blob - if (uint256(params.txListByteOffset) + params.txListByteSize > MAX_BYTES_PER_BLOB) { - revert L1_TXLIST_OFFSET(); - } - - meta_.txListByteOffset = params.txListByteOffset; - meta_.txListByteSize = params.txListByteSize; + if (block.chainid != 1) revert L1_BLOB_NOT_AVAILABLE(); + + // Always use the first blob in this transaction. If the + // proposeBlock functions are called more than once in the same + // L1 transaction, these multiple L2 blocks will share the same + // blob. + meta_.blobHash = blobhash(0); + if (meta_.blobHash == 0) revert L1_BLOB_NOT_FOUND(); } else { // The proposer must be an Externally Owned Account (EOA) for // calldata usage. This ensures that the transaction is not an @@ -182,19 +140,7 @@ library LibProposing { // Taiko node software. if (!LibAddress.isSenderEOA()) revert L1_PROPOSER_NOT_EOA(); - // The txList is the full byte array without any offset - if (params.txListByteOffset != 0) { - revert L1_INVALID_PARAM(); - } - meta_.blobHash = keccak256(_txList); - meta_.txListByteOffset = 0; - meta_.txListByteSize = uint24(_txList.length); - } - - // Check that the tx length is non-zero and within the supported range - if (meta_.txListByteSize == 0 || meta_.txListByteSize > _config.blockMaxTxListBytes) { - revert L1_TXLIST_SIZE(); } // Following the Merge, the L1 mixHash incorporates the @@ -280,23 +226,6 @@ library LibProposing { }); } - /// @notice Checks if a blob is reusable. - /// @param _state Current TaikoData.State. - /// @param _config The TaikoData.Config. - /// @param _blobHash The blob hash - /// @return true if the blob is reusable, false otherwise. - function isBlobReusable( - TaikoData.State storage _state, - TaikoData.Config memory _config, - bytes32 _blobHash - ) - internal - view - returns (bool) - { - return _state.reusableBlobs[_blobHash] + _config.blobExpiry > block.timestamp; - } - function _isProposerPermitted( TaikoData.SlotB memory _slotB, IAddressResolver _resolver diff --git a/packages/protocol/contracts/L1/libs/LibVerifying.sol b/packages/protocol/contracts/L1/libs/LibVerifying.sol index 8d6a2eff10e..6a45983ee0c 100644 --- a/packages/protocol/contracts/L1/libs/LibVerifying.sol +++ b/packages/protocol/contracts/L1/libs/LibVerifying.sol @@ -249,10 +249,8 @@ library LibVerifying { _config.chainId <= 1 || _config.chainId == block.chainid // || _config.blockMaxProposals == 1 || _config.blockRingBufferSize <= _config.blockMaxProposals + 1 - || _config.blockMaxGasLimit == 0 || _config.blockMaxTxListBytes == 0 - || _config.blockMaxTxListBytes > 128 * 1024 // calldata up to 128K - || _config.livenessBond == 0 || _config.ethDepositRingBufferSize <= 1 - || _config.ethDepositMinCountPerBlock == 0 + || _config.blockMaxGasLimit == 0 || _config.livenessBond == 0 + || _config.ethDepositRingBufferSize <= 1 || _config.ethDepositMinCountPerBlock == 0 // Audit recommendation, and gas tested. Processing 32 deposits (as initially set in // TaikoL1.sol) costs 72_502 gas. || _config.ethDepositMaxCountPerBlock > 32 diff --git a/packages/protocol/test/L1/TaikoL1TestBase.sol b/packages/protocol/test/L1/TaikoL1TestBase.sol index a1a9481a5d3..ad3685656ac 100644 --- a/packages/protocol/test/L1/TaikoL1TestBase.sol +++ b/packages/protocol/test/L1/TaikoL1TestBase.sol @@ -195,7 +195,7 @@ abstract contract TaikoL1TestBase is TaikoTest { vm.prank(proposer, proposer); (meta, depositsProcessed) = L1.proposeBlock{ value: msgValue }( - abi.encode(TaikoData.BlockParams(prover, address(0), 0, 0, 0, 0, false, 0, hookcalls)), + abi.encode(TaikoData.BlockParams(prover, address(0), 0, 0, hookcalls)), new bytes(txListSize) ); } From c2d7d6e16ca85e46943af9b520f986921f7b897d Mon Sep 17 00:00:00 2001 From: acceptacross <150119116+acceptacross@users.noreply.github.com> Date: Thu, 14 Mar 2024 20:14:33 +0800 Subject: [PATCH 2/2] chore(protocol): fix some typos (#16438) Signed-off-by: acceptacross Co-authored-by: Daniel Wang <99078276+dantaik@users.noreply.github.com> --- packages/protocol/CHANGELOG.md | 2 +- packages/protocol/contracts/compiled/README.md | 4 ++-- .../contracts/thirdparty/solmate/LibFixedPointMath.sol | 2 +- packages/protocol/docs/actors_privileges_deployments.md | 2 +- packages/protocol/docs/native_token_support.md | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/protocol/CHANGELOG.md b/packages/protocol/CHANGELOG.md index 6e7ae3cb6da..31c4a1f399d 100644 --- a/packages/protocol/CHANGELOG.md +++ b/packages/protocol/CHANGELOG.md @@ -105,7 +105,7 @@ * **protocol:** fix singla service cannot be shared by multiple taiko L1/L2 contracts bug ([#15807](https://github.com/taikoxyz/taiko-mono/issues/15807)) ([a652ae8](https://github.com/taikoxyz/taiko-mono/commit/a652ae8dc0108e2799a449cce4e5f795f87908a1)) * **protocol:** fix some file names of the proxy upgrade scripts ([#15463](https://github.com/taikoxyz/taiko-mono/issues/15463)) ([3430d89](https://github.com/taikoxyz/taiko-mono/commit/3430d89de1d4bc6b4332744daaeac5df2a546fdf)) * **protocol:** Fix taiko token domain separator ([#15717](https://github.com/taikoxyz/taiko-mono/issues/15717)) ([6e2771c](https://github.com/taikoxyz/taiko-mono/commit/6e2771c54e62e73715cfbe2e7d4fc5a2fb54cf5c)) -* **protocol:** imporve bridge `_proveSignalReceived` and fix genesis test ([#15641](https://github.com/taikoxyz/taiko-mono/issues/15641)) ([15f6995](https://github.com/taikoxyz/taiko-mono/commit/15f6995f82d7456458eeecf098bd0d02bc3afec4)) +* **protocol:** improve bridge `_proveSignalReceived` and fix genesis test ([#15641](https://github.com/taikoxyz/taiko-mono/issues/15641)) ([15f6995](https://github.com/taikoxyz/taiko-mono/commit/15f6995f82d7456458eeecf098bd0d02bc3afec4)) * **protocol:** mandate bridge message only calls onMessageInvocation ([#15996](https://github.com/taikoxyz/taiko-mono/issues/15996)) ([f7a12b8](https://github.com/taikoxyz/taiko-mono/commit/f7a12b8601937eef97068c3029c91dff431c03a8)) * **protocol:** need to fix a bug in LibTrieProof (or its test) ([#15739](https://github.com/taikoxyz/taiko-mono/issues/15739)) ([ac1ca31](https://github.com/taikoxyz/taiko-mono/commit/ac1ca310846a075a663c119d404dc8f5f591eb9c)) * **protocol:** new way to calculate meta.difficulty (TKO-11) ([#15568](https://github.com/taikoxyz/taiko-mono/issues/15568)) ([8c4b48e](https://github.com/taikoxyz/taiko-mono/commit/8c4b48e4ae2b8300de2282c7843ecf66e2fe22ae)) diff --git a/packages/protocol/contracts/compiled/README.md b/packages/protocol/contracts/compiled/README.md index 076670757c3..f8767494803 100644 --- a/packages/protocol/contracts/compiled/README.md +++ b/packages/protocol/contracts/compiled/README.md @@ -14,11 +14,11 @@ According to this document: > > Build the FiatToken contracts from source. In this case, the compiler metadata must be published or made available to support full contract verification. Various suggested compiler settings that Circle uses can be found here, which will allow the third-party team to reach the same bytecode if followed consistently. -Following the recommendations the contracts were built with the same compiler settings (version + optimization) and they have bytecode equivalance with the other contracts (mentioned in the doc, and can be found on links below (Arbitrum, Scroll, Polygon, etc.)). +Following the recommendations the contracts were built with the same compiler settings (version + optimization) and they have bytecode equivalence with the other contracts (mentioned in the doc, and can be found on links below (Arbitrum, Scroll, Polygon, etc.)). For reference, here are Arbitrum's proxy + token contracts: - Proxy: https://arbiscan.io/token/0xaf88d065e77c8cc2239327c5edb3a432268e5831#code - Implementation: https://arbiscan.io/address/0x0f4fb9474303d10905AB86aA8d5A65FE44b6E04A#code -As a cross-reference, one can compare the bytecode of the ones present on arbiscan and here in the .json files (under bytcode key), the additional (meta)data could be helpful for contracts verfication. +As a cross-reference, one can compare the bytecode of the ones present on arbiscan and here in the .json files (under bytcode key), the additional (meta)data could be helpful for contracts verification. diff --git a/packages/protocol/contracts/thirdparty/solmate/LibFixedPointMath.sol b/packages/protocol/contracts/thirdparty/solmate/LibFixedPointMath.sol index d30f704559e..2ad599363c2 100644 --- a/packages/protocol/contracts/thirdparty/solmate/LibFixedPointMath.sol +++ b/packages/protocol/contracts/thirdparty/solmate/LibFixedPointMath.sol @@ -69,7 +69,7 @@ library LibFixedPointMath { // We now need to multiply r by // * the scale factor s = ~6.031367120..., // * the 2**k factor from the range reduction, and - // * the 1e18 / 2**96 factor for base converison. + // * the 1e18 / 2**96 factor for base conversion. // We do all of this at once, with an intermediate result in 2**213 // basis // so the final right shift is always by a positive amount. diff --git a/packages/protocol/docs/actors_privileges_deployments.md b/packages/protocol/docs/actors_privileges_deployments.md index 4a8256f82bf..d5eae05377d 100644 --- a/packages/protocol/docs/actors_privileges_deployments.md +++ b/packages/protocol/docs/actors_privileges_deployments.md @@ -21,7 +21,7 @@ In the context of the smart contract system, various actors play distinct roles. - **Role**: This domain role is given to Bridge smart contracts (both chains). - **Privileges**: - - The right to trigger transfering/minting the tokens (on destination chain) (be it ERC20, ERC721, ERC1155) from the vault contracts + - The right to trigger transferring/minting the tokens (on destination chain) (be it ERC20, ERC721, ERC1155) from the vault contracts - The right to trigger releasing the custodied assets on the source chain (if bridging is not successful) ### 1.3 ERCXXX_Vault diff --git a/packages/protocol/docs/native_token_support.md b/packages/protocol/docs/native_token_support.md index f89bfe71ce2..0949b51d335 100644 --- a/packages/protocol/docs/native_token_support.md +++ b/packages/protocol/docs/native_token_support.md @@ -4,7 +4,7 @@ Taiko's briding concept is a lock-and-mint type. It simply means (the red path above) on the canonical chain we take custody of the assets and on the destination chain we mint the wrapped counterpart. When someone wants to bridge back (from destination to canonical) it will first burn the tokens, then release the funds on the canonical chain. -But there might be some incentives (e.g.: adoption, liquidity fragmentation, etc.) when deploying a native token on the destination chain is beneficial. For this reason Taiko introduced the possibilty of deploying the canonical assets (together with all their sub/parent/proxy contracts) and plug it into our ERC20Vault via adapters (green path). +But there might be some incentives (e.g.: adoption, liquidity fragmentation, etc.) when deploying a native token on the destination chain is beneficial. For this reason Taiko introduced the possibility of deploying the canonical assets (together with all their sub/parent/proxy contracts) and plug it into our ERC20Vault via adapters (green path). Important to note that while wrapped asset briding is 'automatical', the native one requires the willingness and efforts from Taiko side (and maybe also original token issuer green light to recognise officially as "native"), to support that type of asset-transfer.