pub enum Opcode<F: AcirField> {
AssertZero(Expression<F>),
BlackBoxFuncCall(BlackBoxFuncCall<F>),
MemoryOp {
block_id: BlockId,
op: MemOp<F>,
predicate: Option<Expression<F>>,
},
MemoryInit {
block_id: BlockId,
init: Vec<Witness>,
block_type: BlockType,
},
BrilligCall {
id: BrilligFunctionId,
inputs: Vec<BrilligInputs<F>>,
outputs: Vec<BrilligOutputs>,
predicate: Option<Expression<F>>,
},
Call {
id: AcirFunctionId,
inputs: Vec<Witness>,
outputs: Vec<Witness>,
predicate: Option<Expression<F>>,
},
}
Expand description
Defines an operation within an ACIR circuit
Expects a type parameter F
which implements AcirField.
Variants§
AssertZero(Expression<F>)
An AssertZero
opcode adds the constraint that P(w) = 0
, where
w=(w_1,..w_n)
is a tuple of n
witnesses, and P
is a multi-variate
polynomial of total degree at most 2
.
The coefficients {q_M}_{i,j}, q_i,q_c
of the polynomial are known
values which define the opcode.
A general expression of assert-zero opcode is the following:
\sum_{i,j} {q_M}_{i,j}w_iw_j + \sum_i q_iw_i +q_c = 0
An assert-zero opcode can be used to:
- express a constraint on witnesses; for instance to express that a
witness
w
is a boolean, you can add the opcode:w*w-w=0
- or, to compute the value of an arithmetic operation of some inputs.
For instance, to multiply two witnesses x
and y
, you would use the
opcode z-x*y=0
, which would constrain z
to be x*y
.
The solver expects that at most one witness is not known when executing the opcode.
BlackBoxFuncCall(BlackBoxFuncCall<F>)
Calls to “gadgets” which rely on backends implementing support for specialized constraints.
Often used for exposing more efficient implementations of SNARK-unfriendly computations.
All black box function inputs are specified as FunctionInput, and they have one or several witnesses as output.
Some more advanced computations assume that the proving system has an ‘embedded curve’. It is a curve that cycles with the main curve of the proving system, i.e the scalar field of the embedded curve is the base field of the main one, and vice-versa. e.g. Aztec’s Barretenberg uses BN254 as the main curve and Grumpkin as the embedded curve.
MemoryOp
Atomic operation on a block of memory
ACIR is able to address any array of witnesses. Each array is assigned an id (BlockId) and needs to be initialized with the Opcode::MemoryInit opcode. Then it is possible to read and write from/to an array by providing the index and the value we read/write as arithmetic expressions. Note that ACIR arrays all have a known fixed length (given in the Opcode::MemoryInit opcode below)
Fields
predicate: Option<Expression<F>>
Predicate of the memory operation - indicates if it should be skipped Disables the execution of the opcode when the expression evaluates to zero
MemoryInit
Initialize an ACIR array from a vector of witnesses.
There must be only one MemoryInit per block_id, and MemoryOp opcodes must come after the MemoryInit.
Fields
BrilligCall
Calls to unconstrained functions. Unconstrained functions are constructed with Brillig.
Fields
id: BrilligFunctionId
Id for the function being called. It is the responsibility of the executor to fetch the appropriate Brillig bytecode from this id.
inputs: Vec<BrilligInputs<F>>
Inputs to the function call
outputs: Vec<BrilligOutputs>
Outputs to the function call
predicate: Option<Expression<F>>
Predicate of the Brillig execution - indicates if it should be skipped
Call
Calls to functions represented as a separate circuit. A call opcode allows us to build a call stack when executing the outer-most circuit.
Fields
id: AcirFunctionId
Id for the function being called. It is the responsibility of the executor to fetch the appropriate circuit from this id.
predicate: Option<Expression<F>>
Predicate of the circuit execution - indicates if it should be skipped
Trait Implementations§
Source§impl<'de, F> Deserialize<'de> for Opcode<F>where
F: Deserialize<'de> + AcirField,
impl<'de, F> Deserialize<'de> for Opcode<F>where
F: Deserialize<'de> + AcirField,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<F> ProtoCodec<Opcode<F>, Opcode> for ProtoSchema<F>where
F: AcirField,
impl<F> ProtoCodec<Opcode<F>, Opcode> for ProtoSchema<F>where
F: AcirField,
Source§fn decode(value: &Opcode) -> Result<Opcode<F>>
fn decode(value: &Opcode) -> Result<Opcode<F>>
R
to domain type T
.Source§fn encode_some(value: &T) -> Option<R>
fn encode_some(value: &T) -> Option<R>
Some
.Source§fn encode_vec<'a, I>(values: I) -> Vec<R>where
I: IntoIterator<Item = &'a T>,
T: 'a,
fn encode_vec<'a, I>(values: I) -> Vec<R>where
I: IntoIterator<Item = &'a T>,
T: 'a,
Source§fn decode_wrap(value: &R, msg: &'static str) -> Result<T, Report>
fn decode_wrap(value: &R, msg: &'static str) -> Result<T, Report>
Source§fn decode_vec_wrap(values: &[R], msg: &'static str) -> Result<Vec<T>, Report>
fn decode_vec_wrap(values: &[R], msg: &'static str) -> Result<Vec<T>, Report>
Source§fn decode_arr<const N: usize>(values: &[R]) -> Result<[T; N], Report>
fn decode_arr<const N: usize>(values: &[R]) -> Result<[T; N], Report>
Source§fn decode_arr_wrap<const N: usize>(
values: &[R],
msg: &'static str,
) -> Result<[T; N], Report>
fn decode_arr_wrap<const N: usize>( values: &[R], msg: &'static str, ) -> Result<[T; N], Report>
Source§fn decode_box_arr<const N: usize>(values: &[R]) -> Result<Box<[T; N]>, Report>
fn decode_box_arr<const N: usize>(values: &[R]) -> Result<Box<[T; N]>, Report>
Source§fn decode_box_arr_wrap<const N: usize>(
values: &[R],
msg: &'static str,
) -> Result<Box<[T; N]>, Report>
fn decode_box_arr_wrap<const N: usize>( values: &[R], msg: &'static str, ) -> Result<Box<[T; N]>, Report>
Source§fn decode_some(value: &Option<R>) -> Result<T, Report>
fn decode_some(value: &Option<R>) -> Result<T, Report>
None
.Source§fn decode_some_wrap(value: &Option<R>, msg: &'static str) -> Result<T, Report>
fn decode_some_wrap(value: &Option<R>, msg: &'static str) -> Result<T, Report>
Source§fn decode_opt_wrap(
value: &Option<R>,
msg: &'static str,
) -> Result<Option<T>, Report>
fn decode_opt_wrap( value: &Option<R>, msg: &'static str, ) -> Result<Option<T>, Report>
None
if the field is missing.impl<F: Eq + AcirField> Eq for Opcode<F>
impl<F: AcirField> StructuralPartialEq for Opcode<F>
Auto Trait Implementations§
impl<F> Freeze for Opcode<F>where
F: Freeze,
impl<F> RefUnwindSafe for Opcode<F>where
F: RefUnwindSafe,
impl<F> Send for Opcode<F>where
F: Send,
impl<F> Sync for Opcode<F>where
F: Sync,
impl<F> Unpin for Opcode<F>where
F: Unpin,
impl<F> UnwindSafe for Opcode<F>where
F: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg
] or
a color-specific method, such as [OwoColorize::green
], Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg
] or
a color-specific method, such as [OwoColorize::on_yellow
], Read more