From 12de2cf03cfd1293591bd135da7c35f4b747520c Mon Sep 17 00:00:00 2001 From: Gavin Yu Date: Wed, 22 Jan 2025 20:00:27 +0800 Subject: [PATCH] feat(protocol): add `anchorV2` back (#18820) --- .../contracts/layer2/based/TaikoAnchor.sol | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/packages/protocol/contracts/layer2/based/TaikoAnchor.sol b/packages/protocol/contracts/layer2/based/TaikoAnchor.sol index 205c2dc03a..4433632a87 100644 --- a/packages/protocol/contracts/layer2/based/TaikoAnchor.sol +++ b/packages/protocol/contracts/layer2/based/TaikoAnchor.sol @@ -172,6 +172,38 @@ contract TaikoAnchor is EssentialContract, IBlockHashProvider, TaikoAnchorDeprec ISignalService(resolve(LibStrings.B_SIGNAL_SERVICE, false)).receiveSignals(_signalSlots); } + /// @notice Anchors the latest L1 block details to L2 for cross-layer + /// message verification. + /// @dev This function can be called freely as the golden touch private key is publicly known, + /// but the Taiko node guarantees the first transaction of each block is always this anchor + /// transaction, and any subsequent calls will revert with L2_PUBLIC_INPUT_HASH_MISMATCH. + /// @param _anchorBlockId The `anchorBlockId` value in this block's metadata. + /// @param _anchorStateRoot The state root for the L1 block with id equals `_anchorBlockId`. + /// @param _parentGasUsed The gas used in the parent block. + /// @param _baseFeeConfig The base fee configuration. + function anchorV2( + uint64 _anchorBlockId, + bytes32 _anchorStateRoot, + uint32 _parentGasUsed, + LibSharedData.BaseFeeConfig calldata _baseFeeConfig + ) + external + nonZeroBytes32(_anchorStateRoot) + nonZeroValue(_anchorBlockId) + nonZeroValue(_baseFeeConfig.gasIssuancePerSecond) + nonZeroValue(_baseFeeConfig.adjustmentQuotient) + onlyGoldenTouch + nonReentrant + { + require(block.number < pacayaForkHeight, L2_FORK_ERROR()); + + uint256 parentId = block.number - 1; + _verifyAndUpdatePublicInputHash(parentId); + _verifyBaseFeeAndUpdateGasExcess(_parentGasUsed, _baseFeeConfig); + _syncChainData(_anchorBlockId, _anchorStateRoot); + _updateParentHashAndTimestamp(parentId); + } + /// @notice Withdraw token or Ether from this address. /// Note: This contract receives a portion of L2 base fees, while the remainder is directed to /// L2 block's coinbase address.