Skip to content

fix(mock-contracts): reject the types the TaskManager rejects - #481

Merged
alexshchur merged 1 commit into
FhenixProtocol:masterfrom
olric3015:fix/mock-unsupported-type
Nov 2, 2026
Merged

alexshchur merged 1 commit into
FhenixProtocol:masterfrom
olric3015:fix/mock-unsupported-type

Conversation

@olric3015

@olric3015 olric3015 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The TaskManager reverts with UnsupportedType when a type is not one it supports, in four places: a task's return type (createTask), the trivialEncrypt target type (validateTrivialEncryptInputs), the cast target type (validateExtraInputs) and the createRandomTask type. It reverts with DecryptFunctionNotSupported when createTask is asked for a decrypt. MockTaskManager had none of the type checks, so it returned a handle, and it answered a decrypt task with InvalidOperationInputs("decrypt").

Same family as #403, which added the trivialEncrypt value range checks.

Impact

Utils.EUINT256_TFHE (8) is still declared in ICofhe.sol, but the TaskManager dropped euint256 (cofhe-contracts #31) and isValidType no longer accepts it. A contract that calls Impl.trivialEncrypt(x, Utils.EUINT256_TFHE, 0), Impl.cast(h, Utils.EUINT256_TFHE) or Impl.random(Utils.EUINT256_TFHE) passes its Hardhat / Foundry tests and reverts with UnsupportedType(8) once deployed. The typed FHE.asE* / FHE.randomE* helpers only pass supported types, so they are not affected.

Fix

  • Declares UnsupportedType(uint256) and DecryptFunctionNotSupported() with the TaskManager's signatures, and adds isValidType with the same seven types.
  • createTask: rejects decrypt, then an unsupported return type, before the other checks, as TaskManager.createTask does. Rejects an unsupported cast target type.
  • validateTrivialEncryptInputs: rejects a target type above uint8 before the security zone check, and an unknown target type instead of returning.
  • createRandomTask: rejects an unsupported type before the security zone check.

The checks and their order match TaskManager in cofhe-contracts 1.0.0 (the pinned version) and 1.0.2. Calls with supported types are unchanged. The two errors are added to the checked-in MockTaskManager ABI (regenerated with the package's build steps; the typechain output does not change).

Test plan

  • New MockUnsupportedType.t.sol (9 tests): euint256 via Impl.trivialEncrypt / Impl.cast / Impl.random, an unknown trivialEncrypt target type, a target type above uint8 together with an out of range zone, an unknown cast target type, an unsupported return type, a decrypt task, and all seven supported types still working
  • Mutation-verified per check: removing each of the six checks on its own makes exactly the test for that check fail (e.g. without the return type check, testCreateTaskUnsupportedReturnTypeReverts fails with next call did not revert; without the decrypt check, InvalidOperationInputs("decrypt") != DecryptFunctionNotSupported); restored → 9/9 pass
  • pnpm --filter @cofhe/mock-contracts test, @cofhe/foundry-plugin (127 tests), @cofhe/hardhat-plugin, @cofhe/hardhat-plugin-test (102 passing), @cofhe/hardhat-3-plugin-test (45 passing), with Foundry 1.7.1 as in CI
  • pnpm check:formatting, check:pinned-deps, check:circles
  • Changeset added (@cofhe/mock-contracts: patch)

Competitor check

Searched UnsupportedType, DecryptFunctionNotSupported, isValidType, euint256, unsupported type, random type across open and closed PRs and issues: none adds these checks. #463, #459 and #445 also touch MockTaskManager.sol; none of them changes type validation, and this branch merges cleanly with each.


Note

Low Risk
Changes are limited to mock contracts and test fidelity; supported-type behavior is unchanged and production TaskManager code is untouched.

Overview
Aligns MockTaskManager with the real TaskManager so local Foundry/Hardhat tests fail the same way mainnet would, instead of returning ciphertext handles for unsupported operations.

The mock now defines UnsupportedType(uint256) and DecryptFunctionNotSupported(), plus isValidType for the seven supported TFHE types (excluding dropped Utils.EUINT256_TFHE). createTask reverts on decrypt tasks, bad return types, and invalid cast targets (matching check order on chain). validateTrivialEncryptInputs reverts on target types above uint8 or unknown types rather than silently succeeding. createRandomTask rejects unsupported return types before zone checks.

Adds MockUnsupportedType.t.sol (nine tests covering euint256 paths, edge cases, decrypt, and supported types), regenerates the checked-in ABI artifact, and a patch changeset for @cofhe/mock-contracts.

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

The TaskManager reverts with UnsupportedType when a task's return type,
a trivialEncrypt or cast target type, or a random type is not one of the
supported types, and with DecryptFunctionNotSupported when createTask is
asked for a decrypt. MockTaskManager accepted the types and returned a
handle, and answered a decrypt task with InvalidOperationInputs.

Utils.EUINT256_TFHE is still declared in ICofhe.sol, but the TaskManager
dropped euint256, so encrypting, casting or generating a random value as
that type passed in local tests and reverted on chain.

The checks and their order follow TaskManager.createTask,
validateTrivialEncryptInputs, validateExtraInputs and createRandomTask in
cofhe-contracts 1.0.0 and 1.0.2.
@changeset-bot

changeset-bot Bot commented Oct 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d29172a

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

This PR includes changesets to release 9 packages
Name Type
@cofhe/mock-contracts Patch
@cofhe/foundry-plugin Patch
@cofhe/hardhat-3-plugin Patch
@cofhe/hardhat-plugin Patch
@cofhe/site Patch
@cofhe/abi Patch
@cofhe/react Patch
@cofhe/sdk Patch
@cofhe/example-react 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

@alexshchur
alexshchur merged commit 8731a28 into FhenixProtocol:master Nov 2, 2026
13 checks passed

@alexshchur alexshchur left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @olric3015, nice one. The mock was more forgiving than the real TaskManager, so a contract could pass local tests and still revert on chain. Now they fail the same way. Merging.

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