From c46b33ba362458ce240c4c06bdaca601b908545d Mon Sep 17 00:00:00 2001 From: Alexandre Carvalheira Date: Wed, 25 Feb 2026 21:10:52 -0300 Subject: [PATCH 1/6] Update fhe-library/core-concepts/conditions.mdx Co-Authored-By: mintlify[bot] <109931778+mintlify[bot]@users.noreply.github.com> --- fhe-library/core-concepts/conditions.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fhe-library/core-concepts/conditions.mdx b/fhe-library/core-concepts/conditions.mdx index 3d4637c..d067669 100644 --- a/fhe-library/core-concepts/conditions.mdx +++ b/fhe-library/core-concepts/conditions.mdx @@ -1,5 +1,5 @@ --- -title: "Conditions" +title: "Conditions (if .. else)" description: "Understanding why if..else isn't possible with FHE and exploring the alternatives" --- From 98d860564cdf36fcb3dba781db79cc9cf56ef176 Mon Sep 17 00:00:00 2001 From: Alexandre Carvalheira Date: Wed, 25 Feb 2026 21:11:12 -0300 Subject: [PATCH 2/6] Update fhe-library/core-concepts/require.mdx Co-Authored-By: mintlify[bot] <109931778+mintlify[bot]@users.noreply.github.com> --- fhe-library/core-concepts/require.mdx | 54 +++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 fhe-library/core-concepts/require.mdx diff --git a/fhe-library/core-concepts/require.mdx b/fhe-library/core-concepts/require.mdx new file mode 100644 index 0000000..73b1742 --- /dev/null +++ b/fhe-library/core-concepts/require.mdx @@ -0,0 +1,54 @@ +--- +title: "Require" +description: "Understanding require statements with encrypted data in FHE" +--- + +## Overview + +The `require` statement in FHE contracts works similarly to [Conditions (if .. else)](/fhe-library/core-concepts/conditions) because both involve conditional logic on encrypted data. Just as you can't use traditional `if...else` statements with encrypted values, you also can't directly use `require` statements with encrypted booleans. + + +Traditional `require` statements cannot evaluate encrypted conditions directly. You must decrypt the condition first or use alternative patterns. + + +--- + +## Why Require is Similar to Conditions + +Both `require` and conditional statements face the same fundamental challenge in FHE: + + + +The condition being checked is encrypted, so the contract cannot directly evaluate whether it's true or false. + + + +Both require branching logic that reveals information about encrypted data, which breaks FHE's privacy guarantees. + + + +--- + +## Working with Require in FHE + +To use `require` with encrypted conditions, you must first decrypt the condition. This should only be done when the result can be safely revealed: + +```solidity +// Decrypt the encrypted boolean before using in require +ebool encryptedCondition = value.gt(threshold); +bool condition = FHE.decrypt(encryptedCondition); + +require(condition, "Condition not met"); +``` + + +Only decrypt conditions when revealing the result doesn't compromise privacy. For internal logic that must remain private, use `FHE.select` instead as shown in the [Conditions (if .. else)](/fhe-library/core-concepts/conditions) guide. + + +--- + +## Related Topics + +- Learn more about conditional logic in [Conditions (if .. else)](/fhe-library/core-concepts/conditions) +- Understand decryption in [Decryption Operations](/fhe-library/core-concepts/decryption-operations) +- Explore access control in [Access Control](/fhe-library/core-concepts/access-control) From 4ee7202e4d625adb37199d8e189b4cab60727e23 Mon Sep 17 00:00:00 2001 From: Alexandre Carvalheira Date: Wed, 25 Feb 2026 21:11:26 -0300 Subject: [PATCH 3/6] Update docs.json Co-Authored-By: mintlify[bot] <109931778+mintlify[bot]@users.noreply.github.com> --- docs.json | 1 + 1 file changed, 1 insertion(+) diff --git a/docs.json b/docs.json index 7475f23..894fadc 100644 --- a/docs.json +++ b/docs.json @@ -111,6 +111,7 @@ "fhe-library/core-concepts/data-evaluation", "fhe-library/core-concepts/encrypted-operations", "fhe-library/core-concepts/conditions", + "fhe-library/core-concepts/require", "fhe-library/core-concepts/access-control", "fhe-library/core-concepts/decryption-operations", "fhe-library/core-concepts/randomness", From 8cae8abdbf559cbf1ef92eca3562d012b4cc567c Mon Sep 17 00:00:00 2001 From: Alexandre Carvalheira Date: Wed, 25 Feb 2026 21:13:44 -0300 Subject: [PATCH 4/6] Update fhe-library/core-concepts/conditions.mdx Co-Authored-By: mintlify[bot] <109931778+mintlify[bot]@users.noreply.github.com> --- fhe-library/core-concepts/conditions.mdx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/fhe-library/core-concepts/conditions.mdx b/fhe-library/core-concepts/conditions.mdx index d067669..05331d3 100644 --- a/fhe-library/core-concepts/conditions.mdx +++ b/fhe-library/core-concepts/conditions.mdx @@ -135,6 +135,26 @@ euint32 feeRate = FHE.select(isPremiumUser, PREMIUM_FEE, STANDARD_FEE); euint32 totalFee = FHE.mul(amount, feeRate); ``` +### 6. Require + +Simulate `require` statements by returning encrypted zero instead of reverting when a condition fails: + +```solidity +// Check if user has sufficient balance +ebool hasSufficientBalance = userBalance.gte(amount); + +// If condition fails, use encrypted zero; otherwise use the actual amount +euint32 transferAmount = FHE.select(hasSufficientBalance, amount, FHE.asEuint32(0)); + +// Process the transfer (will be zero if condition wasn't met) +userBalance = userBalance.sub(transferAmount); +recipientBalance = recipientBalance.add(transferAmount); +``` + + +This pattern simulates transaction invalidation by using encrypted zero when conditions aren't met, effectively making the operation a no-op while maintaining constant-time execution. Learn more in the [Require](/fhe-library/core-concepts/require) guide. + + --- ## Best Practices From fc18079b86bc45da6c72086a214ea8b1429528f4 Mon Sep 17 00:00:00 2001 From: Alexandre Carvalheira Date: Wed, 25 Feb 2026 21:17:35 -0300 Subject: [PATCH 5/6] Update fhe-library/core-concepts/require.mdx Co-Authored-By: mintlify[bot] <109931778+mintlify[bot]@users.noreply.github.com> --- fhe-library/core-concepts/require.mdx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/fhe-library/core-concepts/require.mdx b/fhe-library/core-concepts/require.mdx index 73b1742..a966f9a 100644 --- a/fhe-library/core-concepts/require.mdx +++ b/fhe-library/core-concepts/require.mdx @@ -31,18 +31,22 @@ Both require branching logic that reveals information about encrypted data, whic ## Working with Require in FHE -To use `require` with encrypted conditions, you must first decrypt the condition. This should only be done when the result can be safely revealed: +Since decryption is asynchronous, you cannot use traditional `require` statements with encrypted conditions in the same transaction. Instead, simulate the behavior by using encrypted zero when conditions fail: ```solidity -// Decrypt the encrypted boolean before using in require -ebool encryptedCondition = value.gt(threshold); -bool condition = FHE.decrypt(encryptedCondition); +// Check if user has sufficient balance +ebool hasSufficientBalance = userBalance.gte(amount); -require(condition, "Condition not met"); +// If condition fails, use encrypted zero; otherwise use the actual amount +euint32 transferAmount = FHE.select(hasSufficientBalance, amount, FHE.asEuint32(0)); + +// Process the transfer (will be zero if condition wasn't met) +userBalance = userBalance.sub(transferAmount); +recipientBalance = recipientBalance.add(transferAmount); ``` -Only decrypt conditions when revealing the result doesn't compromise privacy. For internal logic that must remain private, use `FHE.select` instead as shown in the [Conditions (if .. else)](/fhe-library/core-concepts/conditions) guide. +This pattern simulates transaction invalidation by using encrypted zero when conditions aren't met, effectively making the operation a no-op while maintaining constant-time execution and privacy. --- From fa95768fed520585eb41fda3a8443be3cc2ee87c Mon Sep 17 00:00:00 2001 From: Alexandre Carvalheira Date: Wed, 25 Feb 2026 21:17:38 -0300 Subject: [PATCH 6/6] Update fhe-library/core-concepts/conditions.mdx Co-Authored-By: mintlify[bot] <109931778+mintlify[bot]@users.noreply.github.com> --- fhe-library/core-concepts/conditions.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fhe-library/core-concepts/conditions.mdx b/fhe-library/core-concepts/conditions.mdx index 05331d3..bec1a15 100644 --- a/fhe-library/core-concepts/conditions.mdx +++ b/fhe-library/core-concepts/conditions.mdx @@ -137,7 +137,7 @@ euint32 totalFee = FHE.mul(amount, feeRate); ### 6. Require -Simulate `require` statements by returning encrypted zero instead of reverting when a condition fails: +Simulate `require` statements by using encrypted zero when a condition fails: ```solidity // Check if user has sufficient balance