From 7f03d795b845a6108574b69b56c71e95cd5efcd0 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 23 Jan 2023 23:57:06 -0800 Subject: [PATCH 1/4] protocol fixes --- packages/protocol/contracts/L1/TaikoL1.sol | 7 +++++-- packages/protocol/contracts/L1/libs/LibVerifying.sol | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/protocol/contracts/L1/TaikoL1.sol b/packages/protocol/contracts/L1/TaikoL1.sol index 076a09c092c..1ee22f5c98f 100644 --- a/packages/protocol/contracts/L1/TaikoL1.sol +++ b/packages/protocol/contracts/L1/TaikoL1.sol @@ -161,7 +161,7 @@ contract TaikoL1 is EssentialContract, IHeaderSync, TaikoEvents { state: state, config: config, resolver: AddressResolver(this), - maxBlocks: config.maxVerificationsPerTx, + maxBlocks: config.maxVerificationsPerTx + 1, checkHalt: false }); } @@ -247,7 +247,10 @@ contract TaikoL1 is EssentialContract, IHeaderSync, TaikoEvents { } function getLatestSyncedHeader() public view override returns (bytes32) { - return state.getL2BlockHash(state.latestVerifiedHeight); + return + state.getL2BlockHash( + state.latestVerifiedHeight & getConfig().blockHashHistory + ); } function getStateVariables() diff --git a/packages/protocol/contracts/L1/libs/LibVerifying.sol b/packages/protocol/contracts/L1/libs/LibVerifying.sol index 40bcd1dd68d..ecdc3cb726f 100644 --- a/packages/protocol/contracts/L1/libs/LibVerifying.sol +++ b/packages/protocol/contracts/L1/libs/LibVerifying.sol @@ -62,7 +62,7 @@ library LibVerifying { for ( uint256 i = state.latestVerifiedId + 1; - i < state.nextBlockId && processed <= maxBlocks; + i < state.nextBlockId && processed < maxBlocks; i++ ) { TaikoData.ForkChoice storage fc = state.forkChoices[i][ From a20a867e51d29d0a5a7f03e191faceb81d614d9d Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Tue, 24 Jan 2023 00:01:34 -0800 Subject: [PATCH 2/4] typo --- packages/protocol/contracts/L1/TaikoL1.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/protocol/contracts/L1/TaikoL1.sol b/packages/protocol/contracts/L1/TaikoL1.sol index 1ee22f5c98f..3d878e302b8 100644 --- a/packages/protocol/contracts/L1/TaikoL1.sol +++ b/packages/protocol/contracts/L1/TaikoL1.sol @@ -89,7 +89,7 @@ contract TaikoL1 is EssentialContract, IHeaderSync, TaikoEvents { state: state, config: getConfig(), resolver: AddressResolver(this), - maxBlocks: config.maxVerificationsPerTx, + maxBlocks: config.maxVerificationsPerTx + 1, checkHalt: false }); } @@ -125,7 +125,7 @@ contract TaikoL1 is EssentialContract, IHeaderSync, TaikoEvents { state: state, config: config, resolver: AddressResolver(this), - maxBlocks: config.maxVerificationsPerTx, + maxBlocks: config.maxVerificationsPerTx + 1, checkHalt: false }); } @@ -249,7 +249,7 @@ contract TaikoL1 is EssentialContract, IHeaderSync, TaikoEvents { function getLatestSyncedHeader() public view override returns (bytes32) { return state.getL2BlockHash( - state.latestVerifiedHeight & getConfig().blockHashHistory + state.latestVerifiedHeight % getConfig().blockHashHistory ); } From 1ca6b5268169e5cbc32c91b4e45b9ea3082538fd Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Tue, 24 Jan 2023 10:18:09 -0800 Subject: [PATCH 3/4] fix late night sleepy brain --- packages/protocol/contracts/L1/TaikoL1.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/protocol/contracts/L1/TaikoL1.sol b/packages/protocol/contracts/L1/TaikoL1.sol index 3d878e302b8..95ed82d2fdc 100644 --- a/packages/protocol/contracts/L1/TaikoL1.sol +++ b/packages/protocol/contracts/L1/TaikoL1.sol @@ -89,7 +89,7 @@ contract TaikoL1 is EssentialContract, IHeaderSync, TaikoEvents { state: state, config: getConfig(), resolver: AddressResolver(this), - maxBlocks: config.maxVerificationsPerTx + 1, + maxBlocks: config.maxVerificationsPerTx, checkHalt: false }); } @@ -125,7 +125,7 @@ contract TaikoL1 is EssentialContract, IHeaderSync, TaikoEvents { state: state, config: config, resolver: AddressResolver(this), - maxBlocks: config.maxVerificationsPerTx + 1, + maxBlocks: config.maxVerificationsPerTx, checkHalt: false }); } @@ -161,7 +161,7 @@ contract TaikoL1 is EssentialContract, IHeaderSync, TaikoEvents { state: state, config: config, resolver: AddressResolver(this), - maxBlocks: config.maxVerificationsPerTx + 1, + maxBlocks: config.maxVerificationsPerTx, checkHalt: false }); } From a56c4eadebca43fad7a89fbbb5dc17ef20fb6cef Mon Sep 17 00:00:00 2001 From: Daniel Wang <99078276+dantaik@users.noreply.github.com> Date: Wed, 25 Jan 2023 10:00:07 +0800 Subject: [PATCH 4/4] fix(protocol): fix bug in getLatestSyncedHeader on TaikoL1 (#13042) --- packages/protocol/contracts/L1/TaikoL1.sol | 8 ++++---- packages/protocol/contracts/L1/libs/LibUtils.sol | 11 ++++++++--- packages/protocol/contracts/L1/libs/LibVerifying.sol | 4 +++- packages/protocol/test/L1/TaikoL1.test.ts | 2 +- packages/protocol/test/utils/propose.ts | 2 +- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/protocol/contracts/L1/TaikoL1.sol b/packages/protocol/contracts/L1/TaikoL1.sol index 95ed82d2fdc..5116f71aef4 100644 --- a/packages/protocol/contracts/L1/TaikoL1.sol +++ b/packages/protocol/contracts/L1/TaikoL1.sol @@ -241,15 +241,15 @@ 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 % getConfig().blockHashHistory + state.latestVerifiedHeight, + getConfig().blockHashHistory ); } diff --git a/packages/protocol/contracts/L1/libs/LibUtils.sol b/packages/protocol/contracts/L1/libs/LibUtils.sol index 22059debc17..7fd91857d4d 100644 --- a/packages/protocol/contracts/L1/libs/LibUtils.sol +++ b/packages/protocol/contracts/L1/libs/LibUtils.sol @@ -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( diff --git a/packages/protocol/contracts/L1/libs/LibVerifying.sol b/packages/protocol/contracts/L1/libs/LibVerifying.sol index ecdc3cb726f..ab75b355d70 100644 --- a/packages/protocol/contracts/L1/libs/LibVerifying.sol +++ b/packages/protocol/contracts/L1/libs/LibVerifying.sol @@ -57,7 +57,9 @@ library LibVerifying { } uint64 latestL2Height = state.latestVerifiedHeight; - bytes32 latestL2Hash = state.l2Hashes[latestL2Height]; + bytes32 latestL2Hash = state.l2Hashes[ + latestL2Height % config.blockHashHistory + ]; uint64 processed = 0; for ( diff --git a/packages/protocol/test/L1/TaikoL1.test.ts b/packages/protocol/test/L1/TaikoL1.test.ts index 96d70461eb4..3c7c5fb34c0 100644 --- a/packages/protocol/test/L1/TaikoL1.test.ts +++ b/packages/protocol/test/L1/TaikoL1.test.ts @@ -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" ); }); diff --git a/packages/protocol/test/utils/propose.ts b/packages/protocol/test/utils/propose.ts index 7d961c0ae50..2f718fc7610 100644 --- a/packages/protocol/test/utils/propose.ts +++ b/packages/protocol/test/utils/propose.ts @@ -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; };