Skip to content
Business logic Audit finding Intermediate

IndexLogic : An attacker can mint tokens for himself using assets deposited by other users

The mint function in IndexLogic allows an attacker to mint tokens for themselves by monitoring the vToken contract's asset balance and calling mint when the balance exceeds lastBalance, without transferring their own assets. This lets the attacker take tokens backed by other users' deposits.

cccz Follow

Originally disclosed on Code4rena

Submitted by cccz, also found by hyh, Kenshin, pedroais, and TrungOre

In the mint function of the IndexLogic contract, users are required to transfer assets to vToken in advance, and then call the mint function to mint tokens. The attacker can monitor the asset balance in the vToken contract. When the balance is greater than lastBalance, the attacker can call the mint function to mint tokens for himself.

Proof of Concept

IndexLogic.sol#L48

Recommended Mitigation Steps

Call the transferfrom function in the mint function of the IndexLogic contract to transfer the user’s assets.

olivermehr (Phuture Finance) disputed

jn-lp (Phuture Finance) commented:

We don’t expect users to directly call the Mint/Burn functions on Index. Instead, they should use the Router contract, as our frontend does.

moose-code (judge) commented:

There is no mention of the router contract in the contest documentation and this is unreasonable for wardens to know about the Router.

We would like wardens to focus on any core functional logic, boundary case errors or similar issues which could be utilized by an attacker to take funds away from clients who have funds deposited in the protocol.

This a core logic error that could be used to take funds away from clients and given there is no mention of the router and only part of the code is submitted, I am siding with the wardens on this and awarding in full.


The original report as published on Code4rena, by cccz. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

Phuture is a protocol built around index products. The component involved here is the IndexLogic contract, which exposes a mint function used to create index tokens. The intended flow, as described in the finding, is that a user first transfers the underlying assets to the vToken contract and then calls mint to receive tokens in return. The mint function therefore does not itself pull funds from the caller: it relies on the assets already sitting in the vToken contract.

The finding was submitted to the Code4rena audit contest for Phuture by cccz, and the same issue was also found by hyh, Kenshin, pedroais and TrungOre. It was rated high severity.

Setup

No accounts, tools or versions are described in the report. The only concrete reference is the location of the affected code, IndexLogic.sol line 48, in the contest repository:

Text
https://github.com/code-423n4/2022-04-phuture/blob/main/contracts/IndexLogic.sol#L48

The precondition for the attack is simply that some user has deposited assets into the vToken contract in preparation for a mint, and that those assets are sitting there before the mint call is made.

Finding it

The researcher looked at how mint in IndexLogic obtains the assets it is meant to convert into index tokens. The function does not transfer anything from the caller. Instead, the caller is expected to have transferred assets to the vToken contract beforehand, and mint then mints tokens against whatever balance is present.

That separation between payment and minting is the flaw. Because the contract does not tie a mint to a specific depositor, any address can call mint while someone else's assets are in the vToken contract, and the tokens will be minted to the caller.

Exploitation

Step 1: watch the vToken balance

The attacker monitors the asset balance held by the vToken contract. The report describes the trigger condition as the balance becoming greater than lastBalance, that is, the balance growing because a legitimate user has made the advance transfer.

Step 2: call mint before the depositor does

When the balance increases, the attacker calls the mint function of IndexLogic for himself. Since mint does not call transferFrom for the caller and does not check who supplied the assets, the attacker receives tokens backed by the assets deposited by the other user.

The report gives no request, transaction, payload or response for this step; the mechanism is described only in prose.

Root cause

The mistake is in the design of mint in IndexLogic: it assumes the caller has already paid, but never verifies or performs that payment. The transfer of assets and the minting of tokens are two separate actions, and nothing links them to the same address. Any party can therefore complete the second half of the flow against funds provided by someone else.

The report does not describe any other defence in the contract that would have prevented this, and the recommended fix confirms that no transferFrom call exists in mint at the time of the finding.

Impact

An attacker can mint tokens for himself using assets deposited by other users. The attack requires that another user has assets sitting in the vToken contract awaiting a mint; the attacker mints once the balance rises. The result is that the attacker obtains index tokens backed by assets deposited by other users.

Phuture disputed the finding, arguing that users are not expected to call the Mint/Burn functions on Index directly and should instead go through the Router contract, as their frontend does. The judge rejected that argument on two grounds: the Router contract is not mentioned in the contest documentation, so it was unreasonable to expect wardens to know about it, and the stated scope asked wardens to focus on core functional logic or boundary case errors that an attacker could use to take funds away from clients with deposits in the protocol. The judge described this as a core logic error that could be used to take funds away from clients, noted that only part of the code was submitted, and awarded the finding in full.

Fix

The recommended mitigation is to call the transferFrom function inside the mint function of the IndexLogic contract, so that the user's assets are transferred as part of the mint rather than beforehand. This ties the payment to the mint call itself.

The report does not state whether this change was implemented.

