Skip to content

Commit

Permalink
Merge branch 'pacaya_subblocks' into pacaya_fork_client
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored Jan 12, 2025
2 parents f4e64dc + 2284ff9 commit 1924474
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,4 @@ __pycache__/

# Idea
.idea/
packages/protocol/snapshots/InboxTest_Suite1.json
8 changes: 5 additions & 3 deletions packages/protocol/contracts/layer1/based/ITaikoInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ interface ITaikoInbox {
/// @notice Forge is only able to run coverage in case the contracts by default capable of
/// compiling without any optimization (neither optimizer runs, no compiling --via-ir flag).
struct Stats1 {
uint64 __reserved1;
uint64 genesisHeight;
uint64 __reserved2;
uint64 lastSyncedBatchId;
uint64 lastSyncedAt;
Expand Down Expand Up @@ -306,19 +306,21 @@ interface ITaikoInbox {

/// @notice Retrieves the transition used for the last verified batch.
/// @return batchId_ The batch ID of the last verified transition.
/// @return blockId_ The block ID of the last verified block.
/// @return tran_ The last verified transition.
function getLastVerifiedTransition()
external
view
returns (uint64 batchId_, Transition memory tran_);
returns (uint64 batchId_, uint64 blockId_, Transition memory tran_);

/// @notice Retrieves the transition used for the last synced batch.
/// @return batchId_ The batch ID of the last synced transition.
/// @return blockId_ The block ID of the last synced block.
/// @return tran_ The last synced transition.
function getLastSyncedTransition()
external
view
returns (uint64 batchId_, Transition memory tran_);
returns (uint64 batchId_, uint64 blockId_, Transition memory tran_);

/// @notice Retrieves the transition used for verifying a batch.
/// @param _batchId The batch ID.
Expand Down
27 changes: 16 additions & 11 deletions packages/protocol/contracts/layer1/based/TaikoInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -339,19 +339,21 @@ abstract contract TaikoInbox is EssentialContract, ITaikoInbox, ITaiko {
function getLastVerifiedTransition()
external
view
returns (uint64 batchId_, Transition memory tran_)
returns (uint64 batchId_, uint64 blockId_, Transition memory tran_)
{
batchId_ = state.stats2.lastVerifiedBatchId;
blockId_ = getBatch(batchId_).lastBlockId;
tran_ = getBatchVerifyingTransition(batchId_);
}

/// @inheritdoc ITaikoInbox
function getLastSyncedTransition()
external
view
returns (uint64 batchId_, Transition memory tran_)
returns (uint64 batchId_, uint64 blockId_, Transition memory tran_)
{
batchId_ = state.stats1.lastSyncedBatchId;
blockId_ = getBatch(batchId_).lastBlockId;
tran_ = getBatchVerifyingTransition(batchId_);
}

Expand All @@ -360,15 +362,6 @@ abstract contract TaikoInbox is EssentialContract, ITaikoInbox, ITaiko {
return state.bondBalance[_user];
}

/// @inheritdoc ITaikoInbox
function getBatch(uint64 _batchId) external view returns (Batch memory batch_) {
Config memory config = getConfig();
require(_batchId >= config.forkHeights.pacaya, InvalidForkHeight());

batch_ = state.batches[_batchId % config.batchRingBufferSize];
require(batch_.batchId == _batchId, BatchNotFound());
}

/// @notice Determines the operational layer of the contract, whether it is on Layer 1 (L1) or
/// Layer 2 (L2).
/// @return True if the contract is operating on L1, false if on L2.
Expand All @@ -388,6 +381,15 @@ abstract contract TaikoInbox is EssentialContract, ITaikoInbox, ITaiko {
return resolve(LibStrings.B_BOND_TOKEN, true);
}

/// @inheritdoc ITaikoInbox
function getBatch(uint64 _batchId) public view returns (Batch memory batch_) {
Config memory config = getConfig();
require(_batchId >= config.forkHeights.pacaya, InvalidForkHeight());

batch_ = state.batches[_batchId % config.batchRingBufferSize];
require(batch_.batchId == _batchId, BatchNotFound());
}

/// @inheritdoc ITaikoInbox
function getBatchVerifyingTransition(uint64 _batchId)
public
Expand Down Expand Up @@ -429,8 +431,11 @@ abstract contract TaikoInbox is EssentialContract, ITaikoInbox, ITaiko {
batch.nextTransitionId = 2;
batch.verifiedTransitionId = 1;

state.stats1.genesisHeight = uint64(block.number);

state.stats2.lastProposedIn = uint56(block.number);
state.stats2.numBatches = 1;

emit BatchesVerified(0, _genesisBlockHash);
}

Expand Down
4 changes: 0 additions & 4 deletions packages/protocol/snapshots/InboxTest_Suite1.json

This file was deleted.

21 changes: 15 additions & 6 deletions packages/protocol/test/layer1/based/InboxTest_Suite1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,16 @@ contract InboxTest_Suite1 is InboxTestBase {
assertEq(blk.nextTransitionId, 2);
assertEq(blk.verifiedTransitionId, 1);

(uint64 batchId, ITaikoInbox.Transition memory tran) = inbox.getLastVerifiedTransition();
(uint64 batchId, uint64 blockId, ITaikoInbox.Transition memory tran) =
inbox.getLastVerifiedTransition();
assertEq(batchId, 0);
assertEq(blockId, 0);
assertEq(tran.blockHash, correctBlockhash(0));
assertEq(tran.stateRoot, bytes32(uint256(0)));

(batchId, tran) = inbox.getLastSyncedTransition();
(batchId, blockId, tran) = inbox.getLastSyncedTransition();
assertEq(batchId, 0);
assertEq(blockId, 0);
assertEq(tran.blockHash, correctBlockhash(0));
assertEq(tran.stateRoot, bytes32(uint256(0)));
}
Expand Down Expand Up @@ -208,13 +211,16 @@ contract InboxTest_Suite1 is InboxTestBase {
assertEq(stats2.lastProposedIn, block.number);
assertEq(stats2.lastUnpausedAt, 0);

(uint64 batchId, ITaikoInbox.Transition memory tran) = inbox.getLastVerifiedTransition();
(uint64 batchId, uint64 blockId, ITaikoInbox.Transition memory tran) =
inbox.getLastVerifiedTransition();
assertEq(batchId, 9);
assertEq(blockId, 9);
assertEq(tran.blockHash, correctBlockhash(9));
assertEq(tran.stateRoot, bytes32(uint256(0)));

(batchId, tran) = inbox.getLastSyncedTransition();
(batchId, blockId, tran) = inbox.getLastSyncedTransition();
assertEq(batchId, 5);
assertEq(blockId, 5);
assertEq(tran.blockHash, correctBlockhash(5));
assertEq(tran.stateRoot, correctStateRoot(5));

Expand Down Expand Up @@ -316,13 +322,16 @@ contract InboxTest_Suite1 is InboxTestBase {
assertEq(stats2.lastProposedIn, block.number);
assertEq(stats2.lastUnpausedAt, 0);

(uint64 batchId, ITaikoInbox.Transition memory tran) = inbox.getLastVerifiedTransition();
(uint64 batchId, uint64 blockId, ITaikoInbox.Transition memory tran) =
inbox.getLastVerifiedTransition();
assertEq(batchId, 10);
assertEq(blockId, 10);
assertEq(tran.blockHash, correctBlockhash(10));
assertEq(tran.stateRoot, correctStateRoot(10));

(batchId, tran) = inbox.getLastSyncedTransition();
(batchId, blockId, tran) = inbox.getLastSyncedTransition();
assertEq(batchId, 10);
assertEq(blockId, 10);
assertEq(tran.blockHash, correctBlockhash(10));
assertEq(tran.stateRoot, correctStateRoot(10));

Expand Down
8 changes: 6 additions & 2 deletions packages/protocol/test/layer1/based/helpers/StubInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@ contract StubInbox is ITaikoInbox {
function getLastVerifiedTransition()
external
view
returns (uint64 batchId_, Transition memory)
returns (uint64 batchId_, uint64 blockId_, Transition memory)
{ }

function getLastSyncedTransition() external view returns (uint64 batchId_, Transition memory) { }
function getLastSyncedTransition()
external
view
returns (uint64 batchId_, uint64 blockId_, Transition memory)
{ }

function getBatchVerifyingTransition(uint64 _batchId)
external
Expand Down

0 comments on commit 1924474

Please sign in to comment.