Skip to content

Commit

Permalink
Merge branch 'main' into add-blob-storage
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhorsey authored Mar 14, 2024
2 parents 810a5c7 + 07a1a81 commit f833d0c
Show file tree
Hide file tree
Showing 21 changed files with 53 additions and 157 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ require (
golang.org/x/tools v0.15.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -919,8 +919,8 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
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
14 changes: 7 additions & 7 deletions packages/protocol/contracts/L1/TaikoToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ contract TaikoToken is EssentialContract, ERC20SnapshotUpgradeable, ERC20VotesUp
/// @param _from The address to burn tokens from.
/// @param _amount The amount of tokens to burn.
function burn(address _from, uint256 _amount) public onlyOwner {
_burn(_from, _amount);
return _burn(_from, _amount);
}

/// @notice Creates a new token snapshot.
function snapshot() public onlyFromOwnerOrNamed("snapshooter") {
_snapshot();
function snapshot() public onlyFromOwnerOrNamed("snapshooter") returns (uint256) {
return _snapshot();
}

/// @notice Transfers tokens to a specified address.
Expand Down Expand Up @@ -90,7 +90,7 @@ contract TaikoToken is EssentialContract, ERC20SnapshotUpgradeable, ERC20VotesUp
internal
override(ERC20Upgradeable, ERC20SnapshotUpgradeable)
{
super._beforeTokenTransfer(_from, _to, _amount);
return super._beforeTokenTransfer(_from, _to, _amount);
}

function _afterTokenTransfer(
Expand All @@ -101,7 +101,7 @@ contract TaikoToken is EssentialContract, ERC20SnapshotUpgradeable, ERC20VotesUp
internal
override(ERC20Upgradeable, ERC20VotesUpgradeable)
{
super._afterTokenTransfer(_from, _to, _amount);
return super._afterTokenTransfer(_from, _to, _amount);
}

function _mint(
Expand All @@ -111,7 +111,7 @@ contract TaikoToken is EssentialContract, ERC20SnapshotUpgradeable, ERC20VotesUp
internal
override(ERC20Upgradeable, ERC20VotesUpgradeable)
{
super._mint(_to, _amount);
return super._mint(_to, _amount);
}

function _burn(
Expand All @@ -121,6 +121,6 @@ contract TaikoToken is EssentialContract, ERC20SnapshotUpgradeable, ERC20VotesUp
internal
override(ERC20Upgradeable, ERC20VotesUpgradeable)
{
super._burn(_from, _amount);
return super._burn(_from, _amount);
}
}
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/gov/TaikoGovernor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ contract TaikoGovernor is
internal
override(GovernorUpgradeable, GovernorTimelockControlUpgradeable)
{
super._execute(_proposalId, _targets, _values, _calldatas, _descriptionHash);
return super._execute(_proposalId, _targets, _values, _calldatas, _descriptionHash);
}

function _cancel(
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
Loading

0 comments on commit f833d0c

Please sign in to comment.