zkvc 0.1.0

A Rust crate for building zero-knowledge proof-based volunteer computing systems
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use ark_ff::{BigInteger, PrimeField};
use num_bigint::BigUint;

pub(crate) const VERIFY_PATH: &str = "/verify";

pub fn field_to_string<F: PrimeField>(f: F) -> String {
    let big_int = BigUint::from_bytes_le(&f.into_repr().to_bytes_le());
    big_int.to_string()
}

pub fn field_from_string<F: PrimeField>(s: &str) -> Result<F, anyhow::Error> {
    let big_int = BigUint::parse_bytes(s.as_bytes(), 10)
        .ok_or_else(|| anyhow::anyhow!("Failed to parse decimal string"))?;
    let bytes = big_int.to_bytes_le();
    F::from_random_bytes(&bytes).ok_or_else(|| anyhow::anyhow!("Failed to parse field element"))
}