Skip to content

ZK Rust Reference

Covering the types and functions available in ZkRust.

TypeComment
bool
i8
i16
i32
u8
u16
u32
usize
Range
pbc_zk::Sbi1Secret-shared boolean.
pbc_zk::Sbi8Secret-shared 8-bit signed integer.
pbc_zk::Sbi16Secret-shared 16-bit signed integer.
pbc_zk::Sbi32Secret-shared 32-bit signed integer.
pbc_zk::Sbi64Secret-shared 64-bit signed integer.
pbc_zk::Sbi128Secret-shared 128-bit signed integer.

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

TraitDocumentation
PublicPublic 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::SecretSecret types are types like Sbi32 where the data is secret-shared between ZK nodes.
pbc_zk::SecretBinarySub-interface of pbc_zk::Secret where variables are secret-shared as bits.

Does not cover deprecated functions.

FunctionDocumentation
pbc_zk::num_secret_variables() -> i32Determines 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) -> SLoads the secret-shared data associated with variable id as the given type S.
pbc_zk::load_metadata<P: Public>(id: i32) -> PLoads 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.

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

MacroDocumentation
zk_on_secret_inputDeclares an endpoint that the contract can be interacted with to add secret variables.
zk_on_variable_inputtedDeclares an automatic hook for when a variable is confirmed inputted.
zk_on_variable_rejectedDeclares an automatic hook for when a variable is rejected.
zk_on_compute_completeDeclares an automatic hook for when the zero-knowledge computation is finished.
zk_on_variables_openedDeclares an automatic hook for when secret variables is ready to be read..
zk_on_attestation_completeDeclares an automatic hook for when the contract have asked nodes to attest a piece of data,.