Skip to content

Commit

Permalink
Merge branch 'main' into improve_test_coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
adaki2004 authored Mar 14, 2024
2 parents 81eb419 + c2d7d6e commit b2fb0e1
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 130 deletions.
2 changes: 1 addition & 1 deletion packages/protocol/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
22 changes: 3 additions & 19 deletions packages/protocol/contracts/L1/TaikoData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
// ---------------------------------------------------------------------
Expand Down Expand Up @@ -79,10 +71,6 @@ library TaikoData {
address assignedProver;
address coinbase;
bytes32 extraData;
bytes32 blobHash;
uint24 txListByteOffset;
uint24 txListByteSize;
bool cacheBlobForReuse;
bytes32 parentMetaHash;
HookCall[] hookCalls;
}
Expand All @@ -102,8 +90,6 @@ library TaikoData {
uint32 gasLimit;
uint64 timestamp;
uint64 l1Height;
uint24 txListByteOffset;
uint24 txListByteSize;
uint16 minTier;
bool blobUsed;
bytes32 parentMetaHash;
Expand Down Expand Up @@ -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;
}
}
5 changes: 1 addition & 4 deletions packages/protocol/contracts/L1/TaikoErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
4 changes: 0 additions & 4 deletions packages/protocol/contracts/L1/TaikoEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 0 additions & 12 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
89 changes: 9 additions & 80 deletions packages/protocol/contracts/L1/libs/LibProposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();

Expand Down Expand Up @@ -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,
Expand All @@ -140,61 +125,22 @@ 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
// internal one, making calldata retrieval more straightforward for
// 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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions packages/protocol/contracts/L1/libs/LibVerifying.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/protocol/contracts/compiled/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/docs/actors_privileges_deployments.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/docs/native_token_support.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/test/L1/TaikoL1TestBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
Expand Down

0 comments on commit b2fb0e1

Please sign in to comment.