There is no limit on the amount of fee users have to pay
The smart contract allowed an approved caller to set an arbitrarily high withdrawal fee, so users could be forced to pay excessive fees to retrieve their funds. A malicious protocol could set the fee so high that users cannot withdraw at all.
hickuphh3 Follow with 0xSmartContract, xiaoming90 and 5 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2022-09-harpie-judging/tree/main/008-M
Found by
hickuphh3, 0xSmartContract, xiaoming90, ak1, minhquanym, leastwood, defsec, HonorLt
Summary
https://github.com/Harpieio/contracts/blob/97083d7ce8ae9d85e29a139b1e981464ff92b89e/contracts/Transfer.sol#L57 https://github.com/Harpieio/contracts/blob/97083d7ce8ae9d85e29a139b1e981464ff92b89e/contracts/Transfer.sol#L88
Vulnerability Detail
There is no upper limit on the amount of fee users have to pay to withdraw their funds back. So any EOA can call transfer function on Transfer contract can set an unreasonable amount of fee and users have to pay it if they want their funds back. We need to make sure that users' funds cannot be loss even when the protocol acts maliciously.
Impact
In case the protocol acts maliciously and set fee = 1e18 to transfer users' fund to Vault, users cannot withdraw their funds since fee is too high.
Proof of Concept
In both transferERC20() and transferERC721(), EOA is caller and can set fee param to any value it wants.
function transferERC721(address _ownerAddress, address _erc721Address, uint256 _erc721Id, uint128 _fee) public returns (bool) {
require(_transferEOAs[msg.sender] == true || msg.sender == address(this), "Caller must be an approved caller.");
require(_erc721Address != address(this));
(bool transferSuccess, bytes memory transferResult) = address(_erc721Address).call(
abi.encodeCall(IERC721(_erc721Address).transferFrom, (_ownerAddress, vaultAddress, _erc721Id))
);
require(transferSuccess, string (transferResult));
(bool loggingSuccess, bytes memory loggingResult) = address(vaultAddress).call(
abi.encodeCall(Vault.logIncomingERC721, (_ownerAddress, _erc721Address, _erc721Id, _fee))
);
require(loggingSuccess, string (loggingResult));
emit successfulERC721Transfer(_ownerAddress, _erc721Address, _erc721Id);
return transferSuccess;
}
And users need to send enough fee (native token) to withdraw their fund back on Vault
function withdrawERC721(address _originalAddress, address _erc721Address, uint256 _id) payable external {
require(_recipientAddress[_originalAddress] == msg.sender, "Function caller is not an authorized recipientAddress.");
require(_erc721Address != address(this), "The vault is not a token address");
require(canWithdrawERC721(_originalAddress, _erc721Address, _id), "Insufficient withdrawal allowance.");
require(msg.value >= _erc721WithdrawalAllowances[_originalAddress][_erc721Address][_id].fee, "Insufficient payment.");
_erc721WithdrawalAllowances[_originalAddress][_erc721Address][_id].isStored = false;
_erc721WithdrawalAllowances[_originalAddress][_erc721Address][_id].fee = 0;
IERC721(_erc721Address).transferFrom(address(this), msg.sender, _id);
}
Tool used
Manual Review
Recommendation
Consider adding an upper limit on the amount of fee users need to pay
Lead Senior Watson
Currently there is no way to revoke a change fee controller request. I'd shy away from using a mapping, adds unnecessary overhead when it can be handled by a pendingFeeController variable. Also important to note that mapping in changeFeeController() is not cleared.
Harpie Team
Using leastwood's suggestion of a timelock for feeController. Fix here. Supplementary fixes for this issue: 1, 2, 3.
Lead Senior Watson
Confirmed fixes.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
A malicious protocol could set the fee so high that users cannot withdraw their funds, effectively locking them.
What the attacker needed
Caller must be an approved EOA; protocol acts maliciously
The fix
The issue was fixed by adding a timelock for the fee controller and other supplementary changes.
How it was found
- An approved EOA calls transferERC20 or transferERC721 with an arbitrarily high fee value.
- The vault records the high fee for the user's withdrawal.
- The user must pay at least that fee to withdraw, which may be unaffordable.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In this smart contract, when users want to get their tokens back, they must pay a fee. The contract lets the person who initiates the transfer set that fee to any amount, with no maximum. So if the protocol is malicious, it can set a huge fee, and users cannot afford to get their tokens back.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.