Skip to main content

Operations

The Inco Lightning SDK provides arithmetic, comparison, bitwise, and control flow operations on encrypted values.

Arithmetic Operations

All arithmetic operations take a CpiContext, two operands, and a scalar_byte parameter. They return Result<Euint128>.

Example: Encrypted addition with allowance

Every operation that produces a new handle requires calling allow() to grant decryption access. Use the remaining_accounts pattern to pass allowance PDAs and grant access in the same transaction. See Access Control for simulation patterns on the client side.

Comparison Operations

Comparison operations return Result<Ebool>.

Bitwise Operations

Random Number Generation

Control Flow

e_select

Conditional selection on encrypted values without revealing the condition.
Returns if_true when condition is encrypted true, if_false otherwise.

Example: Confidential transfer with balance check and allowance

This pattern ensures:
  • Balance check happens on encrypted values (no information leakage)
  • Transfer is atomic: either full amount transfers or nothing
  • No negative balances possible
  • Both source and destination owners can decrypt their new balances

Access Control Functions

Manage decryption permissions for handles.

allow

Grant or revoke decryption access for a specific address.

is_allowed

Check if an address has decryption permission for a handle.

Attestation Verification

is_validsignature

Verify Ed25519 signatures for attested decryption results.

Example

The last parameter (scalar_byte) in operation calls identifies whether the left-hand side operand is ciphertext (0) or plaintext (1). Always pass 0 when working with encrypted handles.