From dd1eb4fa859f086de00bc82b147da79cf37a5340 Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Fri, 24 Mar 2023 11:04:44 +0800 Subject: [PATCH 1/2] gasUsed --- packages/protocol/contracts/L1/TaikoData.sol | 1 + .../protocol/contracts/L1/libs/LibProving.sol | 9 +++++---- packages/protocol/test2/TaikoL1.t.sol | 15 ++++++++++----- packages/protocol/test2/TaikoL1TestBase.sol | 4 +++- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/packages/protocol/contracts/L1/TaikoData.sol b/packages/protocol/contracts/L1/TaikoData.sol index e34bbed85f3..c3b6a699d52 100644 --- a/packages/protocol/contracts/L1/TaikoData.sol +++ b/packages/protocol/contracts/L1/TaikoData.sol @@ -91,6 +91,7 @@ library TaikoData { bytes32 blockHash; bytes32 signalRoot; address prover; + uint64 gasUsed; } struct ForkChoice { diff --git a/packages/protocol/contracts/L1/libs/LibProving.sol b/packages/protocol/contracts/L1/libs/LibProving.sol index ff4914fef94..d47ddd173d7 100644 --- a/packages/protocol/contracts/L1/libs/LibProving.sol +++ b/packages/protocol/contracts/L1/libs/LibProving.sol @@ -131,7 +131,7 @@ library LibProving { false ); - bytes32[9] memory inputs; + bytes32[10] memory inputs; inputs[0] = bytes32(uint256(uint160(l1SignalService))); inputs[1] = bytes32(uint256(uint160(l2SignalService))); inputs[2] = bytes32(uint256(uint160(taikoL2))); @@ -139,16 +139,17 @@ library LibProving { inputs[4] = evidence.blockHash; inputs[5] = evidence.signalRoot; inputs[6] = bytes32(uint256(uint160(evidence.prover))); - inputs[7] = blk.metaHash; + inputs[7] = bytes32(uint256(evidence.gasUsed)); // TODO(faniel): document this + inputs[8] = blk.metaHash; // Circuits shall use this value to check anchor gas limit. // Note that this value is not necessary and can be hard-coded // in to the circuit code, but if we upgrade the protocol // and the gas limit changes, then having it here may be handy. - inputs[8] = bytes32(config.anchorTxGasLimit); + inputs[9] = bytes32(config.anchorTxGasLimit); assembly { - instance := keccak256(inputs, mul(32, 9)) + instance := keccak256(inputs, mul(32, 10)) } } diff --git a/packages/protocol/test2/TaikoL1.t.sol b/packages/protocol/test2/TaikoL1.t.sol index be427ea5d9a..ff5bb22ea65 100644 --- a/packages/protocol/test2/TaikoL1.t.sol +++ b/packages/protocol/test2/TaikoL1.t.sol @@ -79,6 +79,7 @@ contract TaikoL1Test is TaikoL1TestBase { _depositTaikoToken(Carol, 1E6, 100); bytes32 parentHash = GENESIS_BLOCK_HASH; + uint64 gasUsed = 1000000; for ( uint256 blockId = 1; @@ -92,7 +93,7 @@ contract TaikoL1Test is TaikoL1TestBase { bytes32 blockHash = bytes32(1E10 + blockId); bytes32 signalRoot = bytes32(1E9 + blockId); - proveBlock(Bob, meta, parentHash, blockHash, signalRoot); + proveBlock(Bob, gasUsed, meta, parentHash, blockHash, signalRoot); verifyBlock(Carol, 1); parentHash = blockHash; } @@ -105,6 +106,7 @@ contract TaikoL1Test is TaikoL1TestBase { _depositTaikoToken(Alice, 1000, 1000); bytes32 parentHash = GENESIS_BLOCK_HASH; + uint64 gasUsed = 1000000; for (uint256 blockId = 1; blockId <= 2; blockId++) { printVariables("before propose"); @@ -113,7 +115,7 @@ contract TaikoL1Test is TaikoL1TestBase { bytes32 blockHash = bytes32(1E10 + blockId); bytes32 signalRoot = bytes32(1E9 + blockId); - proveBlock(Alice, meta, parentHash, blockHash, signalRoot); + proveBlock(Alice, gasUsed, meta, parentHash, blockHash, signalRoot); verifyBlock(Alice, 2); parentHash = blockHash; } @@ -125,6 +127,7 @@ contract TaikoL1Test is TaikoL1TestBase { _depositTaikoToken(Alice, 1E6, 100); bytes32 parentHash = GENESIS_BLOCK_HASH; + uint64 gasUsed = 1000000; for ( uint256 blockId = 1; @@ -137,7 +140,7 @@ contract TaikoL1Test is TaikoL1TestBase { bytes32 blockHash = bytes32(1E10 + blockId); bytes32 signalRoot = bytes32(1E9 + blockId); - proveBlock(Alice, meta, parentHash, blockHash, signalRoot); + proveBlock(Alice, gasUsed, meta, parentHash, blockHash, signalRoot); parentHash = blockHash; } verifyBlock(Alice, conf.maxNumProposedBlocks - 2); @@ -153,6 +156,7 @@ contract TaikoL1Test is TaikoL1TestBase { _depositTaikoToken(Carol, 1E6, 100); bytes32 parentHash = GENESIS_BLOCK_HASH; + uint64 gasUsed = 1000000; for ( uint256 blockId = 1; @@ -165,7 +169,7 @@ contract TaikoL1Test is TaikoL1TestBase { bytes32 blockHash = bytes32(1E10 + blockId); bytes32 signalRoot = bytes32(1E9 + blockId); - proveBlock(Bob, meta, parentHash, blockHash, signalRoot); + proveBlock(Bob, gasUsed, meta, parentHash, blockHash, signalRoot); verifyBlock(Carol, 1); mine(blockId); parentHash = blockHash; @@ -181,6 +185,7 @@ contract TaikoL1Test is TaikoL1TestBase { _depositTaikoToken(Carol, 1E6, 100); bytes32 parentHash = GENESIS_BLOCK_HASH; + uint64 gasUsed = 1000000; uint256 total = conf.maxNumProposedBlocks * 10; @@ -191,7 +196,7 @@ contract TaikoL1Test is TaikoL1TestBase { bytes32 blockHash = bytes32(1E10 + blockId); bytes32 signalRoot = bytes32(1E9 + blockId); - proveBlock(Bob, meta, parentHash, blockHash, signalRoot); + proveBlock(Bob, gasUsed, meta, parentHash, blockHash, signalRoot); verifyBlock(Carol, 1); mine(total + 1 - blockId); parentHash = blockHash; diff --git a/packages/protocol/test2/TaikoL1TestBase.sol b/packages/protocol/test2/TaikoL1TestBase.sol index ef4df260133..f2441e63ac5 100644 --- a/packages/protocol/test2/TaikoL1TestBase.sol +++ b/packages/protocol/test2/TaikoL1TestBase.sol @@ -110,6 +110,7 @@ abstract contract TaikoL1TestBase is Test { function proveBlock( address prover, + uint64 gasUsed, TaikoData.BlockMetadata memory meta, bytes32 parentHash, bytes32 blockHash, @@ -126,7 +127,8 @@ abstract contract TaikoL1TestBase is Test { parentHash: parentHash, blockHash: blockHash, signalRoot: signalRoot, - prover: prover + prover: prover, + gasUsed: gasUsed }); vm.prank(prover, prover); From e84b674883084f4aee65200b912ed3b3daab9dcf Mon Sep 17 00:00:00 2001 From: Daniel Wang <99078276+dantaik@users.noreply.github.com> Date: Fri, 24 Mar 2023 12:07:54 +0800 Subject: [PATCH 2/2] Update packages/protocol/contracts/L1/libs/LibProving.sol Co-authored-by: David --- packages/protocol/contracts/L1/libs/LibProving.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/contracts/L1/libs/LibProving.sol b/packages/protocol/contracts/L1/libs/LibProving.sol index d47ddd173d7..60db6f4e63f 100644 --- a/packages/protocol/contracts/L1/libs/LibProving.sol +++ b/packages/protocol/contracts/L1/libs/LibProving.sol @@ -139,7 +139,7 @@ library LibProving { inputs[4] = evidence.blockHash; inputs[5] = evidence.signalRoot; inputs[6] = bytes32(uint256(uint160(evidence.prover))); - inputs[7] = bytes32(uint256(evidence.gasUsed)); // TODO(faniel): document this + inputs[7] = bytes32(uint256(evidence.gasUsed)); // TODO(daniel): document this inputs[8] = blk.metaHash; // Circuits shall use this value to check anchor gas limit.