-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(brillig): implemented blackbox functions (#1788)
* feat(brillig): implemented some blackbox functions * test: added tests for bb funcs * feat: added debug_show for bb funcs
- Loading branch information
1 parent
be36c1e
commit f9f38de
Showing
20 changed files
with
586 additions
and
10 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_blake2s/Nargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[package] | ||
authors = [""] | ||
compiler_version = "0.1" | ||
|
||
[dependencies] |
35 changes: 35 additions & 0 deletions
35
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_blake2s/Prover.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
x = [104, 101, 108, 108, 111] | ||
result = [ | ||
0x19, | ||
0x21, | ||
0x3b, | ||
0xac, | ||
0xc5, | ||
0x8d, | ||
0xee, | ||
0x6d, | ||
0xbd, | ||
0xe3, | ||
0xce, | ||
0xb9, | ||
0xa4, | ||
0x7c, | ||
0xbb, | ||
0x33, | ||
0x0b, | ||
0x3d, | ||
0x86, | ||
0xf8, | ||
0xcc, | ||
0xa8, | ||
0x99, | ||
0x7e, | ||
0xb0, | ||
0x0b, | ||
0xe4, | ||
0x56, | ||
0xf1, | ||
0x40, | ||
0xca, | ||
0x25, | ||
] |
12 changes: 12 additions & 0 deletions
12
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_blake2s/src/main.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use dep::std; | ||
|
||
// Tests a very simple program. | ||
// | ||
// The features being tested is blake2s in brillig | ||
fn main(x: [u8; 5], result: [u8; 32]) { | ||
assert(blake2s(x) == result); | ||
} | ||
|
||
unconstrained fn blake2s(x: [u8; 5]) -> [u8; 32] { | ||
std::hash::blake2s(x) | ||
} |
5 changes: 5 additions & 0 deletions
5
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_ecdsa/Nargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[package] | ||
authors = [""] | ||
compiler_version = "0.1" | ||
|
||
[dependencies] |
169 changes: 169 additions & 0 deletions
169
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_ecdsa/Prover.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
|
||
hashed_message = [ | ||
0x3a, | ||
0x73, | ||
0xf4, | ||
0x12, | ||
0x3a, | ||
0x5c, | ||
0xd2, | ||
0x12, | ||
0x1f, | ||
0x21, | ||
0xcd, | ||
0x7e, | ||
0x8d, | ||
0x35, | ||
0x88, | ||
0x35, | ||
0x47, | ||
0x69, | ||
0x49, | ||
0xd0, | ||
0x35, | ||
0xd9, | ||
0xc2, | ||
0xda, | ||
0x68, | ||
0x06, | ||
0xb4, | ||
0x63, | ||
0x3a, | ||
0xc8, | ||
0xc1, | ||
0xe2, | ||
] | ||
pub_key_x = [ | ||
0xa0, | ||
0x43, | ||
0x4d, | ||
0x9e, | ||
0x47, | ||
0xf3, | ||
0xc8, | ||
0x62, | ||
0x35, | ||
0x47, | ||
0x7c, | ||
0x7b, | ||
0x1a, | ||
0xe6, | ||
0xae, | ||
0x5d, | ||
0x34, | ||
0x42, | ||
0xd4, | ||
0x9b, | ||
0x19, | ||
0x43, | ||
0xc2, | ||
0xb7, | ||
0x52, | ||
0xa6, | ||
0x8e, | ||
0x2a, | ||
0x47, | ||
0xe2, | ||
0x47, | ||
0xc7, | ||
] | ||
pub_key_y = [ | ||
0x89, | ||
0x3a, | ||
0xba, | ||
0x42, | ||
0x54, | ||
0x19, | ||
0xbc, | ||
0x27, | ||
0xa3, | ||
0xb6, | ||
0xc7, | ||
0xe6, | ||
0x93, | ||
0xa2, | ||
0x4c, | ||
0x69, | ||
0x6f, | ||
0x79, | ||
0x4c, | ||
0x2e, | ||
0xd8, | ||
0x77, | ||
0xa1, | ||
0x59, | ||
0x3c, | ||
0xbe, | ||
0xe5, | ||
0x3b, | ||
0x03, | ||
0x73, | ||
0x68, | ||
0xd7, | ||
] | ||
signature = [ | ||
0xe5, | ||
0x08, | ||
0x1c, | ||
0x80, | ||
0xab, | ||
0x42, | ||
0x7d, | ||
0xc3, | ||
0x70, | ||
0x34, | ||
0x6f, | ||
0x4a, | ||
0x0e, | ||
0x31, | ||
0xaa, | ||
0x2b, | ||
0xad, | ||
0x8d, | ||
0x97, | ||
0x98, | ||
0xc3, | ||
0x80, | ||
0x61, | ||
0xdb, | ||
0x9a, | ||
0xe5, | ||
0x5a, | ||
0x4e, | ||
0x8d, | ||
0xf4, | ||
0x54, | ||
0xfd, | ||
0x28, | ||
0x11, | ||
0x98, | ||
0x94, | ||
0x34, | ||
0x4e, | ||
0x71, | ||
0xb7, | ||
0x87, | ||
0x70, | ||
0xcc, | ||
0x93, | ||
0x1d, | ||
0x61, | ||
0xf4, | ||
0x80, | ||
0xec, | ||
0xbb, | ||
0x0b, | ||
0x89, | ||
0xd6, | ||
0xeb, | ||
0x69, | ||
0x69, | ||
0x01, | ||
0x61, | ||
0xe4, | ||
0x9a, | ||
0x71, | ||
0x5f, | ||
0xcd, | ||
0x55, | ||
] |
12 changes: 12 additions & 0 deletions
12
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_ecdsa/src/main.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
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_secp256k1::verify_signature(pub_key_x, pub_key_y, signature, hashed_message) | ||
} |
5 changes: 5 additions & 0 deletions
5
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_hash_to_field/Nargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[package] | ||
authors = [""] | ||
compiler_version = "0.1" | ||
|
||
[dependencies] |
1 change: 1 addition & 0 deletions
1
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_hash_to_field/Prover.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
input = "27" |
12 changes: 12 additions & 0 deletions
12
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_hash_to_field/src/main.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use dep::std; | ||
|
||
// Tests a very simple program. | ||
// | ||
// The features being tested is hash_to_field in brillig | ||
fn main(input: Field) -> pub Field { | ||
hash_to_field(input) | ||
} | ||
|
||
unconstrained fn hash_to_field(input : Field) -> Field { | ||
std::hash::hash_to_field([input]) | ||
} |
5 changes: 5 additions & 0 deletions
5
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_keccak/Nargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[package] | ||
authors = [""] | ||
compiler_version = "0.1" | ||
|
||
[dependencies] |
35 changes: 35 additions & 0 deletions
35
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_keccak/Prover.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
x = 0xbd | ||
result = [ | ||
0x5a, | ||
0x50, | ||
0x2f, | ||
0x9f, | ||
0xca, | ||
0x46, | ||
0x7b, | ||
0x26, | ||
0x6d, | ||
0x5b, | ||
0x78, | ||
0x33, | ||
0x65, | ||
0x19, | ||
0x37, | ||
0xe8, | ||
0x05, | ||
0x27, | ||
0x0c, | ||
0xa3, | ||
0xf3, | ||
0xaf, | ||
0x1c, | ||
0x0d, | ||
0xd2, | ||
0x46, | ||
0x2d, | ||
0xca, | ||
0x4b, | ||
0x3b, | ||
0x1a, | ||
0xbf, | ||
] |
27 changes: 27 additions & 0 deletions
27
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_keccak/src/main.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use dep::std; | ||
|
||
// Tests a very simple program. | ||
// | ||
// The features being tested is keccak256 in brillig | ||
fn main(x: Field, result: [u8; 32]) { | ||
// We use the `as` keyword here to denote the fact that we want to take just the first byte from the x Field | ||
// The padding is taken care of by the program | ||
let digest = keccak256([x as u8], 1); | ||
assert(digest == result); | ||
|
||
//#1399: variable meesage size | ||
let message_size = 4; | ||
let hash_a = keccak256([1,2,3,4], message_size); | ||
let hash_b = keccak256([1,2,3,4,0,0,0,0], message_size); | ||
|
||
assert(hash_a == hash_b); | ||
|
||
let message_size_big = 8; | ||
let hash_c = keccak256([1,2,3,4,0,0,0,0], message_size_big); | ||
|
||
assert(hash_a != hash_c); | ||
} | ||
|
||
unconstrained fn keccak256<N>(data: [u8; N], msg_len: u32) -> [u8; 32] { | ||
std::hash::keccak256(data, msg_len) | ||
} |
5 changes: 5 additions & 0 deletions
5
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_sha256/Nargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[package] | ||
authors = [""] | ||
compiler_version = "0.1" | ||
|
||
[dependencies] |
35 changes: 35 additions & 0 deletions
35
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_sha256/Prover.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
x = 0xbd | ||
result = [ | ||
0x68, | ||
0x32, | ||
0x57, | ||
0x20, | ||
0xaa, | ||
0xbd, | ||
0x7c, | ||
0x82, | ||
0xf3, | ||
0x0f, | ||
0x55, | ||
0x4b, | ||
0x31, | ||
0x3d, | ||
0x05, | ||
0x70, | ||
0xc9, | ||
0x5a, | ||
0xcc, | ||
0xbb, | ||
0x7d, | ||
0xc4, | ||
0xb5, | ||
0xaa, | ||
0xe1, | ||
0x12, | ||
0x04, | ||
0xc0, | ||
0x8f, | ||
0xfe, | ||
0x73, | ||
0x2b, | ||
] |
Oops, something went wrong.