code-423n4 / 2022-06-nibbl-findings

1 stars 0 forks source link

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

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Lines of code

https://github.com/code-423n4/2022-06-nibbl/blob/main/contracts/Basket.sol#L80

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.

Proof of Concept

withdrawETH() uses transfer() to transfer ETH:

contracts/Basket.sol:
  78:        function withdrawETH(address payable _to) external override {
  79:            require(_isApprovedOrOwner(msg.sender, 0), "withdraw:not allowed");
  80:            _to.transfer(address(this).balance);
  81:            emit WithdrawETH(_to);
  82:        }

Recommended Migitation

I recommend using call() instead of transfer().

HardlyDifficult commented 2 years ago

Agree that using .transfer is now discouraged. I think a difference here as compared to other contests is that the _to address is simply an input to this function call -- so if it reverts they could try again with a EOA and then transfer manually to the contract. Lowering risk and merging with the warden's QA report #157