Skip to main content

BinaryInstructions

Trait BinaryInstructions 

Source
pub trait BinaryInstructions<F: CircuitField> {
    // Required methods
    fn and(
        &self,
        layouter: &mut impl Layouter<F>,
        bits: &[AssignedBit<F>],
    ) -> Result<AssignedBit<F>, Error>;
    fn or(
        &self,
        layouter: &mut impl Layouter<F>,
        bits: &[AssignedBit<F>],
    ) -> Result<AssignedBit<F>, Error>;
    fn xor(
        &self,
        layouter: &mut impl Layouter<F>,
        bits: &[AssignedBit<F>],
    ) -> Result<AssignedBit<F>, Error>;
    fn not(
        &self,
        layouter: &mut impl Layouter<F>,
        bit: &AssignedBit<F>,
    ) -> Result<AssignedBit<F>, Error>;
}
Expand description

The set of circuit instructions for binary operations.

Required Methods§

Source

fn and( &self, layouter: &mut impl Layouter<F>, bits: &[AssignedBit<F>], ) -> Result<AssignedBit<F>, Error>

Conjunction of the given assigned bits.

§Panics

If bits is empty.

let b0 = chip.assign(&mut layouter, Value::known(false))?;
let b1 = chip.assign(&mut layouter, Value::known(true))?;

let res = chip.and(&mut layouter, &[b0, b1])?;
chip.assert_equal_to_fixed(&mut layouter, &res, false)?;
let res = chip.and(&mut layouter, &[])?;
Source

fn or( &self, layouter: &mut impl Layouter<F>, bits: &[AssignedBit<F>], ) -> Result<AssignedBit<F>, Error>

Disjunction of the given assigned bits.

§Panics

If bits is empty.

let b0 = chip.assign(&mut layouter, Value::known(false))?;
let b1 = chip.assign(&mut layouter, Value::known(true))?;

let res = chip.or(&mut layouter, &[b0, b1])?;
chip.assert_equal_to_fixed(&mut layouter, &res, true)?;
Source

fn xor( &self, layouter: &mut impl Layouter<F>, bits: &[AssignedBit<F>], ) -> Result<AssignedBit<F>, Error>

Exclusive-OR of all the given assigned bits.

§Panics

If bits is empty.

let b0 = chip.assign(&mut layouter, Value::known(false))?;
let b1 = chip.assign(&mut layouter, Value::known(true))?;
let b2 = chip.assign(&mut layouter, Value::known(true))?;

let res = chip.xor(&mut layouter, &[b0, b1, b2])?;
chip.assert_equal_to_fixed(&mut layouter, &res, false)?;
Source

fn not( &self, layouter: &mut impl Layouter<F>, bit: &AssignedBit<F>, ) -> Result<AssignedBit<F>, Error>

Negation of the given assigned bit.

let b = chip.assign(&mut layouter, Value::known(false))?;

let res = chip.not(&mut layouter, &b)?;
chip.assert_equal_to_fixed(&mut layouter, &res, true)?;

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<F> BinaryInstructions<F> for NativeChip<F>
where F: CircuitField,

Source§

impl<F, CoreDecomposition, NativeArith> BinaryInstructions<F> for NativeGadget<F, CoreDecomposition, NativeArith>
where F: CircuitField, CoreDecomposition: CoreDecompositionInstructions<F>, NativeArith: ArithInstructions<F, AssignedNative<F>> + BinaryInstructions<F>,