Repository navigation
perf + fixes: faster hashing/decoding/detection, network option, Ripple details, missing tests - #10
Closed
Dhananjay-alt wants to merge 6 commits into
Closed
Dhananjay-alt wants to merge 6 commits into
Dhananjay-alt wants to merge 6 commits into
Conversation
Performance (npm run benchmark, Node 24): - ethereum validation ~3.9k/s -> ~42k/s (Keccak-f on 32-bit lane halves) - EVM detection ~3.2k/s -> ~13.8k/s - solana validation ~187k/s -> ~329k/s (typed-array Base58 decoder) - bitcoin / tron ~80k/s -> ~100k/s (hoisted SHA-256 constants) Ripple now reuses the shared Base58 decoder via createBase58Decoder instead of a duplicated copy (-230 B gzip on the ripple chunk). Tests (220 -> 275, branch coverage 91.8% -> 95.4%): - Cosmos family had no unit tests; add per-chain prefix, 20/32-byte length policy, Bech32m, padding, and operator-prefix cases - Cardano Shelley: CIP-19 pointer/enterprise vectors, pointer varint edge cases, header/prefix mismatches; fold cardano_debug test in - Network policy (network/allowTestnet/NETWORK_MISMATCH details) - Aptos formatting, Keccak block boundaries vs @noble/hashes, Base58/Base58Check error paths Tooling: test:package falls back to Playwright's bundled Chromium when system Chrome is absent. Remove stale tracked coverage/ output and old lint/command logs; fix the `.txt` gitignore entry.
Values other than 'mainnet', 'testnet' or 'auto' previously made every network-bearing address fail with NETWORK_MISMATCH while EVM and other network-less chains still passed. Reject them up front like an unsupported chain. Closes Samarth208P#6
Valid XRP results now include details { format: 'classic', checksum: true },
matching the other Base58Check chains. Document that X-addresses (XLS-5d)
are not supported.
Closes Samarth208P#7
All-lowercase or all-uppercase hex carries no checksum, so hashing it only filled details.checksum. Outside strict mode such input is now accepted without hashing, and details.checksum is true only for a verified mixed-case checksum or an address with no hex letters. Strict mode still verifies uniform-case input against EIP-55. Closes Samarth208P#9
Each non-EVM chain now has a necessary condition (Bech32 prefix, Base58 alphabet, 0x prefix, ...) checked before its validator runs, so detection no longer runs every Bech32 polymod and Base58 decode on every input. Results and their order are unchanged; a new test compares detection against exhaustive validation over ~1,000 seeded and mutated inputs. The benchmark now covers lowercase EVM, Bech32, Cosmos and detection of several formats. Benchmark (ops/s): bitcoin detection 17k -> 224k, invalid input 42k -> 1.3M, EVM detection 15k -> 48k, solana detection 30k -> 48k. Closes Samarth208P#8
- Bech32: compute the polymod once while decoding (no hrpExpand/concat arrays, lookup table instead of indexOf) and classify Bech32 vs Bech32m from the residue instead of hashing twice. - SHA-256: one buffer for message and padding, state in locals, rotations inlined. - Byron: return early unless the first byte is a CBOR array, so non-Byron Base58 input no longer throws and catches inside the CBOR reader. Benchmark (ops/s): bitcoin legacy 100k -> 250k, tron 90k -> 245k, bech32 190k -> 460k, cosmos 230k -> 520k, solana detection 50k -> 98k. Add an Unreleased changelog entry for Samarth208P#6-Samarth208P#9 and these changes.
This was referenced Nov 21, 2026
Samarth208P
requested changes
Nov 21, 2026
Samarth208P
left a comment
Owner
There was a problem hiding this comment.
@Dhananjay-alt, thank you for the performance work and the additional protocol tests. All 290 tests and 9,795 differential checks passed locally. An additional regression check found that the uniform-case fast path accepts an EVM address with a repeated prefix and reports a valid checksum. This changes which destinations callers can accept. I’ve posted the details on #9.
I’m closing this PR. Please open a new PR from the latest main with the format check and regression coverage. If the replacement includes #6, please also cover an empty batch and empty detection input with an invalid network option, or document when the RangeError applies. We’ll review the replacement after the CI matrix passes.
Samarth208P
pushed a commit
that referenced
this pull request
Nov 21, 2026
Store each 64-bit lane as two 32-bit halves in a Uint32Array and precompute the rho/pi destinations. Build the EIP-55 string with a loop instead of spread/map/parseInt. Validation results, including details.checksum, are unchanged. Node 24.16, scripts/benchmark.mjs, median of 5 alternating runs on the same host (validations/s): ethereum 11,556 -> 121,126 (10.5x) EVM detection 9,149 -> 36,244 (4.0x) bitcoin/solana/tron unchanged within noise (0.95-0.99x) gzip: ethereum.mjs chunk +139 B, index.umd.js +141 B. Tests: published digests for "" and "abc", and @noble/hashes at 1, 40, 135-137, 271-273 and 500 bytes. The EIP-55 vectors whose checksum form is all lowercase or all uppercase keep checksum: true with and without strict mode. The differential suite now compares valid and details.checksum with a direct EIP-55 implementation over length-preserving mutations (repeated or embedded 0x, case flips, non-hex pairs); it fails on the code reviewed in #10. Closes #1
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.
Closes #1, closes #2, closes #3, closes #4, closes #5, closes #6, closes #7, closes #8, closes #9.
Each commit is self-contained, so the PR can be reviewed one commit at a time.
Performance
npm run benchmark(extended in this PR) on Node 24, 0.4.0 vs this branch, run back to back:All numbers are ops/s.
details.checksumistrueonly for a verified mixed-case checksum, or for an address with no hex letters. Strict mode still checks uniform-case input against EIP-55, including the all-caps EIP-55 vector.detectBlockchainruns every non-EVM validator on every input #8): each non-EVM chain has a cheap necessary precondition (Bech32 prefix, Base58 alphabet,0xprefix) that is checked before its validator runs. Results and their order are unchanged. A new test compares detection against exhaustive validation over about 1,000 seeded and mutated inputs; I confirmed it fails when a gate is deliberately broken.createBase58Decoder(alphabet). Ripple reuses it instead of keeping its own copy.Behaviour changes
All three are noted under "Unreleased" in CHANGELOG.md:
networkoption silently rejects every address #6: an invalidnetworkoption (anything except'mainnet','testnet'or'auto') throws aRangeErrorinstead of failing every network-bearing address withNETWORK_MISMATCH.details#7: valid Ripple results includedetails: { format: 'classic', checksum: true }. The README now states that X-addresses are not supported.details.checksummeaning described above.Tests
Tests go from 220 to 290, and branch coverage from 91.8% to 95.4%.
vitest#2: newtests/cosmos.test.ts.tests/network-policy.test.ts.@noble/hashes, Base58 and Base58Check error paths, Aptos formatting, invalid network options, Ripple details, uniform-case EIP-55 behaviour, and the detection-equivalence test.Tooling and cleanup
npm run test:packagefails without a system Google Chrome #4:test:packagefalls back to Playwright's bundled Chromium when system Chrome isn't installed..gitignorehas a typo #5: removed committedcoverage/output, old lint logs andcommands.txt, and fixed the.txtentry in.gitignore.Verification
npm run check,npm run test:coverageandnpm audit(0 vulnerabilities) pass locally on Node 24. The 9,795 differential comparisons against Node crypto,@noble/hashesand@scure/basestill pass.