diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..d5804b89 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,28 @@ +name: Lint Check + +on: [push] + +env: + FOUNDRY_PROFILE: ci + +jobs: + check: + strategy: + fail-fast: true + + name: Forge Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + with: + version: nightly + + - name: Run Forge fmt --check + run: | + forge fmt --check + id: fmt diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 9be10507..58281c32 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -10,4 +10,5 @@ jobs: - uses: crytic/slither-action@v0.3.0 with: fail-on: high - slither-args: --filter-paths "./lib|./test" \ No newline at end of file + slither-args: --filter-paths "./lib|./test" + node-version: 18 \ No newline at end of file diff --git a/script/InitializeChildContracts.s.sol b/script/InitializeChildContracts.s.sol index 513d0b2e..52cc6994 100644 --- a/script/InitializeChildContracts.s.sol +++ b/script/InitializeChildContracts.s.sol @@ -13,7 +13,8 @@ contract InitializeChildContracts is Script { function run() public { uint256 deployerPrivateKey = vm.envUint("CHILD_PRIVATE_KEY"); ChildERC20Bridge childERC20Bridge = ChildERC20Bridge(vm.envAddress("CHILD_ERC20_BRIDGE")); - ChildAxelarBridgeAdaptor childAxelarBridgeAdaptor = ChildAxelarBridgeAdaptor(vm.envAddress("CHILD_BRIDGE_ADAPTOR")); + ChildAxelarBridgeAdaptor childAxelarBridgeAdaptor = + ChildAxelarBridgeAdaptor(vm.envAddress("CHILD_BRIDGE_ADAPTOR")); address childTokenTemplate = vm.envAddress("CHILDCHAIN_CHILD_TOKEN_TEMPLATE"); address rootERC20BridgeAdaptor = vm.envAddress("ROOT_BRIDGE_ADAPTOR"); string memory childRpcUrl = vm.envString("CHILD_RPC_URL"); @@ -27,8 +28,8 @@ contract InitializeChildContracts is Script { vm.startBroadcast(deployerPrivateKey); childERC20Bridge.initialize( - address(childAxelarBridgeAdaptor), - Strings.toHexString(rootERC20BridgeAdaptor), + address(childAxelarBridgeAdaptor), + Strings.toHexString(rootERC20BridgeAdaptor), childTokenTemplate, rootChainName, rootIMXToken @@ -37,6 +38,5 @@ contract InitializeChildContracts is Script { childAxelarBridgeAdaptor.setRootBridgeAdaptor(); vm.stopBroadcast(); - } } diff --git a/script/InitializeRootContracts.s.sol b/script/InitializeRootContracts.s.sol index 66a53115..515f122d 100644 --- a/script/InitializeRootContracts.s.sol +++ b/script/InitializeRootContracts.s.sol @@ -22,7 +22,7 @@ contract InitializeRootContracts is Script { string memory rootRpcUrl = vm.envString("ROOT_RPC_URL"); uint256 rootPrivateKey = vm.envUint("ROOT_PRIVATE_KEY"); address rootIMXToken = vm.envAddress("ROOT_IMX_ADDRESS"); - address childETHToken = vm.envAddress("CHILD_ETH_ADDRESS"); + address childETHToken = vm.envAddress("CHILD_ETH_ADDRESS"); /** * INITIALIZE ROOT CHAIN CONTRACTS diff --git a/src/child/ChildERC20Bridge.sol b/src/child/ChildERC20Bridge.sol index 105d9787..251d4005 100644 --- a/src/child/ChildERC20Bridge.sol +++ b/src/child/ChildERC20Bridge.sol @@ -192,7 +192,7 @@ contract ChildERC20Bridge is } else { Address.sendValue(payable(receiver), amount); emit IMXDeposit(address(rootToken), sender, receiver, amount); - } + } } function updateBridgeAdaptor(address newBridgeAdaptor) external override onlyOwner { diff --git a/src/root/RootERC20Bridge.sol b/src/root/RootERC20Bridge.sol index 71eebc9b..ec58af89 100644 --- a/src/root/RootERC20Bridge.sol +++ b/src/root/RootERC20Bridge.sol @@ -62,19 +62,15 @@ contract RootERC20Bridge is address newRootBridgeAdaptor, address newChildERC20Bridge, address newChildBridgeAdaptor, - address newChildTokenTemplate, + address newChildTokenTemplate, address newRootIMXToken, - address newChildETHToken) - public - initializer - { - if (newRootBridgeAdaptor == address(0) - || newChildERC20Bridge == address(0) - || newChildTokenTemplate == address(0) - || newChildBridgeAdaptor == address(0) - || newRootIMXToken == address(0) - || newChildETHToken == address(0)) - { + address newChildETHToken + ) public initializer { + if ( + newRootBridgeAdaptor == address(0) || newChildERC20Bridge == address(0) + || newChildTokenTemplate == address(0) || newChildBridgeAdaptor == address(0) + || newRootIMXToken == address(0) || newChildETHToken == address(0) + ) { revert ZeroAddress(); } childERC20Bridge = newChildERC20Bridge; @@ -96,11 +92,13 @@ contract RootERC20Bridge is return _mapToken(rootToken); } - function depositETH(uint256 amount) external payable { //override removed? + function depositETH(uint256 amount) external payable { + //override removed? _depositETH(msg.sender, amount); } - function depositToETH(address receiver, uint256 amount) external payable { //override removed? + function depositToETH(address receiver, uint256 amount) external payable { + //override removed? _depositETH(receiver, amount); } @@ -205,7 +203,7 @@ contract RootERC20Bridge is } else { feeAmount = msg.value - amount; } - + // Deposit sig, root token address, depositor, receiver, amount bytes memory payload = abi.encode(DEPOSIT_SIG, rootToken, msg.sender, receiver, amount); // TODO investigate using delegatecall to keep the axelar message sender as the bridge contract, since adaptor can change. diff --git a/test/integration/root/RootERC20Bridge.t.sol b/test/integration/root/RootERC20Bridge.t.sol index d6bfd4de..8b0c38af 100644 --- a/test/integration/root/RootERC20Bridge.t.sol +++ b/test/integration/root/RootERC20Bridge.t.sol @@ -99,7 +99,8 @@ contract RootERC20BridgeIntegrationTest is Test, IRootERC20BridgeEvents, IRootAx function test_depositToken() public { uint256 tokenAmount = 300; string memory childBridgeAdaptorString = Strings.toHexString(CHILD_BRIDGE_ADAPTOR); - (address childToken, bytes memory predictedPayload) = setupDeposit(token, rootBridge, mapTokenFee, depositFee, tokenAmount, true); + (address childToken, bytes memory predictedPayload) = + setupDeposit(token, rootBridge, mapTokenFee, depositFee, tokenAmount, true); vm.expectEmit(address(axelarAdaptor)); emit MapTokenAxelarMessage(CHILD_CHAIN_NAME, childBridgeAdaptorString, predictedPayload); diff --git a/test/unit/child/ChildERC20Bridge.t.sol b/test/unit/child/ChildERC20Bridge.t.sol index 0d6ed39d..d1b37edb 100644 --- a/test/unit/child/ChildERC20Bridge.t.sol +++ b/test/unit/child/ChildERC20Bridge.t.sol @@ -286,7 +286,6 @@ contract ChildERC20BridgeUnitTest is Test, IChildERC20BridgeEvents, IChildERC20B //Deposit function test_onMessageReceive_DepositIMX_EmitsIMXDepositEvent() public { - uint256 fundedAmount = 10 ether; vm.deal(address(childBridge), fundedAmount); @@ -317,7 +316,7 @@ contract ChildERC20BridgeUnitTest is Test, IChildERC20BridgeEvents, IChildERC20B assertEq(receiver.balance, amount, "receiver balance not increased"); } - function test_RevertIf_onMessageReceive_DepositIMX_InsufficientBalance() public { + function test_RevertIf_onMessageReceive_DepositIMX_InsufficientBalance() public { uint256 fundedAmount = 1 ether; vm.deal(address(childBridge), fundedAmount); diff --git a/test/unit/root/RootERC20Bridge.t.sol b/test/unit/root/RootERC20Bridge.t.sol index 95c60a78..0ca62f8f 100644 --- a/test/unit/root/RootERC20Bridge.t.sol +++ b/test/unit/root/RootERC20Bridge.t.sol @@ -43,7 +43,9 @@ contract RootERC20BridgeUnitTest is Test, IRootERC20BridgeEvents, IRootERC20Brid mockAxelarAdaptor = new MockAdaptor(); // The specific ERC20 token template does not matter for these unit tests - rootBridge.initialize(address(mockAxelarAdaptor), CHILD_BRIDGE, CHILD_BRIDGE_ADAPTOR, address(token), IMX_TOKEN, CHILD_ETH_TOKEN); + rootBridge.initialize( + address(mockAxelarAdaptor), CHILD_BRIDGE, CHILD_BRIDGE_ADAPTOR, address(token), IMX_TOKEN, CHILD_ETH_TOKEN + ); } /** @@ -58,7 +60,9 @@ contract RootERC20BridgeUnitTest is Test, IRootERC20BridgeEvents, IRootERC20Brid function test_RevertIfInitializeTwice() public { vm.expectRevert("Initializable: contract is already initialized"); - rootBridge.initialize(address(mockAxelarAdaptor), CHILD_BRIDGE, CHILD_BRIDGE_ADAPTOR, address(token), IMX_TOKEN, CHILD_ETH_TOKEN); + rootBridge.initialize( + address(mockAxelarAdaptor), CHILD_BRIDGE, CHILD_BRIDGE_ADAPTOR, address(token), IMX_TOKEN, CHILD_ETH_TOKEN + ); } function test_RevertIf_InitializeWithAZeroAddressRootAdapter() public { @@ -118,7 +122,6 @@ contract RootERC20BridgeUnitTest is Test, IRootERC20BridgeEvents, IRootERC20Brid } function test_mapToken_CallsAdaptor() public { - bytes memory payload = abi.encode(rootBridge.MAP_TOKEN_SIG(), token, token.name(), token.symbol(), token.decimals()); @@ -214,7 +217,7 @@ contract RootERC20BridgeUnitTest is Test, IRootERC20BridgeEvents, IRootERC20Brid abi.encodeWithSelector(mockAxelarAdaptor.sendMessage.selector, predictedPayload, address(this)) ); - rootBridge.depositETH{value: amount+depositFee}(amount); + rootBridge.depositETH{value: amount + depositFee}(amount); } function test_depositETHEmitsNativeEthDepositEvent() public { @@ -231,10 +234,10 @@ contract RootERC20BridgeUnitTest is Test, IRootERC20BridgeEvents, IRootERC20Brid setupDeposit(ERC20PresetMinterPauser(NATIVE_ETH), rootBridge, mapTokenFee, depositFee, amount, false); vm.expectRevert(InsufficientValue.selector); - rootBridge.depositETH{value: (amount/2)+depositFee}(amount); + rootBridge.depositETH{value: (amount / 2) + depositFee}(amount); } - /** + /** * DEPOSIT TO ETH */ @@ -248,7 +251,7 @@ contract RootERC20BridgeUnitTest is Test, IRootERC20BridgeEvents, IRootERC20Brid abi.encodeWithSelector(mockAxelarAdaptor.sendMessage.selector, predictedPayload, address(this)) ); - rootBridge.depositToETH{value: amount+depositFee}(receiver, amount); + rootBridge.depositToETH{value: amount + depositFee}(receiver, amount); } function test_depositToETHEmitsNativeEthDepositEvent() public { @@ -267,7 +270,7 @@ contract RootERC20BridgeUnitTest is Test, IRootERC20BridgeEvents, IRootERC20Brid setupDepositTo(ERC20PresetMinterPauser(NATIVE_ETH), rootBridge, mapTokenFee, depositFee, amount, receiver, false); vm.expectRevert(InsufficientValue.selector); - rootBridge.depositToETH{value: (amount/2)+depositFee}(receiver, amount); + rootBridge.depositToETH{value: (amount / 2) + depositFee}(receiver, amount); } /** @@ -279,7 +282,7 @@ contract RootERC20BridgeUnitTest is Test, IRootERC20BridgeEvents, IRootERC20Brid setupDeposit(ERC20PresetMinterPauser(NATIVE_ETH), rootBridge, mapTokenFee, depositFee, amount, false); vm.expectRevert(ZeroAmount.selector); - rootBridge.depositETH{value: amount+depositFee}(amount); + rootBridge.depositETH{value: amount + depositFee}(amount); } function test_RevertIf_depositToETHAmountIsZero() public { @@ -289,7 +292,7 @@ contract RootERC20BridgeUnitTest is Test, IRootERC20BridgeEvents, IRootERC20Brid setupDeposit(ERC20PresetMinterPauser(NATIVE_ETH), rootBridge, mapTokenFee, depositFee, amount, false); vm.expectRevert(ZeroAmount.selector); - rootBridge.depositToETH{value: amount+depositFee}(receiver, amount); + rootBridge.depositToETH{value: amount + depositFee}(receiver, amount); } function test_RevertIf_depositAmountIsZero() public { @@ -411,7 +414,8 @@ contract RootERC20BridgeUnitTest is Test, IRootERC20BridgeEvents, IRootERC20Brid uint256 amount = 100; address receiver = address(12345); - (, bytes memory predictedPayload) = setupDepositTo(token, rootBridge, mapTokenFee, depositFee, amount, receiver, true); + (, bytes memory predictedPayload) = + setupDepositTo(token, rootBridge, mapTokenFee, depositFee, amount, receiver, true); vm.expectCall( address(mockAxelarAdaptor), diff --git a/test/utils.t.sol b/test/utils.t.sol index 5da0769f..a7373846 100644 --- a/test/utils.t.sol +++ b/test/utils.t.sol @@ -12,13 +12,13 @@ import {IChildERC20, ChildERC20} from "../src/child/ChildERC20.sol"; import {RootAxelarBridgeAdaptor} from "../src/root/RootAxelarBridgeAdaptor.sol"; contract Utils is Test { - function integrationSetup( - address childBridge, - address childBridgeAdaptor, + address childBridge, + address childBridgeAdaptor, string memory childBridgeName, address imxTokenAddress, - address ethTokenAddress) + address ethTokenAddress + ) public returns ( ERC20PresetMinterPauser token, @@ -42,7 +42,9 @@ contract Utils is Test { address(axelarGasService) ); - rootBridge.initialize(address(axelarAdaptor), childBridge, childBridgeAdaptor, address(token), imxTokenAddress, ethTokenAddress); + rootBridge.initialize( + address(axelarAdaptor), childBridge, childBridgeAdaptor, address(token), imxTokenAddress, ethTokenAddress + ); axelarAdaptor.setChildBridgeAdaptor(); } @@ -83,12 +85,12 @@ contract Utils is Test { childToken = rootBridge.mapToken{value: mapTokenFee}(token); } if (address(token) == address(0xeee)) { - vm.deal(to, tokenAmount+depositFee); + vm.deal(to, tokenAmount + depositFee); } else { token.mint(address(this), tokenAmount); token.approve(address(rootBridge), tokenAmount); } - + return (childToken, predictedPayload); }