feat: Enforce feature name lengths and character set - #5555
Conversation
1c57402 to
ba2ac69
Compare
|
If it makes more sense, this PR can be merged into |
|
@Bronek is there a reason this is still in draft? Just wondering |
intelliot
left a comment
There was a problem hiding this comment.
notes: this limits feature (amendment) names to <= 63 and prevents names that are exactly 32-33 characters long, because those names would be ambiguous - is it feature name or uint256 hash?
WASM code will use 32-byte strings to select features without ambiguity.
disallowing 33 bytes prevents potential off-by-one mistake since a 32 character string is 33 bytes total (with 1 null terminator byte)
|
I'm marking this as "Ready to merge" on @Bronek's behalf. It's got two trusted reviews, and doesn't seem to have bit-rotted. |
There was a problem hiding this comment.
Pull request overview
This PR adds compile-time enforcement of feature/amendment name length limits to prevent ambiguous selection (e.g., names colliding with alternate uint256-based selection), and updates the RPC feature unit test to compute/verify the feature ID hash.
Changes:
- Add
maxFeatureNameSizeandreservedFeatureNameSizeconstants and enforce them during feature registration via compile-timestatic_asserts. - Update
XRPL_FEATURE/XRPL_FIXmacro expansions to run name literals through the new size-enforcement helper. - Adjust
Feature_testto compute the expected feature ID viasha512Halfwhile still asserting against the fixed known hash.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
include/xrpl/protocol/Feature.h |
Introduces public constants for feature name size limits (and documents reserved lengths). |
src/libxrpl/protocol/Feature.cpp |
Adds compile-time validation helper and wires it into feature/fix registration macros. |
src/test/rpc/Feature_test.cpp |
Computes expected feature hash dynamically and verifies it matches the known constant. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #5555 +/- ##
=========================================
- Coverage 79.8% 79.8% -0.0%
=========================================
Files 878 878
Lines 67887 67887
Branches 7548 7550 +2
=========================================
- Hits 54207 54205 -2
- Misses 13680 13682 +2
🚀 New features to boost your workflow:
|
bthomee
left a comment
There was a problem hiding this comment.
Looking good and very comprehensive. I would just like to see some additional comments in places that would not be intuitive for the standard developer.
This change enforces a maximum length of 63 characters on feature names, as well as not permitting an exactly 32 character long feature name to avoid confusion with those that use a `uint256` hex representation, as that is an alternative way to specify a feature. This change further prevents the use of Unicode characters in feature names, because some can be confused with regular ASCII characters despite being valid in identifiers.
High Level Overview of Change
This PR enforces a maximum length of 63 characters on feature names, as well as not permitting an exactly 32 character long feature name to avoid confusion with those that use a
uint256hex representation, as that is an alternative way to specify a feature. This change further prevents the use of Unicode characters in feature names, because some can be confused with regular ASCII characters despite being valid in identifiers.Context of Change
Useful for WASM interop; improved security.
Type of Change
.gitignore, formatting, dropping support for older tooling)