Skip to content

PoC: flashLoan non-standard ERC20 asset loss (Medium)#975

Open
yuzengbaao wants to merge 1 commit into
morpho-org:mainfrom
yuzengbaao:poc-flashloan-medium
Open

PoC: flashLoan non-standard ERC20 asset loss (Medium)#975
yuzengbaao wants to merge 1 commit into
morpho-org:mainfrom
yuzengbaao:poc-flashloan-medium

Conversation

@yuzengbaao
Copy link
Copy Markdown

PoC demonstrating Medium severity in flashLoan (src/Midnight.sol#L742-L757) with non-standard ERC20 tokens.

Test results: 6/6 passed

  • testPoC_BrokenToken_Exploit: 💥 confirms vulnerability
  • 5 other tests: protection mechanisms verified

Severity: Medium — requires non-standard ERC20 token.
See https://github.com/yuzengbaao/morpho-midnight-poc

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
Copilot AI review requested due to automatic review settings June 3, 2026 16:54
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 BrokenERC20 test 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 thread test/PoC_FlashLoan.t.sol
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 thread test/PoC_FlashLoan.t.sol
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";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants