Support of different ERC20 tokens
The purchase function transfers ERC20 tokens without checking the return value or the actual amount received, so tokens that return false or are deflationary/rebasing could cause the contract to accept payment without receiving the expected value. An attacker could exploit this if the lock manager uses such a token, potentially acquiring keys without paying the full price.
Submitted by pauliax, also found by cmichel, Reigada, kenzo, Ruhum, 0x0x0x, GiveMeTestEther, and WatchPug
The current version of the codebase does not handle special cases of tokens, e.g. deflationary, rebasing, or those that return true/false on success (see: https://github.com/d-xo/weird-erc20). Function purchase transfers tokens from msg.sender but it does not check the return value, nor how many tokens were actually transferred:
token.transferFrom(msg.sender, address(this), pricePaid);
Recommended Mitigation Steps
I have 2 suggestions here:
- Use SafeERC20 library to handle token transfers: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/utils/SafeERC20.sol
- Consider checking the actual balances transferred (balance after-before) or clearly documenting that you do not support deflationary / rebasing / etc tokens.
julien51 (Unlock Protocol) disputed and commented:
The only party that would be penalized in the examples you describe is the lock manager (and beneficiary) who has explicitly deployed the lock using the (noncompliant) ERC20. If we consider the threat model here then I think this is not really an issue, as additional checks would incur a gas cost for everyone.
Please note: the following additional discussions and re-assessment took place approximately 2 months after judging and awarding were finalized. As such, this report will leave this finding in its originally assessed risk category as it simply reflects a snapshot in time.
julien51 (Unlock Protocol) commented:
The fact that this requires an explicit action by the lock manager (ie using a buggy/malicious ERC20 token) and that it puts only their tokens at risk, I think this is
minor.
0xleastwood (judge) decreased severity to Low and commented:
Giving this a bit more thought, I think its always safe to enforce these checks rather than leave it up to the lock manage to potentially make the mistake and then be liable for this mistake later on. However, considering the threat model, I do think this is better suited as a
lowseverity issue.
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 ERC20 transferFrom without checking its return value or verifying the actual balance change, so it does not handle non-standard tokens.
Impact
If a lock manager uses a non-compliant token, an attacker could obtain keys without paying the full price, but only the lock manager's funds are at risk and the issue was rated low severity.
What the attacker needed
Lock manager uses a non-standard ERC20 token
The fix
Use SafeERC20 for token transfers and check the actual balance change, or clearly document that deflationary/rebasing tokens are not supported.
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 tokens do not behave like standard ERC20 tokens: they may return false on failure or transfer fewer tokens than requested. The contract ignores these signals, so it might think a payment succeeded when it did not. This could let someone get a key without paying the correct amount, but only if the lock owner chose such a token.
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.