Skip to content

Add EVM ABI helpers, fix EVM DBG stack view#1123

Merged
kabeor merged 3 commits intoqilingframework:devfrom
TheZ3ro:evm-2
Apr 7, 2022
Merged

Add EVM ABI helpers, fix EVM DBG stack view#1123
kabeor merged 3 commits intoqilingframework:devfrom
TheZ3ro:evm-2

Conversation

@TheZ3ro
Copy link
Contributor

@TheZ3ro TheZ3ro commented Apr 2, 2022

Checklist

Which kind of PR do you create?

  • This PR only contains minor fixes.
  • This PR contains major feature update.
  • This PR introduces a new function/api for Qiling Framework.

Coding convention?

  • The new code conforms to Qiling Framework naming convention.
  • The imports are arranged properly.
  • Essential comments are added.
  • The reference of the new code is pointed out.

Extra tests?

  • No extra tests are needed for this PR.
  • I have added enough tests for this PR.
  • Tests will be added after some discussion and review.

Changelog?

  • This PR doesn't need to update Changelog.
  • Changelog will be updated after some proper review.
  • Changelog has been updated in my PR.

Target branch?

  • The target branch is dev branch.

One last thing


This PR adds some helper methods to deal with ABI encoding/decoding.
In particular I've renamed convert to encode_params while keeping backward compatibility, and I've added decode_params, encode_function_call and encode_function_call_abi functions.

This functions can be used to encode a contract function call and its parameter when the function prototype is known or when the ABI is available.
I've also added a new test for this functionality in the tests/test_evm.py. The relevant lines from 126 to 137 highlight the new feature.

Moreover I've fixed the display of the Stack in the EVM debugger.
When the stack was greater than 8, only the first 8 rows were displayed. Moreover the stack was growing top to bottom.
Now the stack displays the last 8 rows (the most recent and relevant ones) and grows bottom to top.

This can be tested with the following snippet as shown in the screenshot below:

from qiling import *

if __name__ == '__main__':
    contract = '0x' + ('6001' * 10) + '60ff00'
    ql = Qiling(code=contract, archtype="evm")
    ql.debugger = True
    
    user1 = ql.arch.evm.create_account(balance=100*10**18)
    contract_addr = ql.arch.evm.create_account()
    msg0 = ql.arch.evm.create_message(user1, b'', code=ql.code, contract_address=contract_addr)
    ql.run(code=msg0)

q

@kabeor kabeor merged commit 55a8039 into qilingframework:dev Apr 7, 2022
@TheZ3ro TheZ3ro deleted the evm-2 branch April 7, 2022 09:11
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

Successfully merging this pull request may close these issues.

3 participants