Skip to content
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

Wrong instruction string formation #50

Open
SteMak opened this issue Dec 17, 2024 · 0 comments
Open

Wrong instruction string formation #50

SteMak opened this issue Dec 17, 2024 · 0 comments

Comments

@SteMak
Copy link

SteMak commented Dec 17, 2024

The translateOpcodes30 function of the sfs_generator/ir_block.py file aims to translate opcodes into list of instructions for further optimization
However, the instructions partially mismatch the opcodes

CODECOPY opcode produces calldatacopy instruction
This inconsistency might lead to incorrect optimizations or wrong code generation, however, I have not found such issues due to correct opcode saved in NOP virtual instruction is used in code generation instead of parsing the instruction

elif opcode == "CODECOPY":
    v0, updated_variables = get_consume_variable(index_variables)
    v1, updated_variables = get_consume_variable(updated_variables)
    v2, updated_variables = get_consume_variable(updated_variables)

    instr = "calldatacopy("+v0+","+v1+","+v2+")"

EXTCODEHASH, EXTCODESIZE, CALLDATALOAD opcodes produce instructions without or with invalid parameters
I haven't found specific issues which the inconsistent parameters cause

elif opcode == "CALLDATALOAD":
    v0, updated_variables = get_consume_variable(index_variables)
    v1, updated_variables = get_new_variable(updated_variables)

    instr = v1+" = calldataload"

elif opcode == "EXTCODESIZE":
    v0, updated_variables = get_consume_variable(index_variables)
    v1, updated_variables = get_new_variable(updated_variables)
    instr = v1+" = extcodesize"

elif opcode == "EXTCODEHASH":
    _, updated_variables = get_consume_variable(index_variables)
    v1, updated_variables = get_new_variable(updated_variables)
    instr = v1+" = extcodehash("+v1+")"

To resolve this, I suggest to implement the following change

     elif opcode == "CALLDATALOAD":
         v0, updated_variables = get_consume_variable(index_variables)
         v1, updated_variables = get_new_variable(updated_variables)
 
-        instr = v1+" = calldataload"
+        instr = v1+" = calldataload("+v0+")"
 
             
     elif opcode == "CODECOPY":
         v1, updated_variables = get_consume_variable(updated_variables)
         v2, updated_variables = get_consume_variable(updated_variables)
 
-        instr = "calldatacopy("+v0+","+v1+","+v2+")"
+        instr = "codecopy("+v0+","+v1+","+v2+")"

     elif opcode == "EXTCODESIZE":
         v0, updated_variables = get_consume_variable(index_variables)
         v1, updated_variables = get_new_variable(updated_variables)

-        instr = v1+" = extcodesize"
+        instr = v1+" = extcodesize("+v0+")"
 
     elif opcode == "EXTCODEHASH":
-        _, updated_variables = get_consume_variable(index_variables)
+        v0, updated_variables = get_consume_variable(index_variables)
         v1, updated_variables = get_new_variable(updated_variables)
-        instr = v1+" = extcodehash("+v1+")"
+        instr = v1+" = extcodehash("+v0+")"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant