Skip to main content

Operations

Arcis supports many of Rust’s native operations but extends them to work seamlessly with encrypted data, allowing you to write private computations using familiar Rust syntax. See the tables below for a detailed list of supported and unsupported operations.

Table of contents

Expression support:

Expression NameExampleSupportComments
Array literal[a, b]Supported
Assignmenta = b;Supported
Async blockasync { ... }Unsupported
Awaitfoo().awaitUnsupported
Binary expressiona + bPartial SupportSee table below for supported binary expressions.
Block expression{ ... }Supported
Breakbreak;Unsupported
Function callf(a, b)Partial SupportSee table below for supported functions.
Castsa as u16Partial SupportSee table below for supported conversions.
Closures|a, b | a + bSupported
Const blockconst { ... }Supported
Continuecontinue;Unsupported
Field access/setobj.fieldSupported
For loopfor i in expr { ... }SupportedNote that expr will have its length known at compile-time.
Ifif cond { ... } else { ... }SupportedComplexity is in O( then_block + else_block).
Indexinga[idx]SupportedComplexity will be in O(a.len()) if idx isn’t known at compile-time.
If letif let Some(x) = ...Unsupported
Literals1u128Partial SupportSee table below for supported literals.
Loopsloop { ... }UnsupportedCannot be supported as the number of iterations is not known.
Macrosprintln!("{}", q)Partial SupportSee table below for supported macros.
Matchmatch n { ... }Unsupported
Method callsx.foo(a, b)Partial SupportSee table below for supported methods.
Parentheses(a + b)Supported
PathsFoo::barPartial SupportSee table below for supported paths.
Ranges4..5Partial SupportNot supported in arr[4..16].
Raw addresses&raw const fooUnsupported
References&mut fooSupported
Repeat arrays[4u8; 128]Supported
Returnreturn false;Unsupported
Struct literalsMyStruct { a: 12, b }Supported
Try expressionthis_call_can_err()?;Unsupported
Tuple literal(a, 4, c)Supported
Unary expressions!xPartial SupportUser-defined unary operations are not supported.
Unsafeunsafe { ... }Unsupported
While loopswhile x < 64 { ... }UnsupportedCannot be supported as the number of iterations is not known.

Binary expressions

Note: user-defined binary operations are currently unsupported.
ExampleSupported types
a + bIntegers, floats
a - bIntegers, floats
a * bIntegers, floats
a / bIntegers, floats
a % bIntegers
a && bBooleans
a || bBooleans
a ^ bBooleans
a & bBooleans
a | bBooleans
a << bNone
a >> bIntegers, if b is known at compile time.
a == bAll. Use derive(PartialEq) for structs.
a != bAll. Use derive(PartialEq) for structs.
a < bBooleans, integers, floats
a <= bBooleans, integers, floats
a >= bBooleans, integers, floats
a > bBooleans, integers, floats
a += bIntegers, floats
a -= bIntegers, floats
a *= bIntegers, floats
a /= bIntegers, floats
a %= bIntegers
a ^= bBooleans
a &= bBooleans
a |= bBooleans
a <<= bNone
a >>= bIntegers, if b is known at compile time

Cast expressions

a as MyType is only supported:
From TypeTo Type
integer typeinteger type
boolinteger type
integer typebool
&...&T&T

Function calls

The following function calls are supported:
  • user-defined function calls (without recursion)
  • ArcisRNG::bool() to generate a boolean.
  • ArcisRNG::gen_integer_from_width(width: usize) -> u128. Generates a secret integer between 0 and 2^width - 1 included.
  • ArcisRNG::gen_public_integer_from_width(width: usize) -> u128. Generates a public integer between 0 and 2^width - 1 included.
  • ArcisRNG::gen_integer_in_range(min: u128, max: u128, n_attempts: usize) -> (result: u128, success: bool). See function doc for more information.
  • ArcisRNG::shuffle(slice) on slices. Complexity is in O(n*log³(n) + n*log²(n)*sizeof(T)).
  • Mxe::get() to be able to create MXE-owned secret data.
  • Shared::new(arcis_public_key) to share private data with arcis_public_key.
  • ArcisPublicKey::from_base58(base58_byte_string) to create a public key from a base58-encoded address.
  • ArcisPublicKey::from_uint8(u8_byte_slice) to create a public key from a Uint8 array.

