You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: garble_docs/src/guide/const.md
+22
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,8 @@ pub fn main(x: u16) -> u16 {
15
15
}
16
16
```
17
17
18
+
## Min & Max
19
+
18
20
Garble also supports taking the `min()` / `max()` of several constants as part of the declaration of a constant, which, for instance, can be useful to set the size of a collection to the size of the biggest collection provided by different parties:
19
21
20
22
```rust
@@ -37,4 +39,24 @@ pub fn main(x: u16) -> u16 {
37
39
38
40
> Garble currently does not support type inference in const declarations, which is why you always have to use type suffixes even for simple number literals, e.g. use `2u16` instead of `2`.
39
41
42
+
## A Dynamic Number of Parties
43
+
44
+
Using `const` declarations is especially useful for writing Garble programs that work for any number of parties. Simply use a single array as the argument of the main function, Garble will then assume that each array element is provided by a different party:
45
+
46
+
```rust
47
+
constPARTIES:usize=PARTIES::TOTAL;
48
+
49
+
pubfnmain(array: [u16; PARTIES]) ->u16 {
50
+
letmutresult=0u16;
51
+
foreleminarray {
52
+
result=result+elem;
53
+
}
54
+
result
55
+
}
56
+
```
57
+
58
+
The above program can be type checked without specifying the exact number of parties, but all parties need to agree on the number of parties during compilation (if each party is compiling the program locally), otherwise the same program (but with different `PARTIES::TOTAL` constants) would be compiled into incompatible circuits.
59
+
60
+
## Compiling Consts
61
+
40
62
Garble programs can be type checked without providing concrete values for the declared constants, but all const values must be provided during compilation, using [`garble_lang::compile_with_constants`](https://docs.rs/garble_lang/latest/garble_lang/fn.compile_with_constants.html). See [MPC Engine Integration](../integration.md) for more details.
Copy file name to clipboardexpand all lines: garble_docs/src/guide/intro.md
+9-1
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
Garble is a programming language for [MPC](https://en.wikipedia.org/wiki/Secure_multi-party_computation) that is quite easy to learn and mostly works like Rust, except that it is much simpler and only implements a subset of Rust (without the borrow checker). The following guide introduces the main features of Garble.
4
4
5
-
A minimal Garble program is a public function (conventionally called `main`), with each function argument conceptually belonging to a different party in an MPC protocol based on Boolean circuits, e.g. [Garbled Circuits](https://en.wikipedia.org/wiki/Garbled_circuit). For example, the following program computes the Boolean `and` of two parties:
5
+
A minimal Garble program is a public function (conventionally called `main`), with each argument coming from a different party in an MPC protocol based on Boolean circuits, e.g. [Garbled Circuits](https://en.wikipedia.org/wiki/Garbled_circuit). For example, the following program computes the Boolean `and` of two parties:
It is also possible to use a single array as the argument of the main function, Garble will then assume that each array element is coming from a different party. So we could also write the above as:
Garble is developed by the [SINE Foundation](https://sine.foundation/) and is [open source](https://github.com/sine-fdn/garble-lang). We developed Garble for our own MPC engine, but you can use Garble in any [MPC engine](./integration.md) that executes Boolean circuits.
25
+
Garble is developed by the [SINE Foundation](https://sine.foundation/) and is [open source](https://github.com/sine-fdn/garble-lang). Garble is integrated into [Polytune](https://github.com/sine-fdn/polytune), our own MPC engine, but you can use Garble in [any MPC engine](./integration.md) that executes Boolean circuits.
0 commit comments