{"record":{"id":"0ee0d38ecd26b861","repo":"nautechsystems/nautilus_trader","slug":"invalid-receipt-log-quantity","errorCode":null,"errorMessage":"Invalid receipt log quantity","messagePattern":"Invalid receipt log quantity","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/rpc/verification.rs","lineNumber":1954,"sourceCode":"        self.effective_gas_price.write_normalized(output);\n        self.transaction_index.write_normalized(output);\n        self.status.write_normalized(output);\n        self.logs.write_normalized(output);\n    }\n}\n\nfn parse_optional_hash(value: Option<&str>) -> anyhow::Result<Option<B256>> {\n    value\n        .map(|value| B256::from_str(value).map_err(|_| anyhow::anyhow!(\"Invalid receipt log hash\")))\n        .transpose()\n}\n\nfn parse_optional_quantity(value: Option<&str>) -> anyhow::Result<Option<u64>> {\n    value\n        .map(|value| {\n            let value = value.strip_prefix(\"0x\").unwrap_or(value);\n            u64::from_str_radix(value, 16)\n                .map_err(|_| anyhow::anyhow!(\"Invalid receipt log quantity\"))\n        })\n        .transpose()\n}\n\n#[cfg(test)]\nmod tests {\n    use alloy::{\n        primitives::{\n            U256, address,\n            aliases::{U24, U160},\n            b256,\n        },\n        sol_types::SolValue,\n    };\n    use rstest::rstest;\n\n    use super::*;\n    use crate::rpc::http::tests::mock::{MockRpcState, start_mock_rpc_server};","sourceCodeStart":1936,"sourceCodeEnd":1972,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/rpc/verification.rs#L1936-L1972","documentation":"parse_optional_quantity converts an optional string field of a receipt log into a u64, interpreting the value as a base-16 number (an optional 0x prefix is stripped first). If the string is not valid hexadecimal or the number overflows u64, the error 'Invalid receipt log quantity' is returned. It guards numeric log fields (indices, counts, block numbers) from malformed input.","triggerScenarios":"A receipt-log quantity string containing decimal digits beyond a-f, sign characters, whitespace, a double 0x0x prefix, or a value exceeding u64::MAX (e.g. a 256-bit integer) passed to the log parsing path (verification.rs:~1954).","commonSituations":"Storing decimal values in a field expected to be hex; negative numbers ('-1'); very large EVM uint256 values that cannot fit u64; values copied with stray whitespace or surrounding quotes.","solutions":["Ensure the value is stored as a hex string (optionally 0x-prefixed) before parsing","Trim whitespace and normalize the 0x prefix on the source data","If values can exceed u64, widen the parser to u128/U256 instead of u64","Validate the string with a hex regex before calling parse_optional_quantity"],"exampleFix":"// before\nparse_optional_quantity(Some(\"123\"))?; // decimal digits -> fails hex radix parse? actually valid hex too, but \"12z\" fails\n// after\nlet raw = log.quantity.trim();\nlet normalized = if let Some(stripped) = raw.strip_prefix(\"0x\") { stripped.to_lowercase() } else { raw.to_lowercase() };\nassert!(normalized.chars().all(|c| c.is_ascii_hexdigit()));\nparse_optional_quantity(Some(&raw))?;","handlingStrategy":"validation","validationCode":"fn is_valid_hex_u64(s: &str) -> bool {\n    let h = s.trim().trim_start_matches(\"0x\");\n    !h.is_empty() && h.chars().all(|c| c.is_ascii_hexdigit()) && u64::from_str_radix(h, 16).is_ok()\n}","typeGuard":"fn as_u64_quantity(value: Option<&str>) -> Option<u64> {\n    value.and_then(|v| {\n        let h = v.strip_prefix(\"0x\").unwrap_or(v);\n        u64::from_str_radix(h, 16).ok()\n    })\n}","tryCatchPattern":"match parse_optional_quantity(field) {\n    Ok(q) => use_quantity(q),\n    Err(e) => { warn!(\"bad quantity: {e}\"); treat_as_missing(); }\n}","preventionTips":["Always store hex quantities (0x-prefixed) in log rows","Trim whitespace before parsing","Use a wider integer type (u128/U256) if EVM values can exceed u64","Validate at ingestion with a hex regex"],"tags":["parsing","hex","integer-overflow"],"backgroundTag":"invalid-argument-format","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}