Repository navigation
Conversation
|
@backseats is attempting to deploy a commit to the Wevm Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: ab25990 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Member
|
Thanks @backseats! Superseded by #5514, which keeps your commit and adds a test for the EIP-1191 cache keys plus a couple of doc fixes. |
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
Two small caching changes in
src/utils/address/, plus docs and JSDoc for how checksums work inisAddressandgetAddress.checksumAddress: key the cache by the lowercase addressThe cache was keyed by the input string, so each casing of an address was a separate entry. A common flow hashes the same address twice:
decodeAbiParameterscallschecksumAddresswith lowercase hex, so it is cached under the lowercase key.isAddress(strict) inencodeAbiParameters, which callschecksumAddresswith the checksummed string. That is a different key, so it misses and runs keccak again.The checksum depends only on the lowercase address, so the cache is now keyed by it. This also replaces
has+getwith a singleget.isAddress: only cache the checksum comparisonThe regex and lowercase checks are cheaper than an
LruMaplookup, so they now run before the cache. Only the strict mixed-case comparison is cached, keyed by the address.Measured
Node 24, warm caches unless noted.
isAddress, 1,000 lowercase addressesisAddress, 1,000 checksummed (strict)isAddress, 1,000 checksummed (strict: false)isAddress(strict) on eachRemoving the
isAddresscache entirely made the strict checksummed case about 2x slower (418 µs), so it stays for that path.Results are unchanged. I compared outputs against the current implementation for 2,000 addresses, with and without an EIP-1191
chainId, and for mis-cased inputs toisAddress.Docs
isAddressdocs said an all-lowercase address returnsfalsein strict mode. It returnstrue, because it has no checksum to verify. The example now uses a mis-cased mixed-case address.isAddressexplaining EIP-55 with a one-letter mis-casing example, and noting that all-uppercase addresses fail strict mode.getAddressthat it ignores input casing and does not validate the checksum, with an example of pairing it withisAddress.isAddress,getAddressandchecksumAddresscovering the same points.Tests
isAddresscases for a correct checksum, a one-letter mis-casing, all-lowercase, all-uppercase, andstrict: false.pnpm test --run src/utils/address src/utils/abi/{encodeAbiParameters,decodeAbiParameters,getAbiItem,encodePacked}.test.ts src/accounts: 417 passed.tsc -band Biome are clean.