Recipient cannot always claim expected donation amount from a vault
The vault contract records the full donation amount as claimable, but when a fee-on-transfer token is used, the vault receives less than that amount. As a result, recipients cannot claim the expected donation amount.
0x00ffDa Follow with 0xdeadbeef, Arz and 9 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/547
Found by
0x00ffDa, 0xdeadbeef, Arz, BenRai, Kow, Silvermist, ZdravkoHr., alymurtazamemon, hals, jkoppel, lemonmon, p0wd3r
Vulnerability Detail
First, why is this issue valid despite Sherlock rules excluding non-standard ERC20 behavior? While the Sherlock rules currently exclude "issues related to tokens with non-standard behaviors", the rules also state that "In case of conflict between information in the README, vs Sherlock rules, the README overrides Sherlock rules." And the contest README specifically says that all ERC20 with non-standard behavior are supported:
"Q: Do you expect to use any of the following tokens with non-standard behaviour with the smart contracts? Yes as we support all ERC20 tokens."
DonationVotingMerkleDistributionVaultStrategy contracts store donation amounts in a claims mapping per recipient and per donated token. This is intended to also represent all the amounts claimable by registered recipients. However, in the case of donated ERC20 tokens with a non-zero transfer fee, a donated amount is not claimable in full since the transfer from the donor to the vault will reduce the amount that can be claimed by the recipient.
Impact
Recipients cannot claim the amount expected from a vault in a DonationVotingMerkleDistributionVaultStrategy pool when a donated token has a transfer fee.
Code Snippet
DonationVotingMerkleDistributionVaultStrategy._afterAllocate() function - the last line contains the faulty assumption.
/// @notice After allocation hook to store the allocated tokens in the vault
/// @param _data The encoded recipientId, amount and token
/// @param _sender The sender of the allocation
function _afterAllocate(bytes memory _data, address _sender) internal override {
// Decode the '_data' to get the recipientId, amount and token
(address recipientId, Permit2Data memory p2Data) = abi.decode(_data, (address, Permit2Data));
// Get the token address
address token = p2Data.permit.permitted.token;
uint256 amount = p2Data.permit.permitted.amount;
if (token == NATIVE) {
if (msg.value < amount) {
revert AMOUNT_MISMATCH();
}
SafeTransferLib.safeTransferETH(address(this), amount);
} else {
PERMIT2.permitTransferFrom(
// The permit message.
p2Data.permit,
// The transfer recipient and amount.
ISignatureTransfer.SignatureTransferDetails({to: address(this), requestedAmount: amount}),
// Owner of the tokens and signer of the message.
_sender,
// The packed signature that was the result of signing
// the EIP712 hash of `_permit`.
p2Data.signature
);
}
// Update the total payout amount for the claim
claims[recipientId][token] += amount;
}
Tool used
Manual Review
Recommendation
In the _afterAllocate() cited above, compare vault's balance of the token being donated before and after calling permitTransferFrom(). If it is lower than the donated amount, assume this difference is a transfer fee and reduce the claimable amount by the fee.
Discussion
0x00ffDa
Escalate for 10 USDC
This is not a duplicate of https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/19 and the fix for that issue does not affect this issue.
This fee-on-transfer issue is specific to transfers from donors to recipients via DonationVotingMerkleDistributionVaultStrategy.
sherlock-admin2
Escalate for 10 USDC
This is not a duplicate of https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/19 and the fix for that issue does not affect this issue.
This fee-on-transfer issue is specific to transfers from donors to recipients via
DonationVotingMerkleDistributionVaultStrategy.
You've created a valid escalation!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
neeksec
Agree with Escalation that this is not a duplicate of #19 and should be a seperate issue.
Duplicates of this one, #124, #208, #268, #295, #342, #379, #422, #449, #482, #724, #903, #913
MLON33
https://github.com/allo-protocol/allo-v2/pull/381
Evert0x
Planning to accept escalation and create a new medium family (https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/547 https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/124, https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/208, https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/268, https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/295, https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/342, https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/379, https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/422, https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/449, https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/482, https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/724, https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/903, https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/913)
Evert0x
Result: Medium Has Duplicates
sherlock-admin2
Escalations have been resolved successfully!
Escalation status:
- 0x00ffDa: accepted
jack-the-pug
Fixed.
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 credits the claimable amount based on the requested transfer amount rather than the actual increase in the vault's token balance, ignoring transfer fees.
Impact
Recipients may be unable to claim the full expected donation amount when the donated token charges a transfer fee.
What the attacker needed
Donated token charges a transfer fee; donor allocates to a recipient
The fix
The contract should compare the vault's token balance before and after the transfer and reduce the claimable amount by any fee.
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.
Some digital tokens take a small fee when they are transferred, so the receiver gets less than the sender sent. This smart contract assumed the full amount arrived and promised that full amount to the recipient, but the vault actually holds less. So the recipient cannot withdraw everything they were promised.
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.