Skip to content
Business logic Audit finding Intermediate

MerkleVesting withdrawal does not verify that tokens were transferred successfully

The MerkleVesting contract's withdraw function does not check the return value of the ERC20 transfer, so if the transfer fails, the user's state is updated but tokens are not sent, and they cannot withdraw again. An attacker could exploit a temporarily failing token to cause permanent loss of user funds.

kenzo Follow

Originally disclosed on Code4rena

Submitted by kenzo, also found by IllIllI

Across the codebase, the protocol is usually checking that ERC20 transfers have succeeded by checking their return value. This check is missing in MerkleVesting’s withdraw function.

Impact

If for some reason the ERC20 transfer is temporarily failing, the user would totally lose his allocation and funds. All the state variables would already have been updated at this stage, so he can’t call withdraw again. There is no way to withdraw these locked tokens.

Proof of Concept

At the last point of withdraw, the function is sending the funds to the user, and does not check the return value - whether it has succeeded:

        IERC20(tree.tokenAddress).transfer(destination, currentWithdrawal);

Note that this is (nicely and rightfully) done after all the state variables have been updated. As the return value of the external call is not checked, if it has failed, the contract wouldn’t know about it, and the function will finish “successfully”.

Recommended Mitigation Steps

As done throughout the rest of the protocol, add a check that verifies that the transfer has succeeded.

illuzen (FactoryDAO) acknowledged, disagreed with severity and commented:

Debatable, since requiring successful transfer means we can’t do non-standard tokens like USDT. Also, tokens could be malicious and simply lie about the success.

Justin Goro (judge) commented:

Regarding the non standard tokens that don’t return bools, the common approach to performing a low level call with

(bool success, _)  = address(token).call(//etc

allows for transfers to be validated for USDT.

Severity will stand because this function represents user funds.


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

The contract fails to verify the return value of the ERC20 transfer call, so a failed transfer is not detected and state changes are not reverted.

Impact

If the ERC20 transfer fails, the user permanently loses their allocation because the state is already updated and they cannot withdraw again.

What the attacker needed

ERC20 transfer fails temporarily

The fix

The contract should check that the transfer succeeded, for example by using a low-level call that returns a success boolean, as the judge suggested.

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 a smart contract sends tokens, it should check that the transfer actually worked. Here, the contract updates the user's balance before sending tokens and ignores whether the send succeeded. If the token transfer fails, the user's balance is already reduced, and they cannot try again, so their tokens are stuck forever.

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 kenzo

View all

53 more disclosed reports, best first.

More from FactoryDAO contest

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.