Skip to content

fix(sdk): fail fast on chainId mismatch between decrypt builders and ACP - #409

Merged
alexshchur merged 3 commits into
FhenixProtocol:masterfrom
Lesnak1:fix/decrypt-builders-chainid-mismatch
Oct 28, 2026
Merged

alexshchur merged 3 commits into
FhenixProtocol:masterfrom
Lesnak1:fix/decrypt-builders-chainid-mismatch

Conversation

@Lesnak1

@Lesnak1 Lesnak1 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Add ChainIdMismatch error code to CofheErrorCode and reject decrypt execution when builder chainId is explicitly set and differs from the ACP's signed chainId (acp._signedDomain.chainId).

  • In decryptForView and decryptForTx, throw CofheError with CofheErrorCode.ChainIdMismatch naming both chain IDs when they differ.
  • Add regression unit tests in packages/sdk/core/test/decryptBuilders.test.ts for both builders asserting fast failure on mismatch and successful dispatch on matching chain IDs.
  • Include a patch changeset for @cofhe/sdk using ACP.

Note

Low Risk
Targeted validation on the decrypt execution path; wrong-chain requests fail earlier instead of hitting the threshold network.

Overview
decryptForView and decryptForTx now validate that an explicitly set builder chainId matches acp._signedDomain.chainId right after ACP validation, before any threshold-network call. On mismatch they throw CofheError with the new CofheErrorCode.ChainIdMismatch, including both IDs in the message and context. When the builder chainId is unset, behavior is unchanged: it is filled from the ACP’s signed domain and execution continues.

The enum gains ChainIdMismatch (consumers with exhaustive handling over CofheErrorCode need a new branch). Regression tests cover mismatch (no tnDecryptV2 / tnSealOutputV2 dispatch), matching IDs, and unset builder chainId. A patch changeset documents the @cofhe/sdk fix.

Reviewed by Cursor Bugbot for commit d940e8c. Bugbot is set up for automated code reviews on this repo. Configure here.

@changeset-bot

changeset-bot Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d940e8c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@cofhe/sdk Patch
@cofhe/abi Patch
@cofhe/hardhat-3-plugin Patch
@cofhe/hardhat-plugin Patch
@cofhe/mock-contracts Patch
@cofhe/react Patch
@cofhe/site Patch
@cofhe/example-react Patch
@cofhe/foundry-plugin Patch

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

@Lesnak1
Lesnak1 force-pushed the fix/decrypt-builders-chainid-mismatch branch from 08b2e33 to 705d060 Compare October 14, 2026 13:04

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 705d060. Configure here.

@Lesnak1
Lesnak1 force-pushed the fix/decrypt-builders-chainid-mismatch branch from 705d060 to e2f6128 Compare October 14, 2026 13:21
Lesnak1 and others added 3 commits October 28, 2026 14:19
Add ChainIdMismatch error code to CofheErrorCode and reject decrypt execution when builder chainId is explicitly set and differs from the ACP's signed chainId (acp._signedDomain.chainId).

- In decryptForView and decryptForTx, throw CofheError with CofheErrorCode.ChainIdMismatch naming both chain IDs when they differ.
- Fall back to ACP signed chainId when builder chainId is unset and hydrate this.chainId.
- Add regression unit tests in packages/sdk/core/test/decryptBuilders.test.ts asserting fast failure on mismatch and successful dispatch on matching/unset chain IDs.
- Include a patch changeset for @cofhe/sdk.
@alexshchur
alexshchur force-pushed the fix/decrypt-builders-chainid-mismatch branch from d1a994e to d940e8c Compare October 28, 2026 12:25
@alexshchur
alexshchur merged commit 800cdb3 into FhenixProtocol:master Oct 28, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants