Skip to content
Business logic Audit finding Intermediate

Staked service will be irrecoverable by owner if not an ERC721 receiver

The staking contract uses safeTransferFrom to return a staked ERC721 service token to its owner, which fails if the owner is a contract that cannot receive ERC721 tokens. This permanently locks the service in the staking contract, making it irrecoverable.

EV_om Follow

Originally disclosed on Code4rena

Submitted by EV_om

The StakingBase contract allows users to stake services represented by ERC721 tokens. These services are freely transferable, meaning they could be staked by contracts that do not implement the ERC721TokenReceiver interface.

When a user calls unstake() to withdraw their staked service, the contract attempts to transfer the ERC721 token back to the msg.sender (which must match the original depositor) using safeTransferFrom():

File: StakingBase.sol
862:         // Transfer the service back to the owner
863:         // Note that the reentrancy is not possible due to the ServiceInfo struct being deleted
864:         IService(serviceRegistry).safeTransferFrom(address(this), msg.sender, serviceId);

However, if the owner is a contract that does not support receiving ERC721 tokens, this transfer will fail. As a result, the service associated with serviceId will be permanently locked in the StakingBase contract, and the original owner will be unable to recover it.

Impact

Staked services will become permanently irrecoverable if the owner cannot receive ERC721 tokens.

Proof of Concept

  1. User stakes a service by calling stake(serviceId) on the StakingBase contract from a smart contract that is not an ERC721TokenReceiver, and cannot be upgraded to support this (e.g. a Safe with restricted privileges). The service is transferred from the user to the contract.
  2. When the user later tries to unstake and recover their service by calling unstake(serviceId), the safeTransferFrom() call in the function reverts.
  3. The service remains locked in the StakingBase contract indefinitely, and the user is unable to recover it.

Recommended Mitigation Steps

Consider using transferFrom() instead of safeTransferFrom() when transferring the service back to the owner in unstake(). This will allow the transfer to succeed even if the recipient is not an ERC721 receiver.

Assessed type

ERC721

kupermind (Olas) disputed and commented:

msg.sender is the owner that stakes the service, and it’s exactly the same owner that is able to unstake it. What is the scenario that msg.sender was able to be the owner of the service before staking it, but is no longer able to receive ERC721 token when unstaking?

Our protocol assumes a valid ERC721 standard used in all the possible service registry contracts. If someone decides to use a custom broken ERC721 contract that is able to mint tokens to the contract, but cannot receive one by the transfer, this is out of scope of our protocol.

kupermind (Olas) acknowledged and commented:

After several communication rounds we can accept the issue; however, the declared severity completely does not match the issue. There is zero risk factor for the protocol, only the user stupidity that have not checked the staking contract requirements.

None of well-known contract wallets reject the contract ERC721 support. This must be an artificially created scenario when the user deliberately uses the contract without such a support. If one is talking about outdated Safe, for example, there is a way to upgrade the Safe version, and then provide the correct fallbackHandler contract address to deal with ERC721 contracts.

0xA5DF (judge) decreased severity to Medium and commented:

I agree that this is less likely to happen and somewhat on the user to ensure that their contract can receive ERC721 However, I think that the likelihood is sufficient to consider this as medium, given the high impact.

Olas mitigated

Varun_05 (warden) commented:

Fixed.


The original report as published on Code4rena, by EV_om. 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 use of safeTransferFrom instead of transferFrom when returning the staked token, which enforces receiver support that may not exist.

Impact

Staked services could become permanently irrecoverable if the owner cannot receive ERC721 tokens, though the likelihood is low and the protocol itself bears no risk.

What the attacker needed

Owner is a contract; contract cannot receive ERC721 tokens; contract cannot be upgraded to support ERC721

The fix

The issue was mitigated by using transferFrom instead of safeTransferFrom when returning the service to the owner.

How it was found

  1. A user stakes a service by calling stake(serviceId) from a smart contract that is not an ERC721TokenReceiver.
  2. The service is transferred from the user to the staking contract.
  3. Later, the user calls unstake(serviceId) to recover the service.
  4. The safeTransferFrom call in unstake reverts because the owner contract cannot receive ERC721 tokens.
  5. The service remains locked in the staking contract indefinitely.

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 you stake a service (represented as a digital token), the staking contract holds it. To give it back, the contract uses a 'safe' transfer that checks if the receiver can handle tokens. If the receiver is a contract that cannot, the transfer fails and the token stays stuck forever.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by EV_om

View all

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

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.