Operations
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:
Array literal
[a, b]
Supported
Assignment
a = b;
Supported
Async block
async { ... }
Unsupported
Await
foo().await
Unsupported
Block expression
{ ... }
Supported
Break
break;
Unsupported
Closures
|a, b | a + b
Unsupported yet
Const block
const { ... }
Supported
Continue
continue;
Unsupported
Field access/set
obj.field
Supported
For loop
for i in expr { ... }
Supported
Note that expr
will have its length known at compile-time.
If
if cond { ... } else { ... }
Supported
Complexity is in O( then_block + else_block).
Indexing
a[idx]
Supported
Complexity will be in O(a.len()
) if idx
isn't known at compile-time.
If let
if let Some(x) = ...
Unsupported
Loops
loop { ... }
Unsupported
Cannot be supported as the number of iterations is not known.
Match
match n { ... }
Unsupported
Parentheses
(a + b)
Supported
Ranges
4..5
Partial Support
Not supported in arr[4..16]
.
Raw addresses
&raw const foo
Unsupported
References
&mut foo
Supported
Repeat arrays
[4u8; 128]
Supported
Return
return false;
Unsupported
Struct literals
MyStruct { a: 12, b }
Supported
Try expression
this_call_can_err()?;
Unsupported
Tuple literal
(a, 4, c)
Supported
Unary expressions
!x
Partial Support
User-defined unary operations are not supported.
Unsafe
unsafe { ... }
Unsupported
While loops
while x < 64 { ... }
Unsupported
Cannot be supported as the number of iterations is not known.
Binary expressions
Note: user-defined binary operations are currently unsupported.
a + b
Integers, floats
a - b
Integers, floats
a * b
Integers, floats
a / b
Integers, floats
a % b
Integers
a && b
Booleans
a || b
Booleans
a ^ b
Booleans
a & b
Booleans
a | b
Booleans
a << b
None
a >> b
Integers, if b
is known at compile time.
a == b
All. Use derive(PartialEq)
for structs.
a != b
All. Use derive(PartialEq)
for structs.
a < b
Booleans, integers, floats
a <= b
Booleans, integers, floats
a >= b
Booleans, integers, floats
a > b
Booleans, integers, floats
a += b
Integers, floats
a -= b
Integers, floats
a *= b
Integers, floats
a /= b
Integers, floats
a %= b
Integers
a ^= b
Booleans
a &= b
Booleans
a |= b
Booleans
a <<= b
None
a >>= b
Integers, if b
is known at compile time
Cast expressions
a as MyType
is only supported:
integer type
integer type
bool
integer type
integer type
bool
&...&T
&T
Function calls
The following function calls are supported:
user-defined function calls (without generics and 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 inO(n*log³(n) + n*log²(n)*sizeof(T))
.Mxe::get()
to be able to create persistent secret data.Shared::new(arcis_public_key)
to share private data witharcis_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
"foo"
Unsupported
b"foo"
Supported
c"foo"
Unsupported
b'f'
Supported
'a'
Unsupported
1
Supported
1u16
Supported
1f64
Supported
1.0e10f64
Supported
true
Supported
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 allClone
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 inO(n*log²(n)*bit_size)
..enumerate()
,.chain(other)
,.cloned()
,.copied()
,.count()
,.rev()
,.zip(other)
on iterators..take(n)
,.skip(n)
on iterators whenn
is compile-time known..reveal()
if not inside aif
or aelse
.to_arcis()
onEnc
s.from_arcis(x)
onOwner
s (objects of typesMxe
orShared
) if not inside aif
or aelse
.abs()
,.min(x)
,.max(x)
on integers and floats.abs_diff()
,.is_positive()
,.is_negative()
on integers.exp()
,.exp2()
,.ln()
,.log2()
,.sqrt()
on floats.
Paths
The following paths are supported:
IntType::MIN
andIntType::MAX
whereIntType
is an integer type.Paths to user-defined constants, functions and structs, as long as they don't use the unsupported
Self
.
Item support:
Lifetimes are the only generics that are supported on any user-defined object.
Constant
const MAX: u16 = 65535
Supported
Enum
enum MyEnum { ... }
Unsupported
Extern
extern ...
Unsupported
Functions
fn foo() -> u8 { 0 }
Partial Support
Recursive functions are not supported.
Impls
impl MyType { ... }
Partial Support
Traits are not supported. MyType
should not be a reference. Also, MyType
should be used instead of Self
.
Macro Definitions
macro_rules! ...
Unsupported
Modules
mod my_module { ... }
Supported
Statics
static ...
Unsupported
Structs
struct MyStruct { ... }
Supported
Traits
trait MyTrait { ... }
Unsupported
Type Aliases
type MyId = usize;
Unsupported
Union
union MyUnion { ... }
Unsupported
Use
use arcis_imports::*
Partial Support
Only 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.
Last updated