diff --git a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_black_box.rs b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_black_box.rs index 9979bf0cd29..542c23fcd2e 100644 --- a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_black_box.rs +++ b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_black_box.rs @@ -92,6 +92,28 @@ pub(crate) fn convert_black_box_call( ) } } + BlackBoxFunc::EcdsaSecp256r1 => { + if let ( + [BrilligVariable::BrilligArray(public_key_x), BrilligVariable::BrilligArray(public_key_y), BrilligVariable::BrilligArray(signature), message], + [BrilligVariable::Simple(result_register)], + ) = (function_arguments, function_results) + { + let message_hash_vector = + convert_array_or_vector(brillig_context, message, bb_func); + brillig_context.black_box_op_instruction(BlackBoxOp::EcdsaSecp256r1 { + hashed_msg: message_hash_vector.to_heap_vector(), + public_key_x: public_key_x.to_heap_array(), + public_key_y: public_key_y.to_heap_array(), + signature: signature.to_heap_array(), + result: *result_register, + }); + } else { + unreachable!( + "ICE: EcdsaSecp256r1 expects four array arguments and one register result" + ) + } + } + BlackBoxFunc::PedersenCommitment => { if let ( [message, BrilligVariable::Simple(domain_separator)], @@ -160,7 +182,18 @@ pub(crate) fn convert_black_box_call( ) } } - _ => unimplemented!("ICE: Black box function {:?} is not implemented", bb_func), + BlackBoxFunc::AND => { + unreachable!("ICE: `BlackBoxFunc::AND` calls should be transformed into a `BinaryOp`") + } + BlackBoxFunc::XOR => { + unreachable!("ICE: `BlackBoxFunc::XOR` calls should be transformed into a `BinaryOp`") + } + BlackBoxFunc::RANGE => unreachable!( + "ICE: `BlackBoxFunc::RANGE` calls should be transformed into a `Instruction::Cast`" + ), + BlackBoxFunc::RecursiveAggregation => unimplemented!( + "ICE: `BlackBoxFunc::RecursiveAggregation` is not implemented by the Brillig VM" + ), } } diff --git a/test_programs/execution_success/brillig_ecdsa/Nargo.toml b/test_programs/execution_success/brillig_ecdsa_secp256k1/Nargo.toml similarity index 62% rename from test_programs/execution_success/brillig_ecdsa/Nargo.toml rename to test_programs/execution_success/brillig_ecdsa_secp256k1/Nargo.toml index 972dd9ce93b..495a49f2247 100644 --- a/test_programs/execution_success/brillig_ecdsa/Nargo.toml +++ b/test_programs/execution_success/brillig_ecdsa_secp256k1/Nargo.toml @@ -1,5 +1,5 @@ [package] -name = "brillig_ecdsa" +name = "brillig_ecdsa_secp256k1" type = "bin" authors = [""] diff --git a/test_programs/execution_success/brillig_ecdsa/Prover.toml b/test_programs/execution_success/brillig_ecdsa_secp256k1/Prover.toml similarity index 100% rename from test_programs/execution_success/brillig_ecdsa/Prover.toml rename to test_programs/execution_success/brillig_ecdsa_secp256k1/Prover.toml diff --git a/test_programs/execution_success/brillig_ecdsa/src/main.nr b/test_programs/execution_success/brillig_ecdsa_secp256k1/src/main.nr similarity index 52% rename from test_programs/execution_success/brillig_ecdsa/src/main.nr rename to test_programs/execution_success/brillig_ecdsa_secp256k1/src/main.nr index 23f017aa336..5d84d885567 100644 --- a/test_programs/execution_success/brillig_ecdsa/src/main.nr +++ b/test_programs/execution_success/brillig_ecdsa_secp256k1/src/main.nr @@ -2,10 +2,15 @@ use dep::std; // Tests a very simple program. // // The features being tested is ecdsa in brillig -fn main(hashed_message: [u8;32], pub_key_x: [u8;32], pub_key_y: [u8;32], signature: [u8;64]) { +fn main(hashed_message: [u8; 32], pub_key_x: [u8; 32], pub_key_y: [u8; 32], signature: [u8; 64]) { assert(ecdsa(hashed_message, pub_key_x, pub_key_y, signature)); } -unconstrained fn ecdsa(hashed_message: [u8;32], pub_key_x: [u8;32], pub_key_y: [u8;32], signature: [u8;64]) -> bool { +unconstrained fn ecdsa( + hashed_message: [u8; 32], + pub_key_x: [u8; 32], + pub_key_y: [u8; 32], + signature: [u8; 64] +) -> bool { std::ecdsa_secp256k1::verify_signature(pub_key_x, pub_key_y, signature, hashed_message) } diff --git a/test_programs/execution_success/brillig_ecdsa_secp256r1/Nargo.toml b/test_programs/execution_success/brillig_ecdsa_secp256r1/Nargo.toml new file mode 100644 index 00000000000..0a71e782104 --- /dev/null +++ b/test_programs/execution_success/brillig_ecdsa_secp256r1/Nargo.toml @@ -0,0 +1,6 @@ +[package] +name = "brillig_ecdsa_secp256r1" +type = "bin" +authors = [""] + +[dependencies] diff --git a/test_programs/execution_success/brillig_ecdsa_secp256r1/Prover.toml b/test_programs/execution_success/brillig_ecdsa_secp256r1/Prover.toml new file mode 100644 index 00000000000..a45f799877b --- /dev/null +++ b/test_programs/execution_success/brillig_ecdsa_secp256r1/Prover.toml @@ -0,0 +1,20 @@ +hashed_message = [ + 84, 112, 91, 163, 186, 175, 219, 223, 186, 140, 95, 154, 112, 247, 168, 155, 238, 152, + 217, 6, 181, 62, 49, 7, 77, 167, 186, 236, 220, 13, 169, 173, +] +pub_key_x = [ + 85, 15, 71, 16, 3, 243, 223, 151, 195, 223, 80, 106, 199, 151, 246, 114, 31, 177, 161, + 251, 123, 143, 111, 131, 210, 36, 73, 138, 101, 200, 142, 36, +] +pub_key_y = [ + 19, 96, 147, 215, 1, 46, 80, 154, 115, 113, 92, 189, 11, 0, 163, 204, 15, 244, 181, + 192, 27, 63, 250, 25, 106, 177, 251, 50, 112, 54, 184, 230, +] +signature = [ + 44, 112, 168, 208, 132, 182, 43, 252, 92, 224, 54, 65, 202, 249, 247, 42, + 212, 218, 140, 129, 191, 230, 236, 148, 135, 187, 94, 27, 239, 98, 161, 50, + 24, 173, 158, 226, 158, 175, 53, 31, 220, 80, 241, 82, 12, 66, 94, 155, + 144, 138, 7, 39, 139, 67, 176, 236, 123, 135, 39, 120, 193, 78, 7, 132 +] + + diff --git a/test_programs/execution_success/brillig_ecdsa_secp256r1/src/main.nr b/test_programs/execution_success/brillig_ecdsa_secp256r1/src/main.nr new file mode 100644 index 00000000000..9da07f531aa --- /dev/null +++ b/test_programs/execution_success/brillig_ecdsa_secp256r1/src/main.nr @@ -0,0 +1,16 @@ +use dep::std; +// Tests a very simple program. +// +// The features being tested is ecdsa in brillig +fn main(hashed_message: [u8; 32], pub_key_x: [u8; 32], pub_key_y: [u8; 32], signature: [u8; 64]) { + assert(ecdsa(hashed_message, pub_key_x, pub_key_y, signature)); +} + +unconstrained fn ecdsa( + hashed_message: [u8; 32], + pub_key_x: [u8; 32], + pub_key_y: [u8; 32], + signature: [u8; 64] +) -> bool { + std::ecdsa_secp256r1::verify_signature(pub_key_x, pub_key_y, signature, hashed_message) +}