From bf9d167cccd23c552f08b75062c986ba1a657934 Mon Sep 17 00:00:00 2001 From: agusduha Date: Fri, 18 Oct 2024 16:30:46 -0300 Subject: [PATCH 1/2] fix: superchainWETH redesign fixes --- packages/contracts-bedrock/semver-lock.json | 4 +- .../src/L2/SuperchainWETH.sol | 35 ++++++------ .../test/L2/SuperchainWETH.t.sol | 56 +++++++++++++++++++ 3 files changed, 74 insertions(+), 21 deletions(-) diff --git a/packages/contracts-bedrock/semver-lock.json b/packages/contracts-bedrock/semver-lock.json index cf02370f2c40..0fefcd2094a8 100644 --- a/packages/contracts-bedrock/semver-lock.json +++ b/packages/contracts-bedrock/semver-lock.json @@ -132,8 +132,8 @@ "sourceCodeHash": "0xaf2458e48dcadcafa8940cde7368549eae2280eef91247600d864ddac20f5d82" }, "src/L2/SuperchainWETH.sol": { - "initCodeHash": "0x76a6baa0823ca75f32a94ba49592f07129e762f9459be305b95b12475d8a5fce", - "sourceCodeHash": "0xbb6196751e8d1f0c7281bd824f0cb024dda726d65701def59cc3cb6d2bcbe6b3" + "initCodeHash": "0x09c7efed7d6c8ae5981f6e7a75c7b8c675f73d679265d15a010844ad9b41fa9b", + "sourceCodeHash": "0x66b1c79ddec97df2d2cfbc57e3f82e8b642297d267bb1fd960f6fc818b67df0d" }, "src/L2/WETH.sol": { "initCodeHash": "0xfb253765520690623f177941c2cd9eba23e4c6d15063bccdd5e98081329d8956", diff --git a/packages/contracts-bedrock/src/L2/SuperchainWETH.sol b/packages/contracts-bedrock/src/L2/SuperchainWETH.sol index 543580078da2..817ce9861110 100644 --- a/packages/contracts-bedrock/src/L2/SuperchainWETH.sol +++ b/packages/contracts-bedrock/src/L2/SuperchainWETH.sol @@ -21,12 +21,6 @@ import { Unauthorized, NotCustomGasToken } from "src/libraries/errors/CommonErro /// within the superchain. SuperchainWETH can be converted into native ETH on chains that /// do not use a custom gas token. contract SuperchainWETH is WETH98, ICrosschainERC20, ISemver { - /// @notice A modifier that only allows the SuperchainTokenBridge to call - modifier onlySuperchainTokenBridge() { - if (msg.sender != Predeploys.SUPERCHAIN_TOKEN_BRIDGE) revert Unauthorized(); - _; - } - /// @notice Semantic version. /// @custom:semver 1.0.0-beta.7 string public constant version = "1.0.0-beta.7"; @@ -44,26 +38,27 @@ contract SuperchainWETH is WETH98, ICrosschainERC20, ISemver { } /// @notice Mints WETH to an address. - /// @param _guy The address to mint WETH to. - /// @param _wad The amount of WETH to mint. - function _mint(address _guy, uint256 _wad) internal { - balanceOf[_guy] += _wad; - emit Transfer(address(0), _guy, _wad); + /// @param _to The address to mint WETH to. + /// @param _amount The amount of WETH to mint. + function _mint(address _to, uint256 _amount) internal { + balanceOf[_to] += _amount; + emit Transfer(address(0), _to, _amount); } /// @notice Burns WETH from an address. - /// @param _guy The address to burn WETH from. - /// @param _wad The amount of WETH to burn. - function _burn(address _guy, uint256 _wad) internal { - require(balanceOf[_guy] >= _wad); - balanceOf[_guy] -= _wad; - emit Transfer(_guy, address(0), _wad); + /// @param _from The address to burn WETH from. + /// @param _amount The amount of WETH to burn. + function _burn(address _from, uint256 _amount) internal { + balanceOf[_from] -= _amount; + emit Transfer(_from, address(0), _amount); } /// @notice Allows the SuperchainTokenBridge to mint tokens. /// @param _to Address to mint tokens to. /// @param _amount Amount of tokens to mint. - function crosschainMint(address _to, uint256 _amount) external onlySuperchainTokenBridge { + function crosschainMint(address _to, uint256 _amount) external { + if (msg.sender != Predeploys.SUPERCHAIN_TOKEN_BRIDGE) revert Unauthorized(); + _mint(_to, _amount); // Mint from ETHLiquidity contract. @@ -77,7 +72,9 @@ contract SuperchainWETH is WETH98, ICrosschainERC20, ISemver { /// @notice Allows the SuperchainTokenBridge to burn tokens. /// @param _from Address to burn tokens from. /// @param _amount Amount of tokens to burn. - function crosschainBurn(address _from, uint256 _amount) external onlySuperchainTokenBridge { + function crosschainBurn(address _from, uint256 _amount) external { + if (msg.sender != Predeploys.SUPERCHAIN_TOKEN_BRIDGE) revert Unauthorized(); + _burn(_from, _amount); // Burn to ETHLiquidity contract. diff --git a/packages/contracts-bedrock/test/L2/SuperchainWETH.t.sol b/packages/contracts-bedrock/test/L2/SuperchainWETH.t.sol index bee12c00b568..ea02c9c0f45b 100644 --- a/packages/contracts-bedrock/test/L2/SuperchainWETH.t.sol +++ b/packages/contracts-bedrock/test/L2/SuperchainWETH.t.sol @@ -323,4 +323,60 @@ contract SuperchainWETH_Test is CommonTest { assertEq(_from.balance, 0); assertEq(superchainWeth.balanceOf(_from), _amount); } + + /// @notice Test that the internal mint function reverts to protect against accidentally changing the visibility. + function testFuzz_calling_internal_mint_function_reverts(address _caller, address _to, uint256 _amount) public { + // Arrange + bytes memory _calldata = abi.encodeWithSignature("_mint(address,uint256)", _to, _amount); + vm.expectRevert(); + + // Act + vm.prank(_caller); + (bool success,) = address(superchainWeth).call(_calldata); + + // Assert + assertFalse(success); + } + + /// @notice Test that the mint function reverts to protect against accidentally changing the visibility. + function testFuzz_calling_mint_function_reverts(address _caller, address _to, uint256 _amount) public { + // Arrange + bytes memory _calldata = abi.encodeWithSignature("mint(address,uint256)", _to, _amount); + vm.expectRevert(); + + // Act + vm.prank(_caller); + (bool success,) = address(superchainWeth).call(_calldata); + + // Assert + assertFalse(success); + } + + /// @notice Test that the internal burn function reverts to protect against accidentally changing the visibility. + function testFuzz_calling_internal_burn_function_reverts(address _caller, address _from, uint256 _amount) public { + // Arrange + bytes memory _calldata = abi.encodeWithSignature("_burn(address,uint256)", _from, _amount); + vm.expectRevert(); + + // Act + vm.prank(_caller); + (bool success,) = address(superchainWeth).call(_calldata); + + // Assert + assertFalse(success); + } + + /// @notice Test that the burn function reverts to protect against accidentally changing the visibility. + function testFuzz_calling_burn_function_reverts(address _caller, address _from, uint256 _amount) public { + // Arrange + bytes memory _calldata = abi.encodeWithSignature("burn(address,uint256)", _from, _amount); + vm.expectRevert(); + + // Act + vm.prank(_caller); + (bool success,) = address(superchainWeth).call(_calldata); + + // Assert + assertFalse(success); + } } From 07933b5d10634690f15cd5ee56ec1b1fb355d7ab Mon Sep 17 00:00:00 2001 From: agusduha Date: Fri, 18 Oct 2024 17:07:56 -0300 Subject: [PATCH 2/2] fix: withdraw arg --- packages/contracts-bedrock/semver-lock.json | 2 +- packages/contracts-bedrock/snapshots/abi/SuperchainWETH.json | 2 +- packages/contracts-bedrock/src/L2/SuperchainWETH.sol | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/contracts-bedrock/semver-lock.json b/packages/contracts-bedrock/semver-lock.json index 0fefcd2094a8..19292d8fc3ed 100644 --- a/packages/contracts-bedrock/semver-lock.json +++ b/packages/contracts-bedrock/semver-lock.json @@ -133,7 +133,7 @@ }, "src/L2/SuperchainWETH.sol": { "initCodeHash": "0x09c7efed7d6c8ae5981f6e7a75c7b8c675f73d679265d15a010844ad9b41fa9b", - "sourceCodeHash": "0x66b1c79ddec97df2d2cfbc57e3f82e8b642297d267bb1fd960f6fc818b67df0d" + "sourceCodeHash": "0x8d7612a71deaadfb324c4136673df96019211292ff54494fa4b7724e2e5dd22a" }, "src/L2/WETH.sol": { "initCodeHash": "0xfb253765520690623f177941c2cd9eba23e4c6d15063bccdd5e98081329d8956", diff --git a/packages/contracts-bedrock/snapshots/abi/SuperchainWETH.json b/packages/contracts-bedrock/snapshots/abi/SuperchainWETH.json index 1a8a06b1eec9..59e959f9f231 100644 --- a/packages/contracts-bedrock/snapshots/abi/SuperchainWETH.json +++ b/packages/contracts-bedrock/snapshots/abi/SuperchainWETH.json @@ -239,7 +239,7 @@ "inputs": [ { "internalType": "uint256", - "name": "wad", + "name": "_amount", "type": "uint256" } ], diff --git a/packages/contracts-bedrock/src/L2/SuperchainWETH.sol b/packages/contracts-bedrock/src/L2/SuperchainWETH.sol index 817ce9861110..d27c6e7db514 100644 --- a/packages/contracts-bedrock/src/L2/SuperchainWETH.sol +++ b/packages/contracts-bedrock/src/L2/SuperchainWETH.sol @@ -32,9 +32,9 @@ contract SuperchainWETH is WETH98, ICrosschainERC20, ISemver { } /// @inheritdoc WETH98 - function withdraw(uint256 wad) public override { + function withdraw(uint256 _amount) public override { if (IL1Block(Predeploys.L1_BLOCK_ATTRIBUTES).isCustomGasToken()) revert NotCustomGasToken(); - super.withdraw(wad); + super.withdraw(_amount); } /// @notice Mints WETH to an address.