Repository navigation
fix(mock-contracts): match the TaskManager's decrypt result batch functions - #414
Merged
architect-dev merged 1 commit intoOct 16, 2026
Conversation
…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.
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.
Summary
MockTaskManager.publishDecryptResultBatchnow emitsDecryptionResultwith the caller asrequestor, like the TaskManagerpublishDecryptResultBatch,verifyDecryptResultBatchandverifyDecryptResultBatchSaferevert withLengthMismatchwhen the arrays differ in length, like the TaskManagerpackages/foundry-plugin/test/MockDecryptResultBatch.t.solpackages/mock-contracts/src/MockTaskManager.ts: the ABI gains theLengthMismatcherror@cofhe/mock-contractsRoot cause
publishDecryptResultBatchpublished each result throughthis.publishDecryptResult(...). That external call from the mock to itself makes the mock themsg.sender, so everyDecryptionResultfrom a batch carriedrequestor = 0x0000000000000000000000000000000000005000(the mock's own address) instead of the contract that calledFHE.publishDecryptResultBatch. The TaskManager emitsDecryptionResult(ctHash, result, msg.sender)inside the batch loop.requestoris 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()inpublishDecryptResultBatch,verifyDecryptResultBatchandverifyDecryptResultBatchSafe. The mock had no check: a shorter array panicked with0x32and a longer one was ignored.Fix
Both publish functions go through a shared private
_publishDecryptResult, so a batch keeps its caller asmsg.sender, and the three batch functions get the TaskManager's length check.Testing
master, 5 of the 6 new tests fail:DecryptionResultevents carryrequestor = 0x0000000000000000000000000000000000005000instead of the publishing contractnext call did not revert as expectedverifyDecryptResultBatchandverifyDecryptResultBatchSafe:panic: array out-of-bounds access (0x32)instead ofLengthMismatch()packages/foundry-plugin(Foundry 1.7.1): 101 passedpnpm --filter @cofhe/hardhat-plugin-test test: 101 passing;pnpm --filter @cofhe/hardhat-3-plugin-test test: 42 passingpnpm --filter @cofhe/mock-contracts testpassed; rebuilding the package only adds theLengthMismatcherror tosrc/MockTaskManager.tspnpm lint,pnpm check:types,pnpm run check:pinned-deps,pnpm run check:circles, Prettier: passedScope
Mock only. This touches different lines of
MockTaskManager.solthan #413, so the two apply independently; with both,packages/foundry-pluginhas 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.
publishDecryptResultBatchno longer loops through an externalthis.publishDecryptResultcall. Single and batch publish share a private_publishDecryptResult, soDecryptionResultevents use the original caller as the indexedrequestor(not the mock’s fixed address).publishDecryptResultBatch,verifyDecryptResultBatch, andverifyDecryptResultBatchSafenow revert withLengthMismatch()whenctHashes,results, andsignatureslengths differ, instead of panicking or silently ignoring extra entries.Adds
MockDecryptResultBatch.t.solcovering requestor attribution, length mismatch reverts, and successful batch verify. Regenerates the mock ABI (LengthMismatchinMockTaskManager.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.