diff --git a/packages/contracts-bedrock/semver-lock.json b/packages/contracts-bedrock/semver-lock.json index cf02370f2c40..19292d8fc3ed 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": "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 543580078da2..d27c6e7db514 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"; @@ -38,32 +32,33 @@ 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. - /// @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); + } }