Repository navigation
fix(mock-contracts): make FHE.random* handles usable in mocks - #402
Merged
architect-dev merged 1 commit intoOct 14, 2026
Merged
Conversation
MockTaskManager.createRandomTask was a stub returning keccak256(returnType, seed, securityZone, block.timestamp). The handle had no type or security zone metadata, no value in mock storage and no ACL access for the caller, so FHE.random* could not be used in Hardhat or Foundry tests: FHE.add(r, x) reverted with InvalidTypeOrSecurityZone and two calls in one transaction returned the same handle. Follow TaskManager.createRandomTask: validate the zone, derive the seed when it is 0 with a counter, build the handle with calcPlaceholderKey over (seed, msg.sender), grant the caller transient access and emit TaskCreated. As mock only work, store a value derived from the handle.
🦋 Changeset detectedLatest commit: 1deac44 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 |
architect-dev
approved these changes
Oct 14, 2026
architect-dev
left a comment
Collaborator
There was a problem hiding this comment.
Good catch and fix. Happy to have the correct random function in there now. Will merge after tests run (just approved workflow). Tyty 🙏
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.
MockTaskManager.createRandomTaskwas a stub that returnedkeccak256(returnType, seed, securityZone, block.timestamp). That handle has no type or security zone metadata, is not in mock storage, and the caller gets no ACL access. SoFHE.randomEuint*()cannot be used in Hardhat or Foundry tests:FHE.add(r, x)reverts withInvalidTypeOrSecurityZone,FHE.allowThis(r)usually reverts withSenderNotAllowed, and two calls in one transaction return the same handle.This follows
TaskManager.createRandomTaskin cofhe-contracts: validate the security zone, derive the seed when it is 0 (with a counter), build the handle withcalcPlaceholderKeyover(seed, msg.sender), grant transient access to the caller and emitTaskCreated. As mock only work it stores a value derived from the handle, inside the existing gas tracking. The ABI does not change, and the newrandomCounteris appended after the existing storage variables.Tests:
packages/foundry-plugin/test/MockRandom.t.solchecks the handle's type and zone bits and mock storage,allowThisplusaddon a random handle, two random values in one transaction, and the zone check. All 4 fail on master (utype: 84 != 4,InvalidTypeOrSecurityZone("add"),same handle, no revert) and pass with this change. The full foundry plugin suite passes (77 tests). Prettier is clean. A changeset is included.Note
Low Risk
Test-only mock behavior aligned with production random-task flow; no production contract or ABI changes.
Overview
MockTaskManager.createRandomTaskis no longer a barekeccak256stub. It now mirrors production behavior: invalid security zones revert, zero seeds are derived (with a newrandomCounter), handles are built viacalcPlaceholderKeywith caller in the preimage, transient ACL is granted,TaskCreatedis emitted, and a mock plaintext is stored under gas tracking.That makes
FHE.random*handles usable in Hardhat/Foundry tests—correct type/zone metadata, distinct handles per call, and support forallowThis/addwithoutInvalidTypeOrSecurityZoneorSenderNotAllowed.Adds
MockRandom.t.sol(metadata, usability, uniqueness, zone rejection) and a@cofhe/mock-contractspatch changeset. ABI unchanged.Reviewed by Cursor Bugbot for commit 1deac44. Bugbot is set up for automated code reviews on this repo. Configure here.