Contract Address
Data Structures
Ciphertext
PublicKey
PrivateKey
Core Functions
Addition Operations
add
a: First encrypted valueb: Second encrypted valuepublicKey: Public key parameters
BigNumber: Encrypted sum E(m₁ + m₂)
add_const
a: Encrypted valueb: Plaintext constant to addpublicKey: Public key parameters
BigNumber: Encrypted result E(m + k)
Subtraction Operations
sub
a: Encrypted minuendb: Encrypted subtrahendpublicKey: Public key parameters
BigNumber: Encrypted difference E(m₁ - m₂)
sub_const
a: Encrypted valueb: Plaintext constant to subtractpublicKey: Public key parameters
BigNumber: Encrypted result E(m - k)
Multiplication and Division
mul_const
a: Encrypted valueb: Plaintext multiplierpublicKey: Public key parameters
BigNumber: Encrypted product E(m * k)
div_const
a: Encrypted valueb: Plaintext divisorpublicKey: Public key parameters
BigNumber: Encrypted quotient E(m / k)
Cryptographic Operations
encryptZero
rnd: Random value for probabilistic encryptionpublicKey: Public key parameters
BigNumber: Encryption of zero E(0)
encrypt
value: Plaintext value to encryptrnd: Random value for probabilistic encryptionpublicKey: Public key parameters
BigNumber: Encrypted value E(m)
decrypt
encValue: Encrypted value to decryptpublicKey: Public key parametersprivateKey: Private key parameterssigma: Precomputed sigma value for efficient decryption
BigNumber: Decrypted plaintext value
sigma parameter is a precomputed value to avoid expensive big integer division on-chain. The contract verifies that the provided sigma is correct before completing the decryption.
Security Considerations
Key Generation
- Keys should be generated off-chain using secure random number generation
- Public and private keys should have sufficient bit length (recommended: 2048 bits)
- Private keys should never be exposed or stored on-chain
Parameter Validation
Gas Optimization
-
Batch Operations
-
Parameter Size
- Use minimum required bit lengths for parameters
- Consider gas costs when choosing parameter sizes
-
Operation Ordering
- Perform as many operations off-chain as possible
- Batch similar operations together
Integration Example
Error Handling
Common errors and their solutions:-
Invalid Sigma Error
Solution: Ensure sigma is correctly precomputed off-chain
-
Gas Limit Exceeded
Solution: Batch operations or reduce parameter sizes
-
Invalid Parameter Size
Solution: Use appropriate key sizes (≥2048 bits)