Skip to content

Commit

Permalink
add firstBlobIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik committed Jan 13, 2025
1 parent 9590d17 commit 2b4041c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
12 changes: 12 additions & 0 deletions packages/protocol/contracts/layer1/based/ITaikoInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ import "src/shared/based/LibSharedData.sol";
/// @custom:security-contact [email protected]
interface ITaikoInbox {
struct BlockParams {
// the max nubmer of transactions in this block. Note that if there are not enough

Check warning on line 21 in packages/protocol/contracts/layer1/based/ITaikoInbox.sol

View workflow job for this annotation

GitHub Actions / check-for-typos

"nubmer" should be "number".
// transactions in calldata or blobs, the block will contains as many transactions as
// possible.
uint16 numTransactions;
// For the first block in a batch, the block timestamp is the batch params' `timestamp`
// plus this time shift value;
// For all other blocks in the same batch, the block timestamp is its parent block's
// timestamp plus this time shift value.
uint8 timeThift;
}

Expand All @@ -31,9 +38,14 @@ interface ITaikoInbox {
uint64 timestamp;
uint32 txListOffset;
uint32 txListSize;
// The index of the first blob in this batch.
uint8 firstBlobIndex;
// The number of blobs in this batch. Blobs are initially concatenated and subsequently
// decompressed via Zlib.
uint8 numBlobs;
bool revertIfNotFirstProposal;
bytes32[] signalSlots;
// Specifies the number of blocks to be generated from this batch.
BlockParams[] blocks;
}

Expand Down
16 changes: 13 additions & 3 deletions packages/protocol/contracts/layer1/based/TaikoInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ abstract contract TaikoInbox is EssentialContract, ITaikoInbox, ITaiko, IFork {
// the following approach to calculate a block's difficulty:
// `keccak256(abi.encode("TAIKO_DIFFICULTY", block.number))`
meta_ = BatchMetadata({
txListHash: calldataUsed ? keccak256(_txList) : _calcTxListHash(params.numBlobs),
txListHash: calldataUsed
? keccak256(_txList)
: _calcTxListHash(params.firstBlobIndex, params.numBlobs),
extraData: bytes32(uint256(config.baseFeeConfig.sharingPctg)),
coinbase: params.coinbase,
batchId: stats2.numBatches,
Expand Down Expand Up @@ -457,10 +459,18 @@ abstract contract TaikoInbox is EssentialContract, ITaikoInbox, ITaiko, IFork {
state.stats2.paused = true;
}

function _calcTxListHash(uint8 _numBlobs) internal view virtual returns (bytes32) {
function _calcTxListHash(
uint8 _firstBlobIndex,
uint8 _numBlobs
)
internal
view
virtual
returns (bytes32)
{
bytes32[] memory blobHashes = new bytes32[](_numBlobs);
for (uint256 i; i < _numBlobs; ++i) {
blobHashes[i] = blobhash(i);
blobHashes[i] = blobhash(_firstBlobIndex + i);
require(blobHashes[i] != 0, BlobNotFound());
}
return keccak256(abi.encode(blobHashes));
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/test/layer1/Layer1Test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ contract ConfigurableInbox is TaikoInbox {
return __config;
}

function _calcTxListHash(uint8) internal pure override returns (bytes32) {
function _calcTxListHash(uint8, uint8) internal pure override returns (bytes32) {
return keccak256("BLOB");
}
}
Expand Down

0 comments on commit 2b4041c

Please sign in to comment.