Adversary can permanently break percentage tier bounties by funding certain ERC20 tokens then refunding
Some ERC20 tokens revert on zero-value transfers. An attacker can add such a token to a percentage tier bounty and then refund it, leaving the token in the distribution list with a zero balance, so every payout attempt reverts and payouts are permanently bricked.
tsvetanovv Follow with 0x52, unforgiven and 5 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-02-openq-judging/issues/267
Found by
tsvetanovv, 0x52, unforgiven, rvierdiiev, bin2chen, TrungOre, ctf_sec, cccz
Summary
Some ERC20 tokens don't support 0 value transfers. An adversary can abuse this by adding it to a percentage tier bounty then refunding it. This is because after the refund the token will still be on the list of tokens to distribute but it will have a value saved of 0. This means that no matter what it will always try to transfer 0 token and this will always revert because the specified token doesn't support zero transfers.
Vulnerability Detail
TieredPercentageBountyV1#closeCompetition set the final fundingTotals for each token. If a token has no balance then the fundingTotals for that token will be zero.
For each token in tokenAddresses it will send the claimedBalance to the claimant. If fundingTotal is 0 then it will attempt to call transfer with an amount of 0. Some ERC20 tokens will revert on transfers like this.
An adversary can purposefully trigger these conditions by making a deposit with ERC20 token that has this problem. This will add the ERC20 token to tokenAddresses and cause the contract to try to send 0 when making a payout. Payouts will become completely bricked, with no way to recover since fundingTotals can't be set anywhere else.
Submitting as high because it can be used in conjunction with methods of breaking refunds to permanently trap user funds.
Impact
Payouts are permanently bricked
Code Snippet
Tool used
Manual Review
Recommendation
Add two fixes:
- If a deposit is refunded and the contract has no tokens left then remove that token from the list of tokens
- Add a condition to _transferERC20 that only transfers if _volume != 0
Discussion
FlacoJones
Valid. Will fix with an explicity token whitelist and requiring funder == issuer
FlacoJones
https://github.com/OpenQDev/OpenQ-Contracts/pull/112
and
https://github.com/OpenQDev/OpenQ-Contracts/pull/113
and
https://github.com/OpenQDev/OpenQ-Contracts/pull/116
kiseln
Escalate for 27 USDC
Some ERC20 tokens don't support 0 value transfers
There are no relevant tokens that revert on 0 value transfers. LEND is often provided as an example, however, it was discontinued in 2020 and is supposed to be migrated to AAVE https://docs.aave.com/faq/migration-and-staking. I'd say there is 0 chance this token is whitelisted as a valid bounty token by the protocol owners.
I would consider LEND in the same category as any invalid/malicious token that can be added in a permissionless way, in which case this group of issues is a duplicate of #62
sherlock-admin
Escalate for 27 USDC
Some ERC20 tokens don't support 0 value transfers
There are no relevant tokens that revert on 0 value transfers.
LENDis often provided as an example, however, it was discontinued in 2020 and is supposed to be migrated to AAVE https://docs.aave.com/faq/migration-and-staking. I'd say there is 0 chance this token is whitelisted as a valid bounty token by the protocol owners.I would consider
LENDin the same category as any invalid/malicious token that can be added in a permissionless way, in which case this group of issues is a duplicate of #62
You've created a valid escalation for 27 USDC!
To remove the escalation from consideration: Delete your comment. To change the amount you've staked on this escalation: Edit your comment (do not create a new comment).
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
Evert0x
Escalation rejected.
Protocol signaled they were planning to use any token in this protocol, reverting on 0 transfer is uncommon but not unlikely to happen on a legit token.
sherlock-admin
Escalation rejected.
Protocol signaled they were planning to use
anytoken in this protocol, reverting on 0 transfer is uncommon but not unlikely to happen on a legit token.
This issue's escalations have been rejected!
Watsons who escalated this issue will have their escalation amount deducted from their next payout.
jacksanford1
Lead Senior Watson comment on PR #112:
Looks like you got everything. Will keep my eye out when reviewing the rest of the PRs for anything that might have been missed
Lead Senior Watson comment on PR #113:
Changes look good.
Token requirement has been simplified to just a whitelist. It makes the rest changes to support this revision. tokenAddressLimitReach method has been removed from DepositManagerV1. _tokenAddressLimit has been removed from TokenWhitelist constructor. TOKEN_ADDRESS_LIMIT has been removed along with it's setter. Tests have been updated to accommodate changes.
Lead Senior Watson comment on PR #116:
Changes look good. Requires that funder is the issuer. This prevents a whole host of potential exploits in exchange for closing the otherwise open funding model.
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
Root cause
Likely the contract does not remove tokens with zero balance from its distribution list and does not skip zero-value transfers, so a token that reverts on zero transfers causes every payout to fail.
Impact
Payouts are permanently bricked, and this could be combined with other methods to trap user funds.
What the attacker needed
A percentage tier bounty; an ERC20 token that reverts on zero transfers; ability to deposit and refund
The fix
The contract was fixed by adding an explicit token whitelist and requiring the funder to be the issuer, as shown in the linked pull requests.
How it was found
- Deposit an ERC20 token that reverts on zero-value transfers into a percentage tier bounty.
- Refund the deposit so the token remains in the token list but its funding total becomes zero.
- When a payout is attempted, the contract tries to transfer zero of that token and the transfer reverts, bricking all payouts.
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.
A smart contract bounty pays out in several tokens. Some tokens refuse to transfer an amount of zero. If a token with this behaviour is added and then refunded, the contract still tries to send zero of it during payouts, which always fails. This blocks all payouts forever.
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.