Variants to test

  1. Look for mint, deposit, stake or claim functions that read a shared balance (of the contract or of a vault) instead of pulling funds from msg.sender. A positive result is that a second account can call the function after a first account's transfer and receive the shares or tokens.
  2. Check whether the protocol documents a wrapper or router as the only supported entry point while leaving the underlying function callable by anyone. A positive result is that calling the underlying function directly bypasses the intended flow and still succeeds.
  3. Watch for two-step flows where a user transfer and a mint are separate transactions. A positive result is that a mint executed between the two steps is credited to the attacker.
  4. Compare the balance-based accounting against lastBalance style checkpoints. A positive result is that an increase caused by another user's deposit is enough to satisfy the attacker's own mint.

Hunting notes

This kind of bug hides in accounting logic that trusts contract balances rather than per-user accounting, especially in vaults, index products and share-based protocols where a deposit and a mint are split across transactions. During review, the signal is a mint or deposit function that contains no transferFrom from the caller and instead assumes funds are already present. The judge tied the issue to the contest's stated scope of protecting client funds. The dispute over the Router contract is a reminder that undocumented wrapper contracts do not remove the vulnerability in the underlying function, and that the judge accepted the finding in full on that basis.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 9 min read.

What happened, in plain words

Phuture is a protocol that offers index products. An index product is a bundle of several underlying assets that you buy as a single unit, a bit like buying a basket of fruit instead of each fruit separately. The part of the system involved here is a smart contract called IndexLogic. A smart contract is a program that lives on a blockchain and runs automatically when someone calls one of its functions. IndexLogic has a function called mint, and mint is the function you call when you want the system to create new index tokens for you.

The way the system was designed, a user is supposed to do two things in two separate steps. First, they send their underlying assets to another contract called the vToken contract. Then they call mint, and the system gives them index tokens in return. The important detail is that mint does not take the money itself. It just looks at the vToken contract, sees that assets are sitting there, and creates tokens.

The problem is that nothing ties those sitting assets to the person who sent them. So if user A sends assets and is about to call mint, an attacker can watch the vToken contract, notice the new assets, and call mint first. The attacker gets the index tokens, minted against user A's deposited assets. This is a high severity finding, submitted to the Code4rena audit contest for Phuture by cccz, and the same issue was also found by hyh, Kenshin, pedroais and TrungOre.

Context

Phuture is built around index products. The component involved is the IndexLogic contract, which exposes a mint function used to create index tokens. The intended flow, as described in the finding, is that a user first transfers the underlying assets to the vToken contract and then calls mint to receive tokens in return. The mint function therefore does not itself pull funds from the caller: it relies on the assets already sitting in the vToken contract.

A few terms are worth unpacking before going further. A token is a digital unit recorded on a blockchain, and an index token represents a share in the basket of assets that make up the index. A contract is a program on the blockchain with functions that anyone can call, subject to the rules written into it. The vToken contract is the contract that holds the underlying assets in this design. To mint means to create new tokens.

The finding was submitted to the Code4rena audit contest for Phuture by cccz, and the same issue was also found by hyh, Kenshin, pedroais and TrungOre. It was rated high severity.

Setup

No accounts, tools or versions are described in the report. The only concrete reference is the location of the affected code, IndexLogic.sol line 48, in the contest repository:

Text
https://github.com/code-423n4/2022-04-phuture/blob/main/contracts/IndexLogic.sol#L48

This is a link to a file in a public code repository. IndexLogic.sol is the source file of the contract, and #L48 points to line 48 of that file, which is where the mint function lives. The .sol ending means the file is written in Solidity, the programming language used for contracts on Ethereum-style blockchains.

The precondition for the attack is simply that some user has deposited assets into the vToken contract in preparation for a mint, and that those assets are sitting there before the mint call is made. In everyday terms, imagine a shop where you first put your money in a shared till and then tell the cashier how many items you want. The attack works while your money is in the till.

Finding it

The researcher looked at how mint in IndexLogic obtains the assets it is meant to convert into index tokens. The function does not transfer anything from the caller. Instead, the caller is expected to have transferred assets to the vToken contract beforehand, and mint then mints tokens against whatever balance is present.

That separation between payment and minting is the flaw. Because the contract does not tie a mint to a specific depositor, any address can call mint while someone else's assets are in the vToken contract, and the tokens will be minted to the caller. An address here is simply an account identifier on the blockchain, like a bank account number: it identifies who is calling and who receives the tokens.

This class of problem is often described as a missing authorisation or accounting check. The function trusts that the caller has paid, but never verifies it. A useful comparison is a cloakroom that hands out coats to anyone who asks, as long as some coat is hanging on the rack, without checking whose ticket matches which coat.

Exploitation

Step 1: watch the vToken balance

The attacker monitors the asset balance held by the vToken contract. The report describes the trigger condition as the balance becoming greater than lastBalance, that is, the balance growing because a legitimate user has made the advance transfer.

lastBalance is a stored record of the balance at an earlier point in time. By comparing the current balance with lastBalance, the attacker can tell when new assets have arrived. This is the same idea as watching a shared bank statement for a deposit: the moment the number goes up, you know someone has put money in.

Step 2: call mint before the depositor does

When the balance increases, the attacker calls the mint function of IndexLogic for himself. Since mint does not call transferFrom for the caller and does not check who supplied the assets, the attacker receives tokens backed by the assets deposited by the other user.

