Repository navigation
fix(protocol-kit): don't drop SafeProvider from memoized cache key - #1481
Open
Anu (Svector-anu) wants to merge 1 commit into
Open
Anu (Svector-anu) wants to merge 1 commit into
Anu (Svector-anu) wants to merge 1 commit into
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
|
This comment will be updated automatically if new data arrives. 🔗 Commit SHA: f563ad3 | Docs | View more details | Give us feedback! |
Author
|
I have read the CLA Document and I hereby sign the CLA |
1 similar comment
Author
|
I have read the CLA Document and I hereby sign the CLA |
safe-cla-bot Bot
added a commit
to safe-global/cla-signatures
that referenced
this pull request
Nov 30, 2026
This branch has not been deployed
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.
What it solves
createMemoizedFunction(used for every memoized contract lookup incontracts/utils.ts) builds its cache key with a JSON serializer that keeps aseenset to break circular references. That serializer is created once per memoized function, so itsseenset is shared across every call. The first time a givenSafeProvideris serialized it is added toseen; on every later call the same provider is treated as an already-seen reference and dropped from the key.Two consequences:
SafeProviderinstances have each been memoized once, a later call with either produces the same provider-less key, so one provider's cached result is returned for the other. In a process that works with more than one provider, a memoized contract lookup can return the contract resolved for a different provider.Note: this does not make two injected EIP-1193 providers distinguishable — those still serialize to the same placeholder — which is a separate limitation. This change only ensures the key no longer depends on call history.
How this PR fixes it
Create the serializer inside the returned function so each call gets a fresh
seenset. Circular-reference protection still holds within a singleJSON.stringify, but state no longer leaks between calls, so every argument — including theSafeProvider— is represented in the key on every call.Added
packages/protocol-kit/tests/unit/memoized.test.ts: distinct providers keep distinct results, and a repeated identical call is served from cache. Both assertions fail before this change and pass after.