Skip to content
Business logic Audit finding Intermediate

evm_hooks ignores some important errors

The evm_hooks processEvents function ignores errors when handling Turnstile events, so if one event fails, subsequent events are skipped and contracts or NFTs may never receive CSR fees. An attacker could cause a transaction with multiple events to fail silently, leaving contracts unregistered in the CSR store.

hihen Follow

Originally disclosed on Code4rena

Submitted by hihen

https://github.com/code-423n4/2022-11-canto/blob/2733fdd1bee73a6871c6243f92a007a0b80e4c61/Canto/x/csr/keeper/evm_hooks.go#L49

https://github.com/code-423n4/2022-11-canto/blob/2733fdd1bee73a6871c6243f92a007a0b80e4c61/Canto/x/csr/keeper/evm_hooks.go#L101-L135

Impact

Some contracts and some Turnstile tokens (NFTs) will not be able to receive CSR fees forever.

Proof of Concept

In evm*hooks.go, the PostTxProcessing will call h.processEvents(ctx, receipt) to handle Register and Assign events from Turnstile contract first:

h.processEvents(ctx, receipt)

Notice that the processEvents function does not return any error.

However, it is possible for processEvents to encounter an error:

func (h Hooks) processEvents(ctx sdk.Context, receipt *ethtypes.Receipt) {
  ...
  for _, log := range receipt.Logs {
    ...
    if log.Address == turnstileAddress {
      ...
      switch event.Name {
      case types.TurnstileEventRegister:
        err = h.k.RegisterEvent(ctx, log.Data)
      case types.TurnstileEventUpdate:
        err = h.k.UpdateEvent(ctx, log.Data)
      }
      if err != nil {
        h.k.Logger(ctx).Error(err.Error())
        return
      }
    }
  }
}

According to the above implementation of processEvents, it will process all the events emitted by the transaction one by one. If one of them encounters an error, it will return directly without any error, and any subsequent unprocessed events will be ignored.

Suppose we have a transaction containing the following events (by contract calls):

  1. Register C1 with token1
  2. Register C2 with token2
  3. Assign C3 with token1

If RegisterEvent() returns an error when handling the first event, then all of the events will not be handled because processEvents() will return after logging the error.

And PostTxProcessing() continues to execute normally because it is unaware of the error.

According to the current implementation of RegisterEvent() and UpdateEvent, they are both easy to encounter an error. Like register() using a recipient that doesn’t exist yet.

As a result, none of the C1, C2, C3 contracts will be able to receive any CSR fee because they are not recorded in csr store.

Contracts C1, C2, C3 will never be able to register for CSR because they are marked registered in Turnstile contract (evm store) and will be reverted by onlyUnregistered when calling register() or assign().

And all other contracts calling assign(token1) or assign(token2) will enter the same state as C1/C2/C3, because the assign() will succeed in Turnstile contract but fail in UpdateEvent() (because the store can not find token1 or token2):

  // Check if the NFT that is being updated exists in the CSR store
  nftID := event.TokenId.Uint64()
  csr, found := k.GetCSR(ctx, nftID)
  if !found {
  	return sdkerrors.Wrapf(ErrNFTNotFound, "EventHandler::UpdateEvent the nft entered does not currently exist: %d", nftID)
  }

Tools Used

VS Code

Recommended Mitigation Steps

processEvents() should return the error it encounters, and PostTxProcessing() should return that error too.

tkkwon1998 (Canto) confirmed and commented:

If there are multiple TXs registering contracts, but one of them fails, all of them will fail without much of a warning, so issue confirmed. Although, instead of returning the error to revert the TX, the error should be logged and the for loop inside of processEvents should be allowed to continue.


The original report as published on Code4rena, by hihen. 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 processEvents function does not return errors and simply logs them, causing subsequent events to be skipped.

Impact

Some contracts and Turnstile tokens will not be able to receive CSR fees forever, and other contracts calling assign will enter the same state.

What the attacker needed

A transaction with multiple events; one event causes an error

The fix

processEvents should return the error it encounters, and PostTxProcessing should return that error too, but the maintainer suggests logging the error and continuing the loop instead of reverting.

How it was found

  1. A transaction emits multiple events, such as registering contracts with tokens.
  2. processEvents processes events one by one.
  3. If an error occurs on one event, processEvents logs it and returns without processing remaining events.
  4. PostTxProcessing continues normally, unaware of the error.
  5. Contracts or tokens involved in unprocessed events are not recorded in the CSR store.
  6. They cannot receive CSR fees and cannot re-register because they are marked as registered in the Turnstile contract.

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.

This report is about a bug in a blockchain system where a function that processes events from transactions does not properly handle errors. When an error occurs, it stops processing further events without telling anyone, so some contracts or NFTs never get registered for fees. This means they can never receive the fees they are supposed to get.

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 hihen

View all

10 more disclosed reports, best first.

More from Canto

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.