Skip to content
Business logic Audit finding Intermediate

```WrapAndSupply::wrapAndSupplyOnExtensionMarket``` preventes users from supplying on host

The wrapAndSupplyOnExtensionMarket function wraps all of the user's native token value into a wrapped token, leaving no funds to pay the gas fee required by the subsequent supplyOnHost call. As a result, any transaction through this utility reverts when a non-zero gas fee is set, breaking a core functionality.

0xDemon Follow with 0xKann, 0xlucky and 23 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-07-malda-judging/issues/741

Found by

0xDemon, 0xKann, 0xlucky, 7, BADROBINX, Cybrid, ExtraCaterpillar, IvanFitro, Richard796, TECHFUND-inc, WillyCode20, Yaneca_b, ZanyBonzy, Ziusz, bube, dany.armstrong90, dimah7, elolpuer, farismaulana, gh0xt, harry, molaratai, mussucal, sakibcy, teoslaf1, weblogicctf

Summary

WrapAndSupply::wrapAndSupplyOnExtensionMarket first calls deposit to the underlying token contract implementation via the _wrap() function , which takes all the msg.value provided in the transaction, and turns it into the minted tokens. As a result, the subsequent call to supplyOnHost can potentialy always lead to revert if gasFee is set, since all of the msg.value is used AND since all of this happens in single transactoin. There is no amount left for the gasFee. This is a problem because it disrupts the implementation of the crucial functionality for setting gas fees. Transactions passing through the WrapAndSupply service for extension markets are only successful when gasFee = 0.

Root Cause

The functionality that wraps a native coint into its wrapped version uses all of the msg.value provided by the user without taking into account the possible requirement of additional value for gas fees.

Internal Pre-conditions

  1. WrappedNative implementation and mToken market with underlying set to it have to exist
  2. Onwer needs to set gasFee to the mTokenGateway contract.

External Pre-conditions

  1. User has to call the wrap and supply utility provided by the protocol.

Attack Path

.

Impact

Breaks core contract functionality

PoC

  • Used test file: "test/unit/mTokenGateway/mTokenGateway_supplyOnHost.sol"
  • added optional console logs for clarity
Solidity
import {console} from "forge-std/console.sol";
contract mTokenGateway_supplyOnHost is mToken_Unit_Shared {
...
Solidity
 function test_WrapAndSupply() external {
        // set gas fee
        vm.startPrank(address(mWethExtension.owner()));
        mWethExtension.setGasFee(1 wei);
        // console.log("gasFee: ", mWethExtension.gasFee());
        vm.stopPrank();

        // wrap and supply 
        vm.startPrank(address(this));
        // 10000000000000000000 10e18
        vm.deal(address(this), SMALL);
        // console.log(address(this).balance);
        WrapAndSupply wrapAndSupply = new WrapAndSupply(address(weth));
        vm.label(address(wrapAndSupply), "WrapAndSupply Helper");

        uint256 accAmountInBefore = mWethExtension.accAmountIn(address(this));
        // console.log(accAmountInBefore);
        
        wrapAndSupply.wrapAndSupplyOnExtensionMarket{value: SMALL}(
            address(mWethExtension), address(this), mTokenGateway_supplyOnHost.test_RevertWhen_AmountIs0.selector
        );
        vm.stopPrank();

    }

The test reverts with the "mTokenGateway_NotEnoughGasFee()" error as expected

Bash
[FAIL: mTokenGateway_NotEnoughGasFee()] test_WrapAndSupply() (gas: 565393)

Mitigation

Possible solution is to fetch the gasFee price before calling the wrap and supply function, so he can provide enough amount to pass. And then within the _wrap() calculate the new amount to wrap.

  • add view function to the gateway interface
Solidity
  function gasFee() external view returns (uint256);
  • recalculate mint amount
Solidity
  uint256 _gasFee = ImTokenGateway(wrappedNative).gasFee();
        uint256 amount = msg.value - _gasFee;

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/malda-protocol/malda-lending/pull/111

CergyK

Changes requested on the fix

Barnadrot

changes have been added

CergyK

Fix looks good

The original report as published on Sherlock, by 0xDemon. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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 wrapping function uses the entire msg.value without reserving any amount for the gas fee that the subsequent supply call requires.

Impact

Transactions through the WrapAndSupply utility for extension markets always revert when a non-zero gas fee is set, breaking core contract functionality.

What the attacker needed

WrappedNative and mToken market exist; Owner sets gasFee > 0; User calls wrapAndSupply utility

The fix

The protocol team fixed this issue by fetching the gas fee before wrapping and recalculating the amount to wrap.

How it was found

  1. Set a non-zero gas fee on the mTokenGateway contract.
  2. Call wrapAndSupplyOnExtensionMarket with a native token value.
  3. The function wraps the entire value, leaving zero balance for the gas fee.
  4. The subsequent supplyOnHost call reverts with mTokenGateway_NotEnoughGasFee.

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.

When you send cryptocurrency with a transaction, the contract can use that money. Here, the contract first converts all your money into a wrapped version, leaving nothing to pay a required fee. So the next step fails, and the whole transaction is cancelled.

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.

More by 0xDemon

View all

8 more disclosed reports, best first.

More from Malda

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.