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

fix: add minter check #276

Merged
merged 6 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
2 changes: 2 additions & 0 deletions contracts/InterchainTokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M
if (initialSupply > 0) {
minterBytes = address(this).toBytes();
} else if (minter != address(0)) {
if (minter == address(interchainTokenService)) revert InvalidMinter(minter);
ahramy marked this conversation as resolved.
Show resolved Hide resolved
ahramy marked this conversation as resolved.
Show resolved Hide resolved
minterBytes = minter.toBytes();
}

Expand Down Expand Up @@ -202,6 +203,7 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M

if (minter != address(0)) {
if (!token.isMinter(minter)) revert NotMinter(minter);
if (minter == address(interchainTokenService)) revert InvalidMinter(minter);

minter_ = minter.toBytes();
}
Expand Down
1 change: 1 addition & 0 deletions contracts/interfaces/IInterchainTokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { IInterchainTokenService } from './IInterchainTokenService.sol';
interface IInterchainTokenFactory is IUpgradable, IMulticall {
error ZeroAddress();
error InvalidChainName();
error InvalidMinter(address minter);
error NotMinter(address minter);
error NotOperator(address operator);
error GatewayToken(address tokenAddress);
Expand Down
21 changes: 21 additions & 0 deletions test/InterchainTokenFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,16 @@ describe('InterchainTokenFactory', () => {
expect(await tokenManager.isFlowLimiter(service.address)).to.be.true;
};

it('Should revert an interchain token deployment with the minter as interchainTokenService', async () => {
const salt = keccak256('0x1245');
await expectRevert(
(gasOptions) => tokenFactory.deployInterchainToken(salt, name, symbol, decimals, 0, service.address, gasOptions),
tokenFactory,
'InvalidMinter',
[service.address],
);
});

it('Should register a token if the mint amount is zero', async () => {
const salt = keccak256('0x1234');
tokenId = await tokenFactory.interchainTokenId(wallet.address, salt);
Expand Down Expand Up @@ -400,6 +410,17 @@ describe('InterchainTokenFactory', () => {
[otherWallet.address],
);

await expectRevert(
(gasOptions) =>
tokenFactory.deployRemoteInterchainToken(chainName, salt, service.address, destinationChain, gasValue, {
...gasOptions,
value: gasValue,
}),
tokenFactory,
'InvalidMinter',
[service.address],
);

await expect(
tokenFactory.deployRemoteInterchainToken('', salt, wallet.address, destinationChain, gasValue, {
value: gasValue,
Expand Down
Loading