diff --git a/circuits/cpp/barretenberg/acir_tests/acir-to-bberg-circuit/Cargo.lock b/circuits/cpp/barretenberg/acir_tests/acir-to-bberg-circuit/Cargo.lock index 2b176895f30..4fdafa81aa2 100644 --- a/circuits/cpp/barretenberg/acir_tests/acir-to-bberg-circuit/Cargo.lock +++ b/circuits/cpp/barretenberg/acir_tests/acir-to-bberg-circuit/Cargo.lock @@ -18,12 +18,12 @@ dependencies = [ [[package]] name = "acir" -version = "0.16.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bed559b3e6e10a04b2a1af7a8b0f23d4bbaf4a87a6c8ac9946583f8945c53ce5" +checksum = "502a9126627ae67868515031c2283e64f3e1fef5ff93850009ed89a8a24fac60" dependencies = [ - "acir_field 0.16.0", - "brillig_vm 0.16.0", + "acir_field 0.17.0", + "brillig_vm 0.17.0", "flate2", "rmp-serde", "serde", @@ -34,7 +34,7 @@ dependencies = [ name = "acir-to-bberg-circuit" version = "0.1.0" dependencies = [ - "acvm 0.16.0", + "acvm 0.17.0", "base64", "flate2", "noirc_abi", @@ -59,9 +59,9 @@ dependencies = [ [[package]] name = "acir_field" -version = "0.16.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29adbffe34f7ae42e080833364f66ea0e933ca4aa3880e12444780538e1f6767" +checksum = "4a98fe4e3f9156f5551c8c9686e8f720a990d000e1e666e08a86e938a36ac8be" dependencies = [ "ark-bn254", "ark-ff", @@ -92,18 +92,19 @@ dependencies = [ [[package]] name = "acvm" -version = "0.16.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4808764cc92ba018210ec2f276f6d90908263af33f9a8abea6ae4139ba49aa0" +checksum = "95315759a51115860af49a492791ae5155c3d2c0555eec1358faa5d74c763391" dependencies = [ - "acir 0.16.0", - "acvm_stdlib 0.16.0", + "acir 0.17.0", + "acvm_stdlib 0.17.0", "async-trait", "blake2", "indexmap 1.9.3", "k256", "num-bigint", "num-traits", + "p256", "sha2", "sha3", "thiserror", @@ -120,11 +121,11 @@ dependencies = [ [[package]] name = "acvm_stdlib" -version = "0.16.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57b0fea96f9ddc8866782636f1317aa0ac958ab7bc628fa9620a4915cc667edc" +checksum = "0f7d2d8407e55ac26078af1d783408525e7f906e531cb04adcc47650d7994f62" dependencies = [ - "acir 0.16.0", + "acir 0.17.0", ] [[package]] @@ -326,13 +327,14 @@ dependencies = [ [[package]] name = "brillig_vm" -version = "0.16.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9400d1493af661cba05923a5b4a78e3aeaeb4210b321831fc0461b01203191e" +checksum = "36821ba87dd1807784d679bca54d753665014b109f6acfe38516eec7f3d71941" dependencies = [ - "acir_field 0.16.0", + "acir_field 0.17.0", "blake2", "k256", + "p256", "serde", "sha2", "sha3", @@ -691,6 +693,17 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +[[package]] +name = "p256" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51f44edd08f51e2ade572f141051021c5af22677e42b7dd28a88155151c33594" +dependencies = [ + "ecdsa", + "elliptic-curve", + "sha2", +] + [[package]] name = "paste" version = "1.0.13" diff --git a/circuits/cpp/barretenberg/acir_tests/acir-to-bberg-circuit/Cargo.toml b/circuits/cpp/barretenberg/acir_tests/acir-to-bberg-circuit/Cargo.toml index 4b7fc0638ba..21996a28412 100644 --- a/circuits/cpp/barretenberg/acir_tests/acir-to-bberg-circuit/Cargo.toml +++ b/circuits/cpp/barretenberg/acir_tests/acir-to-bberg-circuit/Cargo.toml @@ -12,5 +12,5 @@ serde-big-array = "0.5.1" flate2 = "1.0" base64 = "0.13" -acvm = { version = "0.16.0", features = ["bn254"] } +acvm = { version = "0.17.0", features = ["bn254"] } noirc_abi = { git = "https://github.com/noir-lang/noir.git" } diff --git a/circuits/cpp/barretenberg/acir_tests/acir-to-bberg-circuit/src/barretenberg_structures.rs b/circuits/cpp/barretenberg/acir_tests/acir-to-bberg-circuit/src/barretenberg_structures.rs index cba61049346..8167a1e7af7 100644 --- a/circuits/cpp/barretenberg/acir_tests/acir-to-bberg-circuit/src/barretenberg_structures.rs +++ b/circuits/cpp/barretenberg/acir_tests/acir-to-bberg-circuit/src/barretenberg_structures.rs @@ -126,6 +126,7 @@ impl EcdsaConstraint { buffer } } + #[derive(Clone, Hash, Debug, Serialize, Deserialize)] pub(crate) struct SchnorrConstraint { pub(crate) message: Vec, @@ -390,6 +391,7 @@ pub struct ConstraintSystem { sha256_constraints: Vec, schnorr_constraints: Vec, ecdsa_secp256k1_constraints: Vec, + ecdsa_secp256r1_constraints: Vec, blake2s_constraints: Vec, block_constraints: Vec, keccak_constraints: Vec, @@ -454,6 +456,14 @@ impl ConstraintSystem { self } + pub(crate) fn ecdsa_secp256r1_constraints( + mut self, + ecdsa_secp256r1_constraints: Vec, + ) -> Self { + self.ecdsa_secp256r1_constraints = ecdsa_secp256r1_constraints; + self + } + pub(crate) fn blake2s_constraints( mut self, blake2s_constraints: Vec, @@ -555,12 +565,18 @@ impl ConstraintSystem { } // Serialize each ECDSA constraint - let ecdsa_len = self.ecdsa_secp256k1_constraints.len() as u32; - buffer.extend_from_slice(&ecdsa_len.to_be_bytes()); + let ecdsa_k1_len = self.ecdsa_secp256k1_constraints.len() as u32; + buffer.extend_from_slice(&ecdsa_k1_len.to_be_bytes()); for constraint in self.ecdsa_secp256k1_constraints.iter() { buffer.extend(&constraint.to_bytes()); } + let ecdsa_r1_len = self.ecdsa_secp256r1_constraints.len() as u32; + buffer.extend_from_slice(&ecdsa_r1_len.to_be_bytes()); + for constraint in self.ecdsa_secp256r1_constraints.iter() { + buffer.extend(&constraint.to_bytes()); + } + // Serialize each Blake2s constraint let blake2s_len = self.blake2s_constraints.len() as u32; buffer.extend_from_slice(&blake2s_len.to_be_bytes()); @@ -768,6 +784,7 @@ impl TryFrom<&Circuit> for ConstraintSystem { let mut pedersen_constraints: Vec = Vec::new(); let mut schnorr_constraints: Vec = Vec::new(); let mut ecdsa_secp256k1_constraints: Vec = Vec::new(); + let mut ecdsa_secp256r1_constraints: Vec = Vec::new(); let mut fixed_base_scalar_mul_constraints: Vec = Vec::new(); let mut hash_to_field_constraints: Vec = Vec::new(); let mut recursion_constraints: Vec = Vec::new(); @@ -1018,6 +1035,65 @@ impl TryFrom<&Circuit> for ConstraintSystem { ecdsa_secp256k1_constraints.push(constraint); } + BlackBoxFuncCall::EcdsaSecp256r1 { + public_key_x: public_key_x_inputs, + public_key_y: public_key_y_inputs, + signature: signature_inputs, + hashed_message: hashed_message_inputs, + output, + } => { + // public key x + let mut public_key_x_inputs = public_key_x_inputs.iter(); + let mut public_key_x = [0i32; 32]; + for (i, pkx) in public_key_x.iter_mut().enumerate() { + let x_byte = public_key_x_inputs + .next() + .ok_or_else(|| format!("Missing rest of `x` component for public key. Tried to get byte {i} but failed"))?; + let x_byte_index = x_byte.witness.witness_index() as i32; + *pkx = x_byte_index; + } + + // public key y + let mut public_key_y_inputs = public_key_y_inputs.iter(); + let mut public_key_y = [0i32; 32]; + for (i, pky) in public_key_y.iter_mut().enumerate() { + let y_byte = public_key_y_inputs + .next() + .ok_or_else(|| format!("Missing rest of `y` component for public key. Tried to get byte {i} but failed"))?; + let y_byte_index = y_byte.witness.witness_index() as i32; + *pky = y_byte_index; + } + + // signature + let mut signature_inputs = signature_inputs.iter(); + let mut signature = [0i32; 64]; + for (i, sig) in signature.iter_mut().enumerate() { + let sig_byte = + signature_inputs.next().ok_or_else(|| format!("Missing rest of signature. Tried to get byte {i} but failed"))?; + let sig_byte_index = sig_byte.witness.witness_index() as i32; + *sig = sig_byte_index; + } + + // The rest of the input is the message + let mut hashed_message = Vec::new(); + for msg in hashed_message_inputs.iter() { + let msg_byte_index = msg.witness.witness_index() as i32; + hashed_message.push(msg_byte_index); + } + + // result + let result = output.witness_index() as i32; + + let constraint = EcdsaConstraint { + hashed_message, + signature, + public_key_x, + public_key_y, + result, + }; + + ecdsa_secp256r1_constraints.push(constraint); + } BlackBoxFuncCall::FixedBaseScalarMul { input, outputs } => { let scalar = input.witness.witness_index() as i32; @@ -1204,6 +1280,7 @@ impl TryFrom<&Circuit> for ConstraintSystem { pedersen_constraints, schnorr_constraints, ecdsa_secp256k1_constraints, + ecdsa_secp256r1_constraints, blake2s_constraints, block_constraints, keccak_constraints, diff --git a/circuits/cpp/barretenberg/acir_tests/acir-to-bberg-circuit/src/main.rs b/circuits/cpp/barretenberg/acir_tests/acir-to-bberg-circuit/src/main.rs index f85d7871eeb..d56241508a7 100644 --- a/circuits/cpp/barretenberg/acir_tests/acir-to-bberg-circuit/src/main.rs +++ b/circuits/cpp/barretenberg/acir_tests/acir-to-bberg-circuit/src/main.rs @@ -16,12 +16,9 @@ pub fn main() { let circuit_path = Path::new(&path_string); let circuit_bytes = std::fs::read(&circuit_path).unwrap(); - - let mut program: PreprocessedProgram = - serde_json::from_slice(&circuit_bytes).expect("could not deserialize program"); - program.proving_key = vec![]; - program.verification_key = vec![]; + let program: PreprocessedProgram = + serde_json::from_slice(&circuit_bytes).expect("could not deserialize program"); write_to_file(&serde_json::to_vec(&program).unwrap(), &circuit_path); } @@ -49,10 +46,7 @@ pub struct PreprocessedProgram { serialize_with = "serialize_circuit", deserialize_with = "deserialize_circuit" )] - pub bytecode: Circuit, - - pub proving_key: Vec, - pub verification_key: Vec, + pub bytecode: Circuit } fn serialize_circuit(circuit: &Circuit, s: S) -> Result diff --git a/circuits/cpp/barretenberg/acir_tests/run_acir_tests.sh b/circuits/cpp/barretenberg/acir_tests/run_acir_tests.sh index b1ae31b7ee5..2adc8861c1a 100755 --- a/circuits/cpp/barretenberg/acir_tests/run_acir_tests.sh +++ b/circuits/cpp/barretenberg/acir_tests/run_acir_tests.sh @@ -8,11 +8,12 @@ set -e BB=$PWD/${BB:-../cpp/build/bin/bb} ATBBC=$PWD/acir-to-bberg-circuit/target/release/acir-to-bberg-circuit CRS_PATH=~/.bb-crs +BRANCH=master # Pull down the test vectors from the noir repo, if we don't have the folder already. if [ ! -d acir_tests ]; then rm -rf noir - git clone --filter=blob:none --no-checkout https://github.com/noir-lang/noir.git + git clone -b $BRANCH --filter=blob:none --no-checkout https://github.com/noir-lang/noir.git cd noir git sparse-checkout init --cone git sparse-checkout set crates/nargo_cli/tests/test_data