Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.inco.org/llms.txt

Use this file to discover all available pages before exploring further.

Operations

Inco Lightning provides arithmetic, comparison, and bitwise operations on encrypted values.

Arithmetic Operations

All arithmetic operations return an Euint128.
FunctionDescriptionSignature
e_addAddition(Euint128, Euint128) -> Euint128
e_subSubtraction(Euint128, Euint128) -> Euint128
e_mulMultiplication(Euint128, Euint128) -> Euint128
e_remRemainder(Euint128, Euint128) -> Euint128

Example: Encrypted Addition

pub fn add_balances(
    ctx: Context<AddBalances>,
    amount_a: Euint128,
    amount_b: Euint128,
) -> Result<()> {
    let cpi_ctx = CpiContext::new(
        ctx.accounts.inco_lightning_program.to_account_info(),
        Operation {
            signer: ctx.accounts.authority.to_account_info(),
        },
    );

    // Add two encrypted values
    let result: Euint128 = e_add(cpi_ctx, amount_a, amount_b, 0)?;

    ctx.accounts.account.total = result;

    // IMPORTANT: After storing the result handle, grant decryption access
    // to the appropriate address (e.g., owner) using the `allow` function.
    // See the Access Control guide for details.

    Ok(())
}

Comparison Operations

Comparison operations return an Ebool.
FunctionDescriptionSignature
e_geGreater than or equal(Euint128, Euint128) -> Ebool
e_gtGreater than(Euint128, Euint128) -> Ebool
e_leLess than or equal(Euint128, Euint128) -> Ebool
e_ltLess than(Euint128, Euint128) -> Ebool
e_eqEqual(Euint128, Euint128) -> Ebool

Bitwise Operations

FunctionDescriptionSignature
e_andBitwise AND(Euint128, Euint128) -> Euint128
e_orBitwise OR(Euint128, Euint128) -> Euint128
e_notBitwise NOT(Euint128) -> Euint128
e_shlShift left(Euint128, Euint128) -> Euint128
e_shrShift right(Euint128, Euint128) -> Euint128

CPI Context Pattern

All operations require a CPI context with the Inco Lightning program:
let cpi_ctx = CpiContext::new(
    ctx.accounts.inco_lightning_program.to_account_info(),
    Operation {
        signer: ctx.accounts.authority.to_account_info(),
    },
);

let result = e_add(cpi_ctx, a, b, 0)?;

// IMPORTANT: Define allowance rules after each operation that produces
// a handle you want to decrypt later. See Access Control guide.
The last parameter in operation calls identifies whether the left-hand side operand is ciphertext (0) or plaintext (1). Always pass 0 when working with encrypted handles.