From 1131db4af992783c231676a30c731a86d279b49b Mon Sep 17 00:00:00 2001 From: josojo Date: Wed, 3 Jan 2024 21:48:59 +0100 Subject: [PATCH 1/2] Do not allow gasTokens to be managed by hard asset manager --- contracts/ForkableBridge.sol | 9 ++++++++- contracts/interfaces/IForkableBridge.sol | 2 ++ test/ForkableBridge.t.sol | 9 +++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/contracts/ForkableBridge.sol b/contracts/ForkableBridge.sol index 4aafde3c..edf273de 100644 --- a/contracts/ForkableBridge.sol +++ b/contracts/ForkableBridge.sol @@ -62,6 +62,9 @@ contract ForkableBridge is if (to != children[0] && to != children[1]) { revert InvalidDestinationForHardAsset(); } + if(token==gasTokenAddress){ + revert GasTokenIsNotHardAsset(); + } IERC20(token).transfer(to, amount); } @@ -178,8 +181,12 @@ contract ForkableBridge is * @dev Allows aynone to take out their forkonomic tokens * and send them to the children-bridge contracts * Notice that forkonomic tokens are special, as they their main contract - * is on L1, but they are still forkable tokens as all the tokens from + * is on L1, but they are still forkable tokens, as their contract is forked as well. + * We allow to send tokens only to one child, just in case the one child contract + * was updated shortly after the fork and contains an error (e.g. reverts on sending) + * @param amount Amount of tokens to be sent to the children-bridge contracts * @param useFirstChild boolean indicating for which child the operation should be run + * @param useChildTokenAllowance boolean indicating if the child token allowance (previously burned tokens) should be used */ function sendForkonomicTokensToChild( uint256 amount, diff --git a/contracts/interfaces/IForkableBridge.sol b/contracts/interfaces/IForkableBridge.sol index 5ba2aefb..30c7125d 100644 --- a/contracts/interfaces/IForkableBridge.sol +++ b/contracts/interfaces/IForkableBridge.sol @@ -11,6 +11,8 @@ interface IForkableBridge is IForkableStructure, IPolygonZkEVMBridge { error NotAuthorized(); /// @dev Error thrown when trying to send bridged tokens to a child contract error InvalidDestinationForHardAsset(); + /// @dev Error thrown when hardasset manager tries to send gas token to a child contract + error GasTokenIsNotHardAsset(); /** * @dev Function to initialize the contract diff --git a/test/ForkableBridge.t.sol b/test/ForkableBridge.t.sol index 72536289..ae266dea 100644 --- a/test/ForkableBridge.t.sol +++ b/test/ForkableBridge.t.sol @@ -504,6 +504,15 @@ contract ForkableBridgeTest is Test { to ); + vm.expectRevert( + IForkableBridge.GasTokenIsNotHardAsset.selector + ); + vm.prank(hardAssetManger); + forkableBridge.transferHardAssetsToChild( + address(gasTokenAddress), + amount, + child2 + ); vm.expectRevert( IForkableBridge.InvalidDestinationForHardAsset.selector ); From d4bca5699b2c183acc9a5f5b3646643bfac9d3ba Mon Sep 17 00:00:00 2001 From: josojo Date: Wed, 3 Jan 2024 21:56:58 +0100 Subject: [PATCH 2/2] linting --- contracts/ForkableBridge.sol | 2 +- test/ForkableBridge.t.sol | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/contracts/ForkableBridge.sol b/contracts/ForkableBridge.sol index edf273de..38c65292 100644 --- a/contracts/ForkableBridge.sol +++ b/contracts/ForkableBridge.sol @@ -62,7 +62,7 @@ contract ForkableBridge is if (to != children[0] && to != children[1]) { revert InvalidDestinationForHardAsset(); } - if(token==gasTokenAddress){ + if (token == gasTokenAddress) { revert GasTokenIsNotHardAsset(); } IERC20(token).transfer(to, amount); diff --git a/test/ForkableBridge.t.sol b/test/ForkableBridge.t.sol index ae266dea..1f64c1f7 100644 --- a/test/ForkableBridge.t.sol +++ b/test/ForkableBridge.t.sol @@ -504,9 +504,7 @@ contract ForkableBridgeTest is Test { to ); - vm.expectRevert( - IForkableBridge.GasTokenIsNotHardAsset.selector - ); + vm.expectRevert(IForkableBridge.GasTokenIsNotHardAsset.selector); vm.prank(hardAssetManger); forkableBridge.transferHardAssetsToChild( address(gasTokenAddress),