Skip to content
DoS Audit finding Intermediate

PostTxProcessing can revert user transactions not interacting with Turnstile

The PostTxProcessing hook in the CSR module returns an error when any CSR-specific operation fails, which causes the entire user transaction to be reverted even if it did not interact with the Turnstile contract. An attacker could trigger such errors (e.g., by causing zero fees due to rounding) to revert unrelated transactions.

Jeiwan Follow with hihen

Originally disclosed on Code4rena

Submitted by Jeiwan, also found by hihen

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

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

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

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

Impact

Any transaction, even those that don’t interact with the Turnstile contract, can be reverted by the PostTxProcessing hook if there was a CSR specific error. Thus, the CSR module can impair the behavior of smart contracts not related to the module.

Proof of Concept

The PostTxProcessing is used by the keeper to register contracts with the CSR module and distribute gas fees to registered contracts (evm_hooks.go#L41). The hook can return an error while handling CSR specific operations:

In case any of these operations fails, the whole transaction will be reverted (state_transition.go#L272-L278):

if err = k.PostTxProcessing(tmpCtx, msg, receipt); err != nil {
  // If hooks return error, revert the whole tx.
  res.VmError = types.ErrPostTxProcessing.Error()
  k.Logger(ctx).Error("tx post processing failed", "error", err)

One example of when the hook can revert in normal circumstances is when the fees to be distributed are 0, which can be caused by a combination of low gas usage of a transaction, a small CSR share, and rounding (the fees are a share of the gas spent to execute a transaction: evm_hooks.go#L66-L70). In this case, the distributeFees call will revert and will cause the whole transaction to be reverted as well (evm_hooks.go#L86-L89, Turnstile.sol#L149).

Recommended Mitigation Steps

In the PostTxProcessing hook, consider always logging errors and returning nil to avoid impairing user transactions. Also, consider logging a fatal error and exiting when the module cannot function due to an error.

tkkwon1998 (Canto) confirmed and commented:

Error should not be returned, but rather logged and continued to an eventual nil return.


The original report as published on Code4rena, by Jeiwan. 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

The PostTxProcessing hook returns an error on any CSR-specific failure, and the EVM keeper reverts the entire transaction when the hook returns an error, without checking whether the transaction involved the CSR module.

Impact

Any transaction, even those not interacting with Turnstile, could be reverted if a CSR-specific error occurs, such as when fees to distribute are zero due to rounding.

What the attacker needed

Transaction triggers CSR hook; CSR-specific error occurs (e.g., zero fees)

The fix

The hook should log errors and return nil instead of returning an error, and consider logging a fatal error and exiting when the module cannot 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.

In some blockchain systems, after a transaction runs, extra code (a hook) can run to do things like distribute fees. If that extra code fails, the whole transaction is undone. Here, a failure in the fee-distribution code could undo transactions that had nothing to do with that feature, which is unfair to users.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by Jeiwan

View all

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

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.