Persisted msg.value in a loop of delegate calls can be used to drain ETH from your proxy
The proxy's batch function is payable and uses delegatecall, so msg.value persists across multiple calls to execute, allowing an attacker to reuse the same ETH for multiple deposits and drain proxy funds. Additionally, if the owner mistakenly grants access to a non-existent selector and the target has a fallback, the attacker can drain funds.
I will try to explain it as brief as possible but I can add a PoC in QA stage if required.
First step: Draining ETH
This vulnerability comes from the fact that msg.value and msg.sender are persisted in delegatecall.
It is possible to call execute() (which is payable ) from batch() (which is also payable ) because both are public functions. (For now ignore the fact that execute() has access control).
The attacker would call batch() sending, for example, 1 ETH with an array of 100 equal items that call execute()
This execute() will call and external contract 100 times and in every time it will send 1ETH from proxy funds (not from the attacker).
If the receiving contract stores these value then the proxy wallet will be drained.
Second step: Access control bypass scenario
While this is already a high risk and there should be many attacking scenarios I would like to show you a pretty simple one.
Suppose the owner would like to grant access to a target with a normal function (maybe no even payable).
For example suppose that the owner grant access to the function
function goodFunction() public
This function has the selector 0x0d092393 . However, for some reason. the owner mistyped the selector and grant access to non existing function 0x0d09392.
Then if the target contract has the so common function.
fallback() external payable { }
Then the attacker can drain wallet funds using this selector as I explained above.
Hi @RayXpub . I found that there is an error in the test case that you mentioned. The test is passing because the contract has no ETH and you call batch with false parameter.
The second delegatecall is reverting. However, by design delegatecall will not revert the main transaction and instead will return false that is ignored in this case.
To show you this I have created a PoC with a few modification to your original test. I just send ETH before and then compared that the amount deposited was double.
it("PoC: should be able to reuse msg.value for multiple deposits", async () => {
const { mimoProxy, vaultActions, vaultsDataProvider, wmatic } = await setup();
//Send ETH to the proxy RECEIVE EXTERNAL PAYABLE
const [owner] = await ethers.getSigners();
owner.sendTransaction({ to: mimoProxy.address, value: DEPOSIT_AMOUNT });
await mimoProxy.execute(vaultActions.address, vaultActions.interface.encodeFunctionData("depositETH"), {
value: DEPOSIT_AMOUNT,
});
const vaultIdBefore = await vaultsDataProvider.vaultId(wmatic.address, mimoProxy.address);
const vaultBalanceBefore = await vaultsDataProvider.vaultCollateralBalance(vaultIdBefore);
const data = vaultActions.interface.encodeFunctionData("depositETH");
mimoProxy.batch(
[
mimoProxy.interface.encodeFunctionData("execute", [vaultActions.address, data]),
mimoProxy.interface.encodeFunctionData("execute", [vaultActions.address, data]),
],
true,
{ value: DEPOSIT_AMOUNT },
);
const vaultId = await vaultsDataProvider.vaultId(wmatic.address, mimoProxy.address);
const vaultBalanceAfter = await vaultsDataProvider.vaultCollateralBalance(vaultId);
expect(vaultBalanceAfter).to.be.equal(vaultBalanceBefore.add(DEPOSIT_AMOUNT).add(DEPOSIT_AMOUNT));}
);
Thanks for providing a PoC. It seems we misunderstood the issue as we were looking at it in the context of the miso platform vulnerability described in the paradigm article where it is our understanding that the issue was a msg.value reliant state update. Here ETH are actually transferred in each call. However, for an attacker to be able to call execute() he would need to have been granted permission, so that would rely an approval made by the MIMOProxy owner.
In the case of the fallback function this would require the owner making a mistake while granting permission by entering an erroneous selector and the target contract would need to have a fallback.
As we do not see any scenario where this issue would work without a user mistake we consider that this should be labeled as medium risk. But we are considering making all the MIMOProxy functions non payable, this is still being discussed.
Btw the PoC provided is missing an await on the owner.sendTransaction line which ends up not really showcasing the issue but we did manage to reproduce the scenario.
Agree this is not High Risk due to the requirement of owner privilege.
horsefacts (warden) reviewed mitigation:
Status: 👍 Acknowledged
Finding: Wardens identified that calling payable functions via BoringBatchable#batch could lead to double spends or reuse of msg.value.
What changed: The Mimo team have acknowledged the risk of payable calls to BoringBatchable#batch.
Acknowledgment:
In no normal usage of the MIMOProxy should there ever be ETH stuck in the contract.
In the future, we might need batch to be payable. For example, our main protocol supports calls such as depositETH and depositETHAndBorrow, which we do want to work with the MIMOProxy.
The original report as published on Code4rena, by peritoflores. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
The batch function is payable and uses delegatecall, so msg.value is not reset between calls, allowing the same ETH to be reused.
Impact
An attacker could drain the proxy's ETH balance if they have been granted permission to call execute, or if the owner mistakenly grants access to a non-existent selector and the target has a fallback function.
What the attacker needed
Attacker has permission to call execute; or owner mistakenly grants access to a wrong selector; target contract has a fallback function
The fix
The batch function should be made non-payable to prevent reuse of msg.value.
How it was found
Send ETH to the proxy contract.
Call batch with an array of execute calls, each sending the same ETH value.
Each execute call forwards the ETH to the target, reusing the same msg.value.
The target receives multiple times the ETH sent, draining the proxy.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
When a contract uses delegatecall, it runs another contract's code but keeps its own ETH balance and the original sender's address. If a function that accepts ETH is called multiple times in a loop via delegatecall, the same ETH amount can be counted each time, letting someone withdraw more than they sent. This report shows how that can empty a proxy contract's funds.
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.