The initialize function in three index contracts can be called multiple times with the same asset, causing duplicate entries in the assets list. Any function reading the assets list would then retrieve duplicate assets.
Initialize function can be called multiple times with same asset. Calling with same asset will make duplicate entries in assets list. Any function reading assets will get impacted and would retrieve duplicate asset
Proof of Concept
Observe that initialize function can be called multiple times
Admin calls initialize function with asset X
asset X gets added in assets object
Admin again calls initialize function with asset X
asset X again gets added in assets object making duplicate entries
Recommended Mitigation Steps
Add a check to fail if assets already contains the passed asset argument. Also add a modifier so that initialize could only be called once.
Given the factory contract is not supplied it makes it impossible to know these things and hence siding with the warden for the disclosure.
” to be a factory (which is non-upgradable contract)” i.e. one can’t know this if the factory is not supplied or documented.
The original report as published on Code4rena, by csanuragjain. 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. 3 min read.
Context
Phuture is a protocol whose contracts include index products built on top of a set of tracked assets. Three contracts are relevant here: ManagedIndex.sol, TopNMarketCapIndex.sol and TrackedIndex.sol. Each of them exposes an initialize function that populates an assets list. The finding is that this initialisation does not guard against the same asset being supplied more than once, so repeated calls with the same asset produce duplicate entries in that list.
The report points at three locations in the codebase:
ManagedIndex.sol#L35
TopNMarketCapIndex.sol#L57
TrackedIndex.sol#L45
Setup
The scenario describes an admin calling initialize, though the team's response says only the factory may do so. No tooling, versions or environment details are given in the report. The precondition is simply that initialize can be invoked more than once, which the researcher states as an observation rather than something demonstrated with a transaction trace.
Finding it
The researcher noticed that the initialize function can be called multiple times with the same asset. Because the function appends the supplied asset to the assets object without checking whether it is already present, a second call with the same asset creates a duplicate entry. Any function that reads from assets would then retrieve the same asset twice.
Exploitation
Step 1: Confirm that initialize can be called repeatedly
The researcher's first step is to observe that the initialize function can be called multiple times. The report does not include the function body or a transaction showing this.
Step 2: First call with asset X
The admin calls initialize with asset X.
Step 3: Asset X is stored
Asset X gets added to the assets object.
Step 4: Second call with the same asset X
The admin calls initialize again, this time with the same asset X.
Step 5: Duplicate entry created
Asset X is added to the assets object a second time, so the list now contains duplicate entries. The report does not show the resulting state or any downstream function output.
Root cause
The initialize function lacks two things: a check that the asset being added is not already in assets, and a guard that restricts initialisation to a single call. Without either, the same asset can be appended repeatedly.
The Phuture team disputed the finding. Their argument, from jn-lp, is that the caller of initialize must be a factory, and that the factory is a non-upgradable contract, so the function cannot be called twice:
The judge, moose-code, sided with the warden. The reasoning given is that the factory contract was not supplied, which makes it impossible to verify the team's claim, and that one cannot know the factory is non-upgradable if it is neither supplied nor documented.
Impact
Any function that reads from assets is affected and would retrieve a duplicate asset. The report does not describe a concrete downstream consequence beyond that, and the impact depends on the factory restriction actually holding, which the judge treated as unproven.
Fix
The recommended mitigation is to reject an asset that is already present, and to add a modifier so that initialize can only be called once:
Call initialize twice with the same asset on each of the three contracts named in the report and check whether the assets list grows. A positive result is a duplicated entry in the stored list.
Call initialize with different assets across multiple invocations to see whether the function is intended to be additive at all. A positive result is a list that accepts further entries after the first call.
Read back from any function that iterates assets after a duplicate has been inserted. A positive result is the same asset appearing twice in the output.
Hunting notes
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. 7 min read.
What happened, in plain words
Phuture is a project that runs financial products called indexes on a blockchain. An index is a basket of assets, a bit like a shopping basket that holds several items and whose total value is tracked together. In this codebase, each index keeps its list of assets in a variable called assets, and that list is filled in by a function called initialize.
A function is a named block of code that does one job when it is called. initialize is the setup function: it is meant to be run when the index is first created, to put the starting assets into the basket.
The researcher, csanuragjain, reported that initialize does not check whether an asset is already in the basket. If it is called twice with the same asset, the basket ends up holding that asset twice. Any other part of the code that reads the basket then sees the same asset twice.
The Phuture team disagreed, saying that only a specific contract, called a factory, is allowed to call initialize, and that this factory cannot be replaced, so the function cannot be called twice. The judge, moose-code, sided with the researcher because the factory contract was never provided, so nobody could check that claim.
The three contracts involved
A contract is a program that lives on a blockchain. It has its own storage (data it keeps) and its own functions (things it can do). Once deployed, its code is fixed unless it was written to be replaceable.
The report names three contracts, each of which has an initialize function that fills an assets list:
ManagedIndex.sol
TopNMarketCapIndex.sol
TrackedIndex.sol
The report points at one line in each file:
ManagedIndex.sol#L35
TopNMarketCapIndex.sol#L57
TrackedIndex.sol#L45
These are links into the project's public code repository. The #L35 part means line 35 of that file, and so on. The report gives no other detail about what those lines contain.
The setup the scenario assumes
The scenario describes an admin calling initialize, though the team's response says only the factory may do so. The report gives no tools, no software versions and no environment details. The only precondition is that initialize can be called more than once. The researcher states this as an observation; the report does not include a transaction record proving it.
Finding the problem
The researcher noticed that initialize can be called several times with the same asset. The function adds the asset it receives to the assets object without first asking whether that asset is already there. So a second call with the same asset creates a second copy. Any function that reads assets afterwards would return the same asset twice.
A useful comparison is a guest list at a door. If the person at the door never checks the list before writing a name down, the same guest can be written in twice, and anyone counting the names will count that guest twice.
Walking through the exploitation steps
Step 1: Confirm that initialize can be called repeatedly
The first step is to observe that initialize can be called more than once. The report does not include the body of the function or a transaction showing this happening, so this step rests on reading the code.
Step 2: First call with asset X
The admin calls initialize with asset X. Asset X stands for any asset the index is meant to track.
Step 3: Asset X is stored
Asset X is added to the assets object. The basket now holds one copy of X.
Step 4: Second call with the same asset X
The admin calls initialize again, this time with the same asset X.
Step 5: Duplicate entry created
Asset X is added to the assets object a second time, so the list now contains two copies of X. The report does not show the resulting stored state or the output of any function that reads the list.
Why it happens
The initialize function is missing two safeguards. First, it does not check whether the asset being added is already in assets. Second, it has no guard that limits initialisation to a single call. Without either one, the same asset can be appended again and again.
The team's response
The Phuture team disputed the finding. Their argument, from jn-lp, is that the caller of initialize must be a factory, and that the factory is a non-upgradable contract, so the function cannot be called twice. A factory here is a contract whose job is to create other contracts; a non-upgradable contract is one whose code cannot be swapped out after deployment.
require(...) is a check that must pass. If the condition inside the brackets is false, the whole call is stopped and any changes it made are undone.
msg.sender is the address of whoever is making the current call. An address is the identifier of an account or contract on the blockchain, like a bank account number.
factory is the stored address of the factory contract that this contract trusts.
== means "is equal to". So the condition is: the caller must be the factory.
"ManagedIndex: FORBIDDEN" is the error message shown when the check fails.
In plain words: only the factory may call this function; anyone else is rejected.
The judge's decision
The judge, moose-code, sided with the researcher. The reason given is that the factory contract was not supplied, which makes it impossible to verify the team's claim. The judge also noted that one cannot know the factory is non-upgradable if it is neither supplied nor documented.
What the impact is
Any function that reads from assets is affected and would retrieve a duplicate asset. The report does not describe a concrete downstream consequence beyond that. Whether the problem can actually be triggered depends on the factory restriction holding, and the judge treated that as unproven.
The suggested fix
The recommended mitigation is to reject an asset that is already present, and to add a modifier so that initialize can only be called once. A modifier is a reusable piece of code attached to a function that runs before or after it, often used for checks.
require(...) again means the call stops if the condition is false.
! means "not".
assets.contain(asset) asks whether the assets collection already contains the asset passed in.
So !assets.contain(asset) means "the assets collection does not already contain this asset".
"Asset already exists" is the message shown when the check fails, that is, when the asset is already there.
Other cases worth testing
Call initialize twice with the same asset on each of the three contracts named in the report and check whether the assets list grows. A positive result is a duplicated entry in the stored list.
Call initialize with different assets across several calls to see whether the function is meant to accept additions at all. A positive result is a list that accepts further entries after the first call.
Read back from any function that goes through assets after a duplicate has been inserted. A positive result is the same asset appearing twice in the output.
Notes for anyone hunting similar bugs
It is especially easy to miss when the only protection is a rule that only a trusted caller may invoke the function, and the code of that trusted caller is not part of what is being reviewed.
In this case the report was accepted because the judge would not assume that an undocumented factory prevents the second call.
Glossary
Blockchain: a shared record of transactions that many computers keep in sync, so entries cannot easily be changed afterwards.
Contract: a program deployed on a blockchain, with its own stored data and functions.
Function: a named block of code that performs one job when called.
initialize: the setup function in these contracts that fills the assets list.
assets: the stored list of assets that an index tracks.
Asset: a thing of value that an index tracks, such as a token.
Index: a basket of assets whose combined value is tracked as one product.
Admin: a privileged user allowed to perform restricted actions.
Factory: a contract whose job is to create other contracts.
Non-upgradable: describes a contract whose code cannot be replaced after deployment.
Address: the identifier of an account or contract on the blockchain.
msg.sender: the address of whoever is making the current call.
require: a check that stops the call and undoes its changes if the condition is false.
Modifier: reusable code attached to a function that runs checks before or after it.
Duplicate entry: the same item stored twice in a list.
Idempotency check: a check that prevents an action from having an extra effect when repeated.
Warden: the researcher who submitted the finding in this review process.
Judge: the person who decides whether a submitted finding is valid.