Skip to content

Add ethereum_encoding_util.py ethereum integer encoding helpers #2787

Open

Description

@manishdait

Description

Add a small utility with functions for canonical Ethereum integer encoding. Ethereum RLP encodes integers as minimal big-endian bytes: no leading zeros, and zero is the empty byte string.

Background

Ethereum transaction fields such as nonce, gas_limit, chain_id and value are RLP-encoded as canonical integers. The Ethereum transaction data classes (Legacy, EIP-2930, EIP-1559) store these fields as raw bytes and need a conversion layer for their numeric getters and setters.

Functionality required

Function Input Output Behaviour
_uint64_to_eth_bytes(v) int bytes Treats v as a 64-bit value (a negative int wraps to its unsigned 64-bit form). Returns minimal big-endian bytes. 0 gives b"".
_eth_bytes_to_uint64(b) bytes | None int None or empty gives 0. Input longer than 8 bytes is truncated to the low 8 bytes. Always returns an unsigned value.
_big_int_to_eth_bytes(v) int | None bytes None and 0 give b"". Negative values encode their absolute value. Minimal big-endian bytes, unbounded size.
_eth_bytes_to_big_int(b) bytes | None int None or empty gives 0. Leading zero bytes are tolerated. Unbounded size.

Proposed architecture

  • Location: src/hiero_sdk_python/utils/ethereum_encoding_util.py
  • Add implement for the following methods
def _uint64_to_eth_bytes(v: int) -> bytes:
     ...

def _eth_bytes_to_uint64(b: bytes | None) -> int:
    ...

def _big_int_to_eth_bytes(v: int | None) -> bytes:
   ...

def _eth_bytes_to_big_int(b: bytes | None) -> int:
   ...

Tasks

  • Create src/hiero_sdk_python/utils/ethereum_encoding_util.py
  • Implement the four private functions with type hints and docstrings
  • Add unit tests in tests/unit/test_ethereum_encoding_util.py:
    • Parametrized vectors: 0, 1, 0x7f, 0x80, 0xff, 0x100, 0xffff, 2**64 - 1
    • Zero encodes to b"" and decodes back to 0
    • None decodes to 0 in both decoders, and None encodes to b"" in _big_int_to_eth_bytes
    • Output never starts with a zero byte
    • Leading zeros are tolerated on decode (b"\x00\x00\x01" gives 1)
    • _eth_bytes_to_uint64 truncates input of 9 or more bytes to the low 8 bytes
    • Values beyond 64 bits round-trip through the big-int pair (for example 10**30)
    • Round-trip over a range of values

Activity

  1. added
    skill: advancedrequires knowledge of multiple areas in the codebase without defined steps to implement or examples
    on Nov 12, 2026
  2. github-actions commented on Nov 12, 2026

    @github-actions

    Thanks for your submission.

    This issue is awaiting approval from @hiero-ledger/hiero-sdk-python-triage and @hiero-ledger/hiero-sdk-python-committers and @hiero-ledger/hiero-sdk-python-maintainers.

  3. locked as off topic and limited conversation to collaborators on Nov 12, 2026
  4. added
    approvedIssue has been approved by team member
    and removed on Nov 13, 2026
  5. unlocked this conversation on Nov 13, 2026
  6. github-actions commented on Nov 13, 2026

    @github-actions

    Approved by @hiero-ledger/hiero-sdk-python-triage and @hiero-ledger/hiero-sdk-python-committers and @hiero-ledger/hiero-sdk-python-maintainers.

  7. github-actions commented on Nov 13, 2026

    @github-actions
  8. self-assigned this
    on Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

approvedIssue has been approved by team memberpythonPull requests that update python codeskill: advancedrequires knowledge of multiple areas in the codebase without defined steps to implement or examples

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions