From 71389b6d2344b1db57c5010e5a0bce1b835f50e9 Mon Sep 17 00:00:00 2001 From: AgusDuha <81362284+agusduha@users.noreply.github.com> Date: Fri, 11 Oct 2024 15:23:06 -0300 Subject: [PATCH] fix: rename crosschain functions (#94) --- .../scripts/checks/interfaces/main.go | 2 +- packages/contracts-bedrock/semver-lock.json | 8 +-- .../abi/OptimismSuperchainERC20.json | 68 +++++++++---------- .../src/L2/SuperchainERC20.sol | 4 +- .../src/L2/SuperchainTokenBridge.sol | 4 +- .../src/L2/interfaces/ICrosschainERC20.sol | 4 +- .../test/L2/SuperchainERC20.t.sol | 24 +++---- .../test/L2/SuperchainTokenBridge.t.sol | 2 +- .../fuzz/Protocol.unguided.t.sol | 4 +- .../handlers/Protocol.t.sol | 2 +- 10 files changed, 58 insertions(+), 64 deletions(-) diff --git a/packages/contracts-bedrock/scripts/checks/interfaces/main.go b/packages/contracts-bedrock/scripts/checks/interfaces/main.go index e5f9344f63b3..ab07dbb4d84b 100644 --- a/packages/contracts-bedrock/scripts/checks/interfaces/main.go +++ b/packages/contracts-bedrock/scripts/checks/interfaces/main.go @@ -27,7 +27,7 @@ var excludeContracts = []string{ // TODO: Interfaces that need to be fixed "IInitializable", "IPreimageOracle", "ILegacyMintableERC20", "IOptimismMintableERC20", - "IOptimismMintableERC721", "KontrolCheatsBase", "IWETH", "IDelayedWETH", "ISuperchainWETH", + "IOptimismMintableERC721", "KontrolCheatsBase", "IWETH", "IDelayedWETH", "ISuperchainWETH", "IL2ToL2CrossDomainMessenger", "ICrossL2Inbox", "ISystemConfigInterop", "IResolvedDelegateProxy", } diff --git a/packages/contracts-bedrock/semver-lock.json b/packages/contracts-bedrock/semver-lock.json index 4f5b4bcbf28f..c7f5eeb04a52 100644 --- a/packages/contracts-bedrock/semver-lock.json +++ b/packages/contracts-bedrock/semver-lock.json @@ -108,7 +108,7 @@ "sourceCodeHash": "0xfea53344596d735eff3be945ed1300dc75a6f8b7b2c02c0043af5b0036f5f239" }, "src/L2/OptimismSuperchainERC20.sol": { - "initCodeHash": "0xb5bb005962c7c93d8d84cb6e752983e63dd4c33707dc6361dbbf23dcce1eeea6", + "initCodeHash": "0xd5c84e45746fd741d541a917ddc1cc0c7043c6b21d5c18040d4bc999d6a7b2db", "sourceCodeHash": "0xf32130f0b46333daba062c50ff6dcfadce1f177ff753bed2374d499ea9c2d98a" }, "src/L2/OptimismSuperchainERC20Beacon.sol": { @@ -125,11 +125,11 @@ }, "src/L2/SuperchainERC20.sol": { "initCodeHash": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", - "sourceCodeHash": "0x3dc9534bbadfa01ad9a2d414adf76c2562b2319c33f74cbae7860b48d023aedf" + "sourceCodeHash": "0x75d061633a141af11a19b86e599a1725dfae8d245dcddfb6bb244a50d5e53f96" }, "src/L2/SuperchainTokenBridge.sol": { - "initCodeHash": "0x501741478992b7d97c245674f1ad326f0e09b4b1bb595675d6c1c066f44af424", - "sourceCodeHash": "0x48cf6ba2e53f86345840948c271672489f3fdb484e4ea2c26f94295fdf98bbd8" + "initCodeHash": "0x07fc1d495928d9c13bd945a049d17e1d105d01c2082a7719e5d18cbc0e1c7d9e", + "sourceCodeHash": "0xaf2458e48dcadcafa8940cde7368549eae2280eef91247600d864ddac20f5d82" }, "src/L2/SuperchainWETH.sol": { "initCodeHash": "0x50f6ea9bfe650fcf792e98e44b1bf66c036fd0e6d4b753da680253d7d8609816", diff --git a/packages/contracts-bedrock/snapshots/abi/OptimismSuperchainERC20.json b/packages/contracts-bedrock/snapshots/abi/OptimismSuperchainERC20.json index af1524b311f4..f1b7f83e3b53 100644 --- a/packages/contracts-bedrock/snapshots/abi/OptimismSuperchainERC20.json +++ b/packages/contracts-bedrock/snapshots/abi/OptimismSuperchainERC20.json @@ -21,35 +21,47 @@ "inputs": [ { "internalType": "address", - "name": "_from", + "name": "owner", "type": "address" }, + { + "internalType": "address", + "name": "spender", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ { "internalType": "uint256", - "name": "_amount", + "name": "result", "type": "uint256" } ], - "name": "__crosschainBurn", - "outputs": [], - "stateMutability": "nonpayable", + "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", - "name": "_to", + "name": "spender", "type": "address" }, { "internalType": "uint256", - "name": "_amount", + "name": "amount", "type": "uint256" } ], - "name": "__crosschainMint", - "outputs": [], + "name": "approve", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], "stateMutability": "nonpayable", "type": "function" }, @@ -59,14 +71,9 @@ "internalType": "address", "name": "owner", "type": "address" - }, - { - "internalType": "address", - "name": "spender", - "type": "address" } ], - "name": "allowance", + "name": "balanceOf", "outputs": [ { "internalType": "uint256", @@ -81,23 +88,17 @@ "inputs": [ { "internalType": "address", - "name": "spender", + "name": "_from", "type": "address" }, { "internalType": "uint256", - "name": "amount", + "name": "_amount", "type": "uint256" } ], - "name": "approve", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], + "name": "burn", + "outputs": [], "stateMutability": "nonpayable", "type": "function" }, @@ -105,26 +106,25 @@ "inputs": [ { "internalType": "address", - "name": "owner", + "name": "_from", "type": "address" - } - ], - "name": "balanceOf", - "outputs": [ + }, { "internalType": "uint256", - "name": "result", + "name": "_amount", "type": "uint256" } ], - "stateMutability": "view", + "name": "crosschainBurn", + "outputs": [], + "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "address", - "name": "_from", + "name": "_to", "type": "address" }, { @@ -133,7 +133,7 @@ "type": "uint256" } ], - "name": "burn", + "name": "crosschainMint", "outputs": [], "stateMutability": "nonpayable", "type": "function" diff --git a/packages/contracts-bedrock/src/L2/SuperchainERC20.sol b/packages/contracts-bedrock/src/L2/SuperchainERC20.sol index 629155a847d7..9ead2645828b 100644 --- a/packages/contracts-bedrock/src/L2/SuperchainERC20.sol +++ b/packages/contracts-bedrock/src/L2/SuperchainERC20.sol @@ -27,7 +27,7 @@ abstract contract SuperchainERC20 is ERC20, ICrosschainERC20, ISemver { /// @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 virtual onlySuperchainTokenBridge { + function crosschainMint(address _to, uint256 _amount) external onlySuperchainTokenBridge { _mint(_to, _amount); emit CrosschainMinted(_to, _amount); @@ -36,7 +36,7 @@ abstract contract SuperchainERC20 is ERC20, 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 virtual onlySuperchainTokenBridge { + function crosschainBurn(address _from, uint256 _amount) external onlySuperchainTokenBridge { _burn(_from, _amount); emit CrosschainBurnt(_from, _amount); diff --git a/packages/contracts-bedrock/src/L2/SuperchainTokenBridge.sol b/packages/contracts-bedrock/src/L2/SuperchainTokenBridge.sol index dd5c464e4bd4..1dcc233638f5 100644 --- a/packages/contracts-bedrock/src/L2/SuperchainTokenBridge.sol +++ b/packages/contracts-bedrock/src/L2/SuperchainTokenBridge.sol @@ -63,7 +63,7 @@ contract SuperchainTokenBridge { { if (_to == address(0)) revert ZeroAddress(); - ISuperchainERC20(_token).__crosschainBurn(msg.sender, _amount); + ISuperchainERC20(_token).crosschainBurn(msg.sender, _amount); bytes memory message = abi.encodeCall(this.relayERC20, (_token, msg.sender, _to, _amount)); msgHash_ = IL2ToL2CrossDomainMessenger(MESSENGER).sendMessage(_chainId, address(this), message); @@ -86,7 +86,7 @@ contract SuperchainTokenBridge { uint256 source = IL2ToL2CrossDomainMessenger(MESSENGER).crossDomainMessageSource(); - ISuperchainERC20(_token).__crosschainMint(_to, _amount); + ISuperchainERC20(_token).crosschainMint(_to, _amount); emit RelayERC20(_token, _from, _to, _amount, source); } diff --git a/packages/contracts-bedrock/src/L2/interfaces/ICrosschainERC20.sol b/packages/contracts-bedrock/src/L2/interfaces/ICrosschainERC20.sol index c156b79dc609..efdebe8f8b47 100644 --- a/packages/contracts-bedrock/src/L2/interfaces/ICrosschainERC20.sol +++ b/packages/contracts-bedrock/src/L2/interfaces/ICrosschainERC20.sol @@ -17,10 +17,10 @@ interface ICrosschainERC20 { /// @notice Mint tokens through a crosschain transfer. /// @param _to Address to mint tokens to. /// @param _amount Amount of tokens to mint. - function __crosschainMint(address _to, uint256 _amount) external; + function crosschainMint(address _to, uint256 _amount) external; /// @notice Burn tokens through a crosschain transfer. /// @param _from Address to burn tokens from. /// @param _amount Amount of tokens to burn. - function __crosschainBurn(address _from, uint256 _amount) external; + function crosschainBurn(address _from, uint256 _amount) external; } diff --git a/packages/contracts-bedrock/test/L2/SuperchainERC20.t.sol b/packages/contracts-bedrock/test/L2/SuperchainERC20.t.sol index 399938349c69..999b0ad4ee88 100644 --- a/packages/contracts-bedrock/test/L2/SuperchainERC20.t.sol +++ b/packages/contracts-bedrock/test/L2/SuperchainERC20.t.sol @@ -35,7 +35,7 @@ contract SuperchainERC20Test is Test { } /// @notice Tests the `mint` function reverts when the caller is not the bridge. - function testFuzz___crosschainMint_callerNotBridge_reverts(address _caller, address _to, uint256 _amount) public { + function testFuzz_crosschainMint_callerNotBridge_reverts(address _caller, address _to, uint256 _amount) public { // Ensure the caller is not the bridge vm.assume(_caller != SUPERCHAIN_TOKEN_BRIDGE); @@ -44,11 +44,11 @@ contract SuperchainERC20Test is Test { // Call the `mint` function with the non-bridge caller vm.prank(_caller); - superchainERC20.__crosschainMint(_to, _amount); + superchainERC20.crosschainMint(_to, _amount); } /// @notice Tests the `mint` succeeds and emits the `Mint` event. - function testFuzz___crosschainMint_succeeds(address _to, uint256 _amount) public { + function testFuzz_crosschainMint_succeeds(address _to, uint256 _amount) public { // Ensure `_to` is not the zero address vm.assume(_to != ZERO_ADDRESS); @@ -66,7 +66,7 @@ contract SuperchainERC20Test is Test { // Call the `mint` function with the bridge caller vm.prank(SUPERCHAIN_TOKEN_BRIDGE); - superchainERC20.__crosschainMint(_to, _amount); + superchainERC20.crosschainMint(_to, _amount); // Check the total supply and balance of `_to` after the mint were updated correctly assertEq(superchainERC20.totalSupply(), _totalSupplyBefore + _amount); @@ -74,13 +74,7 @@ contract SuperchainERC20Test is Test { } /// @notice Tests the `burn` function reverts when the caller is not the bridge. - function testFuzz___crosschainBurn_callerNotBridge_reverts( - address _caller, - address _from, - uint256 _amount - ) - public - { + function testFuzz_crosschainBurn_callerNotBridge_reverts(address _caller, address _from, uint256 _amount) public { // Ensure the caller is not the bridge vm.assume(_caller != SUPERCHAIN_TOKEN_BRIDGE); @@ -89,17 +83,17 @@ contract SuperchainERC20Test is Test { // Call the `burn` function with the non-bridge caller vm.prank(_caller); - superchainERC20.__crosschainBurn(_from, _amount); + superchainERC20.crosschainBurn(_from, _amount); } /// @notice Tests the `burn` burns the amount and emits the `CrosschainBurnt` event. - function testFuzz___crosschainBurn_succeeds(address _from, uint256 _amount) public { + function testFuzz_crosschainBurn_succeeds(address _from, uint256 _amount) public { // Ensure `_from` is not the zero address vm.assume(_from != ZERO_ADDRESS); // Mint some tokens to `_from` so then they can be burned vm.prank(SUPERCHAIN_TOKEN_BRIDGE); - superchainERC20.__crosschainMint(_from, _amount); + superchainERC20.crosschainMint(_from, _amount); // Get the total supply and balance of `_from` before the burn to compare later on the assertions uint256 _totalSupplyBefore = superchainERC20.totalSupply(); @@ -115,7 +109,7 @@ contract SuperchainERC20Test is Test { // Call the `burn` function with the bridge caller vm.prank(SUPERCHAIN_TOKEN_BRIDGE); - superchainERC20.__crosschainBurn(_from, _amount); + superchainERC20.crosschainBurn(_from, _amount); // Check the total supply and balance of `_from` after the burn were updated correctly assertEq(superchainERC20.totalSupply(), _totalSupplyBefore - _amount); diff --git a/packages/contracts-bedrock/test/L2/SuperchainTokenBridge.t.sol b/packages/contracts-bedrock/test/L2/SuperchainTokenBridge.t.sol index 8aa533558fe5..8367112a5942 100644 --- a/packages/contracts-bedrock/test/L2/SuperchainTokenBridge.t.sol +++ b/packages/contracts-bedrock/test/L2/SuperchainTokenBridge.t.sol @@ -77,7 +77,7 @@ contract SuperchainTokenBridgeTest is Bridge_Initializer { // Mint some tokens to the sender so then they can be sent vm.prank(Predeploys.SUPERCHAIN_TOKEN_BRIDGE); - superchainERC20.__crosschainMint(_sender, _amount); + superchainERC20.crosschainMint(_sender, _amount); // Get the total supply and balance of `_sender` before the send to compare later on the assertions uint256 _totalSupplyBefore = IERC20(address(superchainERC20)).totalSupply(); diff --git a/packages/contracts-bedrock/test/invariants/OptimismSuperchainERC20/fuzz/Protocol.unguided.t.sol b/packages/contracts-bedrock/test/invariants/OptimismSuperchainERC20/fuzz/Protocol.unguided.t.sol index 2ead177276f8..aa3eaaa93134 100644 --- a/packages/contracts-bedrock/test/invariants/OptimismSuperchainERC20/fuzz/Protocol.unguided.t.sol +++ b/packages/contracts-bedrock/test/invariants/OptimismSuperchainERC20/fuzz/Protocol.unguided.t.sol @@ -17,7 +17,7 @@ contract ProtocolUnguided is ProtocolHandler, CompatibleAssert { bytes32 salt = MESSENGER.superTokenInitDeploySalts(token); amount = bound(amount, 0, type(uint256).max - OptimismSuperchainERC20(token).totalSupply()); vm.prank(sender); - try OptimismSuperchainERC20(token).__crosschainMint(to, amount) { + try OptimismSuperchainERC20(token).crosschainMint(to, amount) { compatibleAssert(sender == BRIDGE); (, uint256 currentValue) = ghost_totalSupplyAcrossChains.tryGet(salt); ghost_totalSupplyAcrossChains.set(salt, currentValue + amount); @@ -33,7 +33,7 @@ contract ProtocolUnguided is ProtocolHandler, CompatibleAssert { bytes32 salt = MESSENGER.superTokenInitDeploySalts(token); uint256 senderBalance = OptimismSuperchainERC20(token).balanceOf(sender); vm.prank(sender); - try OptimismSuperchainERC20(token).__crosschainBurn(from, amount) { + try OptimismSuperchainERC20(token).crosschainBurn(from, amount) { compatibleAssert(sender == BRIDGE); (, uint256 currentValue) = ghost_totalSupplyAcrossChains.tryGet(salt); ghost_totalSupplyAcrossChains.set(salt, currentValue - amount); diff --git a/packages/contracts-bedrock/test/invariants/OptimismSuperchainERC20/handlers/Protocol.t.sol b/packages/contracts-bedrock/test/invariants/OptimismSuperchainERC20/handlers/Protocol.t.sol index 91aa9a81c619..d4a12c4067bd 100644 --- a/packages/contracts-bedrock/test/invariants/OptimismSuperchainERC20/handlers/Protocol.t.sol +++ b/packages/contracts-bedrock/test/invariants/OptimismSuperchainERC20/handlers/Protocol.t.sol @@ -79,7 +79,7 @@ contract ProtocolHandler is TestBase, StdUtils, Actors { index = bound(index, 0, allSuperTokens.length - 1); address addr = allSuperTokens[index]; vm.prank(BRIDGE); - OptimismSuperchainERC20(addr).__crosschainMint(currentActor(), amount); + OptimismSuperchainERC20(addr).crosschainMint(currentActor(), amount); // currentValue will be zero if key is not present (, uint256 currentValue) = ghost_totalSupplyAcrossChains.tryGet(MESSENGER.superTokenInitDeploySalts(addr)); ghost_totalSupplyAcrossChains.set(MESSENGER.superTokenInitDeploySalts(addr), currentValue + amount);