-
-
Notifications
You must be signed in to change notification settings - Fork 824
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
feat[test]: add hevm harness for venom passes #4460
Open
charles-cooper
wants to merge
24
commits into
vyperlang:master
Choose a base branch
from
charles-cooper:feat/venom/hevm-equivalence
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
c166416
add example hevm equivalence test for venom
charles-cooper ee90277
add canary rule
charles-cooper a68af0b
print bytecode
charles-cooper 122377a
fix the harness
charles-cooper 1e7d00f
fix the rule
charles-cooper ebbebb1
fix lint
charles-cooper 3960381
add generalize hevm runner
charles-cooper fce5119
don't run hevm for specific examples
charles-cooper 813514a
refactor - move hevm utils to its own file, add workflow job
charles-cooper a85bced
add a comment
charles-cooper 925614d
add success requirement
charles-cooper 203af2c
debug
charles-cooper 3930b84
update name
charles-cooper 965e5fc
install z3
charles-cooper 2b7a2d0
wget quiet
charles-cooper 6f2bceb
update readme
charles-cooper 45d86d6
factor out hevm bytecode check
charles-cooper b4bfa33
add hevm harness for get_contract
charles-cooper 684a7c9
fix for fixture scope
charles-cooper b4f03e6
Merge branch 'master' into feat/venom/hevm-equivalence
charles-cooper 0987402
formatting
charles-cooper 1e02f4c
Revert "add hevm harness for get_contract"
charles-cooper b3abd41
fix bad name
charles-cooper 50bcaa8
remove dead variable assignment
charles-cooper 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import subprocess | ||
|
||
from tests.venom_utils import parse_from_basic_block | ||
from vyper.ir.compile_ir import assembly_to_evm | ||
from vyper.venom import StoreExpansionPass, VenomCompiler | ||
from vyper.venom.analysis import IRAnalysesCache | ||
from vyper.venom.basicblock import IRInstruction, IRLiteral | ||
|
||
HAS_HEVM: bool = False | ||
|
||
|
||
def _prep_hevm_venom(venom_source_code): | ||
ctx = parse_from_basic_block(venom_source_code) | ||
|
||
num_calldataloads = 0 | ||
for fn in ctx.functions.values(): | ||
for bb in fn.get_basic_blocks(): | ||
for inst in bb.instructions: | ||
# transform `param` instructions into "symbolic" values for | ||
# hevm via calldataload | ||
if inst.opcode == "param": | ||
# hevm limit: 256 bytes of symbolic calldata | ||
assert num_calldataloads < 8 | ||
|
||
inst.opcode = "calldataload" | ||
inst.operands = [IRLiteral(num_calldataloads * 32)] | ||
num_calldataloads += 1 | ||
|
||
term = bb.instructions[-1] | ||
# test convention, terminate by `return`ing the variables | ||
# you want to check | ||
assert term.opcode == "return" | ||
num_return_values = 0 | ||
for op in term.operands: | ||
ptr = IRLiteral(num_return_values * 32) | ||
new_inst = IRInstruction("mstore", [op, ptr]) | ||
bb.insert_instruction(new_inst, index=-1) | ||
num_return_values += 1 | ||
|
||
# return 0, 32 * num_variables | ||
term.operands = [IRLiteral(num_return_values * 32), IRLiteral(0)] | ||
|
||
ac = IRAnalysesCache(fn) | ||
# requirement for venom_to_assembly | ||
StoreExpansionPass(ac, fn).run_pass() | ||
|
||
compiler = VenomCompiler([ctx]) | ||
return assembly_to_evm(compiler.generate_evm(no_optimize=True))[0].hex() | ||
|
||
|
||
def hevm_check_venom(pre, post, verbose=False): | ||
global HAS_HEVM | ||
|
||
if not HAS_HEVM: | ||
return | ||
|
||
# perform hevm equivalence check | ||
if verbose: | ||
print("HEVM COMPARE.") | ||
print("BEFORE:", pre) | ||
print("OPTIMIZED:", post) | ||
bytecode1 = _prep_hevm_venom(pre) | ||
bytecode2 = _prep_hevm_venom(post) | ||
|
||
hevm_check_bytecode(bytecode1, bytecode2, verbose=verbose) | ||
|
||
|
||
def hevm_check_bytecode(bytecode1, bytecode2, verbose=False): | ||
# debug: | ||
if verbose: | ||
print("RUN HEVM:") | ||
print(bytecode1) | ||
print(bytecode2) | ||
|
||
subp_args = ["hevm", "equivalence", "--code-a", bytecode1, "--code-b", bytecode2] | ||
|
||
if verbose: | ||
subprocess.check_call(subp_args) | ||
else: | ||
subprocess.check_output(subp_args) |
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
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.
Do you want to leave this here or could be revert this?
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'll leave it for people to review then remove