Back to Fhevm

Supported types

docs/solidity-guides/types.md

0.12.34.0 KB
Original Source

Supported types

This document introduces the encrypted integer types provided by the FHE library in FHEVM and explains their usage, including casting, state variable declarations, and type-specific considerations.

Introduction

The FHE library offers a robust type system with encrypted integer types, enabling secure computations on confidential data in smart contracts. These encrypted types are validated both at compile time and runtime to ensure correctness and security.

Key features of encrypted types

  • Encrypted integers function similarly to Solidity’s native integer types, but they operate on Fully Homomorphic Encryption (FHE) ciphertexts.
  • Arithmetic operations on e(u)int types are unchecked, meaning they wrap around on overflow. This design choice ensures confidentiality by avoiding the leakage of information through error detection.
  • Future versions of the FHE library will support encrypted integers with overflow checking, but with the trade-off of exposing limited information about the operands.

{% hint style="info" %} Encrypted integers with overflow checking will soon be available in the FHE library. These will allow reversible arithmetic operations but may reveal some information about the input values. {% endhint %}

Encrypted integers in FHEVM are represented as FHE ciphertexts, abstracted using ciphertext handles. These types, prefixed with e (for example, euint64) act as secure wrappers over the ciphertext handles.

List of encrypted types

The FHE library currently supports the following encrypted types:

TypeBit LengthSupported OperatorsAliases (with supported operators)
Ebool2and, or, xor, eq, ne, not, select, rand
Euint88add, sub, mul, div, rem, and, or, xor, shl, shr, rotl, rotr, eq, ne, ge, gt, le, lt, min, max, neg, not, select, rand, randBounded
Euint1616add, sub, mul, div, rem, and, or, xor, shl, shr, rotl, rotr, eq, ne, ge, gt, le, lt, min, max, neg, not, select, rand, randBounded
Euint3232add, sub, mul, div, rem, and, or, xor, shl, shr, rotl, rotr, eq, ne, ge, gt, le, lt, min, max, neg, not, select, rand, randBounded
Euint6464add, sub, mul, div, rem, and, or, xor, shl, shr, rotl, rotr, eq, ne, ge, gt, le, lt, min, max, neg, not, select, rand, randBounded
Euint128128add, sub, mul, div, rem, and, or, xor, shl, shr, rotl, rotr, eq, ne, ge, gt, le, lt, min, max, neg, not, select, rand, randBounded
Euint160160Eaddress (eq, ne, select)
Euint256256and, or, xor, shl, shr, rotl, rotr, eq, ne, neg, not, select, rand, randBounded

{% hint style="info" %}
Division (div) and remainder (rem) operations are only supported when the right-hand side (rhs) operand is a plaintext (non-encrypted) value. Attempting to use an encrypted value as rhs will result in a panic. This restriction ensures correct and secure computation within the current framework. {% endhint %}

{% hint style="info" %} Higher-precision integer types are available in the TFHE-rs library and can be added to fhevm as needed. {% endhint %}