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.
Submitted by Jeiwan, also found by hihen
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:
- Reading a CSR object from the storage (evm_hooks.go#L61-L64);
- Sending gas fees to the module (evm_hooks.go#L73-L76);
- Reading the address of Turnstile (evm_hooks.go#L79-L82);
- Calling the
distributeFeesfunction (evm_hooks.go#L85-L89).
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.
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.