-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent declarations of blackbox functions outside of the stdlib (…
…#4177) # Description ## Problem\* Resolves <!-- Link to GitHub Issue --> ## Summary\* I found this [semaphore lib which is redeclaring pedersen for some reason](https://github.com/siosw/semaphore-noir/blob/main/circuits/src/identity.nr). Let's ~break it!~ give a nice error message to tell users that they're doing something wrong here. ## Additional Context ## Documentation\* Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[Exceptional Case]** Documentation to be submitted in a separate PR. # PR Checklist\* - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
- Loading branch information
1 parent
8f70e57
commit 9fb6b09
Showing
7 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
7 changes: 7 additions & 0 deletions
7
test_programs/compile_failure/builtin_function_declaration/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,7 @@ | ||
[package] | ||
name = "builtin_function_declaration" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.23.0" | ||
|
||
[dependencies] |
10 changes: 10 additions & 0 deletions
10
test_programs/compile_failure/builtin_function_declaration/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,10 @@ | ||
// This test prevents users from trying to create their own builtin functions as these should only exist in the stdlib. | ||
|
||
// This would otherwise be a perfectly valid declaration of the `to_le_bits` builtin function | ||
#[builtin(to_le_bits)] | ||
fn to_le_bits(_x: Field, _bit_size: u32) -> [u1] {} | ||
|
||
fn main(x: Field) -> pub u1 { | ||
let bits = to_le_bits(x, 100); | ||
bits[0] | ||
} |
7 changes: 7 additions & 0 deletions
7
test_programs/compile_failure/foreign_function_declaration/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,7 @@ | ||
[package] | ||
name = "foreign_function_declaration" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.23.0" | ||
|
||
[dependencies] |
10 changes: 10 additions & 0 deletions
10
test_programs/compile_failure/foreign_function_declaration/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,10 @@ | ||
// This test prevents users from trying to create their own blackbox functions as these should only exist in the stdlib. | ||
|
||
// This would otherwise be a perfectly valid definition of the `pedersen_hash` black box function, | ||
// however executing the circuit results in an unhelpful ICE. | ||
#[foreign(pedersen_hash)] | ||
fn my_pedersen_hash<N>(_input: [Field; N]) -> Field {} | ||
|
||
fn main() -> pub Field { | ||
my_pedersen_hash([1]) | ||
} |