ACL examples
This page provides detailed instructions and examples on how to use and implement the ACL (Access Control List) in fhEVM. For an overview of ACL concepts and their importance, refer to the access control list (ACL) overview.
Controlling access: permanent and transient allowances
The ACL system allows you to define two types of permissions for accessing ciphertexts:
Permanent allowance
Function:
TFHE.allow(ciphertext, address)
Purpose: Grants persistent access to a ciphertext for a specific address.
Storage: Permissions are saved in a dedicated ACL contract, making them available across transactions.
Transient allowance
Function:
TFHE.allowTransient(ciphertext, address)
Purpose: Grants temporary access for the duration of a single transaction.
Storage: Permissions are stored in transient storage to save gas costs.
Use Case: Ideal for passing encrypted values between functions or contracts during a transaction.
Syntactic sugar
Function:
TFHE.allowThis(ciphertext)
Equivalent To:
TFHE.allow(ciphertext, address(this))
Purpose: Simplifies granting permanent access to the current contract for managing ciphertexts.
Example: granting permissions in a multi-contract setup
Automatic transient allowance
Some functions automatically grant transient allowances to the calling contract, simplifying workflow. These include:
Type Conversion:
TFHE.asEuintXX()
,TFHE.asEbool()
,TFHE.asEaddress()
Random Value Generation:
TFHE.randXX()
Computation Results:
TFHE.add()
,TFHE.select()
Example: random value generation
🔧 Best practices
Verifying sender access
When processing ciphertexts as input, it’s essential to validate that the sender is authorized to interact with the provided encrypted data. Failing to perform this verification can expose the system to inference attacks where malicious actors attempt to deduce private information.
Example scenario: Encrypted ERC20 attack
Consider an Encrypted ERC20 token. An attacker controlling two accounts, Account A and Account B, with 100 tokens in Account A, could exploit the system as follows:
The attacker attempts to send the target user's encrypted balance from Account A to Account B.
Observing the transaction outcome, the attacker gains information:
If successful: The target's balance is equal to or less than 100 tokens.
If failed: The target's balance exceeds 100 tokens.
This type of attack allows the attacker to infer private balances without explicit access.
To prevent this, always use the TFHE.isSenderAllowed()
function to verify that the sender has legitimate access to the encrypted amount being transferred.
Example: secure verification
By enforcing this check, you can safeguard against inference attacks and ensure that encrypted values are only manipulated by authorized entities.
ACL for reencryption
If a ciphertext can be reencrypted by a user, explicit access must be granted to them. Additionally, the reencryption mechanism requires the signature of a public key associated with the contract address. Therefore, a value that needs to be reencrypted must be explicitly authorized for both the user and the contract.
Due to the reencryption mechanism, a user signs a public key associated with a specific contract; therefore, the ciphertext also needs to be allowed for the contract.
Example: Secure Transfer in Encrypted ERC-20
By understanding how to grant and verify permissions, you can effectively manage access to encrypted data in your fhEVM smart contracts. For additional context, see the ACL overview.
Last updated