The Counter Example
Imagine a smart contract called Counter where each user has their own private counter. Users can increment their counter and read its value with complete privacy—no one, including the smart contract itself, can see the actual counter values.Key Concepts
- Public Key = A lock that anyone can use to seal data
- Private Key = The unique key to unlock sealed data
- CoFHE Co-Processor = Fhenix’s off-chain service that handles FHE operations
- Ciphertext = Encrypted data that can be computed on without decryption
1
Encrypting Input Data
When a user wants to add
5 to their counter, the data must first be encrypted before being sent to the smart contract.What happens:- The user’s plaintext value
5is encrypted using the CoFHE co-processor’s public key - This creates ciphertext—encrypted data that appears as random bytes
- The ciphertext is sent to the smart contract on-chain
- The blockchain sees only encrypted data, never the actual value
5
The “Locked Box” Analogy
Think of this as placing the value5 in a box and locking it with the CoFHE co-processor’s public key. The locked box (ciphertext) can be sent to the smart contract, but no one can see what’s inside without the private key.2
Performing Computations on Encrypted Data
Once the encrypted data reaches the smart contract, FHE magic happens. The smart contract can perform arithmetic operations directly on the ciphertext without ever decrypting it.What happens:
- The smart contract receives the encrypted value
- It retrieves the user’s encrypted counter from storage (also encrypted)
- Using FHE operations, it adds the encrypted values together
- The result is stored as encrypted data
- Critical: At no point does the smart contract, blockchain, or anyone else see the actual numbers
FHE Computation Magic
This is where Fully Homomorphic Encryption shines. The CoFHE co-processor enables the smart contract to:- Add encrypted values together
- Compare encrypted values
- Perform other arithmetic operations
- All while the data remains encrypted and private
3
Retrieving Encrypted Output
When a user wants to read their counter value, they need to retrieve the encrypted data and decrypt it. However, the data is encrypted with the CoFHE co-processor’s public key, so the user needs to request re-encryption.What happens:
- The user retrieves their encrypted counter from the smart contract
- The data is still encrypted with the CoFHE co-processor’s public key
- The user creates a permit with their own public key
- The smart contract requests the CoFHE co-processor to re-encrypt the data
- The co-processor removes its encryption and re-encrypts with the user’s public key
- The user can now decrypt the data using their private key
The “Lock Exchange” Analogy
This is like exchanging locks on the box:- The box starts locked with the CoFHE co-processor’s lock
- The user sends their own lock to the co-processor
- The co-processor removes its lock and applies the user’s lock
- The box remains locked throughout, but now only the user can open it
- The data remains private at every step
The Complete Flow
Key Takeaways
- Encryption happens client-side: Cofhejs encrypts data before it reaches the blockchain
- Computation happens on-chain: Smart contracts perform operations on encrypted data
- FHE enables privacy-preserving computation: The blockchain never sees plaintext values
- Re-encryption enables access control: Only authorized users can decrypt their own data
- CoFHE co-processor is essential: It handles the complex FHE operations off-chain