Skip to content
Race condition Audit finding Advanced

Token Change Can Be Frontrun, Blocking Token

A token ownership transfer could be frontrun by an attacker who calls the change function first, linking the token to their own project and gaining ownership. This could allow the attacker to mint arbitrary amounts of the token if it has an owner-restricted mint function.

philogy Follow

Originally disclosed on Code4rena

Submitted by philogy, also found by berndartmueller and Lambda

https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBTokenStore.sol#L246

https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBTokenStore.sol#L266

https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/828bf2f3e719873daa08081cfa0d0a6deaa5ace5/contracts/JBController.sol#L605

Impact

This vulnerability allows malicious actors to block other users from changing tokens of their projects. Furthermore if ownership over the token contract is transferred to the JBTokenStore contract prior to the change, as suggested in the recourse section of Juicebox’s 24.05.2022 post-mortem update, this vulnerability would allow an attacker to become the owner of tokens being transferred. For JBToken based tokens this would allow an attacker to begin issuing arbitrary amounts the token that was meant to be transferred.

Proof of Concept

Exploit scenario:

  1. Wanting to assign their token to their JB project an unsuspecting owner / admin transfers ownership to a JBTokenStore contract, either directly by calling transferOwnership on the token or indirectly by calling the changeFor method on an older JBTokenStore contract with _newOwner set as the new JBTokenStore contract. (For the newer Juicebox contracts the JBController contract’s changeTokenOf method would be called)
  2. Seeing this change an attacker submits a changeTokenFor calling transaction to the new JBController contract, triggering the JBTokenStore contract’s changeFor method, linking it to one of the attacker’s projects (this could be created in advance or as part of the same transaction via an attack contract)
  3. The attacker can then gain ownership over the token by calling changeTokenFor again with the _newOwner set to the attacker’s address
  4. Assuming the token has an owner restricted mint method like JBToken based tokens the attacker can now mint an arbitrary amount of the token

Recommended Mitigation Steps

Before allowing a caller to change to a specific token ensure that they have control over it. This can be achieved by storing a list of trusted older JB directories and projects which are then queried. Alternatively the contract could require the caller to actually be the .owner() address of the token to migrate, this would require admins to:

  1. Call changeTokenOf with themselves as the new owner
  2. Call the new change token method on the newer contract, since they are the owner they’d pass the check
  3. Independently transfer the ownership to the new token store to ensure that it can issue tokens

Future migrations can be made more seamless by having older contracts directly call new contracts via a sub-call, removing a necessary transaction for the admin. The newer contracts needs to verify that the older contract is the owner address of the token that’s being set and also has approval of the project owner which is being configured.

mejango (Juicebox) confirmed and commented:

Nice. The project should first changeToken and then transfer ownership.

mejango (Juicebox) resolved:

PR with fix: PR #1

berndartmueller (warden) reviewed mitigation:

Changing an already set project token is not possible anymore.


The original report as published on Code4rena, by philogy. 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 contract allows any caller to change a token's project association without verifying that the caller controls the token or the original project.

Impact

An attacker could block token changes and, if ownership was transferred to the token store beforehand, could become the token owner and mint arbitrary amounts.

What the attacker needed

Owner transfers token ownership to token store; attacker can frontrun the transaction

The fix

The fix was to prevent changing an already set project token.

How it was found

  1. The project owner transfers token ownership to the JBTokenStore contract.
  2. The attacker submits a changeTokenFor transaction to link the token to one of their projects.
  3. The attacker calls changeTokenFor again with themselves as the new owner.
  4. The attacker mints an arbitrary amount of the token if it has an owner-restricted mint function.

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 project owner wants to move their token to a new contract, they first transfer ownership of the token to that contract. An attacker can watch for this and quickly call a function that claims the token for their own project before the owner's transaction completes. Because the attacker now controls the token, they could create unlimited new tokens if the token allows the owner to mint.

What is Race condition?

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.

More by philogy

View all

1 more disclosed report, best first.

More from Juicebox Buyback Delegate

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.