-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added additional checks for call contract with token (#249)
* Added additional checks but code size is too large * Added value for contractCallWithToken and optimized contract size * trying to fix tests * Update the create3address of ITS to use a custom bytecodehash. * prettier * fix tests * Added a few tests * fixed one more test * fixed all tests * prettier * made lint happy * working on slither * made slither happy * prettier * Using constant for the hash as well * addressed comments * added some tests * added some coverage tests, found a bug too! * a small style fix * fixed a bug * addressed some comments * prettier * fixed a test * remove modifier that should not exist * rename a function * Update contracts/InterchainTokenService.sol Co-authored-by: Milap Sheth <[email protected]> * reinteroduce the modifiers since they are needed after all * Update contracts/utils/Create3AddressFixed.sol * add a docstring * prettier and fixed tests * address comments * fix factory import --------- Co-authored-by: Milap Sheth <[email protected]> Co-authored-by: Milap Sheth <[email protected]>
- Loading branch information
1 parent
e2cb43c
commit 2ed153a
Showing
12 changed files
with
640 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import { Create3Fixed } from '../../utils/Create3Fixed.sol'; | ||
|
||
contract TestCreate3Fixed is Create3Fixed { | ||
event Deployed(address addr); | ||
|
||
function deploy(bytes memory code, bytes32 salt) public payable returns (address addr) { | ||
addr = _create3(code, salt); | ||
|
||
emit Deployed(addr); | ||
} | ||
|
||
function deployedAddress(bytes32 salt) public view returns (address addr) { | ||
addr = _create3Address(salt); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
/** | ||
* @title Create3AddressFixed contract | ||
* @notice This contract can be used to predict the deterministic deployment address of a contract deployed with the `CREATE3` technique. | ||
* It is equivalent to the Create3Address found in axelar-gmp-sdk-solidity repo but uses a fixed bytecode for CreateDeploy, | ||
* which allows changing compilation options (like number of runs) without affecting the future deployment addresses. | ||
*/ | ||
contract Create3AddressFixed { | ||
// slither-disable-next-line too-many-digits | ||
bytes internal constant CREATE_DEPLOY_BYTECODE = | ||
hex'608060405234801561001057600080fd5b50610162806100206000396000f3fe60806040526004361061001d5760003560e01c806277436014610022575b600080fd5b61003561003036600461007b565b610037565b005b8051602082016000f061004957600080fd5b50565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b60006020828403121561008d57600080fd5b813567ffffffffffffffff808211156100a557600080fd5b818401915084601f8301126100b957600080fd5b8135818111156100cb576100cb61004c565b604051601f8201601f19908116603f011681019083821181831017156100f3576100f361004c565b8160405282815287602084870101111561010c57600080fd5b82602086016020830137600092810160200192909252509594505050505056fea264697066735822122094780ce55d28f1d568f4e0ab1b9dc230b96e952b73d2e06456fbff2289fa27f464736f6c63430008150033'; | ||
bytes32 internal constant CREATE_DEPLOY_BYTECODE_HASH = keccak256(CREATE_DEPLOY_BYTECODE); | ||
|
||
/** | ||
* @notice Compute the deployed address that will result from the `CREATE3` method. | ||
* @param deploySalt A salt to influence the contract address | ||
* @return deployed The deterministic contract address if it was deployed | ||
*/ | ||
function _create3Address(bytes32 deploySalt) internal view returns (address deployed) { | ||
address deployer = address( | ||
uint160(uint256(keccak256(abi.encodePacked(hex'ff', address(this), deploySalt, CREATE_DEPLOY_BYTECODE_HASH)))) | ||
); | ||
|
||
deployed = address(uint160(uint256(keccak256(abi.encodePacked(hex'd6_94', deployer, hex'01'))))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import { IDeploy } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IDeploy.sol'; | ||
import { ContractAddress } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/libs/ContractAddress.sol'; | ||
import { CreateDeploy } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/deploy/CreateDeploy.sol'; | ||
import { Create3AddressFixed } from './Create3AddressFixed.sol'; | ||
|
||
/** | ||
* @title Create3Fixed contract | ||
* @notice This contract can be used to deploy a contract with a deterministic address that depends only on | ||
* the deployer address and deployment salt, not the contract bytecode and constructor parameters. | ||
* It uses a fixed bytecode to allow changing the compilation settings without affecting the deployment address in the future. | ||
*/ | ||
contract Create3Fixed is Create3AddressFixed, IDeploy { | ||
using ContractAddress for address; | ||
|
||
/** | ||
* @notice Deploys a new contract using the `CREATE3` method. | ||
* @dev This function first deploys the CreateDeploy contract using | ||
* the `CREATE2` opcode and then utilizes the CreateDeploy to deploy the | ||
* new contract with the `CREATE` opcode. | ||
* @param bytecode The bytecode of the contract to be deployed | ||
* @param deploySalt A salt to influence the contract address | ||
* @return deployed The address of the deployed contract | ||
*/ | ||
function _create3(bytes memory bytecode, bytes32 deploySalt) internal returns (address deployed) { | ||
deployed = _create3Address(deploySalt); | ||
|
||
if (bytecode.length == 0) revert EmptyBytecode(); | ||
if (deployed.isContract()) revert AlreadyDeployed(); | ||
|
||
// Deploy using create2 | ||
CreateDeploy createDeploy; | ||
bytes memory createDeployBytecode_ = CREATE_DEPLOY_BYTECODE; | ||
uint256 length = createDeployBytecode_.length; | ||
assembly { | ||
createDeploy := create2(0, add(createDeployBytecode_, 0x20), length, deploySalt) | ||
} | ||
|
||
if (address(createDeploy) == address(0)) revert DeployFailed(); | ||
// Deploy using create | ||
createDeploy.deploy(bytecode); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.