> ## Documentation Index
> Fetch the complete documentation index at: https://docs.arcium.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Quick reference

> A quick reference cheatsheet for Arcis syntax and patterns

Arcis is a Rust framework for writing MPC circuits on Solana. This page is a **quick reference**. For conceptual understanding, see [Thinking in MPC](/developers/arcis/mental-model).

<Tip>
  **Use this page when** you need quick syntax lookup while coding.
</Tip>

## Quick reference: limitations

| Category         | Supported                                                                                                                                      | Not supported                                                        |
| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
| **Control flow** | `if`, `if/else`, `else if`, `if let`, `match`, `for` loops                                                                                     | `while`, `loop`, `break`, `continue`, `let ... else`, early `return` |
| **Types**        | Integers, floats, `BaseField25519`, arrays, tuples, structs, enums and `Option<T>` (inside circuits, not encrypted instruction inputs/outputs) | `Vec`, `String`, `HashMap`                                           |
| **Functions**    | Helpers, closures, generics, traits                                                                                                            | Recursion, async/await                                               |
| **Operations**   | Arithmetic, comparisons, right shift (const)                                                                                                   | Left shift, right shift (variable)                                   |

<Tip>
  **Why?** MPC circuits must have fixed structure. See [Thinking in MPC](/developers/arcis/mental-model) for the full explanation.
</Tip>

## Basic structure

```rust theme={null}
use arcis::*;

#[encrypted]
mod my_circuit {
    use arcis::*;

    #[instruction]
    pub fn add(a: u8, b: u8) -> u16 {
        a as u16 + b as u16
    }
}
```

* `#[encrypted]` marks modules containing MPC circuits
* `#[instruction]` marks entry points callable from Solana

## Working with encrypted data

```rust theme={null}
#[instruction]
pub fn process(input: Enc<Shared, u64>) -> Enc<Shared, u64> {
    let value = input.to_arcis();      // Encrypted → secret shares
    let result = value * 2 + 10;       // Compute on shares
    input.owner.from_arcis(result)     // Secret shares → encrypted
}
```

| Owner            | Who Can Decrypt |
| ---------------- | --------------- |
| `Enc<Shared, T>` | Client AND MXE  |
| `Enc<Mxe, T>`    | MXE only        |

## Types

```rust theme={null}
// Integers
let x: u8 = 255;
let y: i64 = -1000;
let z: u128 = 10000;

// Floats (emulated fixed-point)
let pi: f64 = 3.14159;

// Arrays (fixed-size only)
let arr: [u8; 10] = [0; 10];

// Tuples and structs
let pair: (u8, u16) = (1, 2);

#[derive(Copy, Clone)]
struct Point { x: i16, y: i16 }
```

See [Types](/developers/arcis/types) for complete reference.

## Control flow

```rust theme={null}
// if/else: when condition is not a compile-time constant, both branches execute
let result = if condition { a } else { b };

// if without else (for side effects)
if should_update {
    counter += 1;
}

// else if chains work normally
let category = if value < 10 {
    0
} else if value < 100 {
    1
} else {
    2
};

// for loops: fixed iteration count required
for i in 0..10 {
    process(arr[i]);
}

// match expressions with literal, range, struct, tuple, array patterns and guards
let bucket = match x {
    v if v < 5  => 0,
    v if v < 10 => 1,
    _           => 2,
};

// plain if let
if let Point { x: 0, y } = p {
    y
} else {
    -1
}

// if let combined with && requires edition = "2024" in encrypted-ixs/Cargo.toml
if let Point { x: 0, y } = p && y > 0 {
    y
} else {
    -1
}

// matches! macro
let in_range = matches!(x, 0..=9);
let is_small = matches!(x, 0 | 1 | 2);
```

## Functions

```rust theme={null}
// Helper function
fn helper(a: u8, b: u8) -> u16 {
    a as u16 + b as u16
}

// Closures
let double = |x: u8| x * 2;

// Generics
fn set_zero<T: ArcisType + Copy>(a: &mut T) {
    *a = make_zero(*a);
}
```

