Skip to content
Smart contracts Audit finding Advanced

Token Callback Reentrancy

The StakingBase contract violates the checks-effects-interactions pattern by calling an overridable internal transfer function before updating stored balances, allowing a malicious receiver or token to re-enter claim/withdraw and drain funds. ServiceManager.create also performs an external call that can trigger a callback before completing critical operations, enabling reentrancy and inconsistent state.

Olas

Originally disclosed on Code4rena

Found by v12

  • autonolas-registries/../contracts/staking/StakingBase.sol#L540
  • autonolas-registries/../contracts/staking/StakingBase.sol#L929
  • autonolas-registries/../contracts/ServiceManager.sol#L126

Checks-Effects-Interactions violation in StakingBase: virtual _transfer allows reentrancy and balance desynchronization

Targets

  • _claim (StakingBase)
  • _withdraw (StakingBase)
  • *claim/*withdraw (StakingBase)

Description

The StakingBase contract violates the checks-effects-interactions (CEI) pattern in its claim/withdraw flow by performing external interactions through an overridable internal function _transfer(…) before persisting updated balances to storage. _claim zeroes per-service rewards and calls internal _withdraw, which computes a local updatedBalance and issues transfers by calling the internal virtual _transfer for each receiver. Because _transfer is abstract/virtual and the implementation may perform external calls or invoke token callbacks, a malicious receiver or token can re-enter the contract during these transfers. The contract only writes the final updatedBalance to storage after all transfers complete, so any reentrant withdrawal occurring during the external call window will observe stale stored balances and can pass checks multiple times. When control returns to the outer _withdraw, it overwrites storage with a stale balance derived before the reentrant deduction, desynchronizing stored accounting from actual token holdings and enabling theft.

Root cause

Violation of checks-effects-interactions plus unsafe use of an overridable/external-facing transfer hook. The contract computes and uses a local updatedBalance while performing potentially reentrant external interactions via an internal virtual _transfer, and only writes the persistent balance after those interactions complete. There is no reentrancy guard and the abstract/virtual _transfer can trigger external callbacks (e.g., token hooks, receiver fallback), enabling reentrant entry into claim/withdraw logic.

Impact

High — An attacker who can act as a payment receiver or controls a malicious token contract can reenter claim/withdraw during _transfer and cause overlapping withdrawals that individually pass checks but cumulatively drain more tokens than the contract’s stored balance should allow. This can result in: complete or partial draining of contract-held funds, corruption/desynchronization of internal accounting, and loss of user funds. The attack requires the attacker to be a recipient (or control a recipient/token hook) and to have other claimable rewards to trigger reentrancy, but these are realistic in staking/reward systems.

Unsafe external call ordering in ServiceManager.create allows reentrant token-utility interaction via onERC721Received

Targets

  • create (ServiceManager)

Description

ServiceManager.create performs an external call to serviceRegistry.create (which may safe-mint an ERC721) before completing or protecting subsequent cross-contract work (calling the token-utility). The safe-mint can invoke the recipient’s onERC721Received callback while serviceRegistry.create is still executing. Because ServiceManager does not persist state or use a reentrancy guard around these interactions, a malicious recipient can run arbitrary code during the callback and invoke token-utility.createWithToken or re-enter ServiceManager, causing ordering races and inconsistent state.

Root cause

Improper ordering of external interactions and lack of reentrancy protection. The contract calls an untrusted external contract (serviceRegistry.create) that can synchronously call back into user-controlled code (via ERC721Receiver hook) before the manager completes or secures the subsequent critical operation (createWithToken). No persistent state updates or a reentrancy guard are used to prevent reentrant or out-of-order calls to the token-utility or manager functions.

Impact

High (context-dependent). An attacker who controls the recipient/serviceOwner (or otherwise triggers code during the registry’s safeMint) can: (1) call token-utility.createWithToken prematurely or with manipulated inputs, (2) re-enter ServiceManager to create ordering races (leading to double registrations, skipped initializations, or corrupted invariants), or (3) produce inconsistent token/registry state. The exploitability and severity depend on access controls in the token-utility: if createWithToken is publicly callable, the issue is directly exploitable (high); if restricted, the impact may be lower but ordering/invariant violations remain possible.


The original report as published on Code4rena. 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 a violation of the checks-effects-interactions pattern combined with an overridable transfer hook that allows external callbacks before state is persisted, and no reentrancy guard.

Impact

An attacker who is a payment receiver or controls a malicious token could re-enter claim/withdraw to cause overlapping withdrawals that drain more tokens than the stored balance allows, potentially leading to complete or partial loss of contract-held funds.

What the attacker needed

Attacker is a payment receiver; or controls a malicious token contract; attacker has claimable rewards

The fix

The contract should follow the checks-effects-interactions pattern by updating stored balances before making external transfers, and should add a reentrancy guard.

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.

A smart contract is a program on a blockchain that holds and moves digital tokens. This report says the contract updates its internal record of how many tokens each person has only after it sends tokens out. If the recipient is itself a contract, it can call back into the original contract before the record is updated, tricking it into sending tokens multiple times. This is called reentrancy, like withdrawing money from a bank account before the balance is deducted.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More from Olas

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.