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

feat: wrap payload #261

Closed
wants to merge 51 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
48f60e5
Added additional checks but code size is too large
Foivos Feb 6, 2024
fc8cb1a
Added value for contractCallWithToken and optimized contract size
Foivos Feb 7, 2024
ead719d
trying to fix tests
Foivos Feb 7, 2024
800ae3d
Update the create3address of ITS to use a custom bytecodehash.
Foivos Feb 9, 2024
cf016b0
prettier
Foivos Feb 12, 2024
ad53bc2
fix tests
Foivos Feb 12, 2024
7f610e7
Added a few tests
Foivos Feb 12, 2024
7a926fc
fixed one more test
Foivos Feb 12, 2024
83a396a
fixed all tests
Foivos Feb 13, 2024
c326d57
prettier
Foivos Feb 13, 2024
ca2bd91
made lint happy
Foivos Feb 13, 2024
1468d7e
working on slither
Foivos Feb 13, 2024
dccaf3c
made slither happy
Foivos Feb 14, 2024
927e1ce
prettier
Foivos Feb 14, 2024
1fc47a8
Using constant for the hash as well
Foivos Feb 14, 2024
f5823cc
addressed comments
Foivos Feb 14, 2024
c562c6a
added some tests
Foivos Feb 14, 2024
684fda9
Merge remote-tracking branch 'origin/main' into feat/additional-check…
Foivos Feb 15, 2024
f133cc9
added some coverage tests, found a bug too!
Foivos Feb 15, 2024
76a2545
a small style fix
Foivos Feb 16, 2024
74f09c6
fixed a bug
Foivos Feb 16, 2024
e896028
addressed some comments
Foivos Feb 20, 2024
b57cefc
prettier
Foivos Feb 20, 2024
5e311f2
fixed a test
Foivos Feb 20, 2024
f92443b
Merge branch 'main' into feat/additional-checks-for-execute-with-token
milapsheth Feb 21, 2024
0fcba29
remove modifier that should not exist
Foivos Feb 21, 2024
c5a5ba5
rename a function
Foivos Feb 21, 2024
dbc605d
Update contracts/InterchainTokenService.sol
Foivos Feb 21, 2024
b1c9266
reinteroduce the modifiers since they are needed after all
Foivos Feb 21, 2024
515be9c
Update contracts/utils/Create3AddressFixed.sol
milapsheth Feb 23, 2024
f787f13
add a docstring
Foivos Feb 23, 2024
10ed394
prettier and fixed tests
Foivos Mar 7, 2024
d7b0dd8
Merge remote-tracking branch 'origin/releases/1.2.x' into feat/merge-…
Foivos Mar 25, 2024
573569e
Merge remote-tracking branch 'origin/main' into feat/merge-new-token-…
Foivos Mar 25, 2024
ce3cf52
fixed tests
Foivos Mar 25, 2024
d804a7c
Merge branch 'main' into feat/merge-new-token-managers
Foivos Mar 26, 2024
52c75e6
Merge remote-tracking branch 'origin/main' into feat/additional-check…
Foivos Mar 26, 2024
acfbecb
added the changes
Foivos Mar 27, 2024
6b2fc97
Merge branch 'feat/additional-checks-for-execute-with-token' into fea…
Foivos Apr 11, 2024
a4a9a49
Added wrapping and unwrapping of payloads
Foivos Apr 11, 2024
f9734a0
Merge branch 'main' into feat/wrap-payload
Foivos Apr 15, 2024
e005136
Merge remote-tracking branch 'origin/main' into feat/wrap-payload
Foivos Apr 15, 2024
c394e13
fix merge
Foivos Apr 15, 2024
0b0e606
Merge branch 'feat/merge-new-token-managers' into feat/wrap-payload
Foivos Apr 15, 2024
5b0dd0f
fixed compilation
Foivos Apr 15, 2024
faddc28
Merge branch 'feat/reduce-codesize' into feat/wrap-payload
Foivos Apr 15, 2024
8abb2b2
fixed tests
Foivos Apr 15, 2024
f8c449a
Merge branch 'feat/reduce-codesize' into feat/wrap-payload
Foivos Apr 15, 2024
37ee0c4
optimize compilation runs
Foivos Apr 15, 2024
f18b722
make lint happy
Foivos Apr 15, 2024
2fe3777
Merge branch 'feat/reduce-codesize' into feat/wrap-payload
Foivos Apr 15, 2024
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
41 changes: 29 additions & 12 deletions contracts/InterchainTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
pragma solidity ^0.8.0;

import { IERC20 } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IERC20.sol';
import { IAxelarGasService } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGasService.sol';
import { IAxelarGateway } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGateway.sol';
import { ExpressExecutorTracker } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/express/ExpressExecutorTracker.sol';
import { Upgradable } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/upgradable/Upgradable.sol';
Expand Down Expand Up @@ -50,6 +49,8 @@ contract InterchainTokenService is
address public immutable interchainTokenDeployer;
address public immutable tokenManagerDeployer;

string internal constant AXELAR = 'Axelar';

/**
* @dev Token manager implementation addresses
*/
Expand All @@ -70,6 +71,7 @@ contract InterchainTokenService is
uint256 private constant MESSAGE_TYPE_INTERCHAIN_TRANSFER = 0;
uint256 private constant MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN = 1;
uint256 private constant MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER = 2;
uint256 private constant MESSAGE_TYPE_ROUTE_PAYLOAD = 10;

