ark_r1cs_std/boolean/
convert.rs

1use super::*;
2use crate::convert::{ToBytesGadget, ToConstraintFieldGadget};
3
4impl<F: Field> ToBytesGadget<F> for Boolean<F> {
5    /// Outputs `1u8` if `self` is true, and `0u8` otherwise.
6    #[tracing::instrument(target = "r1cs")]
7    fn to_bytes_le(&self) -> Result<Vec<UInt8<F>>, SynthesisError> {
8        let value = self.value().map(u8::from).ok();
9        let mut bits = [Boolean::FALSE; 8];
10        bits[0] = self.clone();
11        Ok(vec![UInt8 { bits, value }])
12    }
13}
14
15impl<F: PrimeField> ToConstraintFieldGadget<F> for Boolean<F> {
16    #[tracing::instrument(target = "r1cs")]
17    fn to_constraint_field(&self) -> Result<Vec<FpVar<F>>, SynthesisError> {
18        let var = From::from(self.clone());
19        Ok(vec![var])
20    }
21}