Skip to content
Access control Audit finding Intermediate

Anyone Can Arbitrarily Mint Fungible Tokens In VaderPoolV2.mintFungible()

The mintFungible() function allowed any user to specify a 'from' address, so an attacker could front-run a victim's approval and mint LP tokens to themselves, taking the victim's deposited funds. The attacker could steal the victim's deposit and receive the LP tokens.

leastwood Follow

Originally disclosed on Code4rena

Submitted by leastwood

Impact

The mintFungible() function is callable by any user that wishes to mint liquidity pool fungible tokens. The protocol expects a user to first approve the contract as a spender before calling mintFungible(). However, any arbitrary user could monitor the blockchain for contract approvals that match VaderPoolV2.sol and effectively frontrun their call to mintFungible() by setting the to argument to their own address. As a result, the nativeDeposit and foreignDeposit amounts are transferred from the victim, and LP tokens are minted and finally transferred to the malicious user who is represented by the to address.

Proof of Concept

https://github.com/code-423n4/2021-11-vader/blob/main/contracts/dex-v2/pool/VaderPoolV2.sol#L284-L335

Tools Used

Manual code review. Discussions with dev.

Recommended Mitigation Steps

Consider removing the from argument in mintFungible() and update the safeTransferFrom() calls to instead transfer from msg.sender.

SamSteinGG (Vader) disputed:

The pool contracts, similarly to Uniswap V2, are never meant to be interacted with directly.

alcueca (judge) commented:

You need to enforce that somehow.

SamSteinGG (Vader) confirmed:

Upon second consideration, the functions relating to the minting of synths and wrapped tokens should have had the onlyRouter modifier and thus are indeed vulnerable. Issue accepted.

The original report as published on Code4rena, by leastwood. 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 mintFungible() function accepted a 'from' argument and used it in safeTransferFrom() without checking that the caller was authorised, so anyone could pull funds from any address that had approved the contract.

Impact

An attacker could steal a victim's deposited funds and receive the corresponding LP tokens, though the protocol disputed that the contracts were meant to be used directly.

What the attacker needed

Victim has approved the pool contract; attacker can front-run transactions

The fix

The functions relating to minting synths and wrapped tokens should have had the onlyRouter modifier, and the 'from' argument should be removed so transfers always come from msg.sender.

How it was found

  1. Victim approves VaderPoolV2 as a spender for their tokens.
  2. Attacker monitors the blockchain for such approvals.
  3. Attacker front-runs the victim's mintFungible() call, setting the 'to' argument to their own address.
  4. The contract transfers the victim's nativeDeposit and foreignDeposit amounts.
  5. LP tokens are minted and transferred to the attacker.

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 deposit money into a pool, the contract is supposed to take it from you and give you pool tokens in return. Here, the contract let the caller say whose money to take, so an attacker could watch for someone approving the contract and then call the function first, taking that person's money and getting the pool tokens themselves.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More by leastwood

View all

70 more disclosed reports, best first.

More from Vader Protocol contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.