Random
Shift Operations in TFHE
The TFHE.shr and TFHE.shl shift operations work with an encrypted integer type (euintX) as the first operand and either uint8 or euint8 as the second operand. The second operand is computed modulo the bit width of the first operand.
Example:
Copy
This results in:
Copy
This differs from standard Solidity shifts where, for instance, a right shift (>>) could result in a null value if the operand exceeds the bit width.
Supported Operators for Encrypted Integers
TFHE supports overloaded operators like +, -, *, &, etc., for encrypted integers. These operators invoke versions without overflow checks by default.
Comparison Operations
In Fully Homomorphic Encryption (FHE), comparison operations yield encrypted boolean results of type ebool. As ebool maintains confidentiality, it cannot be directly used in standard boolean operations.
To address this, the fhEVM framework provides the select function, which is similar to a ternary operator. It enables conditional assignments based on ebool values.
Example:
Copy
Explanation:
Decryption: The encryptedValue is decrypted into an euint64 type using TFHE.asEuint64, preserving confidentiality.
Comparison: The TFHE.lt function compares the current highestBid with the new bid, producing an ebool that indicates if the new bid is higher.
Conditional Assignment: The TFHE.select function updates highestBid based on the isAbove condition.
Error Handling in Encrypted Smart Contracts
Error handling requires custom strategies, as failed conditions in encrypted contracts do not automatically revert transactions. Instead, an error handler records the latest error information for each wallet.
Example:
Copy
Random Number Generation
TFHE enables fully on-chain random number generation with the following functions:
Copy
Encrypted Inputs
Encrypted inputs are fundamental to fhEVM, allowing users to push encrypted data onto the blockchain securely. Users must provide proof of knowledge of the plaintext to prevent ciphertext reuse.
Function Example:
Copy
Client-Side Implementation:
Copy
Access Control List (ACL) System
fhEVM includes an ACL system to define which addresses can manipulate ciphertexts. This feature ensures that unauthorized addresses cannot access or modify the contents of any ciphertext. Two types of allowances are supported:
Permanent Allowance:
Copy
Grants permanent access to a ciphertext for a specific address on the blockchain.
The ciphertext can be used by the authorized address at any time.
The ACL is stored in a dedicated contract.
Temporary Allowance:
Copy
Grants temporary access to a ciphertext for the duration of a transaction.
The ACL is stored in transient storage, saving gas costs.
Particularly useful when calling an external function using a ciphertext as a parameter.
Example: Function Calling Another Function
Copy
Last updated