fix(sdk): cache the CRS per security zone - #322
Open
Dusk1e wants to merge 1 commit into
Open
Conversation
`fetchCrs` requested the CRS for a given `securityZone` but cached it under the chain id alone, while `fetchFhePublicKey` right above it keys by `(chainId, securityZone)`. So after encrypting on one zone, `encryptInputs` on a different zone read the first zone's CRS back out of the store. A stale CRS deserializes fine, so it passed `checkKeyValidity` and was used to build the proof, which the ZK verifier then rejects. CoFHE does serve a distinct CRS per zone. `POST /GetCrs` against testnet-cofhe.fhenix.zone with `securityZone: 0` and `securityZone: 1` returns two different values (both 7,968,512 bytes, sha256 e0cf6cf5a2af9241 vs 9e062a6f0c8208d3). `GetNetworkPublicKey` differs per zone too, which is why the FHE key is already cached per zone. `KeysStore.crs` is now keyed by chain and zone like `KeysStore.fhe`, `getCrs` takes an optional zone defaulting to 0, and `setCrs(chainId, securityZone, crs)` matches `setFheKey`'s argument order. On rehydrate, a `crs` persisted under the old shape (a bare string per chain) is dropped so the CRS is refetched per zone instead of being indexed as a string. Also fixes the `insertMockKeys` test helper, which took a `securityZone` and passed it to `setFheKey` but hardcoded zone 0 for `setCrs` — the same conflation.
🦋 Changeset detectedLatest commit: 6ff3430 The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
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 |
|
@Dusk1e is attempting to deploy a commit to the Fhenix Team on Vercel. A member of the Team first needs to authorize it. |
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.
fetchCrsasks CoFHE for the CRS of a specificsecurityZonebut caches it under the chain id alone, whilefetchFhePublicKeyright above it keys by chain and zone. So once you encrypt on zone 0 and then callsetSecurityZone(1),encryptInputsreads zone 0's CRS back out of the store. A stale CRS deserializes fine, so it passescheckKeyValidityand gets used to build the proof, and the ZK verifier rejects it.The zones really do have different CRS values.
POST /GetCrsto testnet-cofhe.fhenix.zone withsecurityZone: 0andsecurityZone: 1returns two different 7,968,512 byte blobs (sha256e0cf6cf5vs9e062a6f).GetNetworkPublicKeydiffers per zone too, which is why the FHE key was already cached per zone.I keyed
crsby chain and zone the same wayfhealready is, and madesetCrstake the zone in the same positionsetFheKeydoes. Acrspersisted under the old shape holds a bare string per chain, so those entries are dropped on rehydrate and refetched per zone instead of being indexed as a string. Also fixedinsertMockKeysin the tests, which took asecurityZone, passed it tosetFheKey, then hardcoded zone 0 forsetCrs— the same conflation.Added a keyStore test for zone isolation and a fetchKeys test that a zone 0 CRS is not reused for zone 1. The zone isolation test fails on master. Full node suite is 378 passing; the two failing files are the pre-existing
@cofhe/test-setupresolution errors that fail on master too.tsc --noEmitreports the same 3 errors before and after, all from that same missing module.