-
Notifications
You must be signed in to change notification settings - Fork 381
feat(fuzz): Add comptime_vs_brillig_direct target #8924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
70e1ae1
Add target
rkarabut 76d79d7
Clean up
rkarabut 21edf62
Fix typo
rkarabut 61d9572
Fix typo
rkarabut a962bfb
Move logging source
rkarabut 186d08e
Fix typo
rkarabut c829b00
Update tooling/ast_fuzzer/fuzz/src/targets/comptime_vs_brillig_direct.rs
rkarabut 4c6ffd3
Clean up
rkarabut 9ed04d8
Merge remote-tracking branch 'origin/master' into rk/comptime_vs_bril…
rkarabut 9e946a9
Fix phrasing
rkarabut 49a2f1a
Tweak runs
rkarabut 60519ce
Move interpret() into the elaborator
rkarabut 8356502
Move interpret() into the elaborator
rkarabut 788e920
fmt
rkarabut 9bd41b2
Merge branch 'master' into rk/comptime_vs_brillig_direct
rkarabut 3ab3bf0
Merge branch 'master' into rk/comptime_vs_brillig_direct
rkarabut f2008d1
Fixes
rkarabut bfca02f
Fixes
rkarabut 9929d64
Move new functionality under test_utils
rkarabut 7b7efb2
Remove arb_direct, rework exec_direct
rkarabut 0806a7f
Merge branch 'master' into rk/comptime_vs_brillig_direct
rkarabut 35d184f
Merge branch 'master' into rk/comptime_vs_brillig_direct
rkarabut File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
12 changes: 0 additions & 12 deletions
12
tooling/ast_fuzzer/fuzz/fuzz_targets/comptime_vs_brillig.rs
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
tooling/ast_fuzzer/fuzz/fuzz_targets/comptime_vs_brillig_direct.rs
This file contains hidden or 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 @@ | ||
| //! ```text | ||
| //! cargo +nightly fuzz run comptime_vs_brillig_direct | ||
| //! ``` | ||
| #![no_main] | ||
|
|
||
| use libfuzzer_sys::arbitrary::Unstructured; | ||
| use libfuzzer_sys::fuzz_target; | ||
| use noir_ast_fuzzer_fuzz::targets::comptime_vs_brillig_direct; | ||
|
|
||
| fuzz_target!(|data: &[u8]| { | ||
| comptime_vs_brillig_direct::fuzz(&mut Unstructured::new(data)).unwrap(); | ||
| }); |
12 changes: 12 additions & 0 deletions
12
tooling/ast_fuzzer/fuzz/fuzz_targets/comptime_vs_brillig_nargo.rs
This file contains hidden or 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 @@ | ||
| //! ```text | ||
| //! cargo +nightly fuzz run comptime_vs_brillig_nargo | ||
| //! ``` | ||
| #![no_main] | ||
|
|
||
| use libfuzzer_sys::arbitrary::Unstructured; | ||
| use libfuzzer_sys::fuzz_target; | ||
| use noir_ast_fuzzer_fuzz::targets::comptime_vs_brillig_nargo; | ||
|
|
||
| fuzz_target!(|data: &[u8]| { | ||
| comptime_vs_brillig_nargo::fuzz(&mut Unstructured::new(data)).unwrap(); | ||
| }); |
82 changes: 82 additions & 0 deletions
82
tooling/ast_fuzzer/fuzz/src/targets/comptime_vs_brillig_direct.rs
This file contains hidden or 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,82 @@ | ||
| //! Compare the execution of random ASTs between the comptime execution | ||
| //! (after converting the AST to Noir and running it through the comptime | ||
| //! interpreter) vs when everything is forced to be Brillig. | ||
| //! We choose Brillig here because it mostly matches comptime feature set | ||
| //! (e.g. `loop`, `while`, `break` and `continue` are possible) | ||
| //! This variant accesses the interpreter directly instead of going | ||
| //! through nargo, which speeds up execution but also currently | ||
| //! has some issues (inability to use prints among others). | ||
| use crate::{compare_results_comptime, create_ssa_or_die, default_ssa_options}; | ||
| use arbitrary::Unstructured; | ||
| use color_eyre::eyre; | ||
| use noir_ast_fuzzer::Config; | ||
| use noir_ast_fuzzer::compare::CompareComptime; | ||
| use noir_ast_fuzzer::compare::CompareOptions; | ||
| use noir_ast_fuzzer::rewrite::change_all_functions_into_unconstrained; | ||
|
|
||
| pub fn fuzz(u: &mut Unstructured) -> eyre::Result<()> { | ||
| let config = Config { | ||
| // Avoid using large integers in for loops that the frontend would reject. | ||
| avoid_large_int_literals: true, | ||
| // Also avoid negative integers, because the frontend rejects them for loops. | ||
| avoid_negative_int_literals: true, | ||
| // Avoid break/continue | ||
| avoid_loop_control: true, | ||
| // Has to only use expressions valid in comptime | ||
| comptime_friendly: true, | ||
| // Force brillig, to generate loops that the interpreter can do but ACIR cannot. | ||
| force_brillig: true, | ||
| // Avoid overflows, divisions by zero and constraints for now, as we currently | ||
| // don't catch errors issued by the elaborator | ||
| avoid_overflow: true, | ||
| avoid_err_by_zero: true, | ||
| avoid_constrain: true, | ||
| // At the moment prints aren't recognized by elaborator | ||
| avoid_print: true, | ||
aakoshh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Use lower limits because of the interpreter, to avoid stack overflow | ||
| max_loop_size: 5, | ||
| max_recursive_calls: 5, | ||
| ..Default::default() | ||
| }; | ||
|
|
||
| let inputs = CompareComptime::arb_direct( | ||
| u, | ||
| config, | ||
| |program| { | ||
| let options = CompareOptions::default(); | ||
| let ssa = create_ssa_or_die( | ||
| change_all_functions_into_unconstrained(program), | ||
| &options.onto(default_ssa_options()), | ||
| Some("brillig"), | ||
| ); | ||
| Ok((ssa, options)) | ||
| }, | ||
| |program| { | ||
| let options = CompareOptions::default(); | ||
| let ssa = create_ssa_or_die( | ||
| program, | ||
| &options.onto(default_ssa_options()), | ||
| Some("comptime_result_wrapper"), | ||
| ); | ||
| Ok((ssa, options)) | ||
| }, | ||
| )?; | ||
|
|
||
| let result = inputs.exec_direct()?; | ||
|
|
||
| compare_results_comptime(&inputs, &result) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
|
|
||
| /// ```ignore | ||
| /// NOIR_AST_FUZZER_SEED=0x6819c61400001000 \ | ||
| /// NOIR_AST_FUZZER_SHOW_AST=1 \ | ||
| /// cargo test -p noir_ast_fuzzer_fuzz comptime_vs_brillig_direct | ||
| /// ``` | ||
| #[test] | ||
| fn fuzz_with_arbtest() { | ||
| crate::targets::tests::fuzz_with_arbtest(super::fuzz, 500); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.