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.
Submitted by philogy, also found by berndartmueller and Lambda
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:
- Wanting to assign their token to their JB project an unsuspecting owner / admin transfers ownership to a
JBTokenStorecontract, either directly by callingtransferOwnershipon the token or indirectly by calling thechangeFormethod on an olderJBTokenStorecontract with_newOwnerset as the newJBTokenStorecontract. (For the newer Juicebox contracts theJBControllercontract’schangeTokenOfmethod would be called) - Seeing this change an attacker submits a
changeTokenForcalling transaction to the newJBControllercontract, triggering theJBTokenStorecontract’schangeFormethod, 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) - The attacker can then gain ownership over the token by calling
changeTokenForagain with the_newOwnerset to the attacker’s address - Assuming the token has an owner restricted
mintmethod likeJBTokenbased 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:
- Call
changeTokenOfwith themselves as the new owner - Call the new change token method on the newer contract, since they are the owner they’d pass the check
- 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
changeTokenand 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.
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
- The project owner transfers token ownership to the JBTokenStore contract.
- The attacker submits a changeTokenFor transaction to link the token to one of their projects.
- The attacker calls changeTokenFor again with themselves as the new owner.
- 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.