pub enum BlackBoxFuncCall<F> {
Show 20 variants
AES128Encrypt {
inputs: Vec<FunctionInput<F>>,
iv: Box<[FunctionInput<F>; 16]>,
key: Box<[FunctionInput<F>; 16]>,
outputs: Vec<Witness>,
},
AND {
lhs: FunctionInput<F>,
rhs: FunctionInput<F>,
output: Witness,
},
XOR {
lhs: FunctionInput<F>,
rhs: FunctionInput<F>,
output: Witness,
},
RANGE {
input: FunctionInput<F>,
},
Blake2s {
inputs: Vec<FunctionInput<F>>,
outputs: Box<[Witness; 32]>,
},
Blake3 {
inputs: Vec<FunctionInput<F>>,
outputs: Box<[Witness; 32]>,
},
EcdsaSecp256k1 {
public_key_x: Box<[FunctionInput<F>; 32]>,
public_key_y: Box<[FunctionInput<F>; 32]>,
signature: Box<[FunctionInput<F>; 64]>,
hashed_message: Box<[FunctionInput<F>; 32]>,
output: Witness,
},
EcdsaSecp256r1 {
public_key_x: Box<[FunctionInput<F>; 32]>,
public_key_y: Box<[FunctionInput<F>; 32]>,
signature: Box<[FunctionInput<F>; 64]>,
hashed_message: Box<[FunctionInput<F>; 32]>,
output: Witness,
},
MultiScalarMul {
points: Vec<FunctionInput<F>>,
scalars: Vec<FunctionInput<F>>,
outputs: (Witness, Witness, Witness),
},
EmbeddedCurveAdd {
input1: Box<[FunctionInput<F>; 3]>,
input2: Box<[FunctionInput<F>; 3]>,
outputs: (Witness, Witness, Witness),
},
Keccakf1600 {
inputs: Box<[FunctionInput<F>; 25]>,
outputs: Box<[Witness; 25]>,
},
RecursiveAggregation {
verification_key: Vec<FunctionInput<F>>,
proof: Vec<FunctionInput<F>>,
public_inputs: Vec<FunctionInput<F>>,
key_hash: FunctionInput<F>,
proof_type: u32,
},
BigIntAdd {
lhs: u32,
rhs: u32,
output: u32,
},
BigIntSub {
lhs: u32,
rhs: u32,
output: u32,
},
BigIntMul {
lhs: u32,
rhs: u32,
output: u32,
},
BigIntDiv {
lhs: u32,
rhs: u32,
output: u32,
},
BigIntFromLeBytes {
inputs: Vec<FunctionInput<F>>,
modulus: Vec<u8>,
output: u32,
},
BigIntToLeBytes {
input: u32,
outputs: Vec<Witness>,
},
Poseidon2Permutation {
inputs: Vec<FunctionInput<F>>,
outputs: Vec<Witness>,
len: u32,
},
Sha256Compression {
inputs: Box<[FunctionInput<F>; 16]>,
hash_values: Box<[FunctionInput<F>; 8]>,
outputs: Box<[Witness; 8]>,
},
}
Expand description
These opcodes represent a specialized computation. Even if any computation can be done using only assert-zero opcodes, it is not always efficient. Some proving systems, can implement several computations more efficiently using techniques such as custom gates and lookup tables.
Variants§
AES128Encrypt
Ciphers (encrypts) the provided plaintext using AES128 in CBC mode, padding the input using PKCS#7.
- inputs: byte array
[u8; N]
- iv: initialization vector
[u8; 16]
- key: user key
[u8; 16]
- outputs: byte vector
[u8]
of lengthinput.len() + (16 - input.len() % 16)
Fields
inputs: Vec<FunctionInput<F>>
iv: Box<[FunctionInput<F>; 16]>
key: Box<[FunctionInput<F>; 16]>
AND
Performs the bitwise AND of lhs
and rhs
. bit_size
must be the same for
both inputs.
- lhs: (witness, bit_size)
- rhs: (witness, bit_size)
- output: a witness whose value is constrained to be lhs AND rhs, as bit_size bit integers
XOR
Performs the bitwise XOR of lhs
and rhs
. bit_size
must be the same for
both inputs.
- lhs: (witness, bit_size)
- rhs: (witness, bit_size)
- output: a witness whose value is constrained to be lhs XOR rhs, as bit_size bit integers
RANGE
Range constraint to ensure that a witness can be represented in the specified number of bits.
- input: (witness, bit_size)
Fields
input: FunctionInput<F>
Blake2s
Computes the Blake2s hash of the inputs, as specified in https://tools.ietf.org/html/rfc7693
- inputs are a byte array, i.e a vector of (witness, 8)
- output is a byte array of length 32, i.e. an array of 32 (witness, 8), constrained to be the blake2s of the inputs.
Blake3
Computes the Blake3 hash of the inputs
- inputs are a byte array, i.e a vector of (witness, 8)
- output is a byte array of length 32, i.e an array of 32 (witness, 8), constrained to be the blake3 of the inputs.
EcdsaSecp256k1
Verifies a ECDSA signature over the secp256k1 curve.
- inputs:
- x coordinate of public key as 32 bytes
- y coordinate of public key as 32 bytes
- the signature, as a 64 bytes array
The signature internally will be represented as
(r, s)
, wherer
ands
are fixed-sized big endian scalar values. As thesecp256k1
has a 256-bit modulus, we have a 64 byte signature whiler
ands
will both be 32 bytes. We expects
to be normalized. This means given the curve’s order,s
should be less than or equal toorder / 2
. This is done to prevent malleability. For more context regarding malleability you can reference BIP 0062. - the hash of the message, as a vector of bytes
- output: 0 for failure and 1 for success
Expected backend behavior:
- The backend MAY fail to prove this opcode if the public key is not on the secp256k1 curve.
- Otherwise the backend MUST constrain the output to be false.
- The backend MUST constrain the output to be false if
s
is not normalized. - The backend MUST constrain the output to match the signature’s validity.
Fields
public_key_x: Box<[FunctionInput<F>; 32]>
public_key_y: Box<[FunctionInput<F>; 32]>
signature: Box<[FunctionInput<F>; 64]>
hashed_message: Box<[FunctionInput<F>; 32]>
EcdsaSecp256r1
Verifies a ECDSA signature over the secp256r1 curve.
Same as EcdsaSecp256k1, but done over another curve.
Fields
public_key_x: Box<[FunctionInput<F>; 32]>
public_key_y: Box<[FunctionInput<F>; 32]>
signature: Box<[FunctionInput<F>; 64]>
hashed_message: Box<[FunctionInput<F>; 32]>
MultiScalarMul
Multiple scalar multiplication (MSM) with a variable base/input point (P) of the embedded curve. An MSM multiplies the points and scalars and sums the results.
- input:
- points (witness, N) a vector of x and y coordinates of input
- points
[x1, y1, x2, y2,...]
. - scalars (witness, N) a vector of low and high limbs of input
- scalars
[s1_low, s1_high, s2_low, s2_high, ...]
. (witness, N) For Barretenberg, they must both be less than 128 bits.
- output:
- a tuple of
x
andy
coordinates of output points computed ass_low*P+s_high*2^{128}*P
- a tuple of
Because the Grumpkin scalar field is bigger than the ACIR field, we
provide 2 ACIR fields representing the low and high parts of the Grumpkin
scalar $a$: a=low+high*2^{128}
, with low, high < 2^{128}
EmbeddedCurveAdd
Addition over the embedded curve on which the witness is defined The opcode makes the following assumptions but does not enforce them because it is more efficient to do it only when required. For instance, adding two points that are on the curve it guarantee to give a point on the curve.
It assumes that the points are on the curve. If the inputs are the same witnesses index, it will perform a doubling, If not, it assumes that the points’ x-coordinates are not equal. It also assumes neither point is the infinity point.
Keccakf1600
Keccak Permutation function of width 1600
- inputs: An array of 25 64-bit Keccak lanes that represent a keccak sponge of 1600 bits
- outputs: The result of a keccak f1600 permutation on the input state. Also an array of 25 Keccak lanes.
RecursiveAggregation
Computes a recursive aggregation object when verifying a proof inside another circuit. The outputted aggregation object will then be either checked in a top-level verifier or aggregated upon again. The aggregation object should be maintained by the backend implementer.
This opcode prepares the verification of the final proof. In order to fully verify a recursive proof, some operations may still be required to be done by the final verifier (e.g. a pairing check). This is why this black box function does not say if verification is passing or not. It delays the expensive part of verification out of the SNARK and leaves it to the final verifier outside of the SNARK circuit.
This opcode also verifies that the key_hash is indeed a hash of verification_key, allowing the user to use the verification key as private inputs and only have the key_hash as public input, which is more performant.
Warning: the key hash logic does not need to be part of the black box and subject to be removed.
If one of the recursive proofs you verify with the black box function fails to verify, then the verification of the final proof of the main ACIR program will ultimately fail.
Fields
verification_key: Vec<FunctionInput<F>>
Verification key of the circuit being verified
proof: Vec<FunctionInput<F>>
public_inputs: Vec<FunctionInput<F>>
These represent the public inputs of the proof we are verifying They should be checked against in the circuit after construction of a new aggregation state
key_hash: FunctionInput<F>
A key hash is used to check the validity of the verification key. The circuit implementing this opcode can use this hash to ensure that the key provided to the circuit matches the key produced by the circuit creator
proof_type: u32
Backend-specific proof type constant. The proof field is agnostic and can come from witness inputs. However, a backend may have many different verifiers which affect the circuit construction. In order for a backend to construct the correct recursive verifier it expects the user to specify a proof type.
BigIntAdd
BigInt addition
BigIntSub
BigInt subtraction
BigIntMul
BigInt multiplication
BigIntDiv
BigInt division
BigIntFromLeBytes
BigInt from le bytes
BigIntToLeBytes
BigInt to le bytes
Poseidon2Permutation
Applies the Poseidon2 permutation function to the given state, outputting the permuted state.
Fields
inputs: Vec<FunctionInput<F>>
Input state for the permutation of Poseidon2
Sha256Compression
Applies the SHA-256 compression function to the input message
§Arguments
inputs
- input message blockhash_values
- state from the previous compressionoutputs
- result of the input compressed into 256 bits
Implementations§
Source§impl<F> BlackBoxFuncCall<F>
impl<F> BlackBoxFuncCall<F>
pub fn get_black_box_func(&self) -> BlackBoxFunc
pub fn name(&self) -> &str
pub fn get_outputs_vec(&self) -> Vec<Witness>
Source§impl<F: Copy> BlackBoxFuncCall<F>
impl<F: Copy> BlackBoxFuncCall<F>
pub fn get_inputs_vec(&self) -> Vec<FunctionInput<F>>
pub fn get_input_witnesses(&self) -> BTreeSet<Witness>
Trait Implementations§
Source§impl<F: Clone> Clone for BlackBoxFuncCall<F>
impl<F: Clone> Clone for BlackBoxFuncCall<F>
Source§fn clone(&self) -> BlackBoxFuncCall<F>
fn clone(&self) -> BlackBoxFuncCall<F>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<'de, F> Deserialize<'de> for BlackBoxFuncCall<F>where
F: Deserialize<'de>,
impl<'de, F> Deserialize<'de> for BlackBoxFuncCall<F>where
F: Deserialize<'de>,
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: Hash> Hash for BlackBoxFuncCall<F>
impl<F: Hash> Hash for BlackBoxFuncCall<F>
Source§impl<F: PartialEq> PartialEq for BlackBoxFuncCall<F>
impl<F: PartialEq> PartialEq for BlackBoxFuncCall<F>
Source§impl<F> ProtoCodec<BlackBoxFuncCall<F>, BlackBoxFuncCall> for ProtoSchema<F>where
F: AcirField,
impl<F> ProtoCodec<BlackBoxFuncCall<F>, BlackBoxFuncCall> for ProtoSchema<F>where
F: AcirField,
Source§fn encode(value: &BlackBoxFuncCall<F>) -> BlackBoxFuncCall
fn encode(value: &BlackBoxFuncCall<F>) -> BlackBoxFuncCall
T
to protobuf representation R
.Source§fn decode(value: &BlackBoxFuncCall) -> Result<BlackBoxFuncCall<F>>
fn decode(value: &BlackBoxFuncCall) -> Result<BlackBoxFuncCall<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.Source§impl<F> Serialize for BlackBoxFuncCall<F>where
F: Serialize,
impl<F> Serialize for BlackBoxFuncCall<F>where
F: Serialize,
impl<F: Eq> Eq for BlackBoxFuncCall<F>
impl<F> StructuralPartialEq for BlackBoxFuncCall<F>
Auto Trait Implementations§
impl<F> Freeze for BlackBoxFuncCall<F>where
F: Freeze,
impl<F> RefUnwindSafe for BlackBoxFuncCall<F>where
F: RefUnwindSafe,
impl<F> Send for BlackBoxFuncCall<F>where
F: Send,
impl<F> Sync for BlackBoxFuncCall<F>where
F: Sync,
impl<F> Unpin for BlackBoxFuncCall<F>where
F: Unpin,
impl<F> UnwindSafe for BlackBoxFuncCall<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