From b37ad326daa981d7b9fa9aedc0454b5d7dc939a1 Mon Sep 17 00:00:00 2001 From: Milap Sheth Date: Fri, 15 Dec 2023 11:45:34 -0500 Subject: [PATCH] fix: address audit comments (#234) * build: bump cgp and gmp sdk dep * fix: address audit comments --- .../interchain-token/InterchainToken.sol | 1 + contracts/interfaces/IInterchainToken.sol | 1 + contracts/utils/InterchainTokenDeployer.sol | 2 ++ test/InterchainToken.js | 21 ++++++++++++------- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/contracts/interchain-token/InterchainToken.sol b/contracts/interchain-token/InterchainToken.sol index 1b66b582..1dea362a 100644 --- a/contracts/interchain-token/InterchainToken.sol +++ b/contracts/interchain-token/InterchainToken.sol @@ -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; diff --git a/contracts/interfaces/IInterchainToken.sol b/contracts/interfaces/IInterchainToken.sol index ea825627..105cabe4 100644 --- a/contracts/interfaces/IInterchainToken.sol +++ b/contracts/interfaces/IInterchainToken.sol @@ -15,6 +15,7 @@ interface IInterchainToken is IInterchainTokenStandard, IMinter, IERC20MintableB error InterchainTokenServiceAddressZero(); error TokenIdZero(); error TokenNameEmpty(); + error TokenSymbolEmpty(); error AlreadyInitialized(); /** diff --git a/contracts/utils/InterchainTokenDeployer.sol b/contracts/utils/InterchainTokenDeployer.sol index f5c07045..1fabe688 100644 --- a/contracts/utils/InterchainTokenDeployer.sol +++ b/contracts/utils/InterchainTokenDeployer.sol @@ -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); diff --git a/test/InterchainToken.js b/test/InterchainToken.js index e5c25814..7bc35ca9 100644 --- a/test/InterchainToken.js +++ b/test/InterchainToken.js @@ -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', []);