{"record":{"id":"f1af5053728cedf7","repo":"nautechsystems/nautilus_trader","slug":"invalid-event-signature-for-event-name-expect","errorCode":null,"errorMessage":"Invalid event signature for '{event_name}': expected {expected_hex}, was {actual_hex}","messagePattern":"Invalid event signature for '(.+?)': expected (.+?), was (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/exchanges/parsing/core.rs","lineNumber":90,"sourceCode":"    Ok(i32::from_be_bytes(bytes[28..32].try_into()?))\n}\n\n/// Validate event signature matches expected hash.\n///\n/// The first topic (topic0) of an Ethereum event log contains the keccak256 hash\n/// of the event signature. This function validates that the actual signature\n/// matches the expected one.\n///\n/// # Errors\n///\n/// Returns an error if the signatures don't match.\npub fn validate_signature_bytes(\n    actual: &[u8],\n    expected_hex: &str,\n    event_name: &str,\n) -> anyhow::Result<()> {\n    let actual_hex = hex::encode(actual);\n    anyhow::ensure!(\n        actual_hex == expected_hex,\n        \"Invalid event signature for '{event_name}': expected {expected_hex}, was {actual_hex}\",\n    );\n    Ok(())\n}\n\n#[cfg(test)]\nmod tests {\n    use rstest::rstest;\n\n    use super::*;\n\n    #[rstest]\n    fn test_extract_address_token0() {\n        // token0 address from PoolCreated event topic1 at block 185\n        let bytes = hex::decode(\"0000000000000000000000002e5353426c89f4ecd52d1036da822d47e73376c4\")\n            .unwrap();\n","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/exchanges/parsing/core.rs#L72-L108","documentation":"validate_signature_bytes compares the event signature topic bytes (hex-encoded) against the expected keccak256 signature hash for the named event and throws when they differ. This catches decoding a log that is not actually the event the caller assumed, preventing misparsed fields.","triggerScenarios":"Calling validate_signature_bytes with the signature topic of a different event, e.g. passing an Uniswap V3 swap topic to a PancakeSwap V3 parser, or a wrong expected_hex constant; also when topic0 bytes are truncated so the hex never matches.","commonSituations":"Indexing multiple DEX forks whose events share names but different signatures (e.g. Uniswap V3 vs PancakeSwap V3 swap); a contract upgrade changed the event ABI; copy-pasted wrong expected hash.","solutions":["Compare the actual hex in the error with the keccak256 of the event signature you intended; correct expected_hex or route the log to the right parser","Verify topic0 is the signature topic (index 0), not a data or param topic","Recompute the expected hash from the contract's ABI if it was recently upgraded","Add explicit dispatch by topic0 before invoking the specific event parser"],"exampleFix":"// before\nvalidate_signature_bytes(topic0, UNISWAP_V3_SWAP_SIG, \"Swap\")?;\n// after\nif hex::encode(topic0) == PANCAKE_V3_SWAP_SIG {\n    validate_signature_bytes(topic0, PANCAKE_V3_SWAP_SIG, \"Swap\")?;\n} else {\n    return Err(anyhow::anyhow!(\"unsupported swap signature\"));\n}","handlingStrategy":"validation","validationCode":"fn signature_matches(topic0: &[u8], expected_hex: &str) -> bool {\n    hex::encode(topic0) == expected_hex\n}","typeGuard":null,"tryCatchPattern":"match validate_signature_bytes(topic0, EXPECTED_SWAP_SIG, \"Swap\") {\n    Ok(()) => decode_swap(),\n    Err(e) if e.to_string().contains(\"Invalid event signature\") => route_to_correct_parser(topic0),\n    Err(e) => return Err(e),\n}","preventionTips":["Dispatch parsers by topic0 before calling any event-specific decoder","Keep expected signature hashes generated from the contract ABI, not hand-copied","When indexing multiple DEX forks, maintain a topic0 -> parser map","Log the actual hex on mismatch to speed up diagnosis"],"tags":["ethereum","logs","event-signature","validation"],"backgroundTag":"invalid-argument-value","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"}