From 6e07ab5089602ef552592985d230c879b5905312 Mon Sep 17 00:00:00 2001 From: Daniel Wang <99078276+dantaik@users.noreply.github.com> Date: Thu, 20 Jun 2024 15:01:11 +0800 Subject: [PATCH] fix(protocol): fix getLastSyncedBlock by writing the block's verifiedTransitionId (#17624) --- _typos.toml | 1 + packages/protocol/contracts/L1/ITaikoL1.sol | 2 +- packages/protocol/contracts/L1/TaikoL1.sol | 2 +- .../contracts/L1/libs/LibProposing.sol | 7 +++--- .../protocol/contracts/L1/libs/LibProving.sol | 2 -- .../contracts/L1/libs/LibVerifying.sol | 25 +++++++++++++++---- packages/protocol/contracts/bridge/Bridge.sol | 4 ++- .../deployments/mainnet-contract-logs-L1.md | 2 +- packages/protocol/test/L1/TaikoL1.t.sol | 2 +- .../test/L1/TaikoL1LibProvingWithTiers.t.sol | 2 +- .../protocol/test/L1/TaikoL1TestGroupBase.sol | 2 +- 11 files changed, 34 insertions(+), 17 deletions(-) diff --git a/_typos.toml b/_typos.toml index f2944533a6f..4a74cc8a8bc 100644 --- a/_typos.toml +++ b/_typos.toml @@ -5,6 +5,7 @@ extend-ignore-identifiers-re = [ "bafybeiegdqpwx3he5dvoxqklspdjekjepjcobfaakyficksratn73qbbyy", "TGE", "tge", + "baed" ] [files] diff --git a/packages/protocol/contracts/L1/ITaikoL1.sol b/packages/protocol/contracts/L1/ITaikoL1.sol index 2663c8b532e..b758d4a7106 100644 --- a/packages/protocol/contracts/L1/ITaikoL1.sol +++ b/packages/protocol/contracts/L1/ITaikoL1.sol @@ -36,5 +36,5 @@ interface ITaikoL1 { /// @notice Gets the configuration of the TaikoL1 contract. /// @return Config struct containing configuration parameters. - function getConfig() external view returns (TaikoData.Config memory); + function getConfig() external pure returns (TaikoData.Config memory); } diff --git a/packages/protocol/contracts/L1/TaikoL1.sol b/packages/protocol/contracts/L1/TaikoL1.sol index 90f28229707..6ef8058db45 100644 --- a/packages/protocol/contracts/L1/TaikoL1.sol +++ b/packages/protocol/contracts/L1/TaikoL1.sol @@ -222,7 +222,7 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents, TaikoErrors { } /// @inheritdoc ITaikoL1 - function getConfig() public view virtual override returns (TaikoData.Config memory) { + function getConfig() public pure virtual override returns (TaikoData.Config memory) { // All hard-coded configurations: // - treasury: the actual TaikoL2 address. // - anchorGasLimit: 250_000 (based on internal devnet, its ~220_000 diff --git a/packages/protocol/contracts/L1/libs/LibProposing.sol b/packages/protocol/contracts/L1/libs/LibProposing.sol index 7792cef0fd7..10c36e0bd52 100644 --- a/packages/protocol/contracts/L1/libs/LibProposing.sol +++ b/packages/protocol/contracts/L1/libs/LibProposing.sol @@ -174,9 +174,10 @@ library LibProposing { _tko.transferFrom(msg.sender, address(this), _config.livenessBond); - // Refund Ether - if (address(this).balance != 0) { - msg.sender.sendEtherAndVerify(address(this).balance); + // Bribe the block builder. Unlock 1559-tips, this tip is only made + // if this transaction succeeds. + if (msg.value != 0 && block.coinbase != address(0)) { + address(block.coinbase).sendEtherAndVerify(msg.value); } deposits_ = new TaikoData.EthDeposit[](0); diff --git a/packages/protocol/contracts/L1/libs/LibProving.sol b/packages/protocol/contracts/L1/libs/LibProving.sol index ef6f9451f74..5169100547f 100644 --- a/packages/protocol/contracts/L1/libs/LibProving.sol +++ b/packages/protocol/contracts/L1/libs/LibProving.sol @@ -387,8 +387,6 @@ library LibProving { uint256 reward; // reward to the new (current) prover if (_ts.contester != address(0)) { - // assert(_blk.livenessBond == 0); - if (_local.sameTransition) { // The contested transition is proven to be valid, contester loses the game reward = _rewardAfterFriction(_ts.contestBond); diff --git a/packages/protocol/contracts/L1/libs/LibVerifying.sol b/packages/protocol/contracts/L1/libs/LibVerifying.sol index d006d2b5678..a507eee05e5 100644 --- a/packages/protocol/contracts/L1/libs/LibVerifying.sol +++ b/packages/protocol/contracts/L1/libs/LibVerifying.sol @@ -19,8 +19,9 @@ library LibVerifying { uint32 lastVerifiedTransitionId; uint16 tier; bytes32 blockHash; - bytes32 stateRoot; + bytes32 syncStateRoot; uint64 syncBlockId; + uint32 syncTransitionId; address prover; ITierRouter tierRouter; } @@ -140,8 +141,12 @@ library LibVerifying { }); if (LibUtils.shouldSyncStateRoot(_config.stateRootSyncInternal, local.blockId)) { - local.stateRoot = ts.stateRoot; - local.syncBlockId = local.blockId; + bytes32 stateRoot = ts.stateRoot; + if (stateRoot != 0) { + local.syncStateRoot = stateRoot; + local.syncBlockId = local.blockId; + local.syncTransitionId = local.tid; + } } ++local.blockId; @@ -163,13 +168,23 @@ library LibVerifying { } if (!_tko.batchTransfer(provers, bonds)) revert L1_BATCH_TRANSFER_FAILED(); - if (local.stateRoot != 0) { + if (local.syncStateRoot != 0) { _state.slotA.lastSyncedBlockId = local.syncBlockId; _state.slotA.lastSynecdAt = uint64(block.timestamp); + // We write the synced block's verifiedTransitionId to storage + if (local.syncBlockId != lastVerifiedBlockId) { + local.slot = local.syncBlockId % _config.blockRingBufferSize; + _state.blocks[local.slot].verifiedTransitionId = local.syncTransitionId; + } + + // Ask signal service to write cross chain signal ISignalService(_resolver.resolve(LibStrings.B_SIGNAL_SERVICE, false)) .syncChainData( - _config.chainId, LibStrings.H_STATE_ROOT, local.syncBlockId, local.stateRoot + _config.chainId, + LibStrings.H_STATE_ROOT, + local.syncBlockId, + local.syncStateRoot ); } } diff --git a/packages/protocol/contracts/bridge/Bridge.sol b/packages/protocol/contracts/bridge/Bridge.sol index bec10f9fc37..6fa241d72e9 100644 --- a/packages/protocol/contracts/bridge/Bridge.sol +++ b/packages/protocol/contracts/bridge/Bridge.sol @@ -685,7 +685,9 @@ contract Bridge is EssentialContract, IBridge { } /// @dev Suggested by OpenZeppelin and copied from - /// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/83c7e45092dac350b070c421cd2bf7105616cf1a/contracts/metatx/ERC2771Forwarder.sol#L327C1-L370C6 + /// https://github.com/OpenZeppelin/openzeppelin-contracts/ + /// blob/83c7e45092dac350b070c421cd2bf7105616cf1a/contracts/ + /// metatx/ERC2771Forwarder.sol#L327C1-L370C6 /// /// @dev Checks if the requested gas was correctly forwarded to the callee. /// As a consequence of https://eips.ethereum.org/EIPS/eip-150[EIP-150]: diff --git a/packages/protocol/deployments/mainnet-contract-logs-L1.md b/packages/protocol/deployments/mainnet-contract-logs-L1.md index 86f59c09fe0..96ee07119fe 100644 --- a/packages/protocol/deployments/mainnet-contract-logs-L1.md +++ b/packages/protocol/deployments/mainnet-contract-logs-L1.md @@ -92,7 +92,7 @@ - owner: `admin.taiko.eth` - quota: - Quota Period: 24 hours - - ETH: `64516129032258064516` 1000 ETH + - ETH: 1000 ETH - WETH(`0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2`): 1000 ETH - TAIKO(`0x10dea67478c5F8C5E2D90e5E9B26dBe60c54d800`): 2,000,000 - USDT(`0xdAC17F958D2ee523a2206206994597C13D831ec7`): 4,000,000 diff --git a/packages/protocol/test/L1/TaikoL1.t.sol b/packages/protocol/test/L1/TaikoL1.t.sol index f9b0a3a22e6..0715e5acc84 100644 --- a/packages/protocol/test/L1/TaikoL1.t.sol +++ b/packages/protocol/test/L1/TaikoL1.t.sol @@ -4,7 +4,7 @@ pragma solidity 0.8.24; import "./TaikoL1TestBase.sol"; contract TaikoL1_NoCooldown is TaikoL1 { - function getConfig() public view override returns (TaikoData.Config memory config) { + function getConfig() public pure override returns (TaikoData.Config memory config) { config = TaikoL1.getConfig(); // over-write the following config.maxBlocksToVerify = 0; diff --git a/packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol b/packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol index 5c1b71eee2c..62c09633336 100644 --- a/packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol +++ b/packages/protocol/test/L1/TaikoL1LibProvingWithTiers.t.sol @@ -4,7 +4,7 @@ pragma solidity 0.8.24; import "./TaikoL1TestBase.sol"; contract TaikoL1Tiers is TaikoL1 { - function getConfig() public view override returns (TaikoData.Config memory config) { + function getConfig() public pure override returns (TaikoData.Config memory config) { config = TaikoL1.getConfig(); config.maxBlocksToVerify = 0; diff --git a/packages/protocol/test/L1/TaikoL1TestGroupBase.sol b/packages/protocol/test/L1/TaikoL1TestGroupBase.sol index 15df9c54686..a57dbebec3f 100644 --- a/packages/protocol/test/L1/TaikoL1TestGroupBase.sol +++ b/packages/protocol/test/L1/TaikoL1TestGroupBase.sol @@ -4,7 +4,7 @@ pragma solidity 0.8.24; import "./TaikoL1TestBase.sol"; contract TaikoL1New is TaikoL1 { - function getConfig() public view override returns (TaikoData.Config memory config) { + function getConfig() public pure override returns (TaikoData.Config memory config) { config = TaikoL1.getConfig(); config.maxBlocksToVerify = 0; config.blockMaxProposals = 10;