pub trait CircuitInputMapper<F: Fancy>: Circuit<F> {
// Required methods
fn map(&self, inputs: Vec<F::Item>) -> Self::Input;
fn ninputs(&self) -> usize;
fn modulus(&self, i: usize) -> u16;
}Expand description
Trait for defining input-size-dependent Circuits.
The Circuit trait allows one to write circuits for arbitrary-length
inputs, which becomes a problem when needing to be used in, for example, a
garbled circuit protocol, where the input length needs to be know during the
Oblivious Transfer phase of the protocol. This is where CircuitInputMapper
comes in: it provides a CircuitInputMapper::map method for mapping
vectors of inputs to the appropriate input type as required to run
Circuit::execute, alongside CircuitInputMapper::ninputs for
determining the number of inputs for the circuit. Finally,
CircuitInputMapper::modulus outputs the particular modulus required for
the ith input wire.
While certain Fancy instantiations can evaluate Circuits directly,
several, including garbled circuits and zero knowledge protocols, operate
over CircuitInputMappers instead, and any Circuit to be run under
these protocols needs to implement CircuitInputMapper as well.
§Example
The below code extends the AddCircuit example from the Circuit
documentation to support mapping a vector of inputs into the appropriate
input type for the given circuit.
impl<F: FancyArithmetic> CircuitInputMapper<F> for AddCircuit {
fn map(&self, inputs: Vec<F::Item>) -> Self::Input {
assert_eq!(inputs.len(), 2);
(inputs[0].clone(), inputs[1].clone())
}
fn ninputs(&self) -> usize {
2
}
fn modulus(&self, _: usize) -> u16 {
2
}
}Required Methods§
Sourcefn map(&self, inputs: Vec<F::Item>) -> Self::Input
fn map(&self, inputs: Vec<F::Item>) -> Self::Input
Map a vector of inputs to Circuit::Input.
§Panics
This panics if the number of inputs does not match the expected input size.
Sourcefn ninputs(&self) -> usize
fn ninputs(&self) -> usize
The number of inputs to provide to CircuitInputMapper::map.