-
Notifications
You must be signed in to change notification settings - Fork 18
Description
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:
- The hardcoded
indexentry (lines 230-242) correctly hasnth: 258, isSerialized: false - The loop also outputs
sfIndexfromknownCodeToField, but with truncatednth: 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 valueAffected 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!