{"record":{"id":"f1983ab9f1455ff3","repo":"nautechsystems/nautilus_trader","slug":"weth-balance-overflow-for-included-transaction-tx","errorCode":null,"errorMessage":"WETH balance overflow for included transaction {tx_hash} at block {block_number}: wrap amount {amount_wei} from balance {balance_before}","messagePattern":"WETH balance overflow for included transaction (.+?) at block (.+?): wrap amount (.+?) from balance (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/execution/client.rs","lineNumber":701,"sourceCode":"            .erc20_contract\n            .balance_of_at(weth_address, &self.wallet_address, previous_block)\n            .await\n            .with_context(|| {\n                format!(\n                    \"failed to read WETH balance before included transaction {tx_hash} at block {previous_block}\"\n                )\n            })?;\n        let balance_after = self\n            .erc20_contract\n            .balance_of_at(weth_address, &self.wallet_address, block_number)\n            .await\n            .with_context(|| {\n                format!(\n                    \"failed to read WETH balance after included transaction {tx_hash} at block {block_number}\"\n                )\n            })?;\n        let expected_balance = balance_before.checked_add(amount_wei).ok_or_else(|| {\n            anyhow::anyhow!(\n                \"WETH balance overflow for included transaction {tx_hash} at block {block_number}: wrap amount {amount_wei} from balance {balance_before}\"\n            )\n        })?;\n\n        if balance_after != expected_balance {\n            anyhow::bail!(\n                \"WETH balance after transaction {tx_hash} did not increase by {amount_wei}: expected {expected_balance}, was {balance_after}\"\n            );\n        }\n\n        Ok(())\n    }\n\n    /// Ensures the router allowance at the block that included transaction `tx_hash` covers\n    /// `amount`. Shared by the live approve path and restart reconciliation.\n    async fn ensure_approve_allowance(\n        &self,\n        token: &Address,","sourceCodeStart":683,"sourceCodeEnd":719,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/d1527c24afdf475115785557f89a55c3e336c51f/crates/adapters/blockchain/src/execution/client.rs#L683-L719","documentation":"In ensure_wrap_balance_increase (crates/adapters/blockchain/src/execution/client.rs:701) the expected post-wrap balance is computed as balance_before.checked_add(amount_wei); on U256 overflow the check aborts instead of wrapping around. Because 2^256 wei exceeds any real token supply by dozens of orders of magnitude, an overflow can only occur when the RPC returns a corrupted balanceOfAt historical read (balance_before near U256::MAX) or an absurd amount. It is an arithmetic-integrity guard against bad node data, not a realistic accounting event.","triggerScenarios":"A misbehaving or malicious RPC returning garbage for the historical WETH balanceOfAt at block-1; a replayed or tampered RPC response feeding near-max U256 values; wrap amount corrupted in memory or in the persisted intent being reconciled.","commonSituations":"Flaky free RPC endpoints; a node serving inconsistent state during reorgs; extremely rare and almost always a symptom of a broken data source rather than user error.","solutions":["Query the wallet's WETH balance at the named blocks directly (explorer or second RPC) and compare with what the node returned.","Switch to a reliable, synced RPC provider and retry the operation.","If triggered during restart reconciliation, clear the affected intent only after confirming the on-chain final state.","Report recurring garbage reads to the node operator; this error protects against silently accepting fabricated balances."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"fn is_wrap_balance_overflow(e: &anyhow::Error) -> bool {\n    e.to_string().contains(\"WETH balance overflow\")\n}","tryCatchPattern":"match client.wrap(amount_wei).await {\n    Ok(tx_hash) => tx_hash,\n    Err(e) if is_wrap_balance_overflow(&e) => {\n        // node returned a corrupted historical balance; halt and audit the RPC source\n        log::error!(\"suspicious balanceOfAt data from RPC: {e}\");\n        return Err(e);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Treat this error as evidence of RPC data corruption - always investigate the node before retrying.","Cross-check balances reported by your node against a second provider or explorer when it fires.","Prefer dedicated/paid RPC endpoints for anything touching signed transactions."],"tags":["arithmetic","u256","overflow","rpc","data-integrity","rust"],"backgroundTag":"arithmetic-overflow","analyzedSha":"d1527c24afdf475115785557f89a55c3e336c51f","analyzedAt":"2026-08-21T11:28:30.864Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}