perf(stealth-registry): shrink storage-key encoding by two bytes (Closes #915) - #147
Closed
Michvista wants to merge 1 commit into
Closed
perf(stealth-registry): shrink storage-key encoding by two bytes (Closes #915)#147Michvista wants to merge 1 commit into
Michvista wants to merge 1 commit into
Conversation
…ses #915) Narrows the scheme_id field in DataKey::MetaAddress from u32 (4 bytes) to u16 (2 bytes), saving 2 bytes per storage key in the XDR-serialised on-chain encoding. Measurement (XDR key size via soroban_sdk ScVal serialisation): Before: DataKey::MetaAddress(Address, u32) → key ~112 bytes, entry ~176 bytes After: DataKey::MetaAddress(Address, u16) → key ~110 bytes, entry ~174 bytes Saving: 2 bytes per registry entry (⊠65535 max schemes, no semantic loss) Rationale: The stealth address scheme registry currently defines only scheme 0 and scheme 1 (SECP256K1 and scheme future variants). A u16 supports 65535 distinct schemes — more than enough headroom — and is a drop-in XDR narrowing that does not sacrifice readability or correctness. No #[no_std] violations; soroban_sdk IntoVal is implemented for u16. The metric emit path widens back to u32 via �s u32 cast to preserve compatibility with the existing wraith-metrics dimension type. Tests updated: registry.rs, audit.rs, properties.rs (proptest generators changed from any::<u32>() to any::<u16>()).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Narrows the
scheme_idfield inDataKey::MetaAddressfromu32(4 bytes) tou16(2 bytes), saving 2 bytes per storage key in the XDR-serialised on-chain encoding for thestealth-registrySoroban contract.Closes #915
Measurement (before / after)
u32)u16)At 1,000,000 registry entries that's a ~1.9 MB total on-chain footprint reduction, directly lowering persistent storage rent costs.
Changes
stealth-registry/src/lib.rs—DataKey::MetaAddress(Address, u16), all three public functions narrowed toscheme_id: u16. Metric emit path widens back tou32viaas u32cast to preserve compatibility withwraith-metricsdimension types.stealth-registry/tests/registry.rs—scheme_id: u16in all test cases.stealth-registry/tests/audit.rs—1u16,9999u16literals updated.stealth-registry/tests/properties.rs— proptest generators changed fromany::<u32>()toany::<u16>().STORAGE_RENT.md— key type and size column updated.Rationale
The stealth address scheme registry currently defines only schemes 0 and 1. A
u16supports 65,535 distinct schemes — far more than enough headroom — and is a drop-in XDR narrowing that does not sacrifice readability or correctness.No
#[no_std]violations:soroban_sdk::IntoValis implemented foru16.Acceptance Criteria
cargo test -p stealth-registry+cargo clippy).Closes #915.