The StrategySupplyMorpho allow to use wrong token in _asset
Submitted by pfapostol
The StrategySupplyMorpho is designed to supply tokens to a specific market in MorphoBlue. To achieve this, it defines a _marketParams structure that stores all the necessary information for the target market, including loanToken, which is transferred from the strategy during the IMorpho.supply call.
However, the strategy also allows the deployer to specify a different token via the _asset variable. This token is used to pull tokens from users during deposits and transfer tokens to users during withdrawals.
It is unclear whether this behavior is intended by design (e.g., treating _asset as a “collateral” token) or if _asset is always meant to be the same as loanToken in _marketParams. Regardless, the protocol will not function if _asset is different from loanToken.
The main issue is that the _asset variable is used to approve MorphoBlue:
constructor(
address initialOwner,
address asset_,
address morphoBlue,
Id morphoMarketId
) StrategySupplyBase(initialOwner, asset_) {
...
if (!ERC20(asset_).approve(morphoBlue, type(uint256).max)) {
constructor(address initialOwner, address asset_) ReentrancyGuard() Ownable() {
...
_asset = asset_;
But later, in the _deploy call, the loanToken is used to supply to a Morpho position:
function _deploy(uint256 amount) internal override returns (uint256) {
(uint256 deployedAmount, ) = _morpho.supply(_marketParams, amount, 0, address(this), hex"");
function supply(
MarketParams memory marketParams,
uint256 assets,
uint256 shares,
address onBehalf,
bytes calldata data
) external returns (uint256, uint256) {
...
IERC20(marketParams.loanToken).safeTransferFrom(msg.sender, address(this), assets);
Impact
If these two tokens are different, the strategy will be unusable. Even if the design intends for _asset to act as collateral for loanTokens supplied externally (e.g., an initial supply), the protocol will still fail due to the absence of allowance for loanToken in the Morpho market.
Proof of Concept
This PoC demonstrates the following:
-
Create two strategies:
- One in a healthy state.
- Another broken due to token mismatch.
-
Approve the
_assettoken (in this case, WETH) for both strategies. -
Call
deployon both strategies:-
The first strategy succeeds because the token pulled from the user and supplied to Morpho is the same.
-
The second strategy fails because, although WETH is pulled from the user, Morpho does not have allowance for USDC.
├─ [101109] StrategySupplyMorpho_Broken::deploy(10000000000000000000 [1e19]) ... │ │ │ │ ├─ [26048] WETH::transferFrom(DEPLOYER: [0x3A383B39c10856a75B9E3f6eda6fCC8fC3334050], StrategySupplyMorpho_Broken: [0x2e234DAe75C793f67A35089C9d99245E1C58470b], 10000000000000000000 [1e19]) │ │ │ │ │ ├─ emit Transfer(from: DEPLOYER: [0x3A383B39c10856a75B9E3f6eda6fCC8fC3334050], to: StrategySupplyMorpho_Broken: [0x2e234DAe75C793f67A35089C9d99245E1C58470b], value: 10000000000000000000 [1e19]) ... │ ├─ [71962] 0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb::supply(MarketParams({ loanToken: 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48, collateralToken: 0x14d60E7FDC0D71d8611742720E4C50E7a974020c, oracle: 0x68066D2891254F1F3285Cac0bB16B65B28EE3cAb, irm: 0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC, lltv: 915000000000000000 [9.15e17] }), 10000000000000000000 [1e19], 0, StrategySupplyMorpho_Broken: [0x2e234DAe75C793f67A35089C9d99245E1C58470b], 0x) ... │ │ ├─ [8384] USDC::transferFrom(StrategySupplyMorpho_Broken: [0x2e234DAe75C793f67A35089C9d99245E1C58470b], 0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb, 10000000000000000000 [1e19]) │ │ │ ├─ [7573] 0x43506849D7C04F9138D1A2050bbF3A0c054402dd::transferFrom(StrategySupplyMorpho_Broken: [0x2e234DAe75C793f67A35089C9d99245E1C58470b], 0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb, 10000000000000000000 [1e19]) [delegatecall] │ │ │ │ └─ ← [Revert] revert: ERC20: transfer amount exceeds allowance │ │ │ └─ ← [Revert] revert: ERC20: transfer amount exceeds allowance
-
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.24;
import {Test} from "lib/forge-std/src/Test.sol";
import {console} from "lib/forge-std/src/console.sol";
import {MockERC20} from "lib/forge-std/src/mocks/MockERC20.sol";
import {StrategySupplyMorpho, StrategySupplyBase} from "contracts/core/strategies/StrategySupplyMorpho.sol";
import {IMorpho, Id} from "node_modules/@morpho-org/morpho-blue/src/interfaces/IMorpho.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract PoCs is Test {
address immutable DEPLOYER = makeAddr("DEPLOYER");
address immutable USER1 = makeAddr("USER1");
address constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address constant WstETH = 0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0;
address constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
address constant MORPHO_BLUE = 0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb;
Id constant USCC_USDC_MARKET =
Id.wrap(
bytes32(
0x1a9ccaca2dba9469cd9cba3d077466761b05f465c412d2bf2c71614c4963dd84
)
);
Id constant wstETH_WETH_MARKET =
Id.wrap(
bytes32(
0xb8fc70e82bc5bb53e773626fcc6a23f7eefa036918d7ef216ecfb1950a94a85e
)
);
function setUp() public {
vm.label(WETH, "WETH");
vm.label(WstETH, "WstETH");
vm.createSelectFork("https://rpc.ankr.com/eth");
}
function test_wrong_token_for_market() public {
StrategySupplyMorpho _strategy_normal = new StrategySupplyMorpho(
DEPLOYER,
WETH,
MORPHO_BLUE,
wstETH_WETH_MARKET
);
StrategySupplyMorpho _strategy_broken = new StrategySupplyMorpho(
DEPLOYER,
WETH,
MORPHO_BLUE,
USCC_USDC_MARKET
);
vm.label(address(_strategy_normal), "StrategySupplyMorpho_Normal");
vm.label(address(_strategy_broken), "StrategySupplyMorpho_Broken");
vm.label(USDC, "USDC");
vm.startPrank(DEPLOYER);
deal(WETH, DEPLOYER, 20 ether);
deal(USDC, address(_strategy_broken), 1000 ether);
IERC20(WETH).approve(address(_strategy_normal), 10 ether);
IERC20(WETH).approve(address(_strategy_broken), 10 ether);
_strategy_normal.deploy(10 ether);
_strategy_broken.deploy(10 ether);
}
}
Recommended mitigation steps
In the constructor, either:
- Set the
_assettoken to match theloanTokenfromMarketParams:
_marketParams = _morpho.idToMarketParams(morphoMarketId);
_asset = _marketParams.loanToken;
// Allowance approval
if (!ERC20(_marketParams.loanToken).approve(morphoBlue, type(uint256).max)) {
revert FailedToApproveAllowanceForMorpho();
}
- Validate that
_assetmatches theloanToken:
if (asset_ != _marketParams.loanToken) revert();
chefkenji (BakerFi) confirmed
Status: Mitigation confirmed. Full details in reports from 0xlemon and shaflow2.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A medium-severity business logic bug in BakerFi Invitational. Code4rena made it public on 26 February 2025. Found in the 2024-12-bakerfi-invitational audit contest (finding M-14).
About Business logic
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
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.