pub type UInt8<F> = UInt<8, u8, F>;
Aliased Type§
struct UInt8<F> { /* private fields */ }
Implementations§
Source§impl<F: Field> UInt8<F>
impl<F: Field> UInt8<F>
Sourcepub fn new_input_vec(
cs: impl Into<Namespace<F>>,
values: &[u8],
) -> Result<Vec<Self>, SynthesisError>where
F: PrimeField,
pub fn new_input_vec(
cs: impl Into<Namespace<F>>,
values: &[u8],
) -> Result<Vec<Self>, SynthesisError>where
F: PrimeField,
Allocates a slice of u8
’s as public inputs by first packing them into
elements of F
, (thus reducing the number of input allocations),
allocating these elements as public inputs, and then converting
these field variables FpVar<F>
variables back into bytes.
From a user perspective, this trade-off adds constraints, but improves verifier time and verification key size.
// We'll use the BLS12-381 scalar field for our constraints.
use ark_test_curves::bls12_381::Fr;
use ark_relations::r1cs::*;
use ark_r1cs_std::prelude::*;
let cs = ConstraintSystem::<Fr>::new_ref();
let two = UInt8::new_witness(cs.clone(), || Ok(2))?;
let var = vec![two.clone(); 32];
let c = UInt8::new_input_vec(cs.clone(), &[2; 32])?;
var.enforce_equal(&c)?;
assert!(cs.is_satisfied().unwrap());