Skip to content

Commit 66d3275

Browse files
AztecBotTomAFrench
andauthored
feat: Sync from aztec-packages (#6730)
Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com> Co-authored-by: Tom French <tom@tomfren.ch>
1 parent 6d0f86b commit 66d3275

File tree

40 files changed

+62
-1042
lines changed

40 files changed

+62
-1042
lines changed

.aztec-sync-commit

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0577c1a70e9746bd06f07d2813af1be39e01ca02
1+
fca96007d6055dcf00b72a46630c680fcb6d190d

acvm-repo/acir/codegen/acir.cpp

+2-126
Original file line numberDiff line numberDiff line change
@@ -318,18 +318,6 @@ namespace Program {
318318
static EcdsaSecp256r1 bincodeDeserialize(std::vector<uint8_t>);
319319
};
320320

321-
struct SchnorrVerify {
322-
Program::MemoryAddress public_key_x;
323-
Program::MemoryAddress public_key_y;
324-
Program::HeapVector message;
325-
Program::HeapVector signature;
326-
Program::MemoryAddress result;
327-
328-
friend bool operator==(const SchnorrVerify&, const SchnorrVerify&);
329-
std::vector<uint8_t> bincodeSerialize() const;
330-
static SchnorrVerify bincodeDeserialize(std::vector<uint8_t>);
331-
};
332-
333321
struct MultiScalarMul {
334322
Program::HeapVector points;
335323
Program::HeapVector scalars;
@@ -444,7 +432,7 @@ namespace Program {
444432
static ToRadix bincodeDeserialize(std::vector<uint8_t>);
445433
};
446434

447-
std::variant<AES128Encrypt, Blake2s, Blake3, Keccakf1600, EcdsaSecp256k1, EcdsaSecp256r1, SchnorrVerify, MultiScalarMul, EmbeddedCurveAdd, BigIntAdd, BigIntSub, BigIntMul, BigIntDiv, BigIntFromLeBytes, BigIntToLeBytes, Poseidon2Permutation, Sha256Compression, ToRadix> value;
435+
std::variant<AES128Encrypt, Blake2s, Blake3, Keccakf1600, EcdsaSecp256k1, EcdsaSecp256r1, MultiScalarMul, EmbeddedCurveAdd, BigIntAdd, BigIntSub, BigIntMul, BigIntDiv, BigIntFromLeBytes, BigIntToLeBytes, Poseidon2Permutation, Sha256Compression, ToRadix> value;
448436

449437
friend bool operator==(const BlackBoxOp&, const BlackBoxOp&);
450438
std::vector<uint8_t> bincodeSerialize() const;
@@ -817,18 +805,6 @@ namespace Program {
817805
static Blake3 bincodeDeserialize(std::vector<uint8_t>);
818806
};
819807

820-
struct SchnorrVerify {
821-
Program::FunctionInput public_key_x;
822-
Program::FunctionInput public_key_y;
823-
std::array<Program::FunctionInput, 64> signature;
824-
std::vector<Program::FunctionInput> message;
825-
Program::Witness output;
826-
827-
friend bool operator==(const SchnorrVerify&, const SchnorrVerify&);
828-
std::vector<uint8_t> bincodeSerialize() const;
829-
static SchnorrVerify bincodeDeserialize(std::vector<uint8_t>);
830-
};
831-
832808
struct EcdsaSecp256k1 {
833809
std::array<Program::FunctionInput, 32> public_key_x;
834810
std::array<Program::FunctionInput, 32> public_key_y;
@@ -973,7 +949,7 @@ namespace Program {
973949
static Sha256Compression bincodeDeserialize(std::vector<uint8_t>);
974950
};
975951

976-
std::variant<AES128Encrypt, AND, XOR, RANGE, Blake2s, Blake3, SchnorrVerify, EcdsaSecp256k1, EcdsaSecp256r1, MultiScalarMul, EmbeddedCurveAdd, Keccakf1600, RecursiveAggregation, BigIntAdd, BigIntSub, BigIntMul, BigIntDiv, BigIntFromLeBytes, BigIntToLeBytes, Poseidon2Permutation, Sha256Compression> value;
952+
std::variant<AES128Encrypt, AND, XOR, RANGE, Blake2s, Blake3, EcdsaSecp256k1, EcdsaSecp256r1, MultiScalarMul, EmbeddedCurveAdd, Keccakf1600, RecursiveAggregation, BigIntAdd, BigIntSub, BigIntMul, BigIntDiv, BigIntFromLeBytes, BigIntToLeBytes, Poseidon2Permutation, Sha256Compression> value;
977953

978954
friend bool operator==(const BlackBoxFuncCall&, const BlackBoxFuncCall&);
979955
std::vector<uint8_t> bincodeSerialize() const;
@@ -2528,56 +2504,6 @@ Program::BlackBoxFuncCall::Blake3 serde::Deserializable<Program::BlackBoxFuncCal
25282504
return obj;
25292505
}
25302506

2531-
namespace Program {
2532-
2533-
inline bool operator==(const BlackBoxFuncCall::SchnorrVerify &lhs, const BlackBoxFuncCall::SchnorrVerify &rhs) {
2534-
if (!(lhs.public_key_x == rhs.public_key_x)) { return false; }
2535-
if (!(lhs.public_key_y == rhs.public_key_y)) { return false; }
2536-
if (!(lhs.signature == rhs.signature)) { return false; }
2537-
if (!(lhs.message == rhs.message)) { return false; }
2538-
if (!(lhs.output == rhs.output)) { return false; }
2539-
return true;
2540-
}
2541-
2542-
inline std::vector<uint8_t> BlackBoxFuncCall::SchnorrVerify::bincodeSerialize() const {
2543-
auto serializer = serde::BincodeSerializer();
2544-
serde::Serializable<BlackBoxFuncCall::SchnorrVerify>::serialize(*this, serializer);
2545-
return std::move(serializer).bytes();
2546-
}
2547-
2548-
inline BlackBoxFuncCall::SchnorrVerify BlackBoxFuncCall::SchnorrVerify::bincodeDeserialize(std::vector<uint8_t> input) {
2549-
auto deserializer = serde::BincodeDeserializer(input);
2550-
auto value = serde::Deserializable<BlackBoxFuncCall::SchnorrVerify>::deserialize(deserializer);
2551-
if (deserializer.get_buffer_offset() < input.size()) {
2552-
throw serde::deserialization_error("Some input bytes were not read");
2553-
}
2554-
return value;
2555-
}
2556-
2557-
} // end of namespace Program
2558-
2559-
template <>
2560-
template <typename Serializer>
2561-
void serde::Serializable<Program::BlackBoxFuncCall::SchnorrVerify>::serialize(const Program::BlackBoxFuncCall::SchnorrVerify &obj, Serializer &serializer) {
2562-
serde::Serializable<decltype(obj.public_key_x)>::serialize(obj.public_key_x, serializer);
2563-
serde::Serializable<decltype(obj.public_key_y)>::serialize(obj.public_key_y, serializer);
2564-
serde::Serializable<decltype(obj.signature)>::serialize(obj.signature, serializer);
2565-
serde::Serializable<decltype(obj.message)>::serialize(obj.message, serializer);
2566-
serde::Serializable<decltype(obj.output)>::serialize(obj.output, serializer);
2567-
}
2568-
2569-
template <>
2570-
template <typename Deserializer>
2571-
Program::BlackBoxFuncCall::SchnorrVerify serde::Deserializable<Program::BlackBoxFuncCall::SchnorrVerify>::deserialize(Deserializer &deserializer) {
2572-
Program::BlackBoxFuncCall::SchnorrVerify obj;
2573-
obj.public_key_x = serde::Deserializable<decltype(obj.public_key_x)>::deserialize(deserializer);
2574-
obj.public_key_y = serde::Deserializable<decltype(obj.public_key_y)>::deserialize(deserializer);
2575-
obj.signature = serde::Deserializable<decltype(obj.signature)>::deserialize(deserializer);
2576-
obj.message = serde::Deserializable<decltype(obj.message)>::deserialize(deserializer);
2577-
obj.output = serde::Deserializable<decltype(obj.output)>::deserialize(deserializer);
2578-
return obj;
2579-
}
2580-
25812507
namespace Program {
25822508

25832509
inline bool operator==(const BlackBoxFuncCall::EcdsaSecp256k1 &lhs, const BlackBoxFuncCall::EcdsaSecp256k1 &rhs) {
@@ -3518,56 +3444,6 @@ Program::BlackBoxOp::EcdsaSecp256r1 serde::Deserializable<Program::BlackBoxOp::E
35183444
return obj;
35193445
}
35203446

3521-
namespace Program {
3522-
3523-
inline bool operator==(const BlackBoxOp::SchnorrVerify &lhs, const BlackBoxOp::SchnorrVerify &rhs) {
3524-
if (!(lhs.public_key_x == rhs.public_key_x)) { return false; }
3525-
if (!(lhs.public_key_y == rhs.public_key_y)) { return false; }
3526-
if (!(lhs.message == rhs.message)) { return false; }
3527-
if (!(lhs.signature == rhs.signature)) { return false; }
3528-
if (!(lhs.result == rhs.result)) { return false; }
3529-
return true;
3530-
}
3531-
3532-
inline std::vector<uint8_t> BlackBoxOp::SchnorrVerify::bincodeSerialize() const {
3533-
auto serializer = serde::BincodeSerializer();
3534-
serde::Serializable<BlackBoxOp::SchnorrVerify>::serialize(*this, serializer);
3535-
return std::move(serializer).bytes();
3536-
}
3537-
3538-
inline BlackBoxOp::SchnorrVerify BlackBoxOp::SchnorrVerify::bincodeDeserialize(std::vector<uint8_t> input) {
3539-
auto deserializer = serde::BincodeDeserializer(input);
3540-
auto value = serde::Deserializable<BlackBoxOp::SchnorrVerify>::deserialize(deserializer);
3541-
if (deserializer.get_buffer_offset() < input.size()) {
3542-
throw serde::deserialization_error("Some input bytes were not read");
3543-
}
3544-
return value;
3545-
}
3546-
3547-
} // end of namespace Program
3548-
3549-
template <>
3550-
template <typename Serializer>
3551-
void serde::Serializable<Program::BlackBoxOp::SchnorrVerify>::serialize(const Program::BlackBoxOp::SchnorrVerify &obj, Serializer &serializer) {
3552-
serde::Serializable<decltype(obj.public_key_x)>::serialize(obj.public_key_x, serializer);
3553-
serde::Serializable<decltype(obj.public_key_y)>::serialize(obj.public_key_y, serializer);
3554-
serde::Serializable<decltype(obj.message)>::serialize(obj.message, serializer);
3555-
serde::Serializable<decltype(obj.signature)>::serialize(obj.signature, serializer);
3556-
serde::Serializable<decltype(obj.result)>::serialize(obj.result, serializer);
3557-
}
3558-
3559-
template <>
3560-
template <typename Deserializer>
3561-
Program::BlackBoxOp::SchnorrVerify serde::Deserializable<Program::BlackBoxOp::SchnorrVerify>::deserialize(Deserializer &deserializer) {
3562-
Program::BlackBoxOp::SchnorrVerify obj;
3563-
obj.public_key_x = serde::Deserializable<decltype(obj.public_key_x)>::deserialize(deserializer);
3564-
obj.public_key_y = serde::Deserializable<decltype(obj.public_key_y)>::deserialize(deserializer);
3565-
obj.message = serde::Deserializable<decltype(obj.message)>::deserialize(deserializer);
3566-
obj.signature = serde::Deserializable<decltype(obj.signature)>::deserialize(deserializer);
3567-
obj.result = serde::Deserializable<decltype(obj.result)>::deserialize(deserializer);
3568-
return obj;
3569-
}
3570-
35713447
namespace Program {
35723448

35733449
inline bool operator==(const BlackBoxOp::MultiScalarMul &lhs, const BlackBoxOp::MultiScalarMul &rhs) {

acvm-repo/acir/src/circuit/black_box_functions.rs

-30
Original file line numberDiff line numberDiff line change
@@ -51,41 +51,13 @@ pub enum BlackBoxFunc {
5151
/// (witness, 8), constrained to be the blake3 of the inputs.
5252
Blake3,
5353

54-
/// Verify a Schnorr signature over the embedded curve
55-
/// - inputs are:
56-
/// - Public key as 2 (witness, 254)
57-
/// - signature as a vector of 64 bytes (witness, 8)
58-
/// - message as a vector of (witness, 8)
59-
/// - output: A witness representing the result of the signature
60-
/// verification; 0 for failure and 1 for success.
61-
///
62-
/// Since the scalar field of the embedded curve is NOT the ACIR field, the
63-
/// `(r,s)` signature is represented as a 64 bytes array for the two field
64-
/// elements. On the other hand, the public key coordinates are ACIR fields.
65-
/// The proving system decides how the message is to be hashed. Barretenberg
66-
/// uses Blake2s.
67-
///
68-
/// Verifies a Schnorr signature over a curve which is "pairing friendly"
69-
/// with the curve on which the ACIR circuit is defined.
70-
///
71-
/// The exact curve which this signature uses will vary based on the curve
72-
/// being used by ACIR. For example, the BN254 curve supports Schnorr
73-
/// signatures over the [Grumpkin][grumpkin] curve.
74-
///
75-
/// [grumpkin]: https://hackmd.io/@aztec-network/ByzgNxBfd#2-Grumpkin---A-curve-on-top-of-BN-254-for-SNARK-efficient-group-operations
76-
SchnorrVerify,
7754
/// Verifies a ECDSA signature over the secp256k1 curve.
7855
/// - inputs:
7956
/// - x coordinate of public key as 32 bytes
8057
/// - y coordinate of public key as 32 bytes
8158
/// - the signature, as a 64 bytes array
8259
/// - the hash of the message, as a vector of bytes
8360
/// - output: 0 for failure and 1 for success
84-
///
85-
/// Inputs and outputs are similar to SchnorrVerify, except that because we
86-
/// use a different curve (secp256k1), the field elements involved in the
87-
/// signature and the public key are defined as an array of 32 bytes.
88-
/// Another difference is that we assume the message is already hashed.
8961
EcdsaSecp256k1,
9062

9163
/// Verifies a ECDSA signature over the secp256r1 curve.
@@ -196,7 +168,6 @@ impl BlackBoxFunc {
196168
pub fn name(&self) -> &'static str {
197169
match self {
198170
BlackBoxFunc::AES128Encrypt => "aes128_encrypt",
199-
BlackBoxFunc::SchnorrVerify => "schnorr_verify",
200171
BlackBoxFunc::Blake2s => "blake2s",
201172
BlackBoxFunc::Blake3 => "blake3",
202173
BlackBoxFunc::EcdsaSecp256k1 => "ecdsa_secp256k1",
@@ -222,7 +193,6 @@ impl BlackBoxFunc {
222193
pub fn lookup(op_name: &str) -> Option<BlackBoxFunc> {
223194
match op_name {
224195
"aes128_encrypt" => Some(BlackBoxFunc::AES128Encrypt),
225-
"schnorr_verify" => Some(BlackBoxFunc::SchnorrVerify),
226196
"blake2s" => Some(BlackBoxFunc::Blake2s),
227197
"blake3" => Some(BlackBoxFunc::Blake3),
228198
"ecdsa_secp256k1" => Some(BlackBoxFunc::EcdsaSecp256k1),

acvm-repo/acir/src/circuit/mod.rs

+1-19
Original file line numberDiff line numberDiff line change
@@ -406,29 +406,12 @@ mod tests {
406406
Opcode::BlackBoxFuncCall(BlackBoxFuncCall::Keccakf1600 { inputs, outputs })
407407
}
408408

409-
fn schnorr_verify_opcode<F: AcirField>() -> Opcode<F> {
410-
let public_key_x = FunctionInput::witness(Witness(1), FieldElement::max_num_bits());
411-
let public_key_y = FunctionInput::witness(Witness(2), FieldElement::max_num_bits());
412-
let signature: Box<[FunctionInput<F>; 64]> =
413-
Box::new(std::array::from_fn(|i| FunctionInput::witness(Witness(i as u32 + 3), 8)));
414-
let message: Vec<FunctionInput<F>> = vec![FunctionInput::witness(Witness(67), 8)];
415-
let output = Witness(68);
416-
417-
Opcode::BlackBoxFuncCall(BlackBoxFuncCall::SchnorrVerify {
418-
public_key_x,
419-
public_key_y,
420-
signature,
421-
message,
422-
output,
423-
})
424-
}
425-
426409
#[test]
427410
fn serialization_roundtrip() {
428411
let circuit = Circuit {
429412
current_witness_index: 5,
430413
expression_width: ExpressionWidth::Unbounded,
431-
opcodes: vec![and_opcode::<FieldElement>(), range_opcode(), schnorr_verify_opcode()],
414+
opcodes: vec![and_opcode::<FieldElement>(), range_opcode()],
432415
private_parameters: BTreeSet::new(),
433416
public_parameters: PublicInputs(BTreeSet::from_iter(vec![Witness(2), Witness(12)])),
434417
return_values: PublicInputs(BTreeSet::from_iter(vec![Witness(4), Witness(12)])),
@@ -462,7 +445,6 @@ mod tests {
462445
range_opcode(),
463446
and_opcode(),
464447
keccakf1600_opcode(),
465-
schnorr_verify_opcode(),
466448
],
467449
private_parameters: BTreeSet::new(),
468450
public_parameters: PublicInputs(BTreeSet::from_iter(vec![Witness(2)])),

acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs

-52
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,6 @@ pub enum BlackBoxFuncCall<F> {
108108
inputs: Vec<FunctionInput<F>>,
109109
outputs: Box<[Witness; 32]>,
110110
},
111-
SchnorrVerify {
112-
public_key_x: FunctionInput<F>,
113-
public_key_y: FunctionInput<F>,
114-
#[serde(
115-
serialize_with = "serialize_big_array",
116-
deserialize_with = "deserialize_big_array_into_box"
117-
)]
118-
signature: Box<[FunctionInput<F>; 64]>,
119-
message: Vec<FunctionInput<F>>,
120-
output: Witness,
121-
},
122111
EcdsaSecp256k1 {
123112
public_key_x: Box<[FunctionInput<F>; 32]>,
124113
public_key_y: Box<[FunctionInput<F>; 32]>,
@@ -234,7 +223,6 @@ impl<F: Copy> BlackBoxFuncCall<F> {
234223
BlackBoxFuncCall::RANGE { .. } => BlackBoxFunc::RANGE,
235224
BlackBoxFuncCall::Blake2s { .. } => BlackBoxFunc::Blake2s,
236225
BlackBoxFuncCall::Blake3 { .. } => BlackBoxFunc::Blake3,
237-
BlackBoxFuncCall::SchnorrVerify { .. } => BlackBoxFunc::SchnorrVerify,
238226
BlackBoxFuncCall::EcdsaSecp256k1 { .. } => BlackBoxFunc::EcdsaSecp256k1,
239227
BlackBoxFuncCall::EcdsaSecp256r1 { .. } => BlackBoxFunc::EcdsaSecp256r1,
240228
BlackBoxFuncCall::MultiScalarMul { .. } => BlackBoxFunc::MultiScalarMul,
@@ -288,21 +276,6 @@ impl<F: Copy> BlackBoxFuncCall<F> {
288276
vec![input1[0], input1[1], input2[0], input2[1]]
289277
}
290278
BlackBoxFuncCall::RANGE { input } => vec![*input],
291-
BlackBoxFuncCall::SchnorrVerify {
292-
public_key_x,
293-
public_key_y,
294-
signature,
295-
message,
296-
..
297-
} => {
298-
let mut inputs: Vec<FunctionInput<F>> =
299-
Vec::with_capacity(2 + signature.len() + message.len());
300-
inputs.push(*public_key_x);
301-
inputs.push(*public_key_y);
302-
inputs.extend(signature.iter().copied());
303-
inputs.extend(message.iter().copied());
304-
inputs
305-
}
306279
BlackBoxFuncCall::EcdsaSecp256k1 {
307280
public_key_x,
308281
public_key_y,
@@ -372,7 +345,6 @@ impl<F: Copy> BlackBoxFuncCall<F> {
372345

373346
BlackBoxFuncCall::AND { output, .. }
374347
| BlackBoxFuncCall::XOR { output, .. }
375-
| BlackBoxFuncCall::SchnorrVerify { output, .. }
376348
| BlackBoxFuncCall::EcdsaSecp256k1 { output, .. }
377349
| BlackBoxFuncCall::EcdsaSecp256r1 { output, .. } => vec![*output],
378350
BlackBoxFuncCall::MultiScalarMul { outputs, .. }
@@ -525,22 +497,6 @@ mod tests {
525497

526498
Opcode::BlackBoxFuncCall(BlackBoxFuncCall::Keccakf1600 { inputs, outputs })
527499
}
528-
fn schnorr_verify_opcode<F: AcirField>() -> Opcode<F> {
529-
let public_key_x = FunctionInput::witness(Witness(1), FieldElement::max_num_bits());
530-
let public_key_y = FunctionInput::witness(Witness(2), FieldElement::max_num_bits());
531-
let signature: Box<[FunctionInput<F>; 64]> =
532-
Box::new(std::array::from_fn(|i| FunctionInput::witness(Witness(i as u32 + 3), 8)));
533-
let message: Vec<FunctionInput<F>> = vec![FunctionInput::witness(Witness(67), 8)];
534-
let output = Witness(68);
535-
536-
Opcode::BlackBoxFuncCall(BlackBoxFuncCall::SchnorrVerify {
537-
public_key_x,
538-
public_key_y,
539-
signature,
540-
message,
541-
output,
542-
})
543-
}
544500

545501
#[test]
546502
fn keccakf1600_serialization_roundtrip() {
@@ -549,12 +505,4 @@ mod tests {
549505
let recovered_opcode = bincode::deserialize(&buf).unwrap();
550506
assert_eq!(opcode, recovered_opcode);
551507
}
552-
553-
#[test]
554-
fn schnorr_serialization_roundtrip() {
555-
let opcode = schnorr_verify_opcode::<FieldElement>();
556-
let buf = bincode::serialize(&opcode).unwrap();
557-
let recovered_opcode = bincode::deserialize(&buf).unwrap();
558-
assert_eq!(opcode, recovered_opcode);
559-
}
560508
}

0 commit comments

Comments
 (0)