nautechsystems/nautilus_trader · error

Invalid receipt log topic

Error message

Invalid receipt log topic

What it means

Each topic string in a receipt log's topics array is parsed into a 32-byte B256 (fixed bytes) via B256::from_str. A failure while mapping the topics iterator is surfaced as 'Invalid receipt log topic'. A topic must be exactly 64 hex digits (32 bytes), typically 0x-prefixed.

Source

Thrown at crates/adapters/blockchain/src/rpc/verification.rs:174

            .into_iter()
            .map(|log| {
                Ok(VerifiedReceiptLog {
                    removed: log.removed,
                    log_index: parse_optional_quantity(log.log_index.as_deref())?,
                    transaction_index: parse_optional_quantity(log.transaction_index.as_deref())?,
                    transaction_hash: parse_optional_hash(log.transaction_hash.as_deref())?,
                    block_hash: parse_optional_hash(log.block_hash.as_deref())?,
                    block_number: parse_optional_quantity(log.block_number.as_deref())?,
                    address: Address::from_str(&log.address)
                        .map_err(|_| anyhow::anyhow!("Invalid receipt log address"))?,
                    data: Bytes::from_str(&log.data)
                        .map_err(|_| anyhow::anyhow!("Invalid receipt log data"))?,
                    topics: log
                        .topics
                        .iter()
                        .map(|topic| {
                            B256::from_str(topic)
                                .map_err(|_| anyhow::anyhow!("Invalid receipt log topic"))
                        })
                        .collect::<anyhow::Result<_>>()?,
                })
            })
            .collect::<anyhow::Result<_>>()?;
        Ok(Self {
            transaction_hash: receipt.transaction_hash,
            block_hash: receipt.block_hash,
            block_number: receipt.block_number,
            gas_used: receipt.gas_used,
            effective_gas_price: receipt.effective_gas_price,
            transaction_index: receipt.transaction_index,
            status: receipt.status,
            logs,
        })
    }
}

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Check each topic string is exactly 0x + 64 hex characters; pad or left-align values shorter than 32 bytes only if the source semantically allows it.
  2. Pre-validate with B256::from_str per topic before receipt verification to capture the underlying error.
  3. Verify you are not placing parameter data into the topics array; only indexed event parameters and the signature hash belong there.
  4. Fix or regenerate the upstream data (node, indexer, fixture) producing the malformed topic.

Example fix

// before
"topics": ["0xddf252ad"] // truncated topic
// after
"topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"] // full 32-byte hash
Defensive patterns

Strategy: validation

Validate before calling

fn is_valid_topic(s: &str) -> bool {
    let h = s.strip_prefix("0x").unwrap_or(s);
    h.len() == 64 && h.chars().all(|c| c.is_ascii_hexdigit())
}
// check: log.topics.iter().all(|t| is_valid_topic(t))

Try / catch

let topics: Vec<B256> = log.topics.iter()
    .map(|t| B256::from_str(t).map_err(|e| anyhow::anyhow!("Invalid receipt log topic '{}}}': {e}", t)))
    .collect::<anyhow::Result<_>>()?;

Prevention

When it happens

Trigger: Verifying a receipt log containing a topic that is not valid 32-byte hex: short/long strings, non-hex characters, empty string, or a value like an event name fragment instead of the keccak hash.

Common situations: A provider returning topics of nonstandard length (e.g. some chains or L2s emit shorter topics); fixtures with placeholder topic strings; confusing event parameters (data field) with topics and putting non-32-byte values in topics; API version change altering topic encoding.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/1649b27b6cf949b4. Report an issue: GitHub.