Skip to content

Commit

Permalink
Disable token operation through transact
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed Apr 24, 2024
1 parent 1fb852d commit b89cc6c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
7 changes: 5 additions & 2 deletions contracts/src/Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,11 @@ contract Gateway is IGateway, IInitializable, IUpgradable {
abi.decode(params.payload, (AgentExecuteCommand, bytes));
if (command == AgentExecuteCommand.Transact) {
(address target,,) = abi.decode(commandParams, (address, bytes, uint64));
//Todo: Add registered ERC20 to the blacklist
if (target == address(this) || target == agent || target == AGENT_EXECUTOR) {
// blacklist to check with
if (
target == address(this) || target == agent || target == AGENT_EXECUTOR
|| Assets.isTokenRegistered(target)
) {
revert NoPermission();
}
}
Expand Down
32 changes: 26 additions & 6 deletions contracts/test/Gateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
import {WETH9} from "canonical-weth/WETH9.sol";
import {UD60x18, ud60x18, convert} from "prb/math/src/UD60x18.sol";
import {HelloWorld} from "./mocks/HelloWorld.sol";
import {IERC20} from "../src/interfaces/IERC20.sol";

contract GatewayTest is Test {
ParaID public bridgeHubParaID = ParaID.wrap(1001);
Expand Down Expand Up @@ -100,16 +101,12 @@ contract GatewayTest is Test {
HelloWorld helloWorld;

event SaidHello(string indexed message);
event Transfer(address indexed src, address indexed dst, uint256 wad);

function setUp() public {
AgentExecutor executor = new AgentExecutor();
gatewayLogic = new MockGateway(
address(0),
address(executor),
bridgeHubParaID,
bridgeHubAgentID,
foreignTokenDecimals,
maxDestinationFee
address(0), address(executor), bridgeHubParaID, bridgeHubAgentID, foreignTokenDecimals, maxDestinationFee
);
Gateway.Config memory config = Gateway.Config({
mode: OperatingMode.Normal,
Expand Down Expand Up @@ -928,4 +925,27 @@ contract GatewayTest is Test {

MockGateway(address(gateway)).agentExecutePublic(abi.encode(params));
}

function testAgentExecutionTransactToTransferERC20() public {
testRegisterToken();

token.transfer(address(assetHubAgent), 200);

uint256 balanceBefore = IERC20(address(token)).balanceOf(account1);

uint256 amount = 50;
bytes memory payload = abi.encodeCall(IERC20.transfer, (account1, amount));

AgentExecuteParams memory params = AgentExecuteParams({
agentID: assetHubAgentID,
payload: abi.encode(AgentExecuteCommand.Transact, abi.encode(address(token), payload, 100000))
});

vm.expectRevert(Gateway.NoPermission.selector);

MockGateway(address(gateway)).agentExecutePublic(abi.encode(params));

uint256 balanceAfter = IERC20(address(token)).balanceOf(account1);
assertEq(balanceBefore, balanceAfter);
}
}
2 changes: 1 addition & 1 deletion contracts/test/mocks/MockGatewayV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ library AdditionalStorage {
}

// Used to test upgrades.
contract MockGatewayV2 is IInitializable {
contract MockGatewayV2 is IInitializable {
// Reinitialize gateway with some additional storage fields
function initialize(bytes memory params) external {
AdditionalStorage.Layout storage $ = AdditionalStorage.layout();
Expand Down

0 comments on commit b89cc6c

Please sign in to comment.