Literal expressions

ExampleSupport
"foo"Unsupported
b"foo"Supported
c"foo"Unsupported
b'f'Supported
'a'Unsupported
1Supported
1u16Supported
1f64Supported
1.0e10f64Supported
trueSupported

Macros

The following macros are supported in order to help you debug your rust code:
  • debug_assert!, debug_assert_ne!, debug_assert_eq!. They do not change instruction behavior and are only useful for debugging your rust code.
  • eprint!, eprintln!, print!, println!. They do not change instruction behavior and are only useful for debugging your rust code.

Method calls

The following method calls are supported:
  • user-defined method calls (without generics and without recursion)
  • .clone() on all Clone objects.
  • .len(), .is_empty(), .swap(a, b), .fill(value), .reverse(), .iter(), .iter_mut(), .into_iter(), .windows(width) on arrays.
  • .sort() on arrays of integers. Complexity is in O(n*log²(n)*bit_size).
  • .enumerate(), .chain(other), .cloned(), .copied(), .count(), .rev(), .zip(other), .map(func), .for_each(func), .fold(init, func) on iterators.
  • .take(n), .skip(n), .step_by(n) on iterators when n is compile-time known.
  • .reveal() if not inside a if or a else
  • .to_arcis() on Encs
  • .from_arcis(x) on Owners (objects of types Mxe or Shared) if not inside a if or a else
  • .abs(), .min(x), .max(x) on integers and floats
  • .abs_diff(other), .is_positive(), .is_negative() on integers
  • .to_le_bytes(), to_be_bytes() on typed integers (does not work on integers the interpreter does not know the type)
  • .exp(), .exp2(), .ln(), .log2(), .sqrt() on floats.

Paths

The following paths are supported:
  • IntType::BITS, IntType::MIN and IntType::MAX where IntType is an integer type.
  • Paths to user-defined constants, functions and structs, as long as they don’t use the unsupported crate or super.
  • std::mem::replace and std::mem::swap

Item support:

Item NameExampleSupportComments
Constantconst MAX: u16 = 65535Supported
Enumenum MyEnum { ... }Unsupported
Externextern ...Unsupported
Functionsfn foo() -> u8 { 0 }Partial SupportRecursive functions are not supported.
Implsimpl MyType { ... }Partial SupportTraits are not supported. MyType should not be a reference.
Macro Definitionsmacro_rules! ...Unsupported
Macro Invocationsprintln!(...)Partial SupportSee table above for supported macros.
Modulesmod my_module { ... }Supported
Staticsstatic ...Unsupported
Structsstruct MyStruct { ... }Supported
Traitstrait MyTrait { ... }Unsupported
Type Aliasestype MyId = usize;Supported
Unionunion MyUnion { ... }Unsupported
Useuse arcis_imports::*Partial SupportOnly use arcis_imports:: is supported.

Pattern support:

The following patterns are supported in function arguments and let statements:
  • simple idents: let ident = ...;
  • mutable idents: let mut ident = ...;
  • ref idents: let ref ident = ...;
  • mutable ref idents: let ref mut ident = ...;
  • parentheses around a supported pattern: let (...) = ...;
  • reference of a supported pattern: let &... = ...;
  • array of supported patterns: let [...] = ...;
  • struct of supported patterns: let MyStruct { ... } = ...;
  • tuple of supported patterns: let (...) = ...;
  • tuple struct of supported patterns: let MyStruct(...) = ...;
  • type pattern of a supported pattern: let ...: ty = ...;
  • wild pattern: let _ = ...;
Note: in particular, the .. pattern is currently unsupported.

Performance Considerations

While Arcis provides these operations on encrypted data, it’s important to note that operations on encrypted data are more computationally expensive than their plaintext counterparts. Complex calculations can lead to increased computation time and resource usage. It’s recommended to optimize your algorithms to minimize the number of operations on encrypted data where possible.
I