Skip to content

Block object contract drift: required difficulty/totalDifficulty fields are omitted #39

@roninjin10

Description

@roninjin10

Summary

Block object serialization omits required difficulty and totalDifficulty fields in normal dev-node operation.

Why this matters

This is a schema-level contract drift for eth_getBlockByNumber / eth_getBlockByHash. Consumers expecting required fields can break.

Normative contract

  • docs/specs/json-rpc-contract.md:355-356 marks difficulty and totalDifficulty as required non-null QuantityHex fields for block objects.

Evidence

Block conversion conditionally null/omits both fields:

  • src/rpc/handlers/block_query_handlers.zig:353-354
.difficulty = if (resp.difficulty > 0) try quantityFromU256(allocator, resp.difficulty) else null,
.totalDifficulty = if (resp.totalDifficulty) |td| try quantityFromU256(allocator, td) else null,

Mined block header currently sets difficulty to zero:

  • src/rpc/handlers/tx_submission.zig:695
header.difficulty = 0;

With the current conversion logic, this causes difficulty to be omitted/null instead of required "0x0".

Suggested scope

  • Emit difficulty and totalDifficulty unconditionally as QuantityHex per contract.
  • Ensure zero values are serialized as "0x0", not omitted.
  • Add regression tests for both genesis and mined blocks asserting presence and shape of these fields.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions