-
Notifications
You must be signed in to change notification settings - Fork 164
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
create vm diff fuzzer #1358
Merged
Merged
create vm diff fuzzer #1358
Changes from 5 commits
Commits
Show all changes
93 commits
Select commit
Hold shift + click to select a range
1d97172
create vm diff fuzzer
dafifynn 86bf958
Working fuzzer
d73ea83
Change name and paths
2fa9a1b
Delete moved files
710d8b8
Add deps and run commands
5cea92b
Merge branch 'main' into vm-diff-fuzzer
Juan-M-V 7b1b6bf
Add info to readme
a705f86
Merge branch 'vm-diff-fuzzer' of github.com:lambdaclass/cairo-vm into…
f196438
Merge branch 'main' into vm-diff-fuzzer
Juan-M-V 094b133
Prototype new fuzzer
bd28491
generalize program
dafifynn af5f1a9
Add cairo program generator
1c8f1e1
Merge branch 'vm-diff-fuzzer' of github.com:lambdaclass/cairo-vm into…
3b23e36
Integrate with diff fuzzer
d6c35b8
generalize program
dafifynn d945eed
Integrate gen + fuzzer
c83cd63
Consider felt case
fa3da20
generalize parsing for structs and felts
dafifynn 0b49a6f
Add inout vars case
fdd9449
Add inout vars case
da1ffad
add select rand hint code
dafifynn 3e1f1d4
Get random hints
ce7e6a8
Delete uint256_mul_div_mod.cairo
Juan-M-V 4fb18d5
Change fuzzer name
9354138
Consider more terminations
8916de2
Change return line
bc36849
Merge branch 'main' of github.com:lambdaclass/cairo-vm into vm-diff-f…
08406da
Merge branch 'main' into vm-diff-fuzzer
dafifynn 5ccb702
filter hints to try
dafifynn e399f41
Begin direct mem comparison
7bb38ce
Merge branch 'vm-diff-fuzzer' of github.com:lambdaclass/cairo-vm into…
e328bdd
Take any line
3979a67
Merge branch 'vm-diff-fuzzer' of github.com:lambdaclass/cairo-vm into…
86963ce
Consider struct fields called after var
c92dc89
Remove prefix after picking dictionary
f91832c
Remove print
4af6ead
Consider pack case
8809190
Replace for space instead of deleting
9d2effc
Consider ( after variable
50ff613
Add constants definition
3079ac9
add extra hint
dafifynn 2002751
Merge conflicts
b3ac592
Check not keccak works and document
c14633c
fix syntaxis error
dafifynn 9b86391
add error handling
dafifynn ece2754
fix error handling
dafifynn 1f6dd1f
Refactor cairo_program_gen
4743816
Merge with origin
5281a01
Use replace token
2ba9712
Use replace token
6bb6f89
Fix parenthesis
14a1ad5
Reduce replacing
10cb173
Merge with main
9a96ba6
add documentation
dafifynn f908e22
Consider variable in func case
832d04e
Remove debugging
54a2fa0
Merge branch 'generate-cairo-for-diff' of github.com:lambdaclass/cair…
08d715d
Merge branch 'vm-diff-fuzzer' of github.com:lambdaclass/cairo-vm into…
2a780b2
Load all jsons once
07ca7f1
Merge branch 'main' of github.com:lambdaclass/cairo-vm into vm-diff-f…
9267f7c
Fix ids.a.field+3 case
f6e312c
Add case for constants
19fc3fe
Merge branch 'main' of github.com:lambdaclass/cairo-vm into vm-diff-f…
e3515f1
Merge branch 'main' into vm-diff-fuzzer
Juan-M-V d594246
Merge branch 'main' of github.com:lambdaclass/cairo-vm into vm-diff-f…
c7d371d
Merge branch 'vm-diff-fuzzer' of github.com:lambdaclass/cairo-vm into…
e247820
Correct main fuzzer readme
66272d8
Spelling diff fuzzer docu
1c53ef0
Clarify 2. in diff fuzzer docu
fac0d1c
Add make deps step
659887d
Specify constants and cairo structs importing
173d4b5
Add maturing to deps
02debcd
Update Makefile
Juan-M-V f6dad4f
Correct makefile
66f8abf
Correct makefile
215e4ee
Add missing memory checker module
48c220e
Remove initial var declarations
7dddd5f
Merge branch 'main' of github.com:/lambdaclass/cairo-vm into vm-diff-…
14060da
Update changelog
7a888a4
Run cargo fmt
822cf87
Use ast for parsing
c9f114f
Document cairo_program_gen
8ae61bc
Remove commented code
09c95d1
Update Changelog
529ad2d
Update readme doc
1b564b2
Get hints from VM code
7eb0ca2
Merge with main
fe4f228
Change make command name
793f787
Make interrupting more reliable
e14a086
Add targets to PHONY
Juan-M-V 8334165
assignment -> assignments
Juan-M-V 768c0d9
add with
Juan-M-V 7737349
importing -> to be imported
Juan-M-V 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!../cairo-vm-env/bin/python3 | ||
import os | ||
import sys | ||
import subprocess | ||
import atheris | ||
|
||
@atheris.instrument_func | ||
def generate_limb(fdp): | ||
range_check_max = 340282366920938463463374607431768211456 | ||
if fdp.ConsumeProbability() > 0.3: | ||
return fdp.ConsumeIntInRange(range_check_max >> 1, range_check_max) | ||
elif fdp.ConsumeBool(): | ||
return fdp.ConsumeIntInRange(0, 10) | ||
else: | ||
return fdp.ConsumeIntInRange(0, range_check_max) | ||
|
||
@atheris.instrument_func | ||
def diff_fuzzer(data): | ||
fdp = atheris.FuzzedDataProvider(data) | ||
|
||
a_low = generate_limb(fdp) | ||
a_high = generate_limb(fdp) | ||
b_low = generate_limb(fdp) | ||
b_high = generate_limb(fdp) | ||
div_low = generate_limb(fdp) | ||
div_high = generate_limb(fdp) | ||
|
||
# Ensure div != 0 | ||
if div_low + div_high == 0: | ||
new_limb = fdp.ConsumeIntInRange(1, 340282366920938463463374607431768211456) | ||
if fdp.ConsumeBool(): | ||
div_low = new_limb | ||
else: | ||
div_high = new_limb | ||
|
||
with open('uint256_mul_div_mod.json', 'r', encoding='utf-8') as file: | ||
data = file.readlines() | ||
|
||
data[331] = '"' + hex(a_low) + '"' + ",\n" | ||
data[333] = '"' + hex(a_high) + '"' + ",\n" | ||
data[335] = '"' + hex(b_low) + '"' + ",\n" | ||
data[337] = '"' + hex(b_high) + '"' + ",\n" | ||
data[339] = '"' + hex(div_low) + '"' + ",\n" | ||
data[341] = '"' + hex(div_high) + '"' + ",\n" | ||
|
||
filename = hex(fdp.ConsumeUInt(8)) + ".input" | ||
|
||
with open(filename, 'w', encoding='utf-8') as file: | ||
file.writelines(data) | ||
|
||
rust_output = subprocess.run(["./../../target/release/cairo-vm-cli", "--layout", "starknet", "--print_output", filename], stdout=subprocess.PIPE) | ||
python_output = subprocess.run(["cairo-run", "--layout", "starknet", "--print_output", "--program", filename], stdout=subprocess.PIPE) | ||
|
||
os.remove(filename) | ||
|
||
rust_nums = [int(n) for n in rust_output.stdout.split() if n.isdigit()] | ||
python_nums = [int(n) for n in python_output.stdout.split() if n.isdigit()] | ||
|
||
assert rust_nums == python_nums | ||
|
||
atheris.Setup(sys.argv, diff_fuzzer) | ||
atheris.Fuzz() | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if I should include this dependency in requirements.txt