Repository navigation
perf: compute Keccak-256 without BigInt - #12
Merged
Samarth208P merged 4 commits intoNov 21, 2026
Merged
Conversation
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 Samarth208P#10. Closes Samarth208P#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.
Keccak-256 now runs on two 32-bit halves per 64-bit lane (a
Uint32Array) instead of BigInt, and the rho/pi lane destinations are precomputed. The EIP-55 string is built with a loop instead of spread/map/parseInt.Results are unchanged. That includes
validanddetails.checksum, so0xde709f2102306220921060314715629080e2fb77still reportschecksum: truewith strict mode off. The PR includes the #11 repeated-prefix tests frommain.Benchmark
npm run benchmarkwas run unchanged on both revisions, on the same host, alternatingmain(2f6facb) and this branch 7 times each. Values are medians, in validations/s.This PR doesn't touch the non-EVM chains, so their differences are run-to-run noise.
Size
Measured with gzip -9 on
dist/:ethereum.mjschunk: 1,235 → 1,374 B (+139 B)ethereum.cjschunk: 1,264 → 1,394 B (+130 B)index.umd.js: 6,815 → 6,956 B (+141 B)index.mjsandindex.cjsentries: unchangedThe packed-consumer size budgets still pass.
Tests
tests/utils.test.ts:""and"abc"@noble/hashesfor 1, 40, 135, 136, 137, 271, 272, 273 and 500-byte input, which straddles the 136-byte rate and the second blocktests/ethereum.test.ts:0xde709f…) or all uppercase (0x52908400…) return{ valid: true, details: { checksum: true } }, with and without strict modechecksum: false, and is rejected in strict modescripts/test-differential.mjs:validanddetails.checksumwith a direct EIP-55 implementation on@noble/hashes, in both default and strict mode0x/0X, case flips, and non-hex pairsmainand on this branch, and fails on the code reviewed in perf + fixes: faster hashing/decoding/detection, network option, Ripple details, missing tests #10 (0x0x+ 38 digits)@noble/hashesstill passResults
npm ci,npm run checkandnpm audit(0 vulnerabilities) on Node 22.23.5, 24.16.0 and 26.13.1, andnpm run test:coverageon Node 24.16.0. All passed.