Skip to content

Commit

Permalink
Handle custom functions
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcere committed Jul 4, 2024
1 parent db79fb1 commit 7e77fe0
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions parser/cfg_instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def build_push_spec(val, idx, out_idx):

def build_verbatim_spec(function_name: str, input_args: List[str], output_args: List[str], builting_args: List[str]):
"""
Generates the specification of a custom function
Generates the specification of a verbatim
"""
obj = {}

Expand All @@ -72,6 +72,30 @@ def build_verbatim_spec(function_name: str, input_args: List[str], output_args:
return obj


def build_custom_function_spec(function_name: str, input_args: List[str], output_args: List[str], builting_args: List[str]):
"""
Generates the specification of a custom function
"""
obj = {}

# The function name is of the form 'verbatim_<n>i_<m>o("<data>", ...)'
# (see "verbatim" in https://docs.soliditylang.org/en/latest/yul.html)
# Hence, different functions can have the same function name
obj["id"] = function_name
obj["opcode"] = function_name
obj["disasm"] = function_name
obj["inpt_sk"] = input_args
obj["outpt_sk"] = output_args
obj["gas"] = 100 # Random value for gas, as it is unknown
obj["commutative"] = False
obj["push"] = False
obj["storage"] = True # Assuming it must be performed always
obj["size"] = 5 # Assuming builtin args contain the corresponding bytecode

return obj



class CFGInstruction:
def __init__(self, op : str, in_args: List[str], out_args: List[str]):
self.op = op
Expand Down Expand Up @@ -128,7 +152,8 @@ def build_spec(self, out_idx, instrs_idx, map_instructions):
elif opcodes.exists_opcode(op_name):
instr_spec = build_instr_spec(op_name, idx, input_args, self.out_args)
else:
raise ValueError("[ERROR]: Opcode name not found " + op_name)
# TODO: separate wrong opcodes from custom functions
instr_spec = build_custom_function_spec(op_name, input_args, self.out_args, self.builtin_args)

instrs_idx[op_name] = idx+1
map_instructions[(op_name,tuple(self.in_args))] = instr_spec
Expand Down

0 comments on commit 7e77fe0

Please sign in to comment.