Repository navigation
fix(sdk): match the TaskManager's signature checks in verifyDecryptResult - #464
Merged
alexshchur merged 3 commits intoOct 28, 2026
Conversation
🦋 Changeset detectedLatest commit: 02275e0 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 |
kutluhaneth46
left a comment
Contributor
There was a problem hiding this comment.
Checked this against TaskManager / OpenZeppelin ECDSA.tryRecover constraints (65-byte r||s||v, v ∈ {27,28}, low-s).
Ran locally on this branch:
pnpm --filter @cofhe/sdk test -- --run verifyDecryptResult → 6/6 passed (incl. v=0/1, high-s, malformed).
Nice alignment: SDK verifyDecryptResult returning false for encodings that would revert on-chain avoids a false-positive “verified” path. Looks ready from the SDK side.
…sult TaskManager.verifyDecryptResult checks the signature with OpenZeppelin's ECDSA.tryRecover, which only accepts 65 bytes with v = 27 or 28 and a low s value. The SDK's local verifyDecryptResult used viem's recoverAddress, which also accepts v = 0 or 1 and high s values. So a valid signature in either form returned true locally, while verifyDecryptResult and publishDecryptResult on chain revert with InvalidSignature for it. Apply the same checks before recovering the signer.
alexshchur
force-pushed
the
fix/verify-decrypt-result-signature-encoding
branch
from
October 28, 2026 08:58
43b7971 to
02275e0
Compare
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.
client.verifyDecryptResult(ctHash, plaintext, signature)is meant for decrypt results that come from somewhere other than your owndecryptForTxcall (a backend, a cache, another client), and the docs say atrueresult "means the chain’s verifier considers this signature a valid attestation". It can returntruefor signatures the TaskManager rejects.TaskManager._verifyDecryptResultin cofhe-contracts recovers the signer with OpenZeppelin'sECDSA.tryRecover(messageHash, signature), which only accepts a 65 byte signature withvof 27 or 28 andsin the lower half of the curve order.MockTaskManagerdoes the same.verifyDecryptResult.tsrecovers with viem'srecoverAddress, which also acceptsvof 0 or 1 and a highs. So the same valid signature re-encoded in either form:truefrom the SDK'sverifyDecryptResult;verifyDecryptResultandpublishDecryptResulton the TaskManager revert withInvalidSignature(), andverifyDecryptResultSafereturnfalse.An app that checks results from an untrusted source with the SDK before relaying or publishing them can be handed one that passes the check and then reverts on chain. Anyone holding a genuine result can produce the high
sform, and code that serializes the recovery id as 0/1 produces the other. This does not allow a forged plaintext: both forms still recover the configured signer for the same(ctHash, plaintext). Results taken straight fromdecryptForTxare not affected, sincenormalizeTnSignaturealready re-serializes the threshold network signature withvof 27 or 28.This adds the same checks before recovery: 65 bytes of hex,
vof 27 or 28, andsat most the bound used byECDSA.tryRecover. Malformed input still returnsfalserather than throwing. The JSDoc and the docs page mention the rule.Tests:
core/test/verifyDecryptResult.test.tsadds a case forvof 0/1 and one for a highs, both built from the configured signer's own signature. Both fail on master (expected true to equal false) and pass with this change. A malformed signature case covers the input check. For the on-chain side I compiledTaskManagerfrom cofhe-contracts (bbd0196, OpenZeppelin 5.2.0) and this repo'sMockTaskManager, deployed both on an in-process Hardhat network with a signer set, and calledverifyDecryptResult/verifyDecryptResultSafewith the canonical,v0/1 and highsforms of one signature:truefor the canonical one,InvalidSignature()/falsefor the other two, on both contracts. On the same bytes the SDK returnstruefor all three on master, andtrue,false,falsewith this change. In the sdk node test project (run offline) the only failures are the existing network-dependent ones, identical with and without this change. eslint and prettier are clean on the changed files. A changeset is included.This only touches the SDK; #414 covers the mock's batch decrypt result functions.
Note
Medium Risk
Changes decrypt-result trust checks for off-chain sources; stricter rejection may block re-encoded signatures that previously passed the SDK but still fail on-chain anyway.
Overview
verifyDecryptResultnow rejects signature encodings that OpenZeppelinECDSA.tryRecover(and the on-chain TaskManager) would reject, even when viem recovery would still match the configured signer.Before recovery, the SDK requires a 65-byte hex signature with
vof 27 or 28 and a lows(≤ secp256k1 half-order). Alternate encodings of the same valid attestation—v0/1 or highs—returnfalseinstead oftrue, closing the gap where off-chain checks passed butverifyDecryptResult/publishDecryptResultreverted withInvalidSignature.Tests cover those encodings plus malformed input; docs and JSDoc note the formatting rule.
decryptForTxoutputs are unchanged when already normalized.Reviewed by Cursor Bugbot for commit 02275e0. Bugbot is set up for automated code reviews on this repo. Configure here.