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

Lack of Target Data Validation in KyberSwap Command Execution #14

Open
hats-bug-reporter bot opened this issue Nov 13, 2024 · 1 comment
Open
Labels
bug Something isn't working invalid This doesn't seem right

Comments

@hats-bug-reporter
Copy link

Github username: @0xmahdirostami
Twitter username: 0xmahdirostami
Submission hash (on-chain): 0x4a7a612fd62ef9364c23b61b1f39f0277f2ed86f38f288f403cc2da0f79386c3
Severity: high

Description:

Description

In the current implementation of the KyberSwap command, the contract validates only the user's input data but fails to verify targetData passed to the KyberRouter. This targetData is generated off-chain, allowing the msg.sender to manipulate it without the contract enforcing consistency between the user input and the actual swap parameters.

(address tokenIn, uint256 amountIn, address tokenOut, , bytes memory targetData) = abi
.decode(_inputs, (address, uint256, address, uint256, bytes));
if (tokenOut == Constants.ETH) {
revert AddressError();
}
if (tokenIn == Constants.ETH) {
if (msg.value != amountIn) {
revert AmountError();
}

however, contract calls the kyberRouter with target data.

(bool success, ) = kyberRouter.call{value: msg.value}(targetData);

(bool success, ) = kyberRouter.call(targetData);

Since there is no validation on targetData, malicious users could craft off-chain data that differs from the input data, allowing potential exploits during command execution.

Impact

  • Vulnerabilities in Off-Chain Data Generation:

If the off-chain generator of targetData is compromised, there are no safeguards within the contract to protect users from incorrect trade parameters or invalid routes.
consider the fact that _dispatchPreviewRate will show wrong value here as it works with user input not actual targetData


  • Unauthorized Contract Balance Use:

If the contract holds a balance, an attacker could submit msg.value and input amount as minimal values (e.g., 1 wei) but encode targetData with the full contract balance, allowing them to drain contract funds.


  • Partial Fill Exploit:

If partial fills are enabled, it could lead to unintended losses for users. To avoid such scenarios, other protocols ensure that partial fill is disabled. For reference:

i wrote this contract, this is about a 1inch swap but it could give some sense of what i say:
https://github.com/PossumLabsCrypto/Adapters/blob/ac3effb65bf1b72dcadde1059b26345b5b969284/src/AdapterV1.sol#L516


  • Misalignment of Input and Execution Data:

The contract currently assumes that the user-provided inputs align with target data. This assumption could lead to trade execution errors or incorrect balances if the values differ.

Mitigation

To mitigate this risk, the contract should decode targetData internally and validate it against user inputs. This ensures that swap parameters match the expected input, preventing any inconsistencies or exploitative scenarios.

@hats-bug-reporter hats-bug-reporter bot added the bug Something isn't working label Nov 13, 2024
@yanisepfl yanisepfl added the invalid This doesn't seem right label Nov 15, 2024
@yanisepfl
Copy link
Collaborator

Hello,

We classified this issue as Invalid because we consider this to be Kyber router's responsibility to revert upon reception of malicious data.

You will find more information on how to interact with their router here: https://docs.kyberswap.com/kyberswap-solutions/kyberswap-aggregator/developer-guides/execute-a-swap-with-the-aggregator-api.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

1 participant