Loss of user funds - unchecked Return of ERC20 Transfer
The DebtIssuanceModuleV2 contract ignores the return value of ERC20 transfer calls, so tokens that return false instead of reverting can cause transfers to fail silently. This can lead to users losing their borrowed tokens or their entire investment when redeeming.
0x007 Follow with Bauchibred, bitsurfer and 1 other
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-05-Index-judging/issues/169
Found by
0x007, Bauchibred, bitsurfer, shogoki
Summary
Silently failing transfers can result in a partial or total loss of the users investment.
Vulnerability Detail
Some ERC20 Tokens do not revert on failure of the transfer function, but return a bool value instead. Some do not return any value. Therefore it is required to check if a value was returned, and if true, which value it is. This is not done on some places in these contracts.
The DebtIssuanceModulev2, which is required to issue or redeem tokens whenever there is a LeverageModule involved uses the invokeTransfer function of the Invoke library to transfer ERC20 Tokens from the SetToken to the user.
invokeTransfer is encoding the Calldata for the regular transfer function of ERC20 tokens and passes it together with the target (ERC20 token address) the SetTokens generic invoke function, whichin turn uses functionCallWithValue from the Openzeppelin Address Library. This method is bubbling up a possible revert of the call and returning the raw data.
The generic invoke is returning this raw data, however in invokeTransfer the return value of invoke is ignored and not used.
As some ERC20 Tokens do not revert on a failed transfer, but instead return a false bool value, the stated behaviour can lead to silently failing transfers.
This is inside the DebtIssuanceModulev2 used to:
- Transfer The "debt" (borrowed) Tokens to the user at Issuance
- Transfer back the main component Tokens (e.g. aTokens) to the user at Redemption
If such a Transfer silently fails, the funds will remain inside the setToken contract and the user has no chance to recover them.
In the issuance event the user receives the SetTokens but not the borrowed Tokens, which he has to repay when he wants to redeem the tokens. (Results in Loss of the "Debt")
In the redemption event the user repays his debt & bruns his Set Tokens, but never receives his original Tokens back. (Total Loss of investment)
Impact
Possible Loss of all/part of the Investment for the User
Code Snippet
Usage of invokeTransfer inDebtIssuanceModulev2:
invokeTransfer function ignores return value of invoke:
invoke uses functionCallwithValue and returns the raw return Data (which is ignored in this case):
Tool used
Manual Review
Recommendation
Check for the existence and value of the returned data of the Transfer call. If there is a return value, it has to be true. This could be achieved by using Openzeppelins SafeERC20 library´s safeTransfer.
Discussion
Shogoki
Escalate for 10USDC This should be considered a valid finding. it backs up the existing escalation on #236
There exists a risk of loosing funds due to missing checks on the transfer calls, as described in the report.
sherlock-admin
Escalate for 10USDC This should be considered a valid finding. it backs up the existing escalation on #236
There exists a risk of loosing funds due to missing checks on the transfer calls, as described in the report.
You've created a valid escalation for 10 USDC!
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.
0xffff11
This should definitely be a duplicate of the issue that states that the protocol does not work with tokens like USDT. This is just a superset of that issue that has the same fix.
Shogoki
This should definitely be a duplicate of the issue that states that the protocol does not work with tokens like USDT. This is just a superset of that issue that has the same fix.
No it should not. It should be a valid issue together with duplicates like: #155, #236 and #280
This issue is not about USDT. It is about Tokens that do not revert on failure, which can lead to a silently failed transfer.
hrishibhat
Result: Medium Has duplicates Considering this and its duplicates a separate issue as its core issue is different from #314
sherlock-admin2
Escalations have been resolved successfully!
Escalation status:
- Shogoki: accepted
pblivin0x
Fix opened in https://github.com/IndexCoop/index-protocol/pull/28
IAm0x52
Fix looks good. Non-empty return data is now checked to accommodate tokens that return false instead of reverting
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 invokeTransfer function ignores the return value of the low-level call, so it does not check whether the ERC20 transfer succeeded.
Impact
Users could lose part or all of their investment because failed transfers leave funds stuck in the contract.
What the attacker needed
Token returns false on failed transfer; user interacts with DebtIssuanceModuleV2
The fix
The fix was to check for non-empty return data and ensure it is true, as done in the linked pull request.
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 don't signal failure by stopping the transaction; instead they return a 'false' value. The smart contract here ignores that return value, so it thinks the transfer succeeded when it actually failed. As a result, users might not receive their tokens and could lose their money.
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.