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

call() should be used instead of transfer() on an address payable #203

Closed
code423n4 opened this issue Aug 3, 2022 · 2 comments
Closed
Labels
bug Something isn't working duplicate This issue or pull request already exists QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-07-axelar/blob/94498f8ae1fb1df655dfb89f7f525f94d92f5de0/contracts/deposit-service/ReceiverImplementation.sol#L23
https://github.com/code-423n4/2022-07-axelar/blob/94498f8ae1fb1df655dfb89f7f525f94d92f5de0/contracts/deposit-service/ReceiverImplementation.sol#L51
https://github.com/code-423n4/2022-07-axelar/blob/94498f8ae1fb1df655dfb89f7f525f94d92f5de0/contracts/deposit-service/ReceiverImplementation.sol#L71
https://github.com/code-423n4/2022-07-axelar/blob/94498f8ae1fb1df655dfb89f7f525f94d92f5de0/contracts/deposit-service/ReceiverImplementation.sol#L86
https://github.com/code-423n4/2022-07-axelar/blob/94498f8ae1fb1df655dfb89f7f525f94d92f5de0/contracts/gas-service/AxelarGasService.sol#L128
https://github.com/code-423n4/2022-07-axelar/blob/94498f8ae1fb1df655dfb89f7f525f94d92f5de0/contracts/gas-service/AxelarGasService.sol#L144
https://github.com/code-423n4/2022-07-axelar/blob/94498f8ae1fb1df655dfb89f7f525f94d92f5de0/contracts/xc20/contracts/XC20Wrapper.sol#L63

Vulnerability details

This is a classic Code4rena issue:

Impact

The use of the deprecated transfer() function for an address will inevitably make the transaction fail when:

  1. The claimer smart contract does not implement a payable function.
  2. The claimer smart contract does implement a payable fallback which uses more than 2300 gas unit.
  3. The claimer smart contract implements a payable fallback function that needs less than 2300 gas units but is called through proxy, raising the call's gas usage above 2300.

Additionally, using higher than 2300 gas might be mandatory for some multisig wallets.

Impacted lines:

deposit-service/ReceiverImplementation.sol:23:        if (address(this).balance > 0) refundAddress.transfer(address(this).balance);
deposit-service/ReceiverImplementation.sol:51:            if (address(this).balance > 0) refundAddress.transfer(address(this).balance);
deposit-service/ReceiverImplementation.sol:71:        if (address(this).balance > 0) refundAddress.transfer(address(this).balance);
deposit-service/ReceiverImplementation.sol:86:        recipient.transfer(amount);
gas-service/AxelarGasService.sol:128:                if (amount > 0) receiver.transfer(amount);
gas-service/AxelarGasService.sol:144:            receiver.transfer(amount);
xc20/contracts/XC20Wrapper.sol:63:        payable(msg.sender).transfer(address(this).balance);

Recommended Mitigation

Use call() instead of transfer(), but be sure to respect the CEI pattern and/or add re-entrancy guards, as several hacks already happened in the past due to this recommendation not being fully understood.

Relevant links:
https://twitter.com/hacxyk/status/1520715516490379264?s=21&t=fnhDkcC3KpE_kJE8eLiE2A
https://twitter.com/hacxyk/status/1520715536325218304?s=21&t=fnhDkcC3KpE_kJE8eLiE2A
https://twitter.com/hacxyk/status/1520370441705037824?s=21&t=fnhDkcC3KpE_kJE8eLiE2A
https://twitter.com/Hacxyk/status/1521949933380595712

@code423n4 code423n4 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Aug 3, 2022
code423n4 added a commit that referenced this issue Aug 3, 2022
@GalloDaSballo
Copy link
Collaborator

Similar to #230

@re1ro
Copy link
Member

re1ro commented Aug 23, 2022

Duplicate of #4

@re1ro re1ro marked this as a duplicate of #4 Aug 23, 2022
@re1ro re1ro closed this as completed Aug 23, 2022
@re1ro re1ro added the duplicate This issue or pull request already exists label Aug 23, 2022
@GalloDaSballo GalloDaSballo added QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Aug 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
Projects
None yet
Development

No branches or pull requests

3 participants