From ecb9cc543513e61ae9efbdfb17cacda87ce3f70d Mon Sep 17 00:00:00 2001 From: Daniel Wang <99078276+dantaik@users.noreply.github.com> Date: Sat, 24 Dec 2022 15:19:10 +0800 Subject: [PATCH] feat(protocol): invalidBlock must from golden touch address with 0 gasprice (#482) --- packages/protocol/contracts/L2/TaikoL2.sol | 7 ++++++ .../test/genesis/generate_genesis.test.sh | 2 -- .../test/genesis/generate_genesis.test.ts | 22 +++++++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/packages/protocol/contracts/L2/TaikoL2.sol b/packages/protocol/contracts/L2/TaikoL2.sol index 68f4be6a518..1daa811e8bf 100644 --- a/packages/protocol/contracts/L2/TaikoL2.sol +++ b/packages/protocol/contracts/L2/TaikoL2.sol @@ -14,6 +14,7 @@ import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import "../common/AddressResolver.sol"; import "../common/IHeaderSync.sol"; +import "../libs/LibAnchorSignature.sol"; import "../libs/LibInvalidTxList.sol"; import "../libs/LibConstants.sol"; import "../libs/LibTxDecoder.sol"; @@ -96,6 +97,12 @@ contract TaikoL2 is AddressResolver, ReentrancyGuard, IHeaderSync { LibInvalidTxList.Reason hint, uint256 txIdx ) external { + require( + msg.sender == LibAnchorSignature.K_GOLDEN_TOUCH_ADDRESS, + "L2:sender" + ); + require(tx.gasprice == 0, "L2:gasPrice"); + LibInvalidTxList.Reason reason = LibInvalidTxList.isTxListInvalid({ encoded: txList, hint: hint, diff --git a/packages/protocol/test/genesis/generate_genesis.test.sh b/packages/protocol/test/genesis/generate_genesis.test.sh index e7cc7416a74..97dd5112843 100755 --- a/packages/protocol/test/genesis/generate_genesis.test.sh +++ b/packages/protocol/test/genesis/generate_genesis.test.sh @@ -34,8 +34,6 @@ echo ' "istanbulBlock": 0, "muirGlacierBlock": 0, "berlinBlock": 0, - "londonBlock": 0, - "arrowGlacierBlock": 0, "clique": { "period": 0, "epoch": 30000 diff --git a/packages/protocol/test/genesis/generate_genesis.test.ts b/packages/protocol/test/genesis/generate_genesis.test.ts index 42856a22df4..d7721e37cc5 100644 --- a/packages/protocol/test/genesis/generate_genesis.test.ts +++ b/packages/protocol/test/genesis/generate_genesis.test.ts @@ -180,10 +180,28 @@ action("Generate Genesis", function () { const [bytes, txNums] = await generateMaxSizeInvalidTxList(TaikoL2); - const tx = await TaikoL2.invalidateBlock( + await expect( + TaikoL2.invalidateBlock( + bytes, + 5, // hint: TX_INVALID_SIG + 0 + ) + ).to.be.revertedWith("L2:sender") + + const taikoL2WithGoldenTouchSigner = new hre.ethers.Contract( + TaikoL2Alloc.address, + require("../../artifacts/contracts/L2/TaikoL2.sol/TaikoL2.json").abi, + new hre.ethers.Wallet( + "92954368afd3caa1f3ce3ead0069c1af414054aefe1ef9aeacc1bf426222ce38", + provider + ) + ) + + const tx = await taikoL2WithGoldenTouchSigner.invalidateBlock( bytes, 5, // hint: TX_INVALID_SIG - 0 + 0, + { gasPrice: 0 } ); const receipt = await tx.wait();