Skip to content
Race condition Audit finding Advanced

Malicious user can steal native tokens of MoneyMarketHook caller

The MoneyMarketHook contract allows a caller to perform multiple withdrawals in one multicall. If a later withdrawal involves an ERC777 token, the recipient's hook can re-enter the execute function and steal the wrapped native tokens that were withdrawn earlier but not yet sent to the original caller.

rvierdiiev Follow

Originally disclosed on Code4rena

Submitted by rvierdiiev

MoneyMarketHook allows user to chain some actions into one multicall to the InitCore. In the end user can get all wrapped native tokens that he withdrew in a form of native token. Note, that this part of code withdraws all balance from wrapped token and the sends all balance to the msg.sender. In case if balance of contract is 0, then the call will still succeed.

One type of actions that caller can do using execute function is withdraw. In case if caller needs to repay funds to other address then he can provide it as to param. So as result, IInitCore.burnTo will transfer pool tokens to the provided recipient. And in case if token has a hook, like erc777 or erc677, then receiver will be triggered and he has execution control now.

User can have multiple withdraws in same multicall. And it’s possible that first withdraw is wrapped native token withdraw(which user would like to receive as native) and next withdraw is with erc777 token and other recipient.

In such case, when first withdraw is done, then wrapped token is already on MoneyMarketHook balance. And then when second withdraw is handled and attacker get hook, then he can call MoneyMarketHook.execute(it doesn’t have reentrancy check) again with any params that just should pass and _params.returnNative as true. Then all wrapped token balance will be sent to the attacker and then execution will return back to the victim and it will send 0 amount as native token to the victim.

As result attacker is able to steal user’s native tokens.

From the readme, it’s clear that only fee on transfer tokens are not supported and erc777 are supported:

Please list specific ERC20 that your protocol is anticipated to interact with. Could be “any” (literally anything, fee on transfer tokens, ERC777 tokens and so forth) or a list of tokens you envision using on launch. No fee-on-transfer tokens

Impact

It’s possible to steal user’s funds.

Tools Used

VsCode

Recommended Mitigation Steps

Add reentrancy check to the execute function.

fez-init (INIT) confirmed, but disagreed with severity and commented:

This should be a medium issue. There are multiple things that needs to be aligned, including:

  • supporting of ERC777. We did not intend to support ERC777, but acknowledge that it may not be communicated clearly.
  • the victim needs to specify a certain malicious to contract for the attack to happen.

We will add reentrancy check to the execute function to prevent this kind of scenario anyways.

hansfriese (Judge) decreased severity to Medium and commented:

I agree Medium is appropriate due to this requirement: “the victim needs to specify a certain malicious to contract for the attack to happen”.


The original report as published on Code4rena, by rvierdiiev. 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.

How it worked

Root cause

Likely the execute function lacks a reentrancy guard, allowing a malicious ERC777 recipient hook to re-enter and drain the contract's wrapped native token balance before the original caller receives it.

Impact

An attacker could steal the victim's native tokens, but the attack requires the victim to specify a malicious recipient contract and the protocol did not intend to support ERC777 tokens.

What the attacker needed

Victim uses ERC777 token; victim specifies malicious recipient contract; victim includes wrapped native withdrawal first

The fix

A reentrancy check should be added to the execute function.

How it was found

  1. The victim calls execute with multiple withdrawals, the first being a wrapped native token withdrawal and a later one involving an ERC777 token sent to a malicious recipient.
  2. After the first withdrawal, the wrapped native tokens are held in the MoneyMarketHook contract balance.
  3. When the ERC777 token is transferred to the malicious recipient, its hook is triggered and gains execution control.
  4. The attacker re-enters MoneyMarketHook.execute with returnNative set to true, causing all wrapped native tokens to be sent to the attacker.
  5. Execution returns to the victim's original call, which then sends zero native tokens to the victim.

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.

A smart contract lets a user bundle several actions into one transaction. If one of those actions sends a special token that notifies the recipient, the recipient can run code that calls back into the same contract before the first action finishes. Because there is no check to stop this re-entry, the attacker can take tokens that were meant for the original user.

What is Race condition?

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.

More by rvierdiiev

View all

72 more disclosed reports, best first.

More from INIT Capital Invitational

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.