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: added additional checks for call contract with token #249

Merged
merged 36 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 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
52c75e6
Merge remote-tracking branch 'origin/main' into feat/additional-check…
Foivos Mar 26, 2024
72fd642
Merge branch 'main' into feat/additional-checks-for-execute-with-token
milapsheth Apr 12, 2024
a2b9e47
address comments
milapsheth Apr 12, 2024
9d5c152
fix factory import
milapsheth Apr 12, 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
37 changes: 34 additions & 3 deletions contracts/InterchainTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,10 @@ contract InterchainTokenService is
string calldata sourceChain,
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
string calldata sourceAddress,
bytes calldata payload,
string calldata /*tokenSymbol*/,
uint256 /*amount*/
string calldata tokenSymbol,
uint256 amount
) external payable {
_checkPayloadAgainstGatewayData(payload, tokenSymbol, amount);
// It should be ok to ignore the symbol and amount since this info exists on the payload.
expressExecute(commandId, sourceChain, sourceAddress, payload);
}
Expand All @@ -675,7 +676,37 @@ contract InterchainTokenService is
if (!gateway.validateContractCallAndMint(commandId, sourceChain, sourceAddress, payloadHash, tokenSymbol, amount))
revert NotApprovedByGateway();

_execute(commandId, sourceChain, sourceAddress, payload, payloadHash);
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
uint256 messageType = abi.decode(payload, (uint256));
if (messageType != MESSAGE_TYPE_INTERCHAIN_TRANSFER) {
revert InvalidExpressMessageType(messageType);
}

_checkPayloadAgainstGatewayData(payload, tokenSymbol, amount);

address expressExecutor = _popExpressExecutor(commandId, sourceChain, sourceAddress, payloadHash);

if (expressExecutor != address(0)) {
emit ExpressExecutionFulfilled(commandId, sourceChain, sourceAddress, payloadHash, expressExecutor);
}

_processInterchainTransferPayload(
commandId,
expressExecutor,
sourceChain,
payload
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
);
}

function _checkPayloadAgainstGatewayData(bytes calldata payload, string calldata tokenSymbol, uint256 amount) internal view {
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
(, bytes32 tokenId, , , uint256 amountInPayload) = abi.decode(
payload,
(uint256, bytes32, uint256, uint256, uint256)
);

if(
validTokenAddress(tokenId) != gateway.tokenAddresses(tokenSymbol) ||
amount != amountInPayload
) revert CallWithTokenMissmatch(payload, tokenSymbol, amount);
}

/**
Expand Down
1 change: 1 addition & 0 deletions contracts/interfaces/IInterchainTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ interface IInterchainTokenService is
error TokenHandlerFailed(bytes data);
error EmptyData();
error PostDeployFailed(bytes data);
error CallWithTokenMissmatch(bytes payload, string tokenSymbol, uint256 amount);
milapsheth marked this conversation as resolved.
Show resolved Hide resolved

event InterchainTransfer(
bytes32 indexed tokenId,
Expand Down
Loading