pbc_zk

Type Alias Sbi32

source
pub type Sbi32 = Sbi<i32>;
Expand description

A i32 secret-shared using a binary field.

Can be used similarly to normal/public i32 values, with the restriction that any public i32 must be upgraded to an Sbi32 before usage.

For example:

let x = Sbi32::from(1);
let y = Sbi32::from(9);
assert_eq!(x + y, Sbi32::from(10));

§Information Flow Control

Variables in REAL must satisfy some information flow requirements, which states that it must not be possible to infer the value of a secret variable. This basic requirement then results in a bunch of type constraints:

  • Sbi values cannot be downcasted to public integers.
  • While-statements on Sbi values is impossible.
  • If-statements on Sbi values has some additional limitations in the branches:
    • Can only assign secret-shared values.
    • Cannot call functions.
    • Cannot use while-statements.
    • Cannot use public if-statements.

Here are some examples of disallowed data flows:

let x: Sbi32 = Sbi32::from(9);
let y: i32   = x;       // Fails: Secrets cannot become public
let z: Sbi32 = x + 10;  // Fails: Missing cast

§Representation

The true value of instances of this type is secret-shared across several computation nodes, and certain operations require network communication, which may result in a significantly slower operation than on their public equivalents.

Sbi32 uses a binary-field secret-sharing, which allows operations on bits to be done efficiently, but arithmetic operations needs to be implemented using the bit operations, which can be slow.

Here is a rough overview of the theoretic performance. N is the type length in bits. Lower numbers are better:

OperationRounds
(#Networking Packets)
Multiplications
(Size of Networking Packets)
BitXor00
Shl / Shr00
BitAnd1N
BitOr1N
If-expression return value12*N
PartialEq / Eqlog2(N)N-1
Add / SubN2*N
Ord (lt, gt)N2*N
MulN squared2*N squared

§Example

Consider the following program:

fn max(a: Sbi32, b: Sbi32) -> Sbi32 {
    if a < b { b } else { a }
}

One execution of max would involve 33 rounds (32 from < and 1 from if) and 128 multiplications (64 from < and 64 from if).

Aliased Type§

struct Sbi32 { /* private fields */ }