create-fhevm-example 1.4.8 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/contracts/advanced/BlindAuction.sol +3 -6
- package/contracts/advanced/EncryptedEscrow.sol +3 -6
- package/contracts/advanced/HiddenVoting.sol +4 -5
- package/contracts/advanced/PrivateKYC.sol +3 -8
- package/contracts/advanced/PrivatePayroll.sol +3 -5
- package/contracts/basic/decryption/PublicDecryptMultipleValues.sol +4 -7
- package/contracts/basic/decryption/PublicDecryptSingleValue.sol +3 -6
- package/contracts/basic/decryption/UserDecryptMultipleValues.sol +4 -7
- package/contracts/basic/decryption/UserDecryptSingleValue.sol +4 -7
- package/contracts/basic/encryption/EncryptMultipleValues.sol +4 -6
- package/contracts/basic/encryption/FHECounter.sol +3 -5
- package/contracts/basic/fhe-operations/FHEAdd.sol +3 -6
- package/contracts/basic/fhe-operations/FHEArithmetic.sol +4 -7
- package/contracts/basic/fhe-operations/FHEComparison.sol +4 -8
- package/contracts/basic/fhe-operations/FHEIfThenElse.sol +4 -7
- package/contracts/concepts/antipatterns/ControlFlow.sol +3 -5
- package/contracts/concepts/antipatterns/OperationsGasNoise.sol +6 -7
- package/contracts/concepts/antipatterns/Permissions.sol +3 -5
- package/contracts/concepts/core/FHEAccessControl.sol +3 -5
- package/contracts/concepts/core/FHEEdgeCases.sol +376 -0
- package/contracts/concepts/core/FHEHandles.sol +4 -7
- package/contracts/concepts/core/FHEInputProof.sol +4 -6
- package/contracts/gaming/EncryptedLottery.sol +3 -7
- package/contracts/gaming/EncryptedPoker.sol +3 -7
- package/contracts/gaming/RockPaperScissors.sol +4 -8
- package/contracts/openzeppelin/ERC7984.sol +4 -8
- package/contracts/openzeppelin/ERC7984ERC20Wrapper.sol +3 -6
- package/contracts/openzeppelin/SwapERC7984ToERC20.sol +3 -6
- package/contracts/openzeppelin/SwapERC7984ToERC7984.sol +3 -5
- package/contracts/openzeppelin/VestingWallet.sol +2 -5
- package/dist/scripts/commands/add-mode.d.ts.map +1 -1
- package/dist/scripts/commands/add-mode.js +342 -55
- package/dist/scripts/index.js +0 -0
- package/dist/scripts/shared/builders.d.ts.map +1 -1
- package/dist/scripts/shared/builders.js +7 -3
- package/dist/scripts/shared/config.d.ts.map +1 -1
- package/dist/scripts/shared/config.js +41 -29
- package/package.json +1 -2
- package/test/advanced/BlindAuction.ts +66 -3
- package/test/advanced/EncryptedEscrow.ts +73 -3
- package/test/advanced/HiddenVoting.ts +63 -2
- package/test/advanced/PrivateKYC.ts +45 -2
- package/test/advanced/PrivatePayroll.ts +58 -1
- package/test/basic/decryption/PublicDecryptMultipleValues.ts +17 -9
- package/test/basic/decryption/PublicDecryptSingleValue.ts +22 -14
- package/test/basic/decryption/UserDecryptMultipleValues.ts +13 -4
- package/test/basic/decryption/UserDecryptSingleValue.ts +15 -7
- package/test/basic/encryption/EncryptMultipleValues.ts +25 -14
- package/test/basic/encryption/EncryptSingleValue.ts +4 -2
- package/test/basic/encryption/FHECounter.ts +21 -5
- package/test/basic/fhe-operations/FHEAdd.ts +13 -9
- package/test/basic/fhe-operations/FHEArithmetic.ts +15 -3
- package/test/basic/fhe-operations/FHEComparison.ts +14 -2
- package/test/basic/fhe-operations/FHEIfThenElse.ts +12 -9
- package/test/concepts/antipatterns/ControlFlow.ts +14 -2
- package/test/concepts/antipatterns/OperationsGasNoise.ts +15 -2
- package/test/concepts/antipatterns/Permissions.ts +14 -7
- package/test/concepts/core/FHEAccessControl.ts +11 -4
- package/test/concepts/core/FHEEdgeCases.ts +460 -0
- package/test/concepts/core/FHEHandles.ts +9 -3
- package/test/concepts/core/FHEInputProof.ts +9 -4
- package/test/gaming/EncryptedLottery.ts +65 -1
- package/test/gaming/EncryptedPoker.ts +67 -3
- package/test/gaming/RockPaperScissors.ts +56 -5
- package/test/openzeppelin/ERC7984.ts +28 -25
- package/test/openzeppelin/ERC7984ERC20Wrapper.ts +10 -1
- package/test/openzeppelin/SwapERC7984ToERC20.ts +15 -5
- package/test/openzeppelin/SwapERC7984ToERC7984.ts +15 -10
- package/test/openzeppelin/VestingWallet.ts +15 -5
|
@@ -10,15 +10,12 @@ import {
|
|
|
10
10
|
import {ZamaEthereumConfig} from "@fhevm/solidity/config/ZamaConfig.sol";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* @notice Blind auction where bids remain encrypted until the end.
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* Only the winning bid amount is revealed after the auction closes.
|
|
17
|
-
* Losing bids remain private forever, ensuring true bid confidentiality.
|
|
13
|
+
* @notice Blind auction where bids remain fully encrypted until the end.
|
|
14
|
+
* Uses FHE.gt/select to find the winner without decrypting losing bids.
|
|
15
|
+
* Only the winning amount is revealed after the auction closes.
|
|
18
16
|
|
|
19
17
|
* @dev Flow: bid() → endAuction() → revealWinner()
|
|
20
18
|
* Uses FHE.gt/select to find winner without revealing losing bids.
|
|
21
|
-
* Losing bids remain encrypted forever!
|
|
22
19
|
*/
|
|
23
20
|
contract BlindAuction is ZamaEthereumConfig {
|
|
24
21
|
enum AuctionState {
|
|
@@ -10,14 +10,11 @@ import {
|
|
|
10
10
|
import {ZamaEthereumConfig} from "@fhevm/solidity/config/ZamaConfig.sol";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* @notice Confidential escrow service with hidden transaction amounts.
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* view until release or refund. Includes arbiter for dispute resolution.
|
|
17
|
-
* Perfect for high-value transactions requiring privacy.
|
|
13
|
+
* @notice Confidential escrow service with hidden transaction amounts and arbiters.
|
|
14
|
+
* Secures funds with encrypted amounts. Details remain hidden until
|
|
15
|
+
* release or refund, supporting multi-party dispute resolution.
|
|
18
16
|
*
|
|
19
17
|
* @dev Flow: createEscrow() → fundEscrow() → release()/requestRefund()/raiseDispute()
|
|
20
|
-
* Multi-party agreement with arbiter for disputes.
|
|
21
18
|
*/
|
|
22
19
|
contract EncryptedEscrow is ZamaEthereumConfig {
|
|
23
20
|
enum EscrowState {
|
|
@@ -5,11 +5,9 @@ import {FHE, euint64, ebool, externalEuint8} from "@fhevm/solidity/lib/FHE.sol";
|
|
|
5
5
|
import {ZamaEthereumConfig} from "@fhevm/solidity/config/ZamaConfig.sol";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* @notice Private voting system with homomorphic vote tallying.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* final tally is revealed - individual votes remain private forever.
|
|
12
|
-
* Perfect for DAO governance, elections, or any scenario requiring ballot secrecy.
|
|
8
|
+
* @notice Private voting system with homomorphic vote tallying (Yes/No).
|
|
9
|
+
* Ballots are added without decryption. Only final totals are revealed,
|
|
10
|
+
* ensuring individual vote secrecy forever.
|
|
13
11
|
*
|
|
14
12
|
* @dev Flow: vote() → closeVoting() → revealResults()
|
|
15
13
|
* ⚡ Gas: Each vote costs ~200k gas (FHE.add + FHE.select operations)
|
|
@@ -118,6 +116,7 @@ contract HiddenVoting is ZamaEthereumConfig {
|
|
|
118
116
|
);
|
|
119
117
|
_noVotes = FHE.add(_noVotes, noIncrement);
|
|
120
118
|
|
|
119
|
+
FHE.allowThis(_yesVotes);
|
|
121
120
|
FHE.allowThis(_noVotes);
|
|
122
121
|
|
|
123
122
|
hasVoted[msg.sender] = true;
|
|
@@ -12,16 +12,11 @@ import {
|
|
|
12
12
|
import {ZamaEthereumConfig} from "@fhevm/solidity/config/ZamaConfig.sol";
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* @notice Privacy-preserving
|
|
16
|
-
* Users submit encrypted
|
|
17
|
-
*
|
|
18
|
-
* without learning the actual values. Returns encrypted booleans that
|
|
19
|
-
* prove compliance without revealing sensitive information. Revolutionary
|
|
20
|
-
* for KYC/AML compliance while preserving user privacy.
|
|
15
|
+
* @notice Privacy-preserving KYC using encrypted predicate proofs (e.g., 18+ check).
|
|
16
|
+
* Users submit encrypted data. The contract verifies compliance without
|
|
17
|
+
* learning actual values, returning encrypted booleans.
|
|
21
18
|
*
|
|
22
19
|
* @dev Flow: submitKYC() → verifyAge18()/verifyGoodCredit()/etc.
|
|
23
|
-
* Returns encrypted booleans: "Is 18+?", "Good credit?" without revealing actual values.
|
|
24
|
-
* ⚠️ Production KYC needs trusted attesters!
|
|
25
20
|
*/
|
|
26
21
|
contract PrivateKYC is ZamaEthereumConfig {
|
|
27
22
|
struct Identity {
|
|
@@ -10,11 +10,9 @@ import {
|
|
|
10
10
|
import {ZamaEthereumConfig} from "@fhevm/solidity/config/ZamaConfig.sol";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* @notice Confidential payroll system with encrypted salaries.
|
|
14
|
-
* Employers
|
|
15
|
-
*
|
|
16
|
-
* Demonstrates selective decryption permissions where different users
|
|
17
|
-
* see different encrypted values. Perfect for privacy-preserving HR systems.
|
|
13
|
+
* @notice Confidential payroll system with encrypted salaries and selective access.
|
|
14
|
+
* Employers manage employees with hidden salaries. Only the owner and the
|
|
15
|
+
* respective employee can access specific salary data.
|
|
18
16
|
*
|
|
19
17
|
* @dev Flow: addEmployee() → fund() → processPayment()
|
|
20
18
|
* Each employee can decrypt only their own salary.
|
|
@@ -5,14 +5,11 @@ import {FHE, euint8} from "@fhevm/solidity/lib/FHE.sol";
|
|
|
5
5
|
import {ZamaEthereumConfig} from "@fhevm/solidity/config/ZamaConfig.sol";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* @notice
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* checkSignatures() where ORDER MATTERS - the cts[] array must match
|
|
12
|
-
* the order of values in the ABI-encoded result.
|
|
8
|
+
* @notice Dice game demonstrating public decryption of multiple encrypted values.
|
|
9
|
+
* Shows how to use checkSignatures() with multiple values, highlighting
|
|
10
|
+
* that the order in cts[] must match the ABI-encoded results.
|
|
13
11
|
*
|
|
14
|
-
* @dev Uses FHE.randEuint8()
|
|
15
|
-
* ⚠️ Order matters in cts[] array for checkSignatures!
|
|
12
|
+
* @dev Uses FHE.randEuint8() and FHE.makePubliclyDecryptable().
|
|
16
13
|
*/
|
|
17
14
|
contract HighestDieRoll is ZamaEthereumConfig {
|
|
18
15
|
// Simple counter to assign a unique ID to each new game.
|
|
@@ -6,13 +6,10 @@ import {ZamaEthereumConfig} from "@fhevm/solidity/config/ZamaConfig.sol";
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @notice Heads or Tails game with public, permissionless decryption.
|
|
9
|
-
* Demonstrates makePubliclyDecryptable()
|
|
10
|
-
*
|
|
11
|
-
* lottery winners, or voting tallies. Uses FHE.randEbool() for fair
|
|
12
|
-
* randomness and KMS-verified decryption proofs.
|
|
9
|
+
* Demonstrates FHE.makePubliclyDecryptable(), allowing any user to
|
|
10
|
+
* decrypt results like game outcomes or voting tallies using KMS proofs.
|
|
13
11
|
*
|
|
14
|
-
* @dev Uses FHE.randEbool()
|
|
15
|
-
* Anyone can decrypt results with valid KMS proof.
|
|
12
|
+
* @dev Uses FHE.randEbool() and FHE.makePubliclyDecryptable().
|
|
16
13
|
*/
|
|
17
14
|
contract HeadsOrTails is ZamaEthereumConfig {
|
|
18
15
|
/// Simple counter to assign a unique ID to each new game.
|
|
@@ -5,14 +5,11 @@ import {FHE, ebool, euint32, euint64} from "@fhevm/solidity/lib/FHE.sol";
|
|
|
5
5
|
import {ZamaEthereumConfig} from "@fhevm/solidity/config/ZamaConfig.sol";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* @notice Decrypting multiple encrypted values
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* for permissions (unlike input proofs). Demonstrates the pattern of
|
|
12
|
-
* granting allowThis() for each value separately.
|
|
8
|
+
* @notice Decrypting multiple encrypted values (ebool, euint32, euint64) for a user.
|
|
9
|
+
* Highlights that each value requires individual permission grants,
|
|
10
|
+
* as there is no batching for FHE.allow() or FHE.allowThis().
|
|
13
11
|
*
|
|
14
|
-
* @dev
|
|
15
|
-
* ⚠️ Cannot batch permission grants - must call allow() for each value!
|
|
12
|
+
* @dev Individual permissions are required for each encrypted value.
|
|
16
13
|
*/
|
|
17
14
|
contract UserDecryptMultipleValues is ZamaEthereumConfig {
|
|
18
15
|
ebool private _encryptedBool;
|
|
@@ -5,14 +5,11 @@ import {FHE, euint32} from "@fhevm/solidity/lib/FHE.sol";
|
|
|
5
5
|
import {ZamaEthereumConfig} from "@fhevm/solidity/config/ZamaConfig.sol";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* @notice User-controlled decryption with
|
|
9
|
-
* Demonstrates the
|
|
10
|
-
*
|
|
11
|
-
* the user permission to decrypt. Missing either step causes decryption
|
|
12
|
-
* to fail. Includes examples of both correct and incorrect patterns.
|
|
8
|
+
* @notice User-controlled decryption with mandatory two-step permissions.
|
|
9
|
+
* Demonstrates the pattern: allowThis() for contract storage/computation
|
|
10
|
+
* and allow() for user decryption, illustrating correct vs incorrect usage.
|
|
13
11
|
*
|
|
14
|
-
* @dev
|
|
15
|
-
* ⚠️ Both allowThis + allow required for user decryption!
|
|
12
|
+
* @dev Both allowThis and allow are required for successful user decryption.
|
|
16
13
|
*/
|
|
17
14
|
contract UserDecryptSingleValue is ZamaEthereumConfig {
|
|
18
15
|
euint32 private _trivialEuint32;
|
|
@@ -13,13 +13,11 @@ import {
|
|
|
13
13
|
import {ZamaEthereumConfig} from "@fhevm/solidity/config/ZamaConfig.sol";
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* @notice Efficient handling of multiple encrypted values
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* per additional value compared to separate proofs.
|
|
16
|
+
* @notice Efficient handling of multiple encrypted values via batched inputs.
|
|
17
|
+
* Uses a single proof for multiple values (ebool, euint32, eaddress),
|
|
18
|
+
* saving significant gas compared to separate proofs.
|
|
20
19
|
*
|
|
21
|
-
* @dev
|
|
22
|
-
* ⚡ Gas: Batching saves ~50k gas vs separate proofs!
|
|
20
|
+
* @dev Batching saves ~50k gas per additional value.
|
|
23
21
|
*/
|
|
24
22
|
contract EncryptMultipleValues is ZamaEthereumConfig {
|
|
25
23
|
ebool private _encryptedEbool;
|
|
@@ -6,12 +6,10 @@ import {ZamaEthereumConfig} from "@fhevm/solidity/config/ZamaConfig.sol";
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @notice Confidential counter with encrypted increment/decrement operations.
|
|
9
|
-
* Demonstrates the
|
|
10
|
-
*
|
|
11
|
-
* only accessible through decryption by authorized users.
|
|
9
|
+
* Demonstrates the FHE workflow: encryption, computation, and permission
|
|
10
|
+
* management while keeping the counter value private.
|
|
12
11
|
|
|
13
|
-
* @dev
|
|
14
|
-
* All arithmetic happens on encrypted values without revealing the count.
|
|
12
|
+
* @dev Workflow: fromExternal (validation) → arithmetic → permissions.
|
|
15
13
|
*/
|
|
16
14
|
contract FHECounter is ZamaEthereumConfig {
|
|
17
15
|
euint32 private _count;
|
|
@@ -6,13 +6,10 @@ import {ZamaEthereumConfig} from "@fhevm/solidity/config/ZamaConfig.sol";
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @notice Introduction to homomorphic addition on encrypted values.
|
|
9
|
-
* Demonstrates
|
|
10
|
-
*
|
|
11
|
-
* encrypted inputs, performing the addition, and granting permissions
|
|
12
|
-
* for both contract storage and user decryption.
|
|
9
|
+
* Demonstrates adding two encrypted numbers without decryption, including
|
|
10
|
+
* input handling, addition, and permission management.
|
|
13
11
|
|
|
14
|
-
* @dev Shows the
|
|
15
|
-
* ⚡ Gas: FHE.add() costs ~100k gas (coprocessor call)
|
|
12
|
+
* @dev Shows the basic FHE operation and permission flow (FHE.add ~100k gas).
|
|
16
13
|
*/
|
|
17
14
|
contract FHEAdd is ZamaEthereumConfig {
|
|
18
15
|
euint8 private _a;
|
|
@@ -5,14 +5,11 @@ import {FHE, euint32, externalEuint32} from "@fhevm/solidity/lib/FHE.sol";
|
|
|
5
5
|
import {ZamaEthereumConfig} from "@fhevm/solidity/config/ZamaConfig.sol";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* @notice
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* and important limitations (e.g., division/remainder only work with
|
|
12
|
-
* plaintext divisors, not encrypted divisors).
|
|
8
|
+
* @notice FHE arithmetic (add, sub, mul, div, rem, min, max) on encrypted values.
|
|
9
|
+
* Includes gas cost comparisons and key limitations, such as plaintext
|
|
10
|
+
* divisors for division and remainder operations.
|
|
13
11
|
*
|
|
14
|
-
* @dev
|
|
15
|
-
* ⚠️ div/rem only work with plaintext divisor (not encrypted!)
|
|
12
|
+
* @dev div/rem only work with plaintext divisors (not encrypted).
|
|
16
13
|
*/
|
|
17
14
|
contract FHEArithmetic is ZamaEthereumConfig {
|
|
18
15
|
euint32 private _a;
|
|
@@ -10,15 +10,11 @@ import {
|
|
|
10
10
|
import {ZamaEthereumConfig} from "@fhevm/solidity/config/ZamaConfig.sol";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* @notice
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* without information leakage. Critical for implementing logic like
|
|
17
|
-
* "find maximum" or "check threshold" without revealing values.
|
|
13
|
+
* @notice Encrypted comparisons (eq, ne, gt, lt, ge, le) and conditional selection.
|
|
14
|
+
* Demonstrates FHE.select for branching without information leakage,
|
|
15
|
+
* essential for "find maximum" or threshold logic.
|
|
18
16
|
*
|
|
19
|
-
* @dev
|
|
20
|
-
* ⚡ Gas: Comparisons ~100k, select ~120k
|
|
21
|
-
* ❌ WRONG: if (FHE.gt(a,b)) → decrypts! ✅ CORRECT: FHE.select()
|
|
17
|
+
* @dev Comparisons return ebool; select avoids revealing values during branching.
|
|
22
18
|
*/
|
|
23
19
|
contract FHEComparison is ZamaEthereumConfig {
|
|
24
20
|
euint32 private _a;
|
|
@@ -5,14 +5,11 @@ import {FHE, ebool, euint8, externalEuint8} from "@fhevm/solidity/lib/FHE.sol";
|
|
|
5
5
|
import {ZamaEthereumConfig} from "@fhevm/solidity/config/ZamaConfig.sol";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* @notice Conditional logic
|
|
9
|
-
* Demonstrates
|
|
10
|
-
*
|
|
11
|
-
* and leak which branch was taken. FHE.select evaluates BOTH branches
|
|
12
|
-
* and picks one based on the encrypted condition, preserving privacy.
|
|
8
|
+
* @notice Conditional logic using FHE.select for privacy-preserving branching.
|
|
9
|
+
* Demonstrates if-then-else logic on encrypted values. Unlike regular
|
|
10
|
+
* if/else, FHE.select avoids information leakage by evaluating both branches.
|
|
13
11
|
*
|
|
14
|
-
* @dev
|
|
15
|
-
* ⚡ Gas: ~120k for select operation
|
|
12
|
+
* @dev Evaluates both branches using encrypted conditions (FHE.select ~120k gas).
|
|
16
13
|
*/
|
|
17
14
|
contract FHEIfThenElse is ZamaEthereumConfig {
|
|
18
15
|
euint8 private _a;
|
|
@@ -11,12 +11,10 @@ import {ZamaEthereumConfig} from "@fhevm/solidity/config/ZamaConfig.sol";
|
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* @notice Control flow anti-patterns in FHE development.
|
|
14
|
-
* Demonstrates
|
|
15
|
-
*
|
|
14
|
+
* Demonstrates mistakes with conditional logic and loops on encrypted
|
|
15
|
+
* values, providing correct vs incorrect implementations.
|
|
16
16
|
*
|
|
17
|
-
* @dev Covers
|
|
18
|
-
* and encrypted loop iterations.
|
|
19
|
-
* Each shows ❌ WRONG and ✅ CORRECT implementations.
|
|
17
|
+
* @dev Covers if/else branching, require statements, and encrypted loops.
|
|
20
18
|
*/
|
|
21
19
|
contract FHEControlFlowAntiPatterns is ZamaEthereumConfig {
|
|
22
20
|
euint32 private _secretBalance;
|
|
@@ -11,11 +11,10 @@ import {ZamaEthereumConfig} from "@fhevm/solidity/config/ZamaConfig.sol";
|
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* @notice Operations, gas, and noise anti-patterns in FHE development.
|
|
14
|
-
*
|
|
15
|
-
* inefficient encrypted computation patterns.
|
|
14
|
+
* Covers performance issues, side-channel leaks, noise accumulation,
|
|
15
|
+
* and inefficient encrypted computation patterns.
|
|
16
16
|
*
|
|
17
|
-
* @dev
|
|
18
|
-
* deprecated APIs, and type mismatches.
|
|
17
|
+
* @dev Explores timing side channels, noise, deprecated APIs, and type mismatches.
|
|
19
18
|
*/
|
|
20
19
|
contract FHEOperationsGasNoiseAntiPatterns is ZamaEthereumConfig {
|
|
21
20
|
euint32 private _secretValue;
|
|
@@ -117,16 +116,16 @@ contract FHEOperationsGasNoiseAntiPatterns is ZamaEthereumConfig {
|
|
|
117
116
|
// ═══════════════════════════════════════════════════════════════════════
|
|
118
117
|
|
|
119
118
|
/**
|
|
120
|
-
* ❌ WRONG: Using old
|
|
119
|
+
* ❌ WRONG: Using old FHE.decrypt() pattern
|
|
121
120
|
* @dev Deprecated in FHEVM v0.9+
|
|
122
121
|
*/
|
|
123
122
|
function wrongDeprecatedAPI() external pure returns (string memory) {
|
|
124
123
|
// ❌ OLD (v0.8 and earlier):
|
|
125
|
-
//
|
|
124
|
+
// FHE.decrypt() - went through Zama Oracle
|
|
126
125
|
//
|
|
127
126
|
// This pattern is deprecated and no longer supported
|
|
128
127
|
|
|
129
|
-
return "Don't use
|
|
128
|
+
return "Don't use FHE.decrypt() - it's deprecated";
|
|
130
129
|
}
|
|
131
130
|
|
|
132
131
|
/**
|
|
@@ -6,12 +6,10 @@ import {ZamaEthereumConfig} from "@fhevm/solidity/config/ZamaConfig.sol";
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @notice Permission management anti-patterns in FHE development.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* Covers mistakes with allowThis, allow, and permission propagation
|
|
10
|
+
* across transfers and cross-contract calls.
|
|
11
11
|
*
|
|
12
|
-
* @dev
|
|
13
|
-
* view functions without permissions, unauthenticated re-encryption,
|
|
14
|
-
* transfer permission issues, and cross-contract delegation.
|
|
12
|
+
* @dev Explores missing permissions, view function failures, and delegation issues.
|
|
15
13
|
*/
|
|
16
14
|
contract FHEPermissionsAntiPatterns is ZamaEthereumConfig {
|
|
17
15
|
euint32 private _secretValue;
|
|
@@ -5,11 +5,9 @@ import {FHE, euint32, externalEuint32} from "@fhevm/solidity/lib/FHE.sol";
|
|
|
5
5
|
import {ZamaEthereumConfig} from "@fhevm/solidity/config/ZamaConfig.sol";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* @notice
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* temporary cross-contract calls. Includes correct and incorrect
|
|
12
|
-
* usage examples to prevent common decryption failures.
|
|
8
|
+
* @notice FHE permission patterns: allow() permanent, allowThis() contract,
|
|
9
|
+
* and allowTransient() temporary access. Demonstrates usage to
|
|
10
|
+
* prevent common decryption failures.
|
|
13
11
|
|
|
14
12
|
* @dev allow() = permanent, allowThis() = contract permission,
|
|
15
13
|
* allowTransient() = expires at TX end
|