See [Operations](/developers/arcis/operations#generics) for generics and traits.

## Arrays

```rust theme={null}
let arr: [u8; 10] = [0; 10];

// Constant index: O(1)
let x = arr[5];

// Secret index: O(n)
let y = arr[secret_idx];

// Methods
arr.swap(0, 1);
arr.reverse();
arr.fill(42);
arr.sort();  // O(n·log²(n)·bit_size)
```

## Iterators

```rust theme={null}
// Basic iteration
for val in arr.iter() {
    sum += *val;
}

// Chaining
arr.iter().map(|x| *x * 2).sum()
```

See [Operations](/developers/arcis/operations#iterators) for complete iterator support. Note: `.filter()` is not supported.

## Encryption patterns

```rust theme={null}
// Shared: client + MXE can decrypt
fn process(input: Enc<Shared, u64>) -> Enc<Shared, u64>

// MXE-owned: only MXE can decrypt
fn process_state(state: Enc<Mxe, GameState>) -> Enc<Mxe, GameState>

// Reveal (use carefully)
let plain = secret.reveal();

// Create MXE-owned data
let mxe_data = Mxe::get().from_arcis(value);

// EncData output (smaller callback payload)
fn verify(a: Enc<Shared, T>, observer: Shared) -> EncData<bool> {
    observer.from_arcis(result).data
}
```

See [Input/Output](/developers/arcis/input-output) for details. For `EncData` usage, see [Types](/developers/arcis/types#advanced-encdata%3Ct%3E).

## Randomness

```rust theme={null}
let coin = ArcisRNG::bool();
let num = ArcisRNG::gen_integer_from_width(64);
let uniform = ArcisRNG::gen_uniform::<[u8; 32]>();
ArcisRNG::shuffle(&mut arr);
let (val, ok) = ArcisRNG::gen_integer_in_range(1, 100, 24);
```

See [Primitives](/developers/arcis/primitives#random-number-generation) for complete RNG reference.

## Cryptography

```rust theme={null}
// Hashing
let hash = SHA3_256::new().digest(&data).reveal();

// Signature verification
let valid = vk.verify(&message, &signature).reveal();

// Key generation
let sk = SecretKey::new_rand();
let vk = VerifyingKey::from_secret_key(&sk);

// MXE signing
let sig = MXESigningKey::sign(&message).reveal();
```

See [Primitives](/developers/arcis/primitives#cryptographic-operations) for complete crypto reference.

## Field arithmetic

```rust theme={null}
// Construct
let a = BaseField25519::from_u64(42);
let b = BaseField25519::power_of_two(8);  // 256

// Arithmetic (mod 2^255 - 19)
let c = a + b;
let d = a * b;
let e = -a;

// Division (no / operator: use methods)
let inv = b.safe_inverse();           // 0 if b == 0
let quot = a.field_division(b);       // 0 if b == 0
let euc = a.euclidean_division(b);    // panics if b == 0

// Extract
let n: u64 = c.to_u64_unchecked();   // incorrect result if value exceeds u64 range
let bytes = c.to_le_bytes();         // [u8; 32]
```

See [Primitives](/developers/arcis/primitives#basefield25519-operations) for complete reference.

## Data packing

```rust theme={null}
// Pack for efficient storage
let packed = Pack::new(data);

// Unpack to use
let data: [u8; 64] = packed.unpack();
```

See [Primitives](/developers/arcis/primitives#data-packing) for details.

## Debugging

```rust theme={null}
println!("value = {}", x);
debug_assert!(x > 0, "x must be positive");
```

See [Best practices](/developers/arcis/best-practices#debugging) for debugging strategies.

## Testing

```rust theme={null}
#[cfg(test)]
mod tests {
    #[test]
    fn test_helper() {
        // Only non-#[instruction] functions can be unit tested
        assert_eq!(helper(1, 2), 3);
    }
}
```

See [Best practices](/developers/arcis/best-practices#testing) for testing strategies.

## What's next?

Ready to build? Start here:

<CardGroup cols={2}>
  <Card title="Hello World" icon="rocket" href="/developers/hello-world">
    Build your first Arcis circuit step-by-step.
  </Card>

  <Card title="Solana integration" icon="link" href="/developers/program">
    Invoke circuits from your Solana program.
  </Card>

  <Card title="JavaScript client" icon="js" href="/developers/js-client-library">
    Call circuits from TypeScript.
  </Card>
</CardGroup>
