fix(FHE): guard getDecryptResult and getDecryptResultSafe against uninitialized (zero) handles#66
Open
amathxbt wants to merge 1 commit into
Conversation
…lized handles Passing bytes32(0) (an uninitialized ciphertext handle) to getDecryptResult forwards uint256(0) to the task manager, which may accidentally match an existing pending or completed decrypt task at slot 0, returning a potentially wrong uint256 result that the caller treats as a valid plaintext. getDecryptResult now reverts with a clear message on a zero handle. getDecryptResultSafe returns (0, false) for zero handles, consistent with the semantic of "not yet decrypted".
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
Impl.getDecryptResultandImpl.getDecryptResultSafeincontracts/FHE.solaccept anybytes32handle without checking whether it is initialized (non-zero). Passing a zero handle forwardsuint256(0)to the task manager, which may coincidentally match a real pending or completed decrypt task at slot 0, returning a wrong plaintext the caller treats as valid.Bug
Impact: Contracts that accidentally call these functions with an uninitialized
euintXfield get a non-zero, apparently-valid result instead of an error. This can silently corrupt application state (e.g., a balance read from an uninitialized storage slot returns a non-zero plaintext).Fix
getDecryptResult: revert with a clear message when the handle is zero.getDecryptResultSafe: return(0, false)(semantically "not yet decrypted") for zero handles, consistent with the function's safe semantics.