Skip to content

Commit

Permalink
Tests complete generation for pushimmutable error
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcere committed Jan 20, 2025
1 parent 8667992 commit c5bef89
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/execution/main_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def parse_args() -> argparse.Namespace:
help="Keeps the original builtin opcodes")

args = parser.parse_args()
print(args)
return args


Expand Down Expand Up @@ -114,9 +115,8 @@ def analyze_single_cfg(cfg: CFG, final_dir: Path, args: argparse.Namespace):
return json_asm_contract


def main():
def main(args):
print("Grey Main")
args = parse_args()

x = dtimer()
json_dict = yul_cfg_dict_from_format(args.input_format, args.source,
Expand Down
4 changes: 2 additions & 2 deletions src/grey_main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/python3

import logging
from execution.main_execution import main
from execution.main_execution import main, parse_args

if __name__ == "__main__":
# logging.basicConfig(level=logging.DEBUG)
main()
main(parse_args())
34 changes: 34 additions & 0 deletions tests/reconstruct_bytecode/pushimmutable_assignimmutable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"language": "Solidity",
"sources": {
"struct_storage_ptr.sol": {
"content": "library L {\n\tstruct S { uint x; uint y; }\n\tfunction f(uint[] storage r, S storage s) public returns (uint, uint, uint, uint) {\n\t\tr[2] = 8;\n\t\ts.x = 7;\n\t\treturn (r[0], r[1], s.x, s.y);\n\t}\n}\ncontract C {\n\tuint8 x = 3;\n\tL.S s;\n\tuint[] r;\n\tfunction f() public returns (uint, uint, uint, uint, uint, uint) {\n\t\tr = new uint[](6);\n\t\tr[0] = 1;\n\t\tr[1] = 2;\n\t\tr[2] = 3;\n\t\ts.x = 11;\n\t\ts.y = 12;\n\t\t(uint a, uint b, uint c, uint d) = L.f(r, s);\n\t\treturn (r[2], s.x, a, b, c, d);\n\t}\n}\n// ----\n// library: L\n// f() -> 8, 7, 1, 2, 7, 12\n// gas irOptimized: 166761\n// gas legacy: 169273\n// gas legacyOptimized: 167243\n"
}
},
"settings": {
"optimizer": {
"enabled": true,
"runs": 200,
"details": {
"peephole": false,
"inliner": false,
"jumpdestRemover": false,
"orderLiterals": false,
"deduplicate": false,
"cse": false,
"constantOptimizer": false
}
},
"outputSelection": {
"*": {
"*": [
"abi",
"metadata",
"evm.bytecode",
"evm.deployedBytecode",
"evm.methodIdentifiers"
]
}
}
}
}
28 changes: 28 additions & 0 deletions tests/test_reconstruct_bytecode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
from argparse import Namespace
from execution.main_execution import main


class TestReconstructBytecode:

def test_pushimmutable_assignimmutable(self):
"""
20/01/2025: the code generation failed because PUSHIMMUTABLE can be followed by a string that is not
a hexadecimal value and ASSIGNIMMUTABLE must assign only the first builtin args.
Solution: for PUSHIMMUTABLE, define the function "to_hex_default" in solution_generation.utils, which returns
the corresponding hexadecimal if the value a decimal value. Otherwise, it returns the original code.
For ASSIGNIMMUTABLE, introduce the first builtin arg (if any) when reconstructing the split bytecode
"""
# Args
# -s examples/test/semanticTests/abiEncoderV1_struct_struct_storage_ptr/struct_storage_ptr_standard_input.json -g -v -if standard-json -o falla -solc ./solc-latest
current_path = os.path.abspath(os.curdir)
os.chdir("..")
args = Namespace(
source='tests/reconstruct_bytecode/pushimmutable_assignimmutable.json',
input_format='standard-json', contract=None, solc_executable='./solc-latest', folder='falla',
visualize=True, greedy=True, builtin=False)
main(args)
os.chdir(current_path)
assert True, "Falla test"

0 comments on commit c5bef89

Please sign in to comment.