Skip to content

Commit

Permalink
Fix Macro Q3 audit findig (#18)
Browse files Browse the repository at this point in the history
* Move Ownable from XERC20BaseAdapter to L1EXERC20Adapter

* Lint
  • Loading branch information
lmcorbalan authored Jun 27, 2024
1 parent fbb173e commit 7dc6d77
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
9 changes: 6 additions & 3 deletions src/L1XERC20Adapter.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { XERC20BaseAdapter } from "src/XERC20BaseAdapter.sol";
import { L1ArbitrumEnabled } from "src/libraries/L1ArbitrumEnabled.sol";

Expand All @@ -14,7 +15,7 @@ import { L1ArbitrumEnabled } from "src/libraries/L1ArbitrumEnabled.sol";
*
* @author BootNode
*/
contract L1XERC20Adapter is XERC20BaseAdapter, L1ArbitrumEnabled {
contract L1XERC20Adapter is XERC20BaseAdapter, L1ArbitrumEnabled, Ownable {
/**
* @dev Sets the XERC20 token, the gateway and the owner.
*/
Expand All @@ -23,9 +24,11 @@ contract L1XERC20Adapter is XERC20BaseAdapter, L1ArbitrumEnabled {
address _gatewayAddress,
address _owner
)
XERC20BaseAdapter(_xerc20, _owner)
XERC20BaseAdapter(_xerc20)
L1ArbitrumEnabled(_gatewayAddress)
{ }
{
_transferOwnership(_owner);
}

/**
* @dev Sets the token/gateway relation on Arbitrum Router and registers the token on L2 counterpart gateway.
Expand Down
9 changes: 3 additions & 6 deletions src/XERC20BaseAdapter.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { ERC165 } from "@openzeppelin/contracts/utils/introspection/ERC165.sol";

Expand All @@ -13,16 +12,14 @@ import { IXERC20Adapter } from "src/interfaces/IXERC20Adapter.sol";
*
* @author BootNode
*/
abstract contract XERC20BaseAdapter is IXERC20Adapter, ERC165, Ownable {
abstract contract XERC20BaseAdapter is IXERC20Adapter, ERC165 {
address internal xerc20;

/**
* @dev Sets the XERC20 token and the owner of this contract.
* @dev Sets the XERC20 token.
*/
constructor(address _xerc20, address _owner) {
// TODO: maybe we should check whether the token is actually an XERC20
constructor(address _xerc20) {
xerc20 = _xerc20;
_transferOwnership(_owner);
}

function getXERC20() external view returns (address) {
Expand Down
11 changes: 11 additions & 0 deletions test/L1XERC20AdapterTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ contract L1XERC20AdapterTest is XERC20BaseAdapterTest {
assertEq(L1XERC20Adapter(_adapter).isArbitrumEnabled(), uint8(0xb1));
}

function test_registerTokenOnL2_OnlyOwner() public {
address caller = makeAddr("someOther");
deal(caller, 2);

vm.prank(caller);
vm.expectRevert("Ownable: caller is not the owner");
L1XERC20Adapter(_adapter).registerTokenOnL2{ value: 2 }(
makeAddr("l2Token"), 0, 0, 0, 0, 0, 1, 1, makeAddr("creditBack")
);
}

function test_registerTokenOnL2_WrongValue(uint256 valueForGateway, uint256 valueForRouter) public {
// bound to avoid overflow or underflow
valueForGateway = bound(valueForGateway, 1, 1e36);
Expand Down
2 changes: 1 addition & 1 deletion test/L2XERC20Gateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { L2XERC20Gateway } from "src/L2XERC20Gateway.sol";
import { XERC20BaseAdapter } from "src/XERC20BaseAdapter.sol";

contract MockAdapter is XERC20BaseAdapter {
constructor(address _xerc20, address _owner) XERC20BaseAdapter(_xerc20, _owner) { }
constructor(address _xerc20, address _owner) XERC20BaseAdapter(_xerc20) { }
}

contract L2XERC20GatewayTest is Test {
Expand Down

0 comments on commit 7dc6d77

Please sign in to comment.