Skip to content
Business logic Audit finding Intermediate

Wrong requirement in reweight function ( ManagedIndexReweightingLogic.sol )

The reweight function in ManagedIndexReweightingLogic.sol checks the length of the updated asset list against the maximum allowed components, but this list includes assets to be removed, so the check can fail even when the final asset count would be within the limit. This causes the transaction to revert, preventing the asset list from being changed.

TrungOre Follow

Originally disclosed on Code4rena

Submitted by TrungOre

ManagedIndexReweightingLogic.sol#L32 IIndexRegistry.sol#L19

The list of assets won’t be changed after reweight because of reverted tx.

Proof of Concept

require(_updatedAssets.length <= IIndexRegistry(registry).maxComponents()) when reweight is not true, because as in the doc, maxComponent is the maximum assets for an index, but _updatedAssets also contain the assets that you want to remove. So the comparision makes no sense.

Recommended Mitigation Steps

Require assets.length() <= IIndexRegistry(registry).maxComponents() at the end of function instead.

jn-lp (Phuture Finance) confirmed and resolved


The original report as published on Code4rena, by TrungOre. 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 for managed on-chain index products. A managed index holds a set of underlying assets, and its composition can be changed through a reweight operation. The reweight logic lives in ManagedIndexReweightingLogic.sol, and the registry that stores index-wide limits is exposed through IIndexRegistry.sol.

One of those limits is maxComponents, described in the interface as the maximum number of assets an index may hold. The reweight function checks that limit at line 32.

The report points at two locations in the codebase:

  • ManagedIndexReweightingLogic.sol#L32, where the reweight function performs its check.
  • IIndexRegistry.sol#L19, where maxComponents is defined.

Setup

This is a code review finding rather than a live exploitation against a deployed system. The relevant preconditions are simply that a managed index exists and that a reweight is being attempted with a set of updated assets. No accounts, roles, tools or versions are described in the report.

Finding it

The researcher noticed that the reweight function validates the wrong quantity. The check at line 32 of ManagedIndexReweightingLogic.sol is:

Solidity
require(_updatedAssets.length <= IIndexRegistry(registry).maxComponents())

According to the interface documentation, maxComponents is the maximum number of assets an index may hold. The problem is that _updatedAssets is not the final set of assets of the index: it also contains the assets that are being removed by the reweight. Comparing the length of that input array against the limit therefore does not measure what the limit is meant to constrain.

Because the comparison is against the wrong array, the requirement can fail even when the resulting index would be within the allowed number of components. When the require fails, the transaction reverts, and the list of assets is not changed.

Exploitation

Step 1: Attempt a reweight that removes assets

A caller submits a reweight whose _updatedAssets array includes both the assets that will remain and the assets that are to be removed. The array length is checked against maxComponents.

Step 2: The check reverts the transaction

If the combined array (remaining plus removed assets) is longer than maxComponents, the require fails and the whole transaction reverts. The reweight does not go through, so the asset list stays as it was.

The report's summary of the outcome is that the list of assets will not be changed after a reweight because the transaction is reverted.

Root cause

The validation compares the length of the input array _updatedAssets, which mixes assets to keep and assets to remove, against maxComponents, which is defined as the maximum number of assets for an index. The two quantities are not the same thing, so the comparison makes no sense as a guard on the final composition. The report does not describe any other defence that would catch the mismatch.

Impact

A reweight that should be valid, because the resulting index would be within the component limit, can revert instead. The practical effect is that the index's asset list cannot be changed in those cases. The report does not describe who is affected beyond the reweight operation itself, nor any loss of funds.

Fix

The recommended mitigation is to move the check to the end of the function and apply it to the resulting asset set rather than the input array:

Solidity
require(assets.length() <= IIndexRegistry(registry).maxComponents())

The finding was confirmed and resolved by jn-lp (Phuture Finance).

