PoC: flashLoan non-standard ERC20 asset loss (Medium)#975
Open
yuzengbaao wants to merge 1 commit into
Open
Conversation
Demonstrates that flashLoan function (Midnight.sol L742-L757) can permanently lose assets when interacting with non-standard ERC20 tokens that return true from transferFrom without actually transferring. Test results: 6/6 passed - testPoC_BrokenToken_Exploit: 💥 confirms vulnerability - 5 other tests: protection mechanisms verified See: https://github.com/yuzengbaao/morpho-midnight-poc
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a Foundry PoC test suite to validate/triage a claimed flashLoan “arbitrary-send-erc20” issue (tokens sent before callback return-value validation), including scenarios with non-standard ERC20 behaviors.
Changes:
- Introduces a
BrokenERC20test token to simulate pathological ERC20 transfer semantics. - Adds malicious callback contracts to test revert and “spend then succeed” flows.
- Adds multiple test cases covering baseline, non-standard tokens, and mixed-token behavior.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+48
to
+54
| /// @notice Transfers without checking balance. Always succeeds. | ||
| /// SafeTransferLib checks returndata == true -> passes. | ||
| function transfer(address to, uint256 amount) external returns (bool) { | ||
| balanceOf[msg.sender] -= amount; | ||
| balanceOf[to] += amount; | ||
| return true; | ||
| } |
Comment on lines
+15
to
+18
| import {ERC20} from "./erc20s/ERC20.sol"; | ||
| import {ERC20NoRevert} from "./erc20s/ERC20NoRevert.sol"; | ||
| import {ERC20NoReturn} from "./erc20s/ERC20NoReturn.sol"; | ||
| import {SafeTransferLib} from "../src/libraries/SafeTransferLib.sol"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PoC demonstrating Medium severity in
flashLoan(src/Midnight.sol#L742-L757) with non-standard ERC20 tokens.Test results: 6/6 passed
Severity: Medium — requires non-standard ERC20 token.
See https://github.com/yuzengbaao/morpho-midnight-poc