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

Check channel agent Id #1347

Merged
merged 3 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion contracts/src/Assets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,11 @@ library Assets {
}

// @dev Mint foreign token from Polkadot
function mintForeignToken(bytes32 foreignTokenID, address recipient, uint256 amount) external {
function mintForeignToken(address agent, bytes32 foreignTokenID, address recipient, uint256 amount) external {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed before, I prefer if we check the channel id instead of the agent id. Ultimately what we are doing is adding a restriction that the mint message can only be passed via the Channel owned by AssetHub.

Example:

function mintForeignToken(ChannelID channelID, ...) {
   if (channelID == $.assetHubParaID.into()) { ... }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in bbf6532

AssetsStorage.Layout storage $ = AssetsStorage.layout();
if(agent != $.assetHubAgent) {
revert TokenMintFailed();
}
address token = _ensureTokenAddressOf(foreignTokenID);
Token(token).mint(recipient, amount);
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/src/Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ contract Gateway is IGateway, IInitializable, IUpgradable {
success = false;
}
} else if (message.command == Command.MintForeignToken) {
try Gateway(this).mintForeignToken{gas: maxDispatchGas}(message.params) {}
try Gateway(this).mintForeignToken{gas: maxDispatchGas}(channel.agent, message.params) {}
catch {
success = false;
}
Expand Down Expand Up @@ -411,9 +411,9 @@ contract Gateway is IGateway, IInitializable, IUpgradable {
}

// @dev Mint foreign token from polkadot
function mintForeignToken(bytes calldata data) external onlySelf {
function mintForeignToken(address agent, bytes calldata data) external onlySelf {
MintForeignTokenParams memory params = abi.decode(data, (MintForeignTokenParams));
Assets.mintForeignToken(params.foreignTokenID, params.recipient, params.amount);
Assets.mintForeignToken(agent, params.foreignTokenID, params.recipient, params.amount);
}

// @dev Transfer Ethereum native token back from polkadot
Expand Down
13 changes: 11 additions & 2 deletions contracts/test/Gateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ contract GatewayTest is Test {
vm.expectEmit(true, true, false, false);
emit Transfer(address(0), account1, 1000);

MockGateway(address(gateway)).mintForeignTokenPublic(abi.encode(params));
MockGateway(address(gateway)).mintForeignTokenPublic(assetHubAgent, abi.encode(params));

address dotToken = MockGateway(address(gateway)).tokenAddressOf(dotTokenID);

Expand All @@ -916,7 +916,16 @@ contract GatewayTest is Test {

vm.expectRevert(Assets.TokenNotRegistered.selector);

MockGateway(address(gateway)).mintForeignTokenPublic(abi.encode(params));
MockGateway(address(gateway)).mintForeignTokenPublic(assetHubAgent, abi.encode(params));
}

function testMintFromParachainOtherThanAssetHubWillFail() public {
MintForeignTokenParams memory params =
MintForeignTokenParams({foreignTokenID: bytes32(uint256(1)), recipient: account1, amount: 1000});

vm.expectRevert(Assets.TokenMintFailed.selector);

MockGateway(address(gateway)).mintForeignTokenPublic(bridgeHubAgent, abi.encode(params));
}

function testSendRelayTokenToAssetHubWithAddress32() public {
Expand Down
4 changes: 2 additions & 2 deletions contracts/test/mocks/MockGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ contract MockGateway is Gateway {
this.registerForeignToken(params);
}

function mintForeignTokenPublic(bytes calldata params) external {
this.mintForeignToken(params);
function mintForeignTokenPublic(address agent, bytes calldata params) external {
this.mintForeignToken(agent, params);
}

function transferNativeTokenPublic(bytes calldata params) external {
Expand Down
Loading