Variants to test

  • Look for other require statements that validate an input array length against a limit meant for a stored or resulting collection. A positive result is a check that can revert a valid operation or let an invalid one through.
  • Check functions that take a combined list of additions and removals and validate the list length rather than the post-operation length. A positive result is a boundary case where the final set is within the limit but the input array is not.
  • Review limits documented in interfaces (such as maximum counts) and confirm each enforcement site measures the same quantity the documentation describes. A positive result is a mismatch between the documented meaning and the value actually compared.

Hunting notes

This kind of bug tends to hide in state-transition functions that accept a full replacement list, where additions and removals arrive in one array. The signal during review is a require near the top of the function that references an input parameter's length while the documented limit applies to the stored state. To show impact, demonstrate a concrete call where the resulting set is within the limit but the transaction reverts.

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 system that runs "managed index" products on a blockchain. An index is simply a basket of assets, and the system lets someone change what is in the basket through an operation called a reweight. The code that performs a reweight lives in a file called ManagedIndexReweightingLogic.sol, and the code that stores the rules for indexes lives in a file called IIndexRegistry.sol.

One of those rules is called maxComponents, and the documentation describes it as the maximum number of assets an index may hold. The reweight function checks that rule at line 32.

The researcher found that the reweight function checks the wrong thing. It compares the size of the list of assets it is given against maxComponents, but that list also contains the assets that are being removed. So the check can fail even when the final index would be perfectly within the limit. When the check fails, the whole operation is cancelled and the basket stays as it was.

The report points at two places in the code:

  • ManagedIndexReweightingLogic.sol#L32, where the reweight function performs its check.
  • IIndexRegistry.sol#L19, where maxComponents is defined.

Setup

This is a finding from reading the code, not an attack against a live system. The only things needed for it to matter are that a managed index exists and that someone tries a reweight with a list of updated assets. The report does not describe any accounts, roles, tools or software versions.

Finding it

The researcher noticed that the reweight function validates the wrong quantity. The check at line 32 of ManagedIndexReweightingLogic.sol is:

Solidity
require(_updatedAssets.length <= IIndexRegistry(registry).maxComponents())

Line by line, in plain words:

  • require(...) is a guard. It says "only continue if the thing inside the brackets is true". If it is not true, the whole transaction is cancelled and undone, which is called a revert.
  • _updatedAssets is the list of assets handed to the reweight function.
  • .length asks how many items are in that list.
  • <= means "less than or equal to".
  • IIndexRegistry(registry) means "treat the address stored in registry as the index registry contract", so the code can call its functions.
  • .maxComponents() calls the registry to fetch the maximum number of assets an index may hold.

So the line reads: "continue only if the number of assets in the input list is no more than the maximum number of assets an index may hold."

According to the interface documentation, maxComponents is the maximum number of assets an index may hold. The problem is that _updatedAssets is not the final set of assets of the index: it also contains the assets that are being removed by the reweight. Comparing the length of that input list against the limit therefore does not measure what the limit is meant to constrain.

Because the comparison is against the wrong list, the requirement can fail even when the resulting index would be within the allowed number of components. When the require fails, the transaction reverts, and the list of assets is not changed.

Exploitation

Step 1: Attempt a reweight that removes assets

A caller submits a reweight whose _updatedAssets list includes both the assets that will remain and the assets that are to be removed. The list length is checked against maxComponents.

Why this step matters: the caller is doing something legitimate. They want to change the basket, and part of that change is taking some assets out. To describe the change, they send one list that covers both what stays and what goes.

Step 2: The check reverts the transaction

If the combined list (remaining plus removed assets) is longer than maxComponents, the require fails and the whole transaction reverts. The reweight does not go through, so the asset list stays as it was.

Why this step matters: the final basket might be small enough to be allowed, but the check never looks at the final basket. It looks at the longer input list, so it refuses an operation that should have been fine.

The report's summary of the outcome is that the list of assets will not be changed after a reweight because the transaction is reverted.

Root cause

