Skip to content

Commit

Permalink
fix(protocol): fix two protocol bugs (#13034)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Wang <[email protected]>
Co-authored-by: David <[email protected]>
  • Loading branch information
3 people authored Jan 25, 2023
1 parent 088933e commit 1bfa69b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
11 changes: 7 additions & 4 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,16 @@ contract TaikoL1 is EssentialContract, IHeaderSync, TaikoEvents {

function getSyncedHeader(
uint256 number
) public view override returns (bytes32 header) {
header = state.getL2BlockHash(number);
require(header != 0, "L1:number");
) public view override returns (bytes32) {
return state.getL2BlockHash(number, getConfig().blockHashHistory);
}

function getLatestSyncedHeader() public view override returns (bytes32) {
return state.getL2BlockHash(state.latestVerifiedHeight);
return
state.getL2BlockHash(
state.latestVerifiedHeight,
getConfig().blockHashHistory
);
}

function getStateVariables()
Expand Down
11 changes: 8 additions & 3 deletions packages/protocol/contracts/L1/libs/LibUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ library LibUtils {

function getL2BlockHash(
TaikoData.State storage state,
uint256 number
uint256 number,
uint256 blockHashHistory
) internal view returns (bytes32) {
require(number <= state.latestVerifiedHeight, "L1:id");
return state.l2Hashes[number];
require(
number + blockHashHistory > state.latestVerifiedHeight &&
number <= state.latestVerifiedHeight,
"L1:number"
);
return state.l2Hashes[number % blockHashHistory];
}

function getStateVariables(
Expand Down
6 changes: 4 additions & 2 deletions packages/protocol/contracts/L1/libs/LibVerifying.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ library LibVerifying {
}

uint64 latestL2Height = state.latestVerifiedHeight;
bytes32 latestL2Hash = state.l2Hashes[latestL2Height];
bytes32 latestL2Hash = state.l2Hashes[
latestL2Height % config.blockHashHistory
];
uint64 processed = 0;

for (
uint256 i = state.latestVerifiedId + 1;
i < state.nextBlockId && processed <= maxBlocks;
i < state.nextBlockId && processed < maxBlocks;
i++
) {
TaikoData.ForkChoice storage fc = state.forkChoices[i][
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/test/L1/TaikoL1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("TaikoL1", function () {
describe("getSyncedHeader()", async function () {
it("should revert because header number has not been synced", async function () {
await expect(taikoL1.getSyncedHeader(1)).to.be.revertedWith(
"L1:id"
"L1:number"
);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/test/utils/propose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const proposeBlock = async (
const inputs = buildProposeBlockInputs(block, meta);

const tx = await taikoL1.proposeBlock(inputs);
console.log("Proposed block", tx.hash);
// console.log("Proposed block", tx.hash);
const receipt = await tx.wait(1);
return receipt;
};
Expand Down

0 comments on commit 1bfa69b

Please sign in to comment.