Skip to content

Commit

Permalink
fix(protocol): fix tid in getTransitionByParentHash (#18895)
Browse files Browse the repository at this point in the history
Co-authored-by: xiaodino <[email protected]>
  • Loading branch information
davidtaikocha and xiaodino authored Feb 10, 2025
1 parent 30428c2 commit 0071fcb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
15 changes: 14 additions & 1 deletion packages/protocol/contracts/layer1/based/TaikoInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,20 @@ abstract contract TaikoInbox is EssentialContract, ITaikoInbox, ITaiko {
Batch storage batch = state.batches[slot];
require(batch.batchId == _batchId, BatchNotFound());

uint24 tid = state.transitionIds[_batchId][_parentHash];
uint24 tid;
if (batch.nextTransitionId > 1) {
// This batch has at least one transition.
if (state.transitions[slot][1].parentHash == _parentHash) {
// Overwrite the first transition.
tid = 1;
} else if (batch.nextTransitionId > 2) {
// Retrieve the transition ID using the parent hash from the mapping. If the ID
// is 0, it indicates a new transition; otherwise, it's an overwrite of an
// existing transition.
tid = state.transitionIds[_batchId][_parentHash];
}
}

require(tid != 0 && tid < batch.nextTransitionId, TransitionNotFound());
return state.transitions[slot][tid];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,12 @@ contract InboxTest_ProposeAndProve is InboxTestBase {
assertEq(ts.stateRoot, bytes32(uint256(0)));

vm.expectRevert(ITaikoInbox.TransitionNotFound.selector);
ts = inbox.getTransitionByParentHash(9, ts.parentHash);
ts = inbox.getTransitionByParentHash(9, correctBlockhash(9));

ts = inbox.getTransitionByParentHash(9, correctBlockhash(8));
assertEq(ts.parentHash, correctBlockhash(8));
assertEq(ts.blockHash, correctBlockhash(9));
assertEq(ts.stateRoot, bytes32(uint256(0)));

(batchId, blockId, ts) = inbox.getLastSyncedTransition();
assertEq(batchId, 5);
Expand Down

0 comments on commit 0071fcb

Please sign in to comment.