Coder Social home page Coder Social logo

c0de3 / thoth Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fuzzinglabs/thoth

0.0 0.0 0.0 2.89 MB

Cairo/Starknet bytecode analyzer, disassembler & decompiler

Home Page: https://fuzzinglabs.com/

License: GNU Affero General Public License v3.0

Python 51.21% Makefile 0.06% Cairo 48.73%

thoth's Introduction

Thoth, the Cairo/Starknet bytecode analyzer, disassembler and decompiler

Thoth (pronounced "toss") is a Cairo/Starknet analyzer, disassembler & decompiler written in Python 3. Thoth's features also include the generation of the call graph and control-flow graph (CFG) of a given Cairo/Starknet compilation artifact. Demo video

Installation

sudo apt install graphviz

git clone https://github.com/FuzzingLabs/thoth && cd thoth

pip install .

thoth -h

Disassemble the contract's compilation artifact (json)

thoth -f tests/json_files/cairo_array_sum.json

To get a pretty colored version:

thoth -f tests/json_files/cairo_array_sum.json -color

To get a verbose version with more details about decoded bytecodes:

thoth -f tests/json_files/cairo_array_sum.json -vvv

Decompile the contract's compilation artifact (json)

thoth -f tests/json_files/cairo_test_addition_if.json --decompile

Example 1 with strings:

source code

decompiler code

Example 2 with function call:

source code

decompiler code

Print the contract's call graph

The call flow graph represents calling relationships between functions of the contract. We tried to provide a maximum of information, such as the entry-point functions, the imports, decorators, etc.

thoth -f tests/json_files/cairo_array_sum.json -call

The output file (pdf/svg/png) and the dot file are inside the output-callgraph folder. If needed, you can also visualize dot files online using this website. The legend can be found here.

A more complexe callgraph:

For a specific output format (pdf/svg/png):

thoth -f tests/json_files/cairo_array_sum.json -call -format png

Print the contract's control-flow graph (CFG)

thoth -f tests/json_files/cairo_array_sum.json -cfg

The output file (pdf/svg/png) and the dot file are inside the output-cfg folder.

For a specific function:

thoth -f tests/json_files/cairo_array_sum.json -cfg -function "__main__.main"

For a specific output format (pdf/svg/png):

thoth -f tests/json_files/cairo_array_sum.json -cfg -format png

F.A.Q

How to find a Cairo/Starknet compilation artifact (json file)?

Thoth support cairo and starknet compilation artifact (json file) generated after compilation using cairo-compile or starknet-compile. Thoth also support the json file returned by: starknet get_full_contract.

How to run the tests?

python3 tests/test.py

How to build the documentation?

# Install sphinx
apt-get install python3-sphinx

#Create the docs folder
mkdir docs & cd docs

#Init the folder
sphinx-quickstart docs

#Modify the `conf.py` file by adding
import thoth

#Generate the .rst files before the .html files
sphinx-apidoc -f -o . ..

#Generate the .html files
make html

#Run a python http server
cd _build/html; python3 -m http.server

Why my bytecode is empty?

First, verify that your JSON is correct and that it contains a data section. Second, verify that your JSON is not a contract interface. Finally, it is possible that your contract does not generate bytecodes, for example:

%lang starknet

from starkware.cairo.common.cairo_builtins import HashBuiltin

@storage_var
func balance() -> (res : felt):
end

License

Thoth is licensed and distributed under the AGPLv3 license. Contact us if you're looking for an exception to the terms.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.