Skip to content

Commit

Permalink
fix: address audit comments (#234)
Browse files Browse the repository at this point in the history
* build: bump cgp and gmp sdk dep

* fix: address audit comments
  • Loading branch information
milapsheth authored Dec 15, 2023
1 parent e71c9ac commit b37ad32
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions contracts/interchain-token/InterchainToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ contract InterchainToken is InterchainTokenStandard, ERC20, ERC20Permit, Minter,

if (tokenId_ == bytes32(0)) revert TokenIdZero();
if (bytes(tokenName).length == 0) revert TokenNameEmpty();
if (bytes(tokenSymbol).length == 0) revert TokenSymbolEmpty();

name = tokenName;
symbol = tokenSymbol;
Expand Down
1 change: 1 addition & 0 deletions contracts/interfaces/IInterchainToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface IInterchainToken is IInterchainTokenStandard, IMinter, IERC20MintableB
error InterchainTokenServiceAddressZero();
error TokenIdZero();
error TokenNameEmpty();
error TokenSymbolEmpty();
error AlreadyInitialized();

/**
Expand Down
2 changes: 2 additions & 0 deletions contracts/utils/InterchainTokenDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ contract InterchainTokenDeployer is IInterchainTokenDeployer, Create3 {
string calldata symbol,
uint8 decimals
) external returns (address tokenAddress) {
// Use a minimal proxy for cheap token deployment and auto-verification on explorers
// https://eips.ethereum.org/EIPS/eip-1167
// The minimal proxy bytecode is the same as https://github.com/OpenZeppelin/openzeppelin-contracts/blob/94697be8a3f0dfcd95dfb13ffbd39b5973f5c65d/contracts/proxy/Clones.sol#L28
// The minimal proxy bytecode is 0x37 = 55 bytes long
bytes memory bytecode = new bytes(0x37);
Expand Down
21 changes: 13 additions & 8 deletions test/InterchainToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,32 +73,37 @@ describe('InterchainToken', () => {
});

it('revert on init if tokenId is 0', async () => {
const implementationAddress = await interchainTokenDeployer.implementationAddress();
const implementation = await getContractAt('InterchainToken', implementationAddress, owner);

const salt = getRandomBytes32();
const minter = owner.address;
await expectRevert(
(gasOptions) => interchainTokenDeployer.deployInterchainToken(salt, HashZero, minter, name, symbol, decimals, gasOptions),
implementation,
interchainToken,
'TokenIdZero',
);
});

it('revert on init if token name is invalid', async () => {
const implementationAddress = await interchainTokenDeployer.implementationAddress();
const implementation = await getContractAt('InterchainToken', implementationAddress, owner);

const salt = getRandomBytes32();
const tokenId = getRandomBytes32();
const minter = owner.address;
await expectRevert(
(gasOptions) => interchainTokenDeployer.deployInterchainToken(salt, tokenId, minter, '', symbol, decimals, gasOptions),
implementation,
interchainToken,
'TokenNameEmpty',
);
});

it('revert on init if token symbol is invalid', async () => {
const salt = getRandomBytes32();
const tokenId = getRandomBytes32();
const minter = owner.address;
await expectRevert(
(gasOptions) => interchainTokenDeployer.deployInterchainToken(salt, tokenId, minter, name, '', decimals, gasOptions),
interchainToken,
'TokenSymbolEmpty',
);
});

it('should subtract from the spender allowance', async () => {
tokenTest = await deployContract(owner, 'TestInterchainToken', []);

Expand Down

0 comments on commit b37ad32

Please sign in to comment.