Ciphertext Formation

Encrypted Inputs in FHEVM

Encrypted inputs are essential in FHEVM, enabling users to securely push encrypted data onto the blockchain while protecting privacy and security. Here’s an overview of how encrypted inputs work and how you can use them effectively.

Understanding Encrypted Inputs

  • Purpose: Encrypted inputs let users securely push private data to the blockchain without revealing it.

  • Proof Requirement: To prevent malicious use or attacks, every encrypted input includes a proof of knowledge for the plaintext. This ensures that only users who know the actual value behind the encrypted data can push it to the blockchain, preventing others from reusing an encrypted value already stored.

  • Efficient Packing: Encrypted inputs are grouped together into a single ciphertext in a specified order, optimizing space and the time required for generating the zero-knowledge proof (ZKP).

Validating Encrypted Inputs in the Contract

After receiving encrypted inputs, the contract verifies each input before use. This is done by calling the TFHE.asEuintXX (or other relevant TFHE.asE... functions) with the encrypted parameter and its proof.

When calling a function in FHEVM to create a ciphertext handle, you use two types of parameters:

  1. einput: This indicates an encrypted input, given as an index of the parameter.

  2. bytes: This contains the actual ciphertext and the proof required to validate it.

For example, here’s how to validate an encrypted amount in a transfer function by converting it to an encrypted integer type:

function transfer(address to, einput encryptedAmount, bytes calldata inputProof) public {
  // Verify the provided encrypted amount
  euint64 amount = TFHE.asEuint64(encryptedAmount, inputProof);
  ...
}

Last updated