Skip to content

server_definitions: field nth values truncated to 8 bits for fields with nth >= 256 #664

@sublimator

Description

@sublimator

Summary

The server_definitions RPC handler in ServerDefinitions.cpp has a bug where field nth values are truncated to 8 bits, causing incorrect definitions for fields with nth >= 256.

Details

In src/ripple/rpc/handlers/ServerDefinitions.cpp, around line 285:

for (auto const& [code, f] : ripple::SField::knownCodeToField)
{
    // ...
    uint32_t fc = code & 0xFFU;   // <- Bug: only keeps lower 8 bits
    uint32_t tc = code >> 16U;

    innerObj[jss::nth] = fc;
    // ...
}

The mask 0xFFU truncates field values to 8 bits. For fields like sfIndex which has nth=258 (0x102), this becomes nth=2 after truncation.

Impact

This causes the generated server-definitions.json to contain duplicate/conflicting field definitions. For example:

  1. The hardcoded index entry (lines 230-242) correctly has nth: 258, isSerialized: false
  2. The loop also outputs sfIndex from knownCodeToField, but with truncated nth: 2, isSerialized: true

This results in two "index" entries in the FIELDS array, where the second one with nth: 2 collides with ParentHash (which is type: Hash256, nth: 2).

Any parser loading these definitions by field code will have index overwrite ParentHash in the lookup table, causing ParentHash fields to be incorrectly identified as index.

Suggested Fix

Change the mask from 8 bits to 16 bits:

uint32_t fc = code & 0xFFFFU;  // 16 bits to preserve full field value

Affected Fields

Any field with nth >= 256 will be affected. Currently this includes at minimum:

  • sfIndex (nth=258)
  • sfHash (nth=257)
  • taker_gets_funded (nth=258)
  • taker_pays_funded (nth=259)

Thanks for maintaining xahaud!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions