Skip to content

ZK Rust Reference

Covering the types and functions available in ZkRust.

Types

Type Comment
bool
i8
i16
i32
u8
u16
u32
usize
Range
pbc_zk::Sbi1 Secret-shared boolean.
pbc_zk::Sbi8 Secret-shared 8-bit signed integer.
pbc_zk::Sbi16 Secret-shared 16-bit signed integer.
pbc_zk::Sbi32 Secret-shared 32-bit signed integer.
pbc_zk::Sbi64 Secret-shared 64-bit signed integer.
pbc_zk::Sbi128 Secret-shared 128-bit signed integer.

Traits

Note that traits are not fully implemented, and these are mostly for illustrative purposes.

Trait Documentation
Public Public types are "normal" Rust types like i32, where the data is publicly known, for example because it is directly visible in the contract state.
pbc_zk::Secret Secret types are types like Sbi32 where the data is secret-shared between ZK nodes.
pbc_zk::SecretBinary Sub-interface of pbc_zk::Secret where variables are secret-shared as bits.

Functions

Does not cover deprecated functions.

Function Documentation
pbc_zk::num_secret_variables() -> i32 Determines the number of secret variables available to the computation. Variable ids are not contiguous and cannot by iterated over using 1..num_secret_variables()
pbc_zk::load_sbi<S: SecretBinary>(id: i32) -> S Loads the secret-shared data associated with variable id as the given type S.
pbc_zk::load_metadata<P: Public>(id: i32) -> P Loads the public metadata associated with variable id as the given type P.
pbc_zk::secret_variable_ids() -> Iterator<i32> Creates an iterator for secret variable ids.

Lifetime attribute macros

These macros define what the MPC nodes should do when given the input.

Macro Documentation
zk_on_secret_input Declares an endpoint that the contract can be interacted with to add secret variables.
zk_on_variable_inputted Declares an automatic hook for when a variable is confirmed inputted.
zk_on_variable_rejected Declares an automatic hook for when a variable is rejected.
zk_on_compute_complete Declares an automatic hook for when the zero-knowledge computation is finished.
zk_on_variables_opened Declares an automatic hook for when secret variables is ready to be read..
zk_on_attestation_complete Declares an automatic hook for when the contract have asked nodes to attest a piece of data,.

Partisia All Rights Reserved © 2023