The validation compares the length of the input list _updatedAssets, which mixes assets to keep and assets to remove, against maxComponents, which is defined as the maximum number of assets for an index. The two quantities are not the same thing, so the comparison makes no sense as a guard on the final composition. The report does not describe any other defence that would catch the mismatch.

Impact

A reweight that should be valid, because the resulting index would be within the component limit, can revert instead. The practical effect is that the index's asset list cannot be changed in those cases.

Fix

The recommended mitigation is to move the check to the end of the function and apply it to the resulting asset set rather than the input list:

Solidity
require(assets.length() <= IIndexRegistry(registry).maxComponents())

Line by line, in plain words:

  • require(...) is the same guard as before: continue only if what is inside is true.
  • assets is the resulting set of assets, the basket as it will be after the change, rather than the list that was handed in.
  • .length() asks how many assets are in that resulting set.
  • <= means "less than or equal to".
  • IIndexRegistry(registry).maxComponents() fetches the same limit from the registry as before.

So the fixed line reads: "continue only if the number of assets in the final basket is no more than the maximum number of assets an index may hold." That measures exactly the quantity the documentation describes.

The finding was confirmed and resolved by jn-lp (Phuture Finance).

Variants to test

These are things to look for elsewhere, in the same spirit as the bug above.

  • Look for other require statements that validate an input list length against a limit meant for a stored or resulting collection. A positive result is a check that can revert a valid operation or let an invalid one through.
  • Check functions that take a combined list of additions and removals and validate the list length rather than the post-operation length. A positive result is a boundary case where the final set is within the limit but the input list is not.
  • Review limits documented in interfaces (such as maximum counts) and confirm each enforcement site measures the same quantity the documentation describes. A positive result is a mismatch between the documented meaning and the value actually compared.

Hunting notes

This kind of bug tends to hide in state-transition functions that accept a full replacement list, where additions and removals arrive in one list. The signal during review is a require near the top of the function that references an input parameter's length while the documented limit applies to the stored state. To show impact, demonstrate a concrete call where the resulting set is within the limit but the transaction reverts.

Glossary

  • Blockchain: a shared record of transactions that many computers keep in sync, so entries cannot easily be changed afterwards.
  • Smart contract: a program that lives on a blockchain and runs automatically when someone calls it.
  • Solidity: the programming language used to write smart contracts on Ethereum-style blockchains.
  • Protocol: a set of smart contracts and rules that together provide a service, here managed index products.
  • Managed index: a basket of assets whose composition is set and changed by the protocol rather than fixed in advance.
  • Asset: one item held in a basket, such as a token.
  • Component: one asset inside an index; the components are the contents of the basket.
  • Reweight: the operation that changes which assets an index holds.
  • Registry: a contract that stores shared settings and limits for the indexes.
  • Interface: a file that declares what functions a contract offers and what they mean, without containing their implementation.
  • maxComponents: the documented maximum number of assets an index may hold.
  • Function: a named block of code in a contract that can be called to do something.
  • Parameter / argument: a value handed to a function when it is called, such as the list of updated assets.
  • Array / list: an ordered collection of items; .length gives how many items it holds.
  • require: a guard statement that cancels the transaction if its condition is not true.
  • Transaction: a single call submitted to the blockchain that either fully succeeds or is fully undone.
  • Revert: the cancellation of a transaction, undoing every change it made.
  • Input validation: checking values that arrive from outside before using them, to make sure they make sense.
  • Root cause: the underlying reason a bug exists, as opposed to its visible symptom.
  • Impact: the practical consequence of a bug for users or the system.
  • Mitigation / fix: the change that removes the bug.
  • Code review: reading code carefully to find mistakes before or after it is deployed.
  • Proof of concept: a concrete demonstration that a bug is real.
  • State: the data a contract stores and keeps between calls, such as the current contents of an index.
  • State-transition function: a function that changes stored state from one version to another.
  • Boundary case: a situation right at the edge of an allowed limit, where off-by-one style mistakes show up.

More by TrungOre

View all

7 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.