Problems with tokens that transfer less than amount. (Separate from fee-on-transfer issues!)
Some tokens, such as cUSDCv3, treat a transfer amount of type(uint256).max as a request to transfer the sender's entire balance. An attacker could exploit this to cause a denial of service on pool funding and donations by making the pool or a claim appear to have a huge amount of the token, preventing further legitimate transfers.
Source: https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/379
Found by
jkoppel Some tokens such as cUSDCv3 contain a special case for amount == type(uint256).max in their transfer functions that results in only the user's balance being transferred. This can be used to shut down several pool operations.
There are also problems with fee-on-transfer tokens, but that's a separate issue.
The contest FAQ states that all weird tokens should work with this protocol. I also asked the sponsor about this specific category of issues, and they said "this does like something which can be taken advantage of !"
Vulnerability Detail
Several things that can go wrong with this:
-
An attacker can put dust of this token in a wallet, and then call allo.fundPool() with type(uint256).max of this token. If the pool has not already been funded, then poolAmount will not be at type(uint256).max despite nothing being in the pool. It is now not possible to fund the pool.
-
Someone can do this in the DonationVotingMerkleDistributionVaultStrategy to set someones claim of this token to type(uint256).max . It is now impossible for anyone else to donate this token to them.
Impact
Pools cannot work with such tokens
Code Snippet
Tool used
Manual Review
Recommendation
Explicitly do not support these tokens
Discussion
jkoppel
Escalate.
This is not a duplicate of #19. This involves a separate class of token. The available attacks are different, as discussed in the write-up. This is discussed in the issue write-up and confirmed with sponsor.
sherlock-admin2
Escalate.
This is not a duplicate of #19. This involves a separate class of token. The available attacks are different, as discussed in the write-up. This is discussed in the issue write-up and confirmed with sponsor.
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.
nevillehuang
Agree with escalation, this is a valid issue on its on and not at all related to FOT tokens since all ERC-20 tokens are supported.
0x00ffDa
Valid separate issue, but possibly Low since the impacts listed are DoS / griefing rather than loss of funds.
jkoppel
It causes loss of the base fee.
0x00ffDa
It causes loss of the base fee.
... which can be refunded by the protocol owner using Allo.recoverFunds().
jkoppel
There's not clear guidance in the docs, but I can think of other cases where the existence of admin workarounds was insufficient to disqualify something as a medium. n.B. The fee is sent to the treasury, not the Allo contract. Can't use recoverFunds.
neeksec
Suggest to make this low/info.
Since this is a rare token type and the impact(losing base fee which could be refunded by Allo team) is low.
Evert0x
Planning to reject escalation and keep issue state as is.
The impact of this issue is not clear to me.
Pools cannot work with such tokens
Does this mean other pool users can't get out? What is the impact on people?
In case the impact is significant I will consider assigning medium.
jkoppel
I mentioned two attacks. It means that multiple attacks are available if someone creates a pool with this token or tries to use it in donation voting, even though the contract is supposed to work with all token types.
MLON33
https://github.com/allo-protocol/allo-v2/pull/355 https://github.com/allo-protocol/allo-v2/pull/381
Evert0x
Copied from README
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.
It's clear that the issue is in scope. The question to answer is, what is the impact of this issue?
The impact is basically
- DOS on pool funding
- DOS on donations
- Small loss of funds that can technically be recovered but it isn't easy to do so.
Although the language in the judging guidelines should be improved, I plan on making this a separate Medium because of the following rule.
Breaks core contract functionality, rendering the contract useless (should not be easily replaced without loss of funds) or leading to unknown potential exploits/loss of funds. Ex: Unable to remove malicious user/collateral from the contract.
The two DOS attacks can break the core contract functionality. In case a pool is popular, it's a blow to the protocol if that pool is suddenly unavailable. It's not easily replaced.
Evert0x
Result: Medium Unique
sherlock-admin2
Escalations have been resolved successfully!
Escalation status:
- jkoppel: accepted
Evert0x
@jkoppel I might have misinterpreted the report and was under the assumption it would brick other deposits as well (e.g. USDC, WETH,..)
But I think the scope is only limited to tokens that have this special case "amount == type(uint256).max" in their transfer function
In that case the following rule should be applied as the issue is only related to these tokens.
Non-Standard tokens: Issues related to tokens with non-standard behaviors, such as weird-tokens are not considered valid by default unless these tokens are explicitly mentioned in the README.
jkoppel
But it is mentioned in the README.
The protocol team was asked this question as part of the standard intake questionnaire.
Do you expect to use any of the following tokens with non-standard behaviour with the smart contracts?
As part of this question, they were presented a list of tokens with weird behavior, including this one.
They responded:
Yes as we support all ERC20 tokens.
This should be taken to mean the same as if they had listed every token they were asked about.
AhmadDecoded
@jkoppel Posted this in discord now posting it here.
hey i think there is need to check the validity of the claim:
Some tokens such as cUSDCv3 contain a special case for amount == type(uint256).max in their transfer functions that results in only the user's balance being transferred. This can be used to shut down several pool operations.
Which have been copied from :
https://github.com/d-xo/weird-erc20
But as I confirmed from the compound dev, that is only true for internal transfer with in the compound v3 vaults
The code for the ctoken itself does not work like that and works as any standard erc20 token
So the token that you gave example of cusdcv3, that token itself would work fine with the protocol, so in this case the submission becomes arbitrary and invalid anyways, anyone can craft example of a token that may not work with one or other functionality.
Considering the sherlock rules just add another layer of argument.
AhmadDecoded
Here you can see what the dev have to say, also you can look into code yourself, the functionality you mentioned is for internal transfer with in compound v3 vaults in comet files, transfer between accounts works as any normal working erc20 tokens.
nevillehuang
I found the ERC20 implementation of transferFrom of the cUSDCv3 token:
function transferFrom(address src, address dst, uint amount) override external returns (bool) {
transferInternal(msg.sender, src, dst, baseToken, amount);
return true;
}
which calls the internal transferInternal function here so I think the dev might be incorrect here. If you call fundpool with type(uint256).max it seems like it does only transfer the amount of tokens the user owns.
function transferInternal(address operator, address src, address dst, address asset, uint amount) internal {
if (isTransferPaused()) revert Paused();
if (!hasPermission(src, operator)) revert Unauthorized();
if (src == dst) revert NoSelfTransfer();
if (asset == baseToken) {
if (amount == type(uint256).max) {
amount = balanceOf(src);
}
return transferBase(src, dst, amount);
} else {
return transferCollateral(src, dst, asset, safe128(amount));
}
}
Now comes the dilemma between whether this behavior is "weird" token or not (which is not considered valid in sherlocks guidelines) or is the contest READ.ME on the question about non-standard tokens takes priority (sherlock guidelines states the contest details is the single source of truth). One thing important to note that while I could not find much data on the use of this token, it has a total market valuation of >$350 million dollars, which is quite significant.
I will let @Evert0x decide on this one but I am leaning towards validating this issue. But perhaps moving forward, more defined rules revolving weird ERC20 tokens needs to be considered.
AhmadDecoded
@nevillehuang you are checking wrong contract ๐ Comet file represent the market for that token, not the token itself. Those all transfer functions are for internal transfers within that market. Should have asked before commenting.
As far as the question whether the behaviour is weird or not if it exists, this example have been taken directly from the weird tokens github repo.
AhmadDecoded
@quentin-abei you are trying to create mess to impose your decision on judge here. We are discussing validity as the token implementation is being misjudged here. If you want to comvince judge for your issue do it under your own issue, don't try negative reinforcement.
nevillehuang
@nevillehuang you are checking wrong contract ๐ Comet file represent the market for that token, not the token itself. Those all transfer functions are for internal transfers within that market. Should have asked before commenting.
Oh, could you then point me to the correct contract and function details? My understanding is cUSDv3 is a proxy of the implementation contract i linked. Perhaps @jkoppel should assist in this since burden of proof is on the watson.
jkoppel
Not having seen the discussion here, I just spent about 30 minutes hunting for the cUSDCv3 contract. The final answer would require unraveling their deployment scripts, but I'm pretty sure Neville is correct, sans a nitpick.
The description for the Comet repo is "An efficient money market protocol for Ethereum and compatible chains (aka Compound III, Compound v3)." So this looks like the right place.
There are no references to the string "cUSDCv3" in the code. But there are several in configuration files.
Comet.sol implements 5 of the 7 ERC20 methods, all but name and symbol.
This diagram states that Comet delegatecalls to CometExt: https://github.com/compound-finance/comet/blob/22cf923b6263177555272dde8b0791703895517d/diagrams/inheritance_diagram.uml . You can see that Comet does indeed implement fallback() and delegatecall's all other methods to another contract: https://github.com/compound-finance/comet/blob/22cf923b6263177555272dde8b0791703895517d/contracts/Comet.sol#L1318
CometExt provides the missing name() and symbol() methods, which it pulls from data: https://github.com/compound-finance/comet/blob/22cf923b6263177555272dde8b0791703895517d/contracts/CometExt.sol#L71
So it looks indeed that Comet.sol is in fact the implementation code for cUSDCv3, and it does have the issue reported in the Weird ERC20 repo.
In conclusion: cUSDCv3 is almost certainly a deployment of Comet.sol where some functionality is provided by delegating to a deployment of CometExt.sol.
I have also E-mailed the person who added this issue to the Weird ERC20 repo to confirm.
I think what probably caused the confusion is that the Compound dev saw the function name transferInternal and misunderstood it. It appears this dev has edited the documentation in this repo, but has not actually touched protocol code. https://github.com/compound-finance/comet/commits?author=ajb413
Evert0x
It seems like @jkoppel is correct that the cUSDCv3 token contains the behavior described in his initial report.
It's a hard judgment to make as the context QA doesn't align with the judging guidelines
README states
Do you expect to use any of the following tokens with non-standard behavior with the smart contracts? Yes as we support all ERC20 tokens.
Judging rules state
Issues related to tokens with non-standard behaviors, such as weird-tokens are not considered valid by default unless these tokens are explicitly mentioned in the README.
cUSDCv3 is not explicitly mentioned in the README. But the protocol indicated they plan on supporting any token with non-standard behavior.
The last resort is to depend on the opinion of the protocol, they confirmed the issue and are even planning on fixing the issue.
AhmadDecoded
Ok my mistake, I ran a simulation on tenderly, it does actually works like described.
I will leave it here, now upto judge for the final decision about the ruling on the weird tokens.
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 protocol does not account for tokens that interpret a transfer amount of type(uint256).max as a request to transfer the sender's balance, leading to incorrect state updates.
Impact
Pools cannot work with such tokens, causing a denial of service on pool funding and donations, and potentially a small loss of base fee.
What the attacker needed
A pool using a token with this special case; attacker has a tiny amount of the token
The fix
The protocol should explicitly not support these tokens, as recommended in the report.
How it was found
- An attacker puts a tiny amount of the special token into a wallet.
- The attacker calls allo.fundPool() with type(uint256).max of that token.
- The pool's recorded amount becomes type(uint256).max even though only dust was transferred.
- The pool can no longer be funded with that token.
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 have a special rule: if you ask to transfer the maximum possible number, they only send what you actually own. This can confuse a smart contract that expects the full amount to be moved. An attacker can use this to make a pool or a donation claim look like it already has a huge amount of the token, so no one else can add more.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.