Expand description
§Test utility library for testing Zero-Knowledge computations
NOTICE: This library cannot perform MPC; it can only mock MPC.
This library tries to mimic the type system and semantics of the Zero-Knowledge compiler and stack, in order allow contracts to test their contract computations without deploying on the test net. This library is the first testing step for a contract, followed by
- Integration testing between public contract and computation
- Full integration testing on test-net.
This library also acts as documentation of the various builtin functions available in the Zk-compiler.
§Example Computation of variable summation
Simple example of a computation summing all input variables:
use pbc_zk::{Sbi32, load_sbi, secret_variable_ids, zk_compute};
#[zk_compute(shortname = 0x01)]
pub fn sum_all_variables() -> Sbi32 {
let mut sum: Sbi32 = Sbi32::from(0);
for variable_id in secret_variable_ids() {
sum = sum + load_sbi::<Sbi32>(variable_id);
}
sum
}
§Example Computation of loading struct
Another example that sums all values of a specific type
use pbc_zk::{Sbi8, Sbi32, secret_variable_ids, load_sbi, SecretBinary, zk_compute};
#[derive(Clone, SecretBinary)]
struct MyStruct {
variable_type: Sbi8,
value: Sbi32,
}
#[zk_compute(shortname = 0x02)]
pub fn sum_all_variables() -> Sbi32 {
let mut sum: Sbi32 = Sbi32::from(0);
for variable_id in secret_variable_ids() {
let value = load_sbi::<MyStruct>(variable_id);
if value.variable_type == Sbi8::from(0) {
sum = sum + value.value;
}
}
sum
}
Modules§
- Module for configuring outside environment of test.
Macros§
- Testing macro for Zero-knowledge computations.
Structs§
- Identifier for a secret variable.
Traits§
- Exposes interface for splitting elements into an array of its composite bits.
- Required for secret-shared values. Secret variables are serialized like their public counterparts using the State serialization format.
- Required for secret-shared values. Secret variables are serialized like their public counterparts using the State serialization format.
- Required for secret-shared values. Used to determine the size of secret-shared inputs.
Functions§
- Retrieve the metadata from
variable_id
asT
. - Retrieve the input from
variable_id
asT
. - num_
secret_ variables Deprecated Get the number of secret variables. - Save the secret variable as an output, allowing for variable number of outputs.
- Creates an iterator for secret variable ids.
Type Aliases§
- Sbi1
Deprecated - A
i8
secret-shared using a binary field. - A
i16
secret-shared using a binary field. - A
i32
secret-shared using a binary field. - A
i64
secret-shared using a binary field. - A
i128
secret-shared using a binary field. - A secret-shared
bool
value. - A
u8
secret-shared using a binary field. - A
u16
secret-shared using a binary field. - A
u32
secret-shared using a binary field. - A
u64
secret-shared using a binary field. - A
u128
secret-shared using a binary field.
Attribute Macros§
- Marks function as a ZK computation entry point with a given shortname.
Derive Macros§
- Implements
#[derive(SecretBinary)]
.