transferFrom is a standard function on tokens that moves funds from one account to another on someone's behalf. Because mint never calls it, no money is taken from the attacker at the moment of minting. The attacker is effectively paying with the other user's deposit.

The attacker acts as soon as the balance rises, before the depositor's own mint. Think of two people at a ticket counter: one puts cash on the counter and turns to pick up their bag, and the other person grabs the ticket first.

The report gives no request, transaction, payload or response for this step; the mechanism is described only in prose.

Root cause

The mistake is in the design of mint in IndexLogic: it assumes the caller has already paid, but never verifies or performs that payment. The transfer of assets and the minting of tokens are two separate actions, and nothing links them to the same address. Any party can therefore complete the second half of the flow against funds provided by someone else.

The report does not describe any other defence in the contract that would have prevented this, and the recommended fix confirms that no transferFrom call exists in mint at the time of the finding.

Impact

An attacker can mint tokens for himself using assets deposited by other users. The attack requires that another user has assets sitting in the vToken contract awaiting a mint, and it works by front-running that user's mint call. The result is that the attacker obtains index tokens backed by assets deposited by other users.

Phuture disputed the finding, arguing that users are not expected to call the Mint/Burn functions on Index directly and should instead go through the Router contract, as their frontend does. A Router contract is a helper contract that sits in front of the main one and walks users through the correct sequence of steps. The frontend is the website users click through, and it would call the Router rather than the underlying contract.

The judge rejected that argument on two grounds: the Router contract is not mentioned in the contest documentation, so it was unreasonable to expect wardens to know about it, and the stated scope asked wardens to focus on core functional logic or boundary case errors that an attacker could use to take funds away from clients with deposits in the protocol. Wardens are the independent researchers taking part in the contest. The judge described this as a core logic error that could be used to take funds away from clients, noted that only part of the code was submitted, and awarded the finding in full.

Fix

The recommended mitigation is to call the transferFrom function inside the mint function of the IndexLogic contract, so that the user's assets are transferred as part of the mint rather than beforehand. This ties the payment to the mint call itself.

In plain terms, the fix makes paying and minting a single action: the contract takes your money from your own account at the moment it gives you tokens, so there is no shared pile for anyone else to reach into.

The report does not state whether this change was implemented.

Variants to test

  1. Look for mint, deposit, stake or claim functions that read a shared balance (of the contract or of a vault) instead of pulling funds from msg.sender. msg.sender is the address that called the function. A positive result is that a second account can call the function after a first account's transfer and receive the shares or tokens.
  2. Check whether the protocol documents a wrapper or router as the only supported entry point while leaving the underlying function callable by anyone. A positive result is that calling the underlying function directly bypasses the intended flow and still succeeds.
  3. Watch for two-step flows where a user transfer and a mint are separate transactions. A transaction is a single recorded action on the blockchain. A positive result is that a mint executed between the two steps is credited to the attacker.
  4. Compare the balance-based accounting against lastBalance style checkpoints. A positive result is that an increase caused by another user's deposit is enough to satisfy the attacker's own mint.

Hunting notes

This kind of bug hides in accounting logic that trusts contract balances rather than per-user accounting, especially in vaults, index products and share-based protocols where a deposit and a mint are split across transactions. During review, the signal is a mint or deposit function that contains no transferFrom from the caller and instead assumes funds are already present. The judge tied the issue to the contest's stated scope of protecting client funds. The dispute over the Router contract is a reminder that undocumented wrapper contracts do not remove the vulnerability in the underlying function, and that the judge accepted the finding in full on that basis.

Glossary

  • Smart contract: a program stored on a blockchain that runs automatically when someone calls one of its functions.
  • Token: a digital unit recorded on a blockchain, representing value or a share in something.
  • Index product: a bundle of several underlying assets bought and held as a single unit.
  • Index token: a token representing a share in an index product.
  • Mint: to create new tokens.
  • Burn: to destroy tokens, the opposite of minting.
  • vToken contract: the contract that holds the underlying assets in this design.
  • IndexLogic: the contract that contains the mint function involved in this finding.
  • Solidity: the programming language used to write contracts on Ethereum-style blockchains; source files end in .sol.
  • Address: an account identifier on the blockchain, like a bank account number.
  • transferFrom: a standard token function that moves funds from one account to another on someone's behalf.
  • msg.sender: the address that called the current function.
  • lastBalance: a stored record of a balance at an earlier point in time, used to detect changes.
  • Balance: the amount of an asset held by an account or contract.
  • Front-running: acting just before someone else's pending transaction to take advantage of it.
  • Transaction: a single recorded action on the blockchain.
  • Router contract: a helper contract that sits in front of the main contract and guides users through the correct sequence of steps.
  • Frontend: the website users interact with, which sends the calls to the contracts.
  • Warden: an independent researcher taking part in an audit contest.
  • Audit contest: a public competition where researchers review code and submit findings, which a judge then assesses.
  • Severity: the rating given to a finding to reflect how serious it is, here high.

More by cccz

View all

104 more disclosed reports, best first.

More from Phuture

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.