Skip to content

Commit

Permalink
Handle assignimmutable and pushimmutable with libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcere committed Jan 20, 2025
1 parent 663db4d commit 8667992
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/solution_generation/reconstruct_bytecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
import json
from typing import Dict, Any, List, Optional, Union, Iterable, Tuple
from solution_generation.utils import to_hex_default
from global_params.types import SMS_T, ASM_bytecode_T, ASM_contract_T, block_id_T, function_name_T
from parser.cfg import CFG
from parser.cfg_object import CFGObject
Expand Down Expand Up @@ -46,7 +47,7 @@ def id_to_asm_bytecode(uf_instrs: Dict[str, Dict[str, Any]], instr_id: str) -> A
# Special PUSH cases that were transformed to decimal are analyzed separately
elif associated_instr['disasm'] == "PUSH" or associated_instr['disasm'] == "PUSH data" \
or associated_instr['disasm'] == "PUSHIMMUTABLE":
value = hex(int(associated_instr['value'][0]))[2:]
value = to_hex_default(associated_instr['value'][0])
return asm_from_op_info(associated_instr['disasm'], value)
elif associated_instr["disasm"] == "PUSH [TAG]":
value = int(associated_instr["outpt_sk"][0])
Expand Down Expand Up @@ -95,7 +96,9 @@ def asm_for_split_instruction(split_ins: CFGInstruction,

else:
# Just include the corresponding instruction and the value field for builtin translations
asm_ins = asm_from_op_info(split_ins.get_op_name().upper(), split_ins.translate_builtin_args)
builtin_args = split_ins.get_builtin_args()
asm_ins = asm_from_op_info(split_ins.get_op_name().upper(), builtin_args[0] if builtin_args is not None and
len(builtin_args) > 0 else None)

asm_subblock = [asm_ins]

Expand Down
2 changes: 1 addition & 1 deletion src/solution_generation/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
def generate_statistics_info(block_id: str, solution_found: List[str], greedy_time: float,
original_sfs: Dict) -> Dict:
csv_row = {"block_id": block_id, "original_instrs": original_sfs["yul_expressions"]}
csv_row.update(**{"solution_found": ' '.join(solution_found) if solution_found is not None else "",
csv_row.update(**{"solution_found": '\n'.join(solution_found) if solution_found is not None else "",
"time": greedy_time, "source_stack": original_sfs["src_ws"],
"target_stack": original_sfs["tgt_ws"]})
return csv_row
9 changes: 9 additions & 0 deletions src/solution_generation/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def to_hex_default(value: str):
"""
Returns the hexadecimal value of the decimal value "value", which is a string. If the conversion is
not possible, returns directly value
"""
try:
return hex(int(value))[2:]
except:
return value

0 comments on commit 8667992

Please sign in to comment.