Skip to content
Smart contracts Audit finding Advanced

Service owner can steal protocol tokens by exploiting reentrancy in create

ServiceManager.create() calls the registry's create function, which mints a service NFT, before recording the token bond, so a malicious service owner can reenter during the NFT mint callback and lower the bond. The attacker then pays only the reduced bond but later withdraws the originally specified larger bond, draining the token utility contract's funds.

SpicyMeatball Follow with Cecuro and Race

Originally disclosed on Code4rena

Submitted by SpicyMeatball, also found by Cecuro and Race

  • autonolas-registries/../contracts/ServiceManager.sol #L168
  • autonolas-registries/../contracts/ServiceRegistry.sol #L270

ServiceManager.create() does not follow the Checks-Effects-Interactions (CEI) pattern. This allows a malicious service creator to reenter the contract and modify service parameters before ServiceRegistryTokenUtility.createWithToken() is executed:

    function create(
        address serviceOwner,
        address token,
        bytes32 configHash,
        uint32[] memory agentIds,
        IService.AgentParams[] memory agentParams,
        uint32 threshold
    ) external returns (uint256 serviceId) {
        --- SNIP ---
        } else {
            --- SNIP ---
            // Call the original ServiceRegistry contract function
>>>         serviceId = IService(serviceRegistry).create(serviceOwner, configHash, agentIds, agentParams, threshold);
            // Create a token-related record for the service
>>>         IServiceTokenUtility(serviceRegistryTokenUtility).createWithToken(serviceId, token, agentIds, bonds);
        }
    }

Attack Scenario

  • The attacker creates a service with a single agent and specifies a large USDC bond (e.g. ServiceRegistryTokenUtility balance);
  • ServiceRegistry.create() mints a service NFT to the attacker using _safeMint;
  • During the onERC721Received callback, the attacker reenters ServiceManager by calling update() and changes the bond amount to 1 wei;
  • The attacker then calls ServiceManager.activateRegistration() and only pays the reduced bond amount;
  • Execution resumes after the callback, and ServiceRegistryTokenUtility.createWithToken() is called using the stale bond configuration captured before reentrancy;
  • Finally, the attacker terminates the service and withdraws the originally specified USDC bond from ServiceRegistryTokenUtility, effectively draining its funds.

Recommended mitigation steps

To enforce a secure CEI pattern and prevent reentrancy:

  • Since ServiceRegistry.totalSupply() is known prior to minting, derive the expected serviceId in advance and call serviceRegistryTokenUtility.createWithToken() before invoking ServiceRegistry.create(). This ensures all state related to token bonds is finalized before any external calls occur.

Additionally or alternatively:

  • Introduce a reentrancy guard on ServiceManager.create() and ServiceManager.update().

Proof of Concept

View detailed Proof of Concept


The original report as published on Code4rena, by SpicyMeatball. 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 create function performs an external call that mints an NFT to the caller before the token bond is recorded, breaking the checks-effects-interactions order and leaving a stale bond value in use.

Impact

A malicious service owner could drain the token utility contract's funds by paying a reduced bond and withdrawing the larger one.

What the attacker needed

Attacker can create a service; attacker controls the receiving contract

The fix

The bond should be recorded before the registry mints the NFT, or a reentrancy guard should be added to create and update.

How it was found

  1. Create a service with one agent and a large token bond.
  2. The registry mints the service NFT, triggering the attacker's receive callback.
  3. In the callback, reenter ServiceManager.update() and set the bond to a tiny amount.
  4. Call activateRegistration() and pay only the reduced bond.
  5. After the callback returns, createWithToken() runs with the old, large bond value.
  6. Terminate the service and withdraw the large bond, draining the token utility.

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 can call back into the contract that just called it, a bit like a shop assistant handing you a receipt and you running back to the till before they finish the sale. Here the contract mints a token to the attacker before it writes down how much money the attacker must lock up, so the attacker changes that amount in the gap. They then pay the small amount but withdraw the large amount they originally promised.

What is Smart contracts?

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

More by SpicyMeatball

View all

18 more disclosed reports, best first.

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.