Skip to content

fix(mock-contracts): match the TaskManager's decrypt result batch functions - #414

Merged
architect-dev merged 1 commit into
FhenixProtocol:masterfrom
nftpoetrist:fix/mock-decrypt-result-batch
Oct 16, 2026
Merged

architect-dev merged 1 commit into
FhenixProtocol:masterfrom
nftpoetrist:fix/mock-decrypt-result-batch

Conversation

@nftpoetrist

@nftpoetrist nftpoetrist commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • MockTaskManager.publishDecryptResultBatch now emits DecryptionResult with the caller as requestor, like the TaskManager
  • publishDecryptResultBatch, verifyDecryptResultBatch and verifyDecryptResultBatchSafe revert with LengthMismatch when the arrays differ in length, like the TaskManager
  • Add packages/foundry-plugin/test/MockDecryptResultBatch.t.sol
  • Regenerate packages/mock-contracts/src/MockTaskManager.ts: the ABI gains the LengthMismatch error
  • Add a patch changeset for @cofhe/mock-contracts

Root cause

publishDecryptResultBatch published each result through this.publishDecryptResult(...). That external call from the mock to itself makes the mock the msg.sender, so every DecryptionResult from a batch carried requestor = 0x0000000000000000000000000000000000005000 (the mock's own address) instead of the contract that called FHE.publishDecryptResultBatch. The TaskManager emits DecryptionResult(ctHash, result, msg.sender) inside the batch loop. requestor is indexed, so filtering the events by the publishing contract found nothing in Hardhat and Foundry tests.

The TaskManager also rejects arrays of different lengths with LengthMismatch() in publishDecryptResultBatch, verifyDecryptResultBatch and verifyDecryptResultBatchSafe. The mock had no check: a shorter array panicked with 0x32 and a longer one was ignored.

Fix

Both publish functions go through a shared private _publishDecryptResult, so a batch keeps its caller as msg.sender, and the three batch functions get the TaskManager's length check.

Testing

  • RED control on master, 5 of the 6 new tests fail:
    • the batch's DecryptionResult events carry requestor = 0x0000000000000000000000000000000000005000 instead of the publishing contract
    • an extra result: next call did not revert as expected
    • a missing signature, verifyDecryptResultBatch and verifyDecryptResultBatchSafe: panic: array out-of-bounds access (0x32) instead of LengthMismatch()
    • matching arrays still verify on both
  • packages/foundry-plugin (Foundry 1.7.1): 101 passed
  • pnpm --filter @cofhe/hardhat-plugin-test test: 101 passing; pnpm --filter @cofhe/hardhat-3-plugin-test test: 42 passing
  • pnpm --filter @cofhe/mock-contracts test passed; rebuilding the package only adds the LengthMismatch error to src/MockTaskManager.ts
  • pnpm lint, pnpm check:types, pnpm run check:pinned-deps, pnpm run check:circles, Prettier: passed

Scope

Mock only. This touches different lines of MockTaskManager.sol than #413, so the two apply independently; with both, packages/foundry-plugin has 105 passing tests.


Note

Low Risk
Mock-only contract changes for test parity; no production TaskManager or host-chain logic is modified.

Overview
Aligns MockTaskManager batch decrypt publish/verify behavior with the real TaskManager so Foundry and Hardhat tests can rely on the same semantics.

publishDecryptResultBatch no longer loops through an external this.publishDecryptResult call. Single and batch publish share a private _publishDecryptResult, so DecryptionResult events use the original caller as the indexed requestor (not the mock’s fixed address). publishDecryptResultBatch, verifyDecryptResultBatch, and verifyDecryptResultBatchSafe now revert with LengthMismatch() when ctHashes, results, and signatures lengths differ, instead of panicking or silently ignoring extra entries.

Adds MockDecryptResultBatch.t.sol covering requestor attribution, length mismatch reverts, and successful batch verify. Regenerates the mock ABI (LengthMismatch in MockTaskManager.ts) and a patch changeset for @cofhe/mock-contracts.

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

…ctions

publishDecryptResultBatch published each result through an external call to
the mock itself, so DecryptionResult carried the task manager's own address
as the requestor instead of the caller. The batch functions also skipped the
TaskManager's length check, panicking or ignoring extra entries when the
arrays differ in length.

Publish through a shared private _publishDecryptResult, and revert with
LengthMismatch in publishDecryptResultBatch, verifyDecryptResultBatch and
verifyDecryptResultBatchSafe like the TaskManager.

@architect-dev architect-dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm

@architect-dev
architect-dev merged commit c08a828 into FhenixProtocol:master Oct 16, 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