Skip to content

Decorators & Attributes

Defined in stdlib/sequre/attributes.codon, stdlib/sequre/decorators.codon, and stdlib/sequre/runtime.codon

Sequre uses compile-time attributes (processed by the Sequre IR plugin) and runtime decorators to control how functions are transformed, optimized, and executed.


Compiler attributes

These decorators are processed by the Sequre compiler plugin during IR transformation passes. They do not exist at runtime — they instruct the compiler to rewrite annotated functions.

@sequre

The primary attribute. Marks a function for Sequre's IR rewriting pipeline. The compiler:

  1. Expressiveness transformations — rewrites operator overloads (e.g., a > b on encrypted types dispatches to secure comparison)
  2. MPC optimizations (@mpc_poly_opt) — polynomial-evaluation optimizations for MPC operations
  3. MHE optimizations (@mhe_mat_opt, @mhe_cipher_opt, @mhe_enc_opt) — HE-specific optimizations
from sequre.attributes import sequre

@sequre
def my_secure_function(mpc, x, y):
    return x @ y + x * y  # operators are rewritten to secure versions

Note

Every function that operates on Sequre types (Sharetensor, Ciphertensor, MPU, etc.) should be annotated with @sequre.


Runtime decorators

@flatten(idx)

Defined in stdlib/sequre/decorators.codon

A runtime decorator that automatically flattens the first idx tensor arguments before calling the function, and reshapes the result back to the original shape. Useful for functions that operate on 1-D vectors but should accept matrices transparently.

from sequre.decorators import flatten

@flatten(1)
def fp_div(mpc, a, b):
    # a and b are flattened to 1-D here
    ...
    # result is reshaped back to original shape of args[1]

@local

Defined in stdlib/sequre/runtime.codon

A runtime decorator that forks the current process into N parties (using fork()), each running the decorated function as a separate MPC party with its own MPCEnv. Used for local testing where all parties run on a single machine.

from sequre.runtime import local

@local
def my_protocol(mpc):
    # Each forked process gets its own mpc with a unique pid
    X = MPU(mpc, local_data, "partition")
    result = X @ X.T
    print(f"CP{mpc.pid}: done")

Command-line flags (e.g., --ring, --skip-mhe-setup) are parsed from sys.argv and passed as control toggles.


Runtime initialization

Defined in stdlib/sequre/runtime.codon

These functions set up the MPC environment for distributed (non-local) execution:

Function Description
mpc() Parse command-line args, create an MPCEnv for the current party, run MHE setup. Returns the initialized environment.

Typical distributed entry point

from sequre.runtime import mpc as init_mpc

mpc = init_mpc()
# mpc.pid is set from sys.argv
# mpc.mhe is initialized with default_setup()

Typical local entry point

from sequre.runtime import local

@local
def main(mpc):
    ...  # protocol logic

main()  # forks N parties automatically --- no need to pass mpc instance

Compiler IR passes

The Sequre compiler plugin processes @sequre-annotated functions through these IR passes (in order):

Pass Description
ExpressivenessTransformations Rewrites standard operators on secure types to their secure equivalents
MPCOptimizations Optimizes polynomial evaluations and MPC-specific patterns
MHEOptimizations Optimizes HE expression ordering, encoding modes, and matrix strategies