Skip to content

[executor] NonceManager::init uses 'latest' nonce tag — re-issued nonces on restart with pending txs #184

@obchain

Description

@obchain

Summary

NonceManager::init calls eth_getTransactionCount to seed the local nonce counter. If the alloy default block tag (Latest) is used, any transactions submitted by a previous bot run that are still pending in the mempool are invisible. The manager starts at the mined nonce, re-issues those nonces, and the new txs will either:

  1. Replace the old pending txs (if max_fee is higher) — unintended replacement of a previous liquidation with different params
  2. Be rejected by the node as nonce-already-used if the old tx is already in mempool with same or higher fee

The correct call uses the Pending block tag:

provider
    .get_transaction_count(signer.address())
    .block_id(BlockId::Tag(BlockNumberOrTag::Pending))
    .await

This exact bug was flagged as Finding 2 in PR #41 for the old TxBuilder nonce handling. The nonce manager is the intended fix — if it makes the same mistake, the fix is incomplete and PR #41 Finding 2 remains open.

File

crates/charon-executor/src/nonce.rsNonceManager::init()

Risk

On bot restart after a crash (the most important scenario for the nonce manager), re-issued nonces silently replace or collide with pending liquidation txs in the BSC mempool.

Refs #43

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinglayer:rustRust crates (core / scanner / protocols / executor / cli)pr-reviewFindings from PR review processpriority:p1-coreCore MVP scopestatus:readyScoped and ready to pick up

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions