1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
use ;
use TokenStream;
/// Tells our arcis compiler to create encrypted instructions that mimic the rust module you wrote.
/// Use `#[instruction]` to mark the functions that will be the entry points.
/// Validates an arcis library, trying to find errors.
/// Allows to build a library that can be used in `#[encrypted]` instructions.
///
/// Will transform
/// ```
/// mod arcis_library {
/// /* content */
/// }
/// ```
/// into
/// ```
/// /* content */
/// ```
/// if it does not detect any errors.
/// Derives `ArcisType`, a trait that helps to use the type in automated tests.
/// An `#[instruction]`. Should be inside an `#[encrypted]` module.
/// Use another file as a module in an `#[encrypted]` module.
///
/// Use `encrypted_mod!("path/to/my_module_name.rs")` or
/// `encrypted_mod!("path/to/my_module.rs", my_module_name)`
/// to use another file as a module. The path is relative to the current file.
///
/// The other file needs to look like this:
///
/// path/to/my_module.rs:
/// ```
/// use arcis::*;
///
/// #[encrypted_library]
/// mod arcis_library {
/// // Put your content here.
///
/// // Accessible through `my_module_name::MY_CONST`.
/// pub const MY_CONST: u16 = 67;
/// }
/// ```
/// And then it can be used it like this:
///
/// lib.rs:
/// ```
/// use arcis::*;
///
/// #[encrypted]
/// mod circuits {
/// use arcis::*;
///
/// // Allowing to use the contents of my_module.rs as `my_module_name::...`.
/// encrypted_mod!("path/to/my_module.rs", my_module_name);
///
/// pub struct InputValues {
/// v1: u8,
/// v2: u8,
/// }
///
/// #[instruction]
/// pub fn add_together(input_ctxt: Enc<Shared, InputValues>) -> Enc<Shared, u16> {
/// let input = input_ctxt.to_arcis();
/// let mut sum = input.v1 as u16 + input.v2 as u16;
///
/// // Using the constant declared in the other file.
/// sum += my_module_name::MY_CONST;
///
/// input_ctxt.owner.from_arcis(sum)
/// }
/// }
/// ```
/// Allows to use `crate::` in an #[encrypted] module.
/// Use it like this: `assert_current_module!(crate::path::to::encrypted::module);`
///
/// Example lib.rs:
/// ```
/// use arcis::*;
///
/// #[encrypted]
/// mod circuits {
/// use arcis::*;
///
/// assert_current_module!(crate::circuits);
/// // now I can use crate::circuits
///
/// const MY_CONST: usize = 0;
///
/// #[instruction]
/// fn return_my_const() -> usize {
/// crate::circuits::MY_CONST
/// }
/// }
/// ```