```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.
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
- WrappedNative implementation and mToken market with
underlyingset to it have to exist - Onwer needs to set gasFee to the
mTokenGatewaycontract.
External Pre-conditions
- 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
import {console} from "forge-std/console.sol";
contract mTokenGateway_supplyOnHost is mToken_Unit_Shared {
...
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
[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
function gasFee() external view returns (uint256);
- recalculate mint amount
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
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
- Set a non-zero gas fee on the mTokenGateway contract.
- Call wrapAndSupplyOnExtensionMarket with a native token value.
- The function wraps the entire value, leaving zero balance for the gas fee.
- 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.