Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(protocol): fix tid in getTransitionByParentHash #18895

Merged
merged 2 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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