transferFrom uses allowance even if spender == from
The pool's transferFrom function always deducted an allowance, even when the caller was the token holder themselves. This broke compatibility with protocols that only use transferFrom, which could leave tokens stranded in those protocols.
Source: https://github.com/sherlock-audit/2023-02-surge-judging/issues/214
Found by
0x52
Summary
Pool#transferFrom attempts to use allowance even when spender = from. This breaks compatibility with a large number of protocol who opt to use the transferFrom method all the time (pull only) instead of using both transfer and transferFrom (push and pull). The ERC20 standard only does an allowance check when spender != from. The result of this difference will likely result in tokens becoming irreversibly stranded across different protocols.
Vulnerability Detail
https://github.com/sherlock-audit/2023-02-surge/blob/main/surge-protocol-v1/src/Pool.sol#L284-L293
The trasnferFrom method shown above always uses allowance even if spender = from.
Impact
Token won't be compatible with some protocols and will end up stranded
Code Snippet
https://github.com/sherlock-audit/2023-02-surge/blob/main/surge-protocol-v1/src/Pool.sol#L284-L293
Tool used
Recommendation
Only use allowance when spender != from:
require(to != address(0), "Pool: to cannot be address 0");
+ if (from != msg.sender) {
+ allowance[from][msg.sender] -= amount;
+ }
balanceOf[from] -= amount;
Discussion
xeious
Fixed
xeious
https://github.com/Surge-fi/surge-protocol-v1/commit/08422f62cc5bc8b5a8f53bd14fadece66814e9de
IAm0x52
Fix looks good. Allowance check is bypassed if msg.sender == from
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 allowance was decremented unconditionally instead of only when the caller differs from the token owner.
Impact
Tokens may become incompatible with some protocols and end up irreversibly stranded.
What the attacker needed
A protocol that only calls transferFrom
The fix
The allowance should only be reduced when the caller is not the token owner, and the project states this was fixed.
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 token contract lets one person spend another person's tokens, but only up to an amount they have approved, called an allowance. The usual rule is that you do not need your own permission to move your own tokens. Here the contract asked for that permission anyway, so other software that moves tokens on a user's behalf could fail and leave funds stuck.
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.