Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: SuperchainWETH redesign fixes #110

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/contracts-bedrock/semver-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@
"sourceCodeHash": "0xaf2458e48dcadcafa8940cde7368549eae2280eef91247600d864ddac20f5d82"
},
"src/L2/SuperchainWETH.sol": {
"initCodeHash": "0x76a6baa0823ca75f32a94ba49592f07129e762f9459be305b95b12475d8a5fce",
"sourceCodeHash": "0xbb6196751e8d1f0c7281bd824f0cb024dda726d65701def59cc3cb6d2bcbe6b3"
"initCodeHash": "0x09c7efed7d6c8ae5981f6e7a75c7b8c675f73d679265d15a010844ad9b41fa9b",
"sourceCodeHash": "0x8d7612a71deaadfb324c4136673df96019211292ff54494fa4b7724e2e5dd22a"
},
"src/L2/WETH.sol": {
"initCodeHash": "0xfb253765520690623f177941c2cd9eba23e4c6d15063bccdd5e98081329d8956",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
"inputs": [
{
"internalType": "uint256",
"name": "wad",
"name": "_amount",
"type": "uint256"
}
],
Expand Down
39 changes: 18 additions & 21 deletions packages/contracts-bedrock/src/L2/SuperchainWETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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.
Expand All @@ -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.
Expand Down
56 changes: 56 additions & 0 deletions packages/contracts-bedrock/test/L2/SuperchainWETH.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}