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 two protocol bugs #13034

Merged
merged 6 commits into from
Jan 25, 2023
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
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(
dantaik marked this conversation as resolved.
Show resolved Hide resolved
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;
cyberhorsey marked this conversation as resolved.
Show resolved Hide resolved
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