Skip to content

Commit

Permalink
Merge pull request #144 from FuzzingLabs/feat/sierra-analyzer
Browse files Browse the repository at this point in the history
Include sierra-analyzer in the Thoth repository
  • Loading branch information
Rog3rSm1th authored Sep 19, 2024
2 parents be96364 + 6bf0890 commit eef24b3
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "contract-class-converter/cairo"]
path = contract-class-converter/cairo
url = https://github.com/starkware-libs/cairo.git
[submodule "sierra-analyzer"]
path = sierra-analyzer
url = [email protected]:FuzzingLabs/sierra-analyzer.git
1 change: 1 addition & 0 deletions sierra-analyzer
Submodule sierra-analyzer added at 7fb790
3 changes: 3 additions & 0 deletions sierra/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
> [!IMPORTANT]
> *thoth-sierra* has been rewritten in Rust in a new version: [sierra-analyzer](https://github.com/FuzzingLabs/thoth/tree/master/sierra-analyzer). It contains all the features of *thoth-sierra* (CFG, Callgraph, decompiler, detectors) and is more maintainable and efficient.
## Decompile the Sierra file

```python
Expand Down
6 changes: 3 additions & 3 deletions thoth/app/disassembler/abi_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ def parse_to_json(json_data: str, json_type: dict) -> dict:
incr = 2
key = str(offset)
bytecodes_to_json[actual_function]["instruction"][key] = {}
bytecodes_to_json[actual_function]["instruction"][key][
hex(bytecode_data[offset])
] = decode_to_json(str(decoded))
bytecodes_to_json[actual_function]["instruction"][key][hex(bytecode_data[offset])] = (
decode_to_json(str(decoded))
)
offset += incr
return bytecodes_to_json
8 changes: 5 additions & 3 deletions thoth/app/disassembler/cairo_instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,11 @@ def decode_instruction(encoding: int, imm: Optional[int] = None) -> Instruction:
res = {
(1, 0): Instruction.Res.ADD,
(0, 1): Instruction.Res.MUL,
(0, 0): Instruction.Res.UNCONSTRAINED
if pc_update is Instruction.PcUpdate.JNZ
else Instruction.Res.OP1,
(0, 0): (
Instruction.Res.UNCONSTRAINED
if pc_update is Instruction.PcUpdate.JNZ
else Instruction.Res.OP1
),
}[(flags >> RES_ADD_BIT) & 1, (flags >> RES_MUL_BIT) & 1]

# JNZ opcode means res must be UNCONSTRAINED.
Expand Down
8 changes: 5 additions & 3 deletions thoth/app/disassembler/disassembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,11 @@ def analyze(self) -> None:
ret,
decorators,
self.labels,
entry_point=self.json[function]["data"]["entry_point"]
if json_type != "get_code"
else True,
entry_point=(
self.json[function]["data"]["entry_point"]
if json_type != "get_code"
else True
),
is_import=is_import,
)
)
Expand Down
10 changes: 2 additions & 8 deletions thoth/app/disassembler/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,7 @@ def get_prototype(self) -> str:
prototype += (
" -> ("
if data_name == "ret" and data_content is not None
else "("
if data_name == "args"
else "{"
if data_name == "implicitargs"
else ""
else "(" if data_name == "args" else "{" if data_name == "implicitargs" else ""
)
if data_content is not None:
for idarg in data_content:
Expand All @@ -155,9 +151,7 @@ def get_prototype(self) -> str:
prototype += (
")"
if (data_name == "args" or (data_name == "ret" and data_content is not None))
else "}"
if data_name == "implicitargs"
else ""
else "}" if data_name == "implicitargs" else ""
)
return prototype

Expand Down

0 comments on commit eef24b3

Please sign in to comment.