/**
* @dev Tokens and token managers deployed via the Token Factory contract use a special deployer address.
Expand Down Expand Up @@ -700,8 +702,8 @@ contract InterchainTokenService is
function _processInterchainTransferPayload(
bytes32 commandId,
address expressExecutor,
string calldata sourceChain,
bytes calldata payload
string memory sourceChain,
bytes memory payload
) internal {
bytes32 tokenId;
bytes memory sourceAddress;
Expand Down Expand Up @@ -757,7 +759,7 @@ contract InterchainTokenService is
/**
* @notice Processes a deploy token manager payload.
*/
function _processDeployTokenManagerPayload(bytes calldata payload) internal {
function _processDeployTokenManagerPayload(bytes memory payload) internal {
(, bytes32 tokenId, TokenManagerType tokenManagerType, bytes memory params) = abi.decode(
payload,
(uint256, bytes32, TokenManagerType, bytes)
Expand All @@ -772,7 +774,7 @@ contract InterchainTokenService is
* @notice Processes a deploy interchain token manager payload.
* @param payload The encoded data payload to be processed.
*/
function _processDeployInterchainTokenPayload(bytes calldata payload) internal {
function _processDeployInterchainTokenPayload(bytes memory payload) internal {
(, bytes32 tokenId, string memory name, string memory symbol, uint8 decimals, bytes memory minterBytes) = abi.decode(
payload,
(uint256, bytes32, string, string, uint8, bytes)
Expand All @@ -791,14 +793,20 @@ contract InterchainTokenService is
* @param gasValue The amount of gas to be paid for the transaction.
*/
function _callContract(
string calldata destinationChain,
string memory destinationChain,
bytes memory payload,
MetadataVersion metadataVersion,
uint256 gasValue
) internal {
string memory destinationAddress = trustedAddress(destinationChain);
if (bytes(destinationAddress).length == 0) revert UntrustedChain();

if (bytes(destinationAddress).length == 1) {
payload = abi.encode(MESSAGE_TYPE_ROUTE_PAYLOAD, destinationChain, payload);
destinationChain = AXELAR;
destinationAddress = trustedAddress(destinationChain);
}

(bool success, ) = tokenHandler.delegatecall(
abi.encodeWithSelector(
ITokenHandler.callContract.selector,
Expand All @@ -819,7 +827,7 @@ contract InterchainTokenService is
* @param gasValue The amount of gas to be paid for the transaction.
*/
function _callContractWithToken(
string calldata destinationChain,
string memory destinationChain,
bytes memory payload,
string memory symbol,
uint256 amount,
Expand All @@ -829,6 +837,12 @@ contract InterchainTokenService is
string memory destinationAddress = trustedAddress(destinationChain);
if (bytes(destinationAddress).length == 0) revert UntrustedChain();

if (bytes(destinationAddress).length == 1) {
payload = abi.encode(MESSAGE_TYPE_ROUTE_PAYLOAD, destinationChain, payload);
destinationChain = AXELAR;
destinationAddress = trustedAddress(destinationChain);
}

(bool success, ) = tokenHandler.delegatecall(
abi.encodeWithSelector(
ITokenHandler.callContractWithToken.selector,
Expand All @@ -846,9 +860,9 @@ contract InterchainTokenService is

function _execute(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
bytes calldata payload,
string memory sourceChain,
string memory sourceAddress,
bytes memory payload,
bytes32 payloadHash
) internal {
uint256 messageType = abi.decode(payload, (uint256));
Expand All @@ -859,6 +873,9 @@ contract InterchainTokenService is
_processDeployTokenManagerPayload(payload);
} else if (messageType == MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN) {
_processDeployInterchainTokenPayload(payload);
} else if (messageType == MESSAGE_TYPE_ROUTE_PAYLOAD) {
(, sourceChain, sourceAddress, payload) = abi.decode(payload, (uint256, string, string, bytes));
_execute(commandId, sourceChain, sourceAddress, payload, keccak256(payload));
} else {
revert InvalidMessageType(messageType);
}
Expand Down Expand Up @@ -1127,8 +1144,8 @@ contract InterchainTokenService is

function _getExpressExecutorAndEmitEvent(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
string memory sourceChain,
string memory sourceAddress,
bytes32 payloadHash
) internal returns (address expressExecutor) {
expressExecutor = _popExpressExecutor(commandId, sourceChain, sourceAddress, payloadHash);
Expand Down
14 changes: 12 additions & 2 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,17 @@ const itsCompilerSettings = {
evmVersion: process.env.EVM_VERSION || 'london',
optimizer: {
...optimizerSettings,
runs: 1000, // Reduce runs to keep bytecode size under limit
runs: 800, // Reduce runs to keep bytecode size under limit
},
},
};
const itsTestCompilerSettings = {
version: '0.8.21',
settings: {
evmVersion: process.env.EVM_VERSION || 'london',
optimizer: {
...optimizerSettings,
runs: 200, // Reduce runs to keep bytecode size under limit
},
},
};
Expand All @@ -58,7 +68,7 @@ module.exports = {
'contracts/proxies/Proxy.sol': compilerSettings,
'contracts/proxies/TokenManagerProxy.sol': compilerSettings,
'contracts/InterchainTokenService.sol': itsCompilerSettings,
'contracts/test/TestInterchainTokenService.sol': itsCompilerSettings,
'contracts/test/TestInterchainTokenService.sol': itsTestCompilerSettings,
},
},
defaultNetwork: 'hardhat',
Expand Down
Loading