degenbot.crypto¶

EVM hashing + selector helpers — the stable mirror home for crypto surfaces.

Provides three public functions:

  • function_selector() — the 4-byte Solidity selector for a function signature. Delegates to degenbot.contract.get_function_selector() (alloy keccak256 under the hood) so the selector computation is owned by Rust, not by a Python keccak re-export.

  • keccak256() — the full 32-byte keccak digest of a byte string. Delegates to the Rust FFI keccak256 pyfunction; parity with the pre-removal eth_utils vectors is pinned in tests/test_crypto_parity.py.

  • event_topic() — the 32-byte event topic hash for an ABI event entry. Computes keccak256(canonical_event_signature) in Rust from the ABI entry dict.

Package Contents¶

degenbot.crypto.function_selector(signature: str) → bytes¶

Return the 4-byte Solidity function selector for signature.

Parameters:

signature – A Solidity function signature, e.g. "transfer(address,uint256)".

Returns:

The 4-byte selector (e.g. b"\\xa9\\x05\\x9c\\xbb").

degenbot.crypto.keccak256(data: bytes) → bytes¶

Return the 32-byte keccak256 digest of data.

Parameters:

data – The input bytes to hash.

Returns:

The 32-byte digest as plain bytes (callers wanting the 0x-prefixed string use degenbot.utils.bytes.to_0x_hex()).

degenbot.crypto.event_topic(event_abi_entry: degenbot.types.chain.ABIEvent) → bytes¶

Return the 32-byte event topic hash for an ABI event entry.

Replaces Web3().eth.contract(abi=...).events.<Name>().topic. Computes keccak256(canonical_event_signature) from the ABI entry (the canonical signature omits indexed markers and uses the parameter types in order), so the result is byte-identical to the web3-derived topic without importing web3.

Parameters:

event_abi_entry – A single ABI dict with "type": "event".

Returns:

The 32-byte topic as plain bytes.