Skip to content

Commit

Permalink
fix: rename crosschain functions (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
agusduha authored Oct 11, 2024
1 parent 97fb300 commit 71389b6
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}

Expand Down
8 changes: 4 additions & 4 deletions packages/contracts-bedrock/semver-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"sourceCodeHash": "0xfea53344596d735eff3be945ed1300dc75a6f8b7b2c02c0043af5b0036f5f239"
},
"src/L2/OptimismSuperchainERC20.sol": {
"initCodeHash": "0xb5bb005962c7c93d8d84cb6e752983e63dd4c33707dc6361dbbf23dcce1eeea6",
"initCodeHash": "0xd5c84e45746fd741d541a917ddc1cc0c7043c6b21d5c18040d4bc999d6a7b2db",
"sourceCodeHash": "0xf32130f0b46333daba062c50ff6dcfadce1f177ff753bed2374d499ea9c2d98a"
},
"src/L2/OptimismSuperchainERC20Beacon.sol": {
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -59,14 +71,9 @@
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"internalType": "address",
"name": "spender",
"type": "address"
}
],
"name": "allowance",
"name": "balanceOf",
"outputs": [
{
"internalType": "uint256",
Expand All @@ -81,50 +88,43 @@
"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"
},
{
"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"
},
{
Expand All @@ -133,7 +133,7 @@
"type": "uint256"
}
],
"name": "burn",
"name": "crosschainMint",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts-bedrock/src/L2/SuperchainERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts-bedrock/src/L2/SuperchainTokenBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
24 changes: 9 additions & 15 deletions packages/contracts-bedrock/test/L2/SuperchainERC20.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -66,21 +66,15 @@ 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);
assertEq(superchainERC20.balanceOf(_to), _toBalanceBefore + _amount);
}

/// @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);

Expand All @@ -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();
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 71389b6

Please sign in to comment.