From 3e3d299b89487a0f71187bbc95e9f2c8a64fe48a Mon Sep 17 00:00:00 2001 From: zkbenny Date: Thu, 21 Mar 2024 19:41:29 +0800 Subject: [PATCH 01/33] fix: abdk-cvf-3 --- contracts/gateway/BaseGateway.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/gateway/BaseGateway.sol b/contracts/gateway/BaseGateway.sol index 9e4bf7e..f4c622d 100644 --- a/contracts/gateway/BaseGateway.sol +++ b/contracts/gateway/BaseGateway.sol @@ -39,6 +39,7 @@ abstract contract BaseGateway is IGateway, OwnableUpgradeable, UUPSUpgradeable, /// @param _remoteGateway remote gateway address function setRemoteGateway(address _remoteGateway) external onlyOwner { require(remoteGateway == address(0), "Duplicate init remote gateway"); + require(_remoteGateway != address(0), "Invalid gateway"); remoteGateway = _remoteGateway; emit SetRemoteGateway(_remoteGateway); } From 389322aa3a33928c59d634c4b71b6c1509b731de Mon Sep 17 00:00:00 2001 From: zkbenny Date: Thu, 21 Mar 2024 19:45:57 +0800 Subject: [PATCH 02/33] fix: abdk-cvf-4 --- contracts/ZkLink.sol | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contracts/ZkLink.sol b/contracts/ZkLink.sol index 4543bf1..a80687f 100644 --- a/contracts/ZkLink.sol +++ b/contracts/ZkLink.sol @@ -137,10 +137,10 @@ contract ZkLink is } function initialize() external initializer { - __Ownable_init(); - __UUPSUpgradeable_init(); - __ReentrancyGuard_init(); - __Pausable_init(); + __Ownable_init_unchained(); + __UUPSUpgradeable_init_unchained(); + __ReentrancyGuard_init_unchained(); + __Pausable_init_unchained(); } function _authorizeUpgrade(address newImplementation) internal override onlyOwner {} From 123377e265b49574f3f6ed564e9c8db79eb086d1 Mon Sep 17 00:00:00 2001 From: zkbenny Date: Thu, 21 Mar 2024 20:11:54 +0800 Subject: [PATCH 03/33] fix: abdk-cvf-5 --- contracts/ZkLink.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/ZkLink.sol b/contracts/ZkLink.sol index a80687f..5561ee2 100644 --- a/contracts/ZkLink.sol +++ b/contracts/ZkLink.sol @@ -186,6 +186,7 @@ contract ZkLink is /// @dev Init gateway, can only be called by the owner function setGateway(IL2Gateway _gateway) external onlyOwner { require(address(gateway) == address(0), "Duplicate init gateway"); + require(address(_gateway) != address(0), "Invalid gateway"); gateway = _gateway; emit InitGateway(_gateway); } From 7681fac6b0da66846896b49642df7f7e2ce1a7bc Mon Sep 17 00:00:00 2001 From: zkbenny Date: Thu, 21 Mar 2024 20:13:12 +0800 Subject: [PATCH 04/33] fix: abdk-cvf-6 --- contracts/Arbitrator.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/Arbitrator.sol b/contracts/Arbitrator.sol index 42371de..5c2f717 100644 --- a/contracts/Arbitrator.sol +++ b/contracts/Arbitrator.sol @@ -60,9 +60,9 @@ contract Arbitrator is IArbitrator, OwnableUpgradeable, UUPSUpgradeable, Reentra } function initialize() external initializer { - __Ownable_init(); - __UUPSUpgradeable_init(); - __ReentrancyGuard_init(); + __Ownable_init_unchained(); + __UUPSUpgradeable_init_unchained(); + __ReentrancyGuard_init_unchained(); } function _authorizeUpgrade(address newImplementation) internal override onlyOwner {} From d059105bf614ee598418884dc54ae864c5d67f2a Mon Sep 17 00:00:00 2001 From: zkbenny Date: Thu, 21 Mar 2024 20:14:08 +0800 Subject: [PATCH 05/33] fix: abdk-cvf-7 --- contracts/Arbitrator.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/Arbitrator.sol b/contracts/Arbitrator.sol index 5c2f717..4c3529a 100644 --- a/contracts/Arbitrator.sol +++ b/contracts/Arbitrator.sol @@ -79,6 +79,7 @@ contract Arbitrator is IArbitrator, OwnableUpgradeable, UUPSUpgradeable, Reentra /// @dev Set primary chain function setPrimaryChainGateway(IL1Gateway _gateway) external onlyOwner { require(address(primaryChainGateway) == address(0), "Duplicate init gateway"); + require(address(primaryChainGateway) != address(0), "Invalid gateway"); primaryChainGateway = _gateway; emit InitPrimaryChain(_gateway); } From 935b1b15aa3be1032f69bd1a296ceae029d04ba8 Mon Sep 17 00:00:00 2001 From: zkbenny Date: Thu, 21 Mar 2024 20:49:09 +0800 Subject: [PATCH 06/33] fix: abdk-cvf-11 --- contracts/Arbitrator.sol | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/contracts/Arbitrator.sol b/contracts/Arbitrator.sol index 4c3529a..2c9408a 100644 --- a/contracts/Arbitrator.sol +++ b/contracts/Arbitrator.sol @@ -91,11 +91,13 @@ contract Arbitrator is IArbitrator, OwnableUpgradeable, UUPSUpgradeable, Reentra bytes calldata _adapterParams ) external payable onlyOwner { require(_gateway != primaryChainGateway, "Invalid gateway"); - secondaryChainGateways[_gateway] = _active; - bytes memory callData = abi.encodeCall(IZkSync.setSecondaryChainGateway, (address(_gateway), _active)); - // Forward fee to send message - primaryChainGateway.sendMessage{value: msg.value}(0, callData, _adapterParams); - emit SecondaryChainStatusUpdate(_gateway, _active); + if (_active != secondaryChainGateways[_gateway]) { + secondaryChainGateways[_gateway] = _active; + bytes memory callData = abi.encodeCall(IZkSync.setSecondaryChainGateway, (address(_gateway), _active)); + // Forward fee to send message + primaryChainGateway.sendMessage{value: msg.value}(0, callData, _adapterParams); + emit SecondaryChainStatusUpdate(_gateway, _active); + } } /// @dev Set relayer From 9bed074348f3953092abbae689129c58210a58dc Mon Sep 17 00:00:00 2001 From: zkbenny Date: Thu, 21 Mar 2024 21:04:25 +0800 Subject: [PATCH 07/33] fix: abdk-cvf-13 --- contracts/gateway/zksync/ZkSyncL2Gateway.sol | 4 ---- contracts/interfaces/zksync/IL2Messenger.sol | 8 -------- 2 files changed, 12 deletions(-) delete mode 100644 contracts/interfaces/zksync/IL2Messenger.sol diff --git a/contracts/gateway/zksync/ZkSyncL2Gateway.sol b/contracts/gateway/zksync/ZkSyncL2Gateway.sol index d42f471..68652bf 100644 --- a/contracts/gateway/zksync/ZkSyncL2Gateway.sol +++ b/contracts/gateway/zksync/ZkSyncL2Gateway.sol @@ -1,7 +1,6 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity ^0.8.0; -import {IL2Messenger} from "../../interfaces/zksync/IL2Messenger.sol"; import {IL2ETHToken} from "../../interfaces/zksync/IL2ETHToken.sol"; import {L2BaseGateway} from "../L2BaseGateway.sol"; import {AddressAliasHelper} from "../../zksync/l1-contracts/vendor/AddressAliasHelper.sol"; @@ -11,9 +10,6 @@ import {BaseGateway} from "../BaseGateway.sol"; contract ZkSyncL2Gateway is IMessageClaimer, L2BaseGateway, BaseGateway { uint160 internal constant SYSTEM_CONTRACTS_OFFSET = 0x8000; // 2^15 - /// @notice ZkSync system message service on local chain - IL2Messenger public constant L2_MESSENGER = IL2Messenger(address(SYSTEM_CONTRACTS_OFFSET + 0x08)); - /// @notice ZkSync eth bridge service on local chain IL2ETHToken public constant L2_ETH_ADDRESS = IL2ETHToken(address(SYSTEM_CONTRACTS_OFFSET + 0x0a)); diff --git a/contracts/interfaces/zksync/IL2Messenger.sol b/contracts/interfaces/zksync/IL2Messenger.sol deleted file mode 100644 index e4f773e..0000000 --- a/contracts/interfaces/zksync/IL2Messenger.sol +++ /dev/null @@ -1,8 +0,0 @@ -// SPDX-License-Identifier: MIT OR Apache-2.0 - -pragma solidity ^0.8.0; - -/// @author Matter Labs -interface IL2Messenger { - function sendToL1(bytes memory _message) external returns (bytes32); -} From 44b9cc8435069841262658870e3f8f1523d46bea Mon Sep 17 00:00:00 2001 From: zkbenny Date: Fri, 22 Mar 2024 09:49:05 +0800 Subject: [PATCH 08/33] fix: abdk-cvf-14 --- contracts/interfaces/zkpolygon/IZkPolygon.sol | 35 ------------------- 1 file changed, 35 deletions(-) diff --git a/contracts/interfaces/zkpolygon/IZkPolygon.sol b/contracts/interfaces/zkpolygon/IZkPolygon.sol index 711becf..6678fa5 100644 --- a/contracts/interfaces/zkpolygon/IZkPolygon.sol +++ b/contracts/interfaces/zkpolygon/IZkPolygon.sol @@ -2,45 +2,10 @@ pragma solidity ^0.8.0; interface IZkPolygon { - function bridgeAsset( - uint32 destinationNetwork, - address destinationAddress, - uint256 amount, - address token, - bool forceUpdateGlobalExitRoot, - bytes calldata permitData - ) external payable; - function bridgeMessage( uint32 destinationNetwork, address destinationAddress, bool forceUpdateGlobalExitRoot, bytes calldata metadata ) external payable; - - function claimAsset( - bytes32[32] calldata smtProof, - uint32 index, - bytes32 mainnetExitRoot, - bytes32 rollupExitRoot, - uint32 originNetwork, - address originTokenAddress, - uint32 destinationNetwork, - address destinationAddress, - uint256 amount, - bytes calldata metadata - ) external; - - function claimMessage( - bytes32[32] calldata smtProof, - uint32 index, - bytes32 mainnetExitRoot, - bytes32 rollupExitRoot, - uint32 originNetwork, - address originAddress, - uint32 destinationNetwork, - address destinationAddress, - uint256 amount, - bytes calldata metadata - ) external; } From 80fedf4f818349d7b78e81ae423824197874633b Mon Sep 17 00:00:00 2001 From: zkbenny Date: Fri, 22 Mar 2024 09:55:15 +0800 Subject: [PATCH 09/33] fix: abdk-cvf-15 --- contracts/interfaces/linea/IL2MessageService.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/interfaces/linea/IL2MessageService.sol b/contracts/interfaces/linea/IL2MessageService.sol index d04f02d..fc5399e 100644 --- a/contracts/interfaces/linea/IL2MessageService.sol +++ b/contracts/interfaces/linea/IL2MessageService.sol @@ -4,6 +4,6 @@ pragma solidity ^0.8.0; import {IMessageService} from "./IMessageService.sol"; interface IL2MessageService is IMessageService { - /// @notice Returns coinbase fee when sendMessage + /// @notice Returns the fee charged by Linea canonical message service when sending a message function minimumFeeInWei() external view returns (uint256); } From c2e254809c799deb3ab1b89ab0d9e27c549e58f1 Mon Sep 17 00:00:00 2001 From: zkbenny Date: Fri, 22 Mar 2024 10:16:09 +0800 Subject: [PATCH 10/33] fix: abdk-cvf-18 --- contracts/gateway/zksync/ZkSyncL1Gateway.sol | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contracts/gateway/zksync/ZkSyncL1Gateway.sol b/contracts/gateway/zksync/ZkSyncL1Gateway.sol index 9ddc1a1..e27cdd2 100644 --- a/contracts/gateway/zksync/ZkSyncL1Gateway.sol +++ b/contracts/gateway/zksync/ZkSyncL1Gateway.sol @@ -26,7 +26,9 @@ contract ZkSyncL1Gateway is IZkSyncL1Gateway, L1BaseGateway, BaseGateway { } /// @dev Receive eth from zkSync canonical bridge - receive() external payable {} + receive() external payable { + // nothing to do here + } function initialize() external initializer { __BaseGateway_init(); From 357b8223c6af820246fb04a80a378ee864202685 Mon Sep 17 00:00:00 2001 From: zkbenny Date: Fri, 22 Mar 2024 10:20:18 +0800 Subject: [PATCH 11/33] fix: abdk-cvf-19 --- contracts/gateway/zksync/ZkSyncL1Gateway.sol | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contracts/gateway/zksync/ZkSyncL1Gateway.sol b/contracts/gateway/zksync/ZkSyncL1Gateway.sol index e27cdd2..4bcea85 100644 --- a/contracts/gateway/zksync/ZkSyncL1Gateway.sol +++ b/contracts/gateway/zksync/ZkSyncL1Gateway.sol @@ -50,6 +50,8 @@ contract ZkSyncL1Gateway is IZkSyncL1Gateway, L1BaseGateway, BaseGateway { _l2GasPerPubdataByteLimit, new bytes[](0), // solhint-disable-next-line avoid-tx-origin + // The origin address paid the network fees of L2 on L1 + // So the origin address is set as the refund address for the excess network fees on L2. tx.origin ); } From b346e6c1dd31a41b6054eea7329904a5d7ef2db5 Mon Sep 17 00:00:00 2001 From: zkbenny Date: Fri, 22 Mar 2024 10:36:54 +0800 Subject: [PATCH 12/33] fix: abdk-cvf-20 --- contracts/gateway/zksync/ZkSyncL1Gateway.sol | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contracts/gateway/zksync/ZkSyncL1Gateway.sol b/contracts/gateway/zksync/ZkSyncL1Gateway.sol index 4bcea85..944eb87 100644 --- a/contracts/gateway/zksync/ZkSyncL1Gateway.sol +++ b/contracts/gateway/zksync/ZkSyncL1Gateway.sol @@ -13,6 +13,9 @@ import {UnsafeBytes} from "../../zksync/l1-contracts/common/libraries/UnsafeByte import {L2_ETH_TOKEN_SYSTEM_CONTRACT_ADDR} from "../../zksync/l1-contracts/common/L2ContractAddresses.sol"; contract ZkSyncL1Gateway is IZkSyncL1Gateway, L1BaseGateway, BaseGateway { + /// @dev The L2 eth withdraw message minimum length + uint256 constant private L2_ETH_WITHDRAW_MESSAGE_MINIMUM_LENGTH = 108; + /// @notice ZkSync message service on local chain IMailbox public immutable MESSAGE_SERVICE; @@ -112,7 +115,7 @@ contract ZkSyncL1Gateway is IZkSyncL1Gateway, L1BaseGateway, BaseGateway { // additionalData (sendMessage): l2Value + l2CallData >= 32 (bytes) // It should be equal to the length of the function signature + eth receiver address + uint256 amount + l2Sender // + additionalData >= 4 + 20 + 32 + 20 + 32 = 108 (bytes). - require(_message.length >= 108, "Incorrect message length"); + require(_message.length >= L2_ETH_WITHDRAW_MESSAGE_MINIMUM_LENGTH, "Incorrect message length"); (uint32 functionSignature, uint256 offset) = UnsafeBytes.readUint32(_message, 0); require(bytes4(functionSignature) == IMailbox.finalizeEthWithdrawal.selector, "Incorrect function selector"); From 12739edea8889d00f76e4719bff0585751b8aa3f Mon Sep 17 00:00:00 2001 From: zkbenny Date: Fri, 22 Mar 2024 11:19:58 +0800 Subject: [PATCH 13/33] fix: abdk-cvf-23 --- contracts/gateway/zkpolygon/ZkPolygonL1Gateway.sol | 3 ++- contracts/interfaces/zkpolygon/IZkPolygon.sol | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/contracts/gateway/zkpolygon/ZkPolygonL1Gateway.sol b/contracts/gateway/zkpolygon/ZkPolygonL1Gateway.sol index f220275..8c4975a 100644 --- a/contracts/gateway/zkpolygon/ZkPolygonL1Gateway.sol +++ b/contracts/gateway/zkpolygon/ZkPolygonL1Gateway.sol @@ -11,8 +11,9 @@ contract ZkPolygonL1Gateway is IBridgeMessageReceiver, L1BaseGateway, BaseGatewa /// @notice ZkPolygon message service on local chain IZkPolygon public immutable MESSAGE_SERVICE; + /// @dev The destination network of Polygon zkEVM uint32 public constant ETH_NETWORK_ID = 1; - // Default to true + // @dev Set to true for claiming asset on the destination network bool public constant FORCE_UPDATE_GLOBAL_EXIT_ROOT = true; modifier onlyMessageService() { diff --git a/contracts/interfaces/zkpolygon/IZkPolygon.sol b/contracts/interfaces/zkpolygon/IZkPolygon.sol index 6678fa5..13e97b8 100644 --- a/contracts/interfaces/zkpolygon/IZkPolygon.sol +++ b/contracts/interfaces/zkpolygon/IZkPolygon.sol @@ -2,6 +2,14 @@ pragma solidity ^0.8.0; interface IZkPolygon { + /** + * @notice Bridge message and send ETH value + * note User/UI must be aware of the existing/available networks when choosing the destination network + * @param destinationNetwork Network destination + * @param destinationAddress Address destination + * @param forceUpdateGlobalExitRoot Indicates if the new global exit root is updated or not + * @param metadata Message metadata + */ function bridgeMessage( uint32 destinationNetwork, address destinationAddress, From 72b0291f40d35c5ad1930badf157aeff873be393 Mon Sep 17 00:00:00 2001 From: zkbenny Date: Fri, 22 Mar 2024 11:20:06 +0800 Subject: [PATCH 14/33] fix: abdk-cvf-24 --- contracts/gateway/zkpolygon/ZkPolygonL2Gateway.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contracts/gateway/zkpolygon/ZkPolygonL2Gateway.sol b/contracts/gateway/zkpolygon/ZkPolygonL2Gateway.sol index 9c142bc..c25029b 100644 --- a/contracts/gateway/zkpolygon/ZkPolygonL2Gateway.sol +++ b/contracts/gateway/zkpolygon/ZkPolygonL2Gateway.sol @@ -10,8 +10,9 @@ contract ZkPolygonL2Gateway is IBridgeMessageReceiver, L2BaseGateway, BaseGatewa /// @notice ZkPolygon message service on local chain IZkPolygon public immutable MESSAGE_SERVICE; + /// @dev The destination network of Ethereum uint32 public constant ETH_NETWORK_ID = 0; - // Default to true + // @dev Set to true for claiming asset on the destination network bool public constant FORCE_UPDATE_GLOBAL_EXIT_ROOT = true; /// @dev Modifier to make sure the original sender is messageService on remote chain. From 854f346b311386c2a73b1e48d30ea5717f2ce6c1 Mon Sep 17 00:00:00 2001 From: zkbenny Date: Fri, 22 Mar 2024 11:22:16 +0800 Subject: [PATCH 15/33] fix: abdk-cvf-26 --- contracts/gateway/scroll/ScrollL1Gateway.sol | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contracts/gateway/scroll/ScrollL1Gateway.sol b/contracts/gateway/scroll/ScrollL1Gateway.sol index 6b4de6f..92272d5 100644 --- a/contracts/gateway/scroll/ScrollL1Gateway.sol +++ b/contracts/gateway/scroll/ScrollL1Gateway.sol @@ -33,6 +33,8 @@ contract ScrollL1Gateway is ScrollGateway, L1BaseGateway { executeData, _finalizeMessageGasLimit, // solhint-disable-next-line avoid-tx-origin + // The origin address paid the network fees of L2 on L1 + // So the origin address is set as the refund address for the excess network fees on L2. tx.origin ); } From d9e34bd326b1e8bef585722f8ffeb2f27a0e42ec Mon Sep 17 00:00:00 2001 From: zkbenny Date: Fri, 22 Mar 2024 11:27:31 +0800 Subject: [PATCH 16/33] fix: abdk-cvf-29 --- contracts/gateway/optimism/OptimismL2Gateway.sol | 9 ++++++--- contracts/gateway/zksync/ZkSyncL1Gateway.sol | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/contracts/gateway/optimism/OptimismL2Gateway.sol b/contracts/gateway/optimism/OptimismL2Gateway.sol index 6362b4f..1f0a232 100644 --- a/contracts/gateway/optimism/OptimismL2Gateway.sol +++ b/contracts/gateway/optimism/OptimismL2Gateway.sol @@ -7,9 +7,12 @@ import {OptimismGateway} from "./OptimismGateway.sol"; import {L2BaseGateway} from "../L2BaseGateway.sol"; contract OptimismL2Gateway is L2BaseGateway, OptimismGateway { - constructor( - address _zkLink - ) L2BaseGateway(_zkLink) OptimismGateway(IOptimismMessenger(0x4200000000000000000000000000000000000007)) { + /// @dev The L2CrossDomainMessenger deployed on OP + /// see https://docs.optimism.io/chain/addresses + IOptimismMessenger private constant L2_CROSS_DOMAIN_MESSENGER = + IOptimismMessenger(0x4200000000000000000000000000000000000007); + + constructor(address _zkLink) L2BaseGateway(_zkLink) OptimismGateway(L2_CROSS_DOMAIN_MESSENGER) { _disableInitializers(); } diff --git a/contracts/gateway/zksync/ZkSyncL1Gateway.sol b/contracts/gateway/zksync/ZkSyncL1Gateway.sol index 944eb87..9ef7220 100644 --- a/contracts/gateway/zksync/ZkSyncL1Gateway.sol +++ b/contracts/gateway/zksync/ZkSyncL1Gateway.sol @@ -14,7 +14,7 @@ import {L2_ETH_TOKEN_SYSTEM_CONTRACT_ADDR} from "../../zksync/l1-contracts/commo contract ZkSyncL1Gateway is IZkSyncL1Gateway, L1BaseGateway, BaseGateway { /// @dev The L2 eth withdraw message minimum length - uint256 constant private L2_ETH_WITHDRAW_MESSAGE_MINIMUM_LENGTH = 108; + uint256 private constant L2_ETH_WITHDRAW_MESSAGE_MINIMUM_LENGTH = 108; /// @notice ZkSync message service on local chain IMailbox public immutable MESSAGE_SERVICE; From 457343d3b2640ef273df17c1bdfaea684be86bbb Mon Sep 17 00:00:00 2001 From: zkbenny Date: Fri, 22 Mar 2024 11:36:09 +0800 Subject: [PATCH 17/33] fix: abdk-cvf-37 --- contracts/gateway/BaseGateway.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/gateway/BaseGateway.sol b/contracts/gateway/BaseGateway.sol index f4c622d..b12d3fa 100644 --- a/contracts/gateway/BaseGateway.sol +++ b/contracts/gateway/BaseGateway.sol @@ -17,7 +17,7 @@ abstract contract BaseGateway is IGateway, OwnableUpgradeable, UUPSUpgradeable, */ uint256[49] private __gap; - event SetRemoteGateway(address remoteGateWay); + event NewRemoteGateway(address remoteGateWay); function __BaseGateway_init() internal onlyInitializing { __BaseGateway_init_unchained(); @@ -41,6 +41,6 @@ abstract contract BaseGateway is IGateway, OwnableUpgradeable, UUPSUpgradeable, require(remoteGateway == address(0), "Duplicate init remote gateway"); require(_remoteGateway != address(0), "Invalid gateway"); remoteGateway = _remoteGateway; - emit SetRemoteGateway(_remoteGateway); + emit NewRemoteGateway(_remoteGateway); } } From 8d991a615d8c4fbbef2f2eafce75077416a0623f Mon Sep 17 00:00:00 2001 From: zkbenny Date: Fri, 22 Mar 2024 11:38:42 +0800 Subject: [PATCH 18/33] fix: abdk-cvf-43 --- contracts/gateway/L2BaseGateway.sol | 2 -- contracts/interfaces/IL2Gateway.sol | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/contracts/gateway/L2BaseGateway.sol b/contracts/gateway/L2BaseGateway.sol index a305f89..fc37d0d 100644 --- a/contracts/gateway/L2BaseGateway.sol +++ b/contracts/gateway/L2BaseGateway.sol @@ -14,8 +14,6 @@ abstract contract L2BaseGateway is IL2Gateway { */ uint256[50] private __gap; - event L2GatewayMessageSent(uint256 value, bytes callData); - /// @dev Ensure withdraw come from zkLink modifier onlyZkLink() { require(msg.sender == ZKLINK, "Not zkLink contract"); diff --git a/contracts/interfaces/IL2Gateway.sol b/contracts/interfaces/IL2Gateway.sol index f932a6d..8035b0a 100644 --- a/contracts/interfaces/IL2Gateway.sol +++ b/contracts/interfaces/IL2Gateway.sol @@ -4,6 +4,9 @@ pragma solidity ^0.8.0; import {IGateway} from "./IGateway.sol"; interface IL2Gateway is IGateway { + /// @notice Emit when sending a message + event L2GatewayMessageSent(uint256 value, bytes callData); + /// @notice Send message to remote gateway /// @param _value The msg value /// @param _callData The call data From e510901b3e8304e4d1a50951cfbec30092695774 Mon Sep 17 00:00:00 2001 From: zkbenny Date: Fri, 22 Mar 2024 13:08:26 +0800 Subject: [PATCH 19/33] fix: abdk-cvf-46 --- contracts/ZkLink.sol | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/contracts/ZkLink.sol b/contracts/ZkLink.sol index 5561ee2..27fa1b6 100644 --- a/contracts/ZkLink.sol +++ b/contracts/ZkLink.sol @@ -36,9 +36,11 @@ contract ZkLink is { using UncheckedMath for uint256; - // keccak256("ForwardL2Request(address gateway,bool isContractCall,address sender,uint256 txId,address contractAddressL2,uint256 l2Value,bytes32 l2CallDataHash,uint256 l2GasLimit,uint256 l2GasPricePerPubdata,bytes32 factoryDepsHash,address refundRecipient)") + /// @dev The forward request type hash bytes32 public constant FORWARD_REQUEST_TYPE_HASH = - 0xe0aaca1722ef50bb0c9b032e5b16ce2b79fa9f23638835456b27fd6894f8292c; + keccak256( + "ForwardL2Request(address gateway,bool isContractCall,address sender,uint256 txId,address contractAddressL2,uint256 l2Value,bytes32 l2CallDataHash,uint256 l2GasLimit,uint256 l2GasPricePerPubdata,bytes32 factoryDepsHash,address refundRecipient)" + ); /// @dev Whether eth is the gas token bool public immutable IS_ETH_GAS_TOKEN; From c48bc5aa2c0bc107f57a6cc6c263defb47206822 Mon Sep 17 00:00:00 2001 From: zkbenny Date: Fri, 22 Mar 2024 13:09:09 +0800 Subject: [PATCH 20/33] fix: abdk-cvf-47 --- contracts/ZkLink.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/ZkLink.sol b/contracts/ZkLink.sol index 27fa1b6..b1545fd 100644 --- a/contracts/ZkLink.sol +++ b/contracts/ZkLink.sol @@ -89,7 +89,7 @@ contract ZkLink is uint256[50] private __gap; /// @notice Gateway init - event InitGateway(IL2Gateway gateway); + event InitGateway(IL2Gateway indexed gateway); /// @notice Contract's permit status changed event ContractAllowStatusUpdate(address contractAddress, bool isPermit); /// @notice Tx gas price changed From 9a957d6828a3ae927f00ac0e806ae38695b6eb8b Mon Sep 17 00:00:00 2001 From: zkbenny Date: Fri, 22 Mar 2024 13:09:57 +0800 Subject: [PATCH 21/33] fix: abdk-cvf-48 --- contracts/ZkLink.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/ZkLink.sol b/contracts/ZkLink.sol index b1545fd..b9f4c78 100644 --- a/contracts/ZkLink.sol +++ b/contracts/ZkLink.sol @@ -91,7 +91,7 @@ contract ZkLink is /// @notice Gateway init event InitGateway(IL2Gateway indexed gateway); /// @notice Contract's permit status changed - event ContractAllowStatusUpdate(address contractAddress, bool isPermit); + event ContractAllowStatusUpdate(address indexed contractAddress, bool isPermit); /// @notice Tx gas price changed event TxGasPriceUpdate(uint256 oldTxGasPrice, uint256 newTxGasPrice); /// @notice Validator's status changed From f52b6da1c3d9715ad4beee9ace75bc8d2c7accc1 Mon Sep 17 00:00:00 2001 From: zkbenny Date: Fri, 22 Mar 2024 13:12:07 +0800 Subject: [PATCH 22/33] fix: abdk-cvf-50 --- contracts/ZkLink.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/ZkLink.sol b/contracts/ZkLink.sol index b9f4c78..d60864d 100644 --- a/contracts/ZkLink.sol +++ b/contracts/ZkLink.sol @@ -95,7 +95,7 @@ contract ZkLink is /// @notice Tx gas price changed event TxGasPriceUpdate(uint256 oldTxGasPrice, uint256 newTxGasPrice); /// @notice Validator's status changed - event ValidatorStatusUpdate(address validatorAddress, bool isActive); + event ValidatorStatusUpdate(address indexed validatorAddress, bool isActive); /// @notice Fee params for L1->L2 transactions changed event NewFeeParams(FeeParams oldFeeParams, FeeParams newFeeParams); /// @notice New priority request event. Emitted when a request is placed into the priority queue From 46ebcc2aa45b5af96f1fd07d7c92feb66f16eaa4 Mon Sep 17 00:00:00 2001 From: zkbenny Date: Fri, 22 Mar 2024 13:12:25 +0800 Subject: [PATCH 23/33] fix: abdk-cvf-51 --- contracts/ZkLink.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/ZkLink.sol b/contracts/ZkLink.sol index d60864d..54e3979 100644 --- a/contracts/ZkLink.sol +++ b/contracts/ZkLink.sol @@ -107,7 +107,7 @@ contract ZkLink is /// @notice Emitted when receive l2 tx hash from primary chain. event SyncL2TxHash(bytes32 l2TxHash, bytes32 primaryChainL2TxHash); /// @notice Emitted when validator withdraw forward fee - event WithdrawForwardFee(address receiver, uint256 amount); + event WithdrawForwardFee(address indexed receiver, uint256 amount); /// @notice Emitted when the withdrawal is finalized on L1 and funds are released. /// @param to The address to which the funds were sent /// @param amount The amount of funds that were sent From ccf51b751a7412c5b0c28bb78ca0027e27360211 Mon Sep 17 00:00:00 2001 From: zkbenny Date: Fri, 22 Mar 2024 13:14:55 +0800 Subject: [PATCH 24/33] fix: abdk-cvf-53 --- contracts/ZkLink.sol | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contracts/ZkLink.sol b/contracts/ZkLink.sol index 54e3979..0b76005 100644 --- a/contracts/ZkLink.sol +++ b/contracts/ZkLink.sol @@ -145,7 +145,9 @@ contract ZkLink is __Pausable_init_unchained(); } - function _authorizeUpgrade(address newImplementation) internal override onlyOwner {} + function _authorizeUpgrade(address newImplementation) internal override onlyOwner { + // can only called by owner + } /// @dev Pause the contract, can only be called by the owner function pause() external onlyOwner { From 06b900e64559932a89c589ea4a642d5c8bd89c2e Mon Sep 17 00:00:00 2001 From: zkbenny Date: Fri, 22 Mar 2024 13:22:18 +0800 Subject: [PATCH 25/33] fix: abdk-cvf-54 --- contracts/ZkLink.sol | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/contracts/ZkLink.sol b/contracts/ZkLink.sol index 0b76005..2b0ea39 100644 --- a/contracts/ZkLink.sol +++ b/contracts/ZkLink.sol @@ -197,22 +197,29 @@ contract ZkLink is /// @dev Update the permit status of contract, can only be called by the owner function setAllowList(address _contractAddress, bool _permitted) external onlyOwner { - allowLists[_contractAddress] = _permitted; - emit ContractAllowStatusUpdate(_contractAddress, _permitted); + if (allowLists[_contractAddress] != _permitted) { + allowLists[_contractAddress] = _permitted; + emit ContractAllowStatusUpdate(_contractAddress, _permitted); + } } /// @dev Update the tx gas price function setTxGasPrice(uint256 _newTxGasPrice) external onlyOwner { uint256 oldTxGasPrice = txGasPrice; - txGasPrice = _newTxGasPrice; - emit TxGasPriceUpdate(oldTxGasPrice, _newTxGasPrice); + if (oldTxGasPrice != _newTxGasPrice) { + txGasPrice = _newTxGasPrice; + emit TxGasPriceUpdate(oldTxGasPrice, _newTxGasPrice); + } } function setValidator(address _validator, bool _active) external onlyGateway { - validators[_validator] = _active; - emit ValidatorStatusUpdate(_validator, _active); + if (validators[_validator] != _active) { + validators[_validator] = _active; + emit ValidatorStatusUpdate(_validator, _active); + } } + /// @dev https://github.com/matter-labs/era-contracts/blob/e0a33ce73c4decd381446a6eb812b14c2ff69c47/l1-contracts/contracts/zksync/facets/Admin.sol#L88 function changeFeeParams(FeeParams calldata _newFeeParams) external onlyGateway { // Double checking that the new fee params are valid, i.e. // the maximal pubdata per batch is not less than the maximal pubdata per priority transaction. @@ -228,8 +235,10 @@ contract ZkLink is function setForwardFeeAllocator(address _newForwardFeeAllocator) external onlyOwner { require(_newForwardFeeAllocator != address(0), "Invalid allocator"); address oldAllocator = forwardFeeAllocator; - forwardFeeAllocator = _newForwardFeeAllocator; - emit ForwardFeeAllocatorUpdate(oldAllocator, _newForwardFeeAllocator); + if (oldAllocator != _newForwardFeeAllocator) { + forwardFeeAllocator = _newForwardFeeAllocator; + emit ForwardFeeAllocatorUpdate(oldAllocator, _newForwardFeeAllocator); + } } function l2TransactionBaseCost( From 14f074bc6a2b2e3c5b8d9cf21ba5f9b38e040b10 Mon Sep 17 00:00:00 2001 From: zkbenny Date: Fri, 22 Mar 2024 13:32:44 +0800 Subject: [PATCH 26/33] fix: abdk-cvf-56 --- contracts/ZkLink.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/ZkLink.sol b/contracts/ZkLink.sol index 2b0ea39..d5731b4 100644 --- a/contracts/ZkLink.sol +++ b/contracts/ZkLink.sol @@ -474,6 +474,7 @@ contract ZkLink is } /// @notice Derives the price for L2 gas in ETH to be paid. + /// @dev https://github.com/matter-labs/era-contracts/blob/e0a33ce73c4decd381446a6eb812b14c2ff69c47/l1-contracts/contracts/zksync/facets/Mailbox.sol#L147 /// @param _l1GasPrice The gas price on L1. /// @param _gasPerPubdata The price for each pubdata byte in L2 gas /// @return The price of L2 gas in ETH From f13b44090c7cf0a86674c62dde2d86eda827e835 Mon Sep 17 00:00:00 2001 From: zkbenny Date: Fri, 22 Mar 2024 13:35:11 +0800 Subject: [PATCH 27/33] fix: abdk-cvf-57 --- contracts/ZkLink.sol | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contracts/ZkLink.sol b/contracts/ZkLink.sol index d5731b4..7ecbe73 100644 --- a/contracts/ZkLink.sol +++ b/contracts/ZkLink.sol @@ -42,6 +42,9 @@ contract ZkLink is "ForwardL2Request(address gateway,bool isContractCall,address sender,uint256 txId,address contractAddressL2,uint256 l2Value,bytes32 l2CallDataHash,uint256 l2GasLimit,uint256 l2GasPricePerPubdata,bytes32 factoryDepsHash,address refundRecipient)" ); + /// @dev The length of withdraw message sent to secondary chain + uint256 private constant L2_WITHDRAW_MESSAGE_LENGTH = 108; + /// @dev Whether eth is the gas token bool public immutable IS_ETH_GAS_TOKEN; @@ -570,7 +573,7 @@ contract ZkLink is // bytes4 function signature + address l1Gateway + uint256 amount + address l2Sender + bytes _additionalData // (where the _additionalData = abi.encode(l1Receiver)) // = 4 + 20 + 32 + 20 + 32 == 108 (bytes). - require(_message.length == 108, "pm"); + require(_message.length == L2_WITHDRAW_MESSAGE_LENGTH, "pm"); (uint32 functionSignature, uint256 offset) = UnsafeBytes.readUint32(_message, 0); require(bytes4(functionSignature) == this.finalizeEthWithdrawal.selector, "is"); From 999e0368c2a8b78583c2c46fec527e63489da95e Mon Sep 17 00:00:00 2001 From: zkbenny Date: Fri, 22 Mar 2024 13:38:34 +0800 Subject: [PATCH 28/33] fix: abdk-cvf-59 --- contracts/Arbitrator.sol | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/contracts/Arbitrator.sol b/contracts/Arbitrator.sol index 2c9408a..e0e1c0e 100644 --- a/contracts/Arbitrator.sol +++ b/contracts/Arbitrator.sol @@ -35,19 +35,19 @@ contract Arbitrator is IArbitrator, OwnableUpgradeable, UUPSUpgradeable, Reentra uint256[50] private __gap; /// @notice Primary chain gateway init - event InitPrimaryChain(IL1Gateway gateway); + event InitPrimaryChain(IL1Gateway indexed gateway); /// @notice SecondaryChain's status changed - event SecondaryChainStatusUpdate(IL1Gateway gateway, bool isActive); + event SecondaryChainStatusUpdate(IL1Gateway indexed gateway, bool isActive); /// @notice Relayer's status changed event RelayerStatusUpdate(address relayer, bool isActive); /// @notice Validator's status changed - event ValidatorStatusUpdate(IL1Gateway gateway, address validatorAddress, bool isActive); + event ValidatorStatusUpdate(IL1Gateway indexed gateway, address validatorAddress, bool isActive); /// @notice Fee params for L1->L2 transactions changed - event NewFeeParams(IL1Gateway gateway, FeeParams newFeeParams); + event NewFeeParams(IL1Gateway indexed gateway, FeeParams newFeeParams); /// @notice Emit when receive message from l1 gateway event MessageReceived(uint256 value, bytes callData); /// @notice Emit when forward message to l1 gateway - event MessageForwarded(IL1Gateway gateway, uint256 value, bytes callData); + event MessageForwarded(IL1Gateway indexed gateway, uint256 value, bytes callData); /// @notice Checks if relayer is active modifier onlyRelayer() { From 103b4a8b4e21bb0699f9d61d655c5de9868d1203 Mon Sep 17 00:00:00 2001 From: zkbenny Date: Fri, 22 Mar 2024 13:39:02 +0800 Subject: [PATCH 29/33] fix: abdk-cvf-60 --- contracts/Arbitrator.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/Arbitrator.sol b/contracts/Arbitrator.sol index e0e1c0e..b25ba5f 100644 --- a/contracts/Arbitrator.sol +++ b/contracts/Arbitrator.sol @@ -39,7 +39,7 @@ contract Arbitrator is IArbitrator, OwnableUpgradeable, UUPSUpgradeable, Reentra /// @notice SecondaryChain's status changed event SecondaryChainStatusUpdate(IL1Gateway indexed gateway, bool isActive); /// @notice Relayer's status changed - event RelayerStatusUpdate(address relayer, bool isActive); + event RelayerStatusUpdate(address indexed relayer, bool isActive); /// @notice Validator's status changed event ValidatorStatusUpdate(IL1Gateway indexed gateway, address validatorAddress, bool isActive); /// @notice Fee params for L1->L2 transactions changed From 7cbeb08c0ff7b023d0158026601c07f14e84b5d9 Mon Sep 17 00:00:00 2001 From: zkbenny Date: Fri, 22 Mar 2024 13:39:31 +0800 Subject: [PATCH 30/33] fix: abdk-cvf-61 --- contracts/Arbitrator.sol | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contracts/Arbitrator.sol b/contracts/Arbitrator.sol index b25ba5f..b581faf 100644 --- a/contracts/Arbitrator.sol +++ b/contracts/Arbitrator.sol @@ -65,7 +65,9 @@ contract Arbitrator is IArbitrator, OwnableUpgradeable, UUPSUpgradeable, Reentra __ReentrancyGuard_init_unchained(); } - function _authorizeUpgrade(address newImplementation) internal override onlyOwner {} + function _authorizeUpgrade(address newImplementation) internal override onlyOwner { + // can only call by owner + } /// @notice Return the message hash at a position stored in queue function getMessageHash(IL1Gateway _gateway, uint256 _index) external view returns (bytes32 messageHash) { From 65cecf4f517c0e01d6e5bbe281b80bb03b36115e Mon Sep 17 00:00:00 2001 From: zkbenny Date: Fri, 22 Mar 2024 13:40:19 +0800 Subject: [PATCH 31/33] fix: abdk-cvf-62 --- contracts/Arbitrator.sol | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/contracts/Arbitrator.sol b/contracts/Arbitrator.sol index b581faf..7465a12 100644 --- a/contracts/Arbitrator.sol +++ b/contracts/Arbitrator.sol @@ -104,8 +104,10 @@ contract Arbitrator is IArbitrator, OwnableUpgradeable, UUPSUpgradeable, Reentra /// @dev Set relayer function setRelayer(address _relayer, bool _active) external onlyOwner { - relayers[_relayer] = _active; - emit RelayerStatusUpdate(_relayer, _active); + if (relayers[_relayer] != _active) { + relayers[_relayer] = _active; + emit RelayerStatusUpdate(_relayer, _active); + } } /// @dev Set validator for a chain From fba01f859e5b88cf32a8710ec79e0509d798f662 Mon Sep 17 00:00:00 2001 From: zkbenny Date: Fri, 22 Mar 2024 14:17:24 +0800 Subject: [PATCH 32/33] fix: abdk-cvf-2 --- contracts/gateway/zkpolygon/ZkPolygonL1Gateway.sol | 4 ---- 1 file changed, 4 deletions(-) diff --git a/contracts/gateway/zkpolygon/ZkPolygonL1Gateway.sol b/contracts/gateway/zkpolygon/ZkPolygonL1Gateway.sol index 8c4975a..db1f4fc 100644 --- a/contracts/gateway/zkpolygon/ZkPolygonL1Gateway.sol +++ b/contracts/gateway/zkpolygon/ZkPolygonL1Gateway.sol @@ -21,10 +21,6 @@ contract ZkPolygonL1Gateway is IBridgeMessageReceiver, L1BaseGateway, BaseGatewa _; } - /// @dev A mapping L2 batch number => message number => flag - /// @dev Used to indicate that zkSync L2 -> L1 message was already processed - mapping(uint256 => mapping(uint256 => bool)) public isMessageFinalized; - constructor(IArbitrator _arbitrator, IZkPolygon _messageService) L1BaseGateway(_arbitrator) { _disableInitializers(); MESSAGE_SERVICE = _messageService; From 7813bdb935c190e6c6bd35e001a7594b76d1d971 Mon Sep 17 00:00:00 2001 From: zkbenny Date: Fri, 22 Mar 2024 14:54:44 +0800 Subject: [PATCH 33/33] fix: abdk-cvf-7 --- contracts/Arbitrator.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/Arbitrator.sol b/contracts/Arbitrator.sol index 7465a12..862e898 100644 --- a/contracts/Arbitrator.sol +++ b/contracts/Arbitrator.sol @@ -81,7 +81,7 @@ contract Arbitrator is IArbitrator, OwnableUpgradeable, UUPSUpgradeable, Reentra /// @dev Set primary chain function setPrimaryChainGateway(IL1Gateway _gateway) external onlyOwner { require(address(primaryChainGateway) == address(0), "Duplicate init gateway"); - require(address(primaryChainGateway) != address(0), "Invalid gateway"); + require(address(_gateway) != address(0), "Invalid gateway"); primaryChainGateway = _gateway; emit InitPrimaryChain(_gateway); }