Transferring any amount of the underlying token to the CNote contract will make the contract functions unusable
The CNote contract requires its underlying token balance to be zero for several functions to work. An attacker can transfer a small amount of the token directly to the contract, causing those functions to revert and making the contract unusable.
Submitted by Tutturu, also found by 0x52, hyh, p4st13r4, and WatchPug
The contract expects the balance of the underlying token to == 0 at all points when calling the contract functions by requiring getCashPrior() == 0, which checks token.balanceOf(address(this)) where token is the underlying asset.
An attacker can transfer any amount of the underlying asset directly to the contract and make all of the functions requiring getCashPrior() == 0 to revert.
Proof of Concept
CNote.sol#L43 CNote.sol#L114 CNote.sol#198 CNote.sol#310
- Attacker gets any balance of Note (amount = 1 token)
- Attacker transfers the token to CNote which uses Note as an underlying asset, by calling note.transfer(CNoteAddress, amount). The function is available since Note inherits from ERC20
- Any calls to CNote functions now revert due to getCashPrior() not being equal to 0
Recommended Mitigation Steps
Instead of checking the underlying token balance via balanceOf(address(this)) the contract could hold an internal balance of the token, mitigating the impact of tokens being forcefully transferred to the contract.
Alex the Entreprenerd (judge) commented:
The warden has shown how, via a simple transfer of 1 wei of token, the invariant of
getCashPrior() == 0can be broken, bricking the functionality.Because of:
- the simplicity of the exploit
- The impact being inability to interact with the contract
- A protocol invariant is broken
I agree with High Severity.
Mitigation would require using delta balances and perhaps re-thinking the need for those intermediary checks.
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
The contract uses its actual token balance as an internal accounting value, which can be changed by anyone via a direct transfer.
Impact
The contract's functions become unusable, preventing any interaction with the contract.
What the attacker needed
Any amount of the underlying token
The fix
The contract should track its internal balance instead of relying on the token's balanceOf, so that forced transfers do not affect its logic.
How it was found
- Attacker obtains any amount of the Note token.
- Attacker transfers the token directly to the CNote contract.
- Calls to CNote functions that require getCashPrior() == 0 now revert.
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 can hold tokens, and its code can check how many tokens it holds. This contract wrongly assumes it will always hold zero of a certain token. Anyone can send tokens to the contract without its permission, so an attacker can send just one token and break the check, stopping the contract from working.
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.