Skip to content

Commit

Permalink
feat: extract traces_parser to own package
Browse files Browse the repository at this point in the history
  • Loading branch information
Otto-AA committed Jun 14, 2024
1 parent bb03ff4 commit 87e4be9
Show file tree
Hide file tree
Showing 71 changed files with 110 additions and 6,805 deletions.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ tqdm==4.66.1
typing_extensions==4.10.0
requests==2.31.0
networkx==3.3
types_networkx==3.2.1.20240425
types_networkx==3.2.1.20240425
traces_parser @ git+https://github.com/TOD-theses/traces_parser@e210157775dc15c7b5bead669918a789631a07ba
6 changes: 3 additions & 3 deletions tests/analysis/test_analysis_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
RunInfo,
FeatureExtractionRunner,
)
from traces_analyzer.parser.environment.call_context_manager import CallTree
from traces_analyzer.parser.instructions_parser import ParsedTransaction
from traces_analyzer.parser.instructions.instructions import POP
from traces_parser.parser.environment.call_context_manager import CallTree
from traces_parser.parser.instructions_parser import ParsedTransaction
from traces_parser.parser.instructions.instructions import POP


def test_analysis_runner_empty_does_not_call_analyzer():
Expand Down
6 changes: 3 additions & 3 deletions tests/analysis/test_instruction_input_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
from traces_analyzer.features.extractors.instruction_differences import (
InstructionDifferencesFeatureExtractor,
)
from traces_analyzer.parser.instructions.instructions import (
from traces_parser.parser.instructions.instructions import (
CALL,
JUMPDEST,
STOP,
)
from traces_analyzer.parser.storage.storage_writes import StorageAccesses
from traces_analyzer.utils.hexstring import HexString
from traces_parser.parser.storage.storage_writes import StorageAccesses
from traces_parser.datatypes import HexString


def test_instruction_input_analyzer():
Expand Down
2 changes: 1 addition & 1 deletion tests/analysis/test_instruction_usage_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from traces_analyzer.features.extractors.instruction_usages import (
InstructionUsagesFeatureExtractor,
)
from traces_analyzer.parser.instructions.instructions import (
from traces_parser.parser.instructions.instructions import (
JUMPDEST,
POP,
PUSH32,
Expand Down
8 changes: 4 additions & 4 deletions tests/analysis/test_tod_source_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
_test_stack_pushes,
)
from traces_analyzer.features.extractors.tod_source import TODSourceFeatureExtractor
from traces_analyzer.parser.information_flow.constant_step_indexes import (
from traces_parser.parser.information_flow.constant_step_indexes import (
SPECIAL_STEP_INDEXES,
)
from traces_analyzer.parser.instructions.instructions import POP, SLOAD
from traces_analyzer.parser.storage.storage_writes import (
from traces_parser.parser.instructions.instructions import POP, SLOAD
from traces_parser.parser.storage.storage_writes import (
PersistentStorageAccess,
StorageAccesses,
StorageWrites,
)
from traces_analyzer.utils.hexstring import HexString
from traces_parser.datatypes import HexString


def test_tod_source_analyzer() -> None:
Expand Down
14 changes: 7 additions & 7 deletions tests/e2e/test_sample_traces_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
)
from traces_analyzer.features.extractors.tod_source import TODSourceFeatureExtractor
from traces_analyzer.loader.directory_loader import DirectoryLoader
from traces_analyzer.parser.events_parser import parse_events
from traces_analyzer.parser.instructions.instructions import LOG3, SLOAD
from traces_analyzer.parser.instructions_parser import (
from traces_parser.parser.instructions.instructions import LOG3, SLOAD
from traces_parser.parser.events_parser import parse_events
from traces_parser.parser.instructions_parser import (
parse_transaction,
TransactionParsingInfo,
parse_instructions,
)
from traces_analyzer.utils.hexstring import HexString
from traces_parser.datatypes import HexString
from snapshottest.pytest import PyTestSnapshotTest


Expand All @@ -35,7 +35,7 @@ def test_sample_traces_analysis_e2e(
attack_id = "62a8b9ece30161692b68cbb5"

with DirectoryLoader(sample_traces_path / attack_id) as bundle:
transactions_actual = parse_instructions(
transactions_actual = parse_transaction(
TransactionParsingInfo(
bundle.tx_victim.caller,
bundle.tx_victim.to,
Expand All @@ -44,7 +44,7 @@ def test_sample_traces_analysis_e2e(
),
parse_events(bundle.tx_victim.trace_actual),
)
transactions_reverse = parse_instructions(
transactions_reverse = parse_transaction(
TransactionParsingInfo(
bundle.tx_victim.caller,
bundle.tx_victim.to,
Expand Down
8 changes: 4 additions & 4 deletions tests/evaluation/test_instruction_differences_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
from traces_analyzer.evaluation.instruction_differences_evaluation import (
InstructionDifferencesEvaluation,
)
from traces_analyzer.parser.instructions.instruction import Instruction
from traces_analyzer.parser.instructions.instructions import CALL, SLOAD
from traces_analyzer.parser.storage.storage_writes import StorageAccesses, StorageWrites
from traces_analyzer.utils.hexstring import HexString
from traces_parser.parser.instructions.instruction import Instruction
from traces_parser.parser.instructions.instructions import CALL, SLOAD
from traces_parser.parser.storage.storage_writes import StorageAccesses, StorageWrites
from traces_parser.datatypes import HexString
from snapshottest.pytest import PyTestSnapshotTest


Expand Down
2 changes: 1 addition & 1 deletion tests/evaluation/test_instruction_usage_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from traces_analyzer.evaluation.instruction_usage_evaluation import (
InstructionUsageEvaluation,
)
from traces_analyzer.utils.hexstring import HexString
from traces_parser.datatypes import HexString
from snapshottest.pytest import PyTestSnapshotTest


Expand Down
2 changes: 1 addition & 1 deletion tests/evaluation/test_tod_source_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from tests.test_utils.test_utils import _test_root, _test_sload
from traces_analyzer.features.extractors.tod_source import TODSource
from traces_analyzer.evaluation.tod_source_evaluation import TODSourceEvaluation
from traces_analyzer.parser.instructions.instruction import Instruction
from traces_parser.parser.instructions.instruction import Instruction
from snapshottest.pytest import PyTestSnapshotTest


Expand Down
10 changes: 5 additions & 5 deletions tests/integration/test_balances_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@
_test_root,
assert_flow_dependencies,
)
from traces_analyzer.parser.environment.parsing_environment import (
from traces_parser.parser.environment.parsing_environment import (
InstructionOutputOracle,
ParsingEnvironment,
)
from traces_analyzer.parser.information_flow.constant_step_indexes import (
from traces_parser.parser.information_flow.constant_step_indexes import (
SPECIAL_STEP_INDEXES,
)
from traces_analyzer.parser.information_flow.information_flow_graph import (
from traces_parser.parser.information_flow.information_flow_graph import (
build_information_flow_graph,
)
from traces_analyzer.parser.instructions.instructions import (
from traces_parser.parser.instructions.instructions import (
BALANCE,
CALL,
POP,
REVERT,
STOP,
)
from traces_analyzer.parser.trace_evm.trace_evm import InstructionMetadata, TraceEVM
from traces_parser.parser.trace_evm.trace_evm import InstructionMetadata, TraceEVM


def test_balances_across_calls() -> None:
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/test_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
_test_push_steps,
_test_root,
)
from traces_analyzer.parser.environment.parsing_environment import (
from traces_parser.parser.environment.parsing_environment import (
InstructionOutputOracle,
ParsingEnvironment,
)
from traces_analyzer.parser.information_flow.information_flow_graph import (
from traces_parser.parser.information_flow.information_flow_graph import (
build_information_flow_graph,
)
from traces_analyzer.parser.instructions.instructions import (
from traces_parser.parser.instructions.instructions import (
CALL,
CALLDATACOPY,
CALLVALUE,
Expand All @@ -26,7 +26,7 @@
RETURN,
RETURNDATASIZE,
)
from traces_analyzer.parser.trace_evm.trace_evm import InstructionMetadata, TraceEVM
from traces_parser.parser.trace_evm.trace_evm import InstructionMetadata, TraceEVM


def test_call_data_and_return_data_flow() -> None:
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/test_callcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
_test_push_steps,
_test_root,
)
from traces_analyzer.parser.environment.parsing_environment import (
from traces_parser.parser.environment.parsing_environment import (
InstructionOutputOracle,
ParsingEnvironment,
)
from traces_analyzer.parser.information_flow.information_flow_graph import (
from traces_parser.parser.information_flow.information_flow_graph import (
build_information_flow_graph,
)
from traces_analyzer.parser.instructions.instructions import (
from traces_parser.parser.instructions.instructions import (
CALLCODE,
CALLDATACOPY,
CALLVALUE,
Expand All @@ -28,7 +28,7 @@
SLOAD,
SSTORE,
)
from traces_analyzer.parser.trace_evm.trace_evm import InstructionMetadata, TraceEVM
from traces_parser.parser.trace_evm.trace_evm import InstructionMetadata, TraceEVM


def test_callcode_with_persisten_storage_writes() -> None:
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/test_delegatecall.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
_test_push_steps,
_test_root,
)
from traces_analyzer.parser.environment.parsing_environment import (
from traces_parser.parser.environment.parsing_environment import (
InstructionOutputOracle,
ParsingEnvironment,
)
from traces_analyzer.parser.information_flow.constant_step_indexes import (
from traces_parser.parser.information_flow.constant_step_indexes import (
SPECIAL_STEP_INDEXES,
)
from traces_analyzer.parser.information_flow.information_flow_graph import (
from traces_parser.parser.information_flow.information_flow_graph import (
build_information_flow_graph,
)
from traces_analyzer.parser.instructions.instructions import (
from traces_parser.parser.instructions.instructions import (
DELEGATECALL,
CALLDATACOPY,
CALLVALUE,
Expand All @@ -32,7 +32,7 @@
SLOAD,
SSTORE,
)
from traces_analyzer.parser.trace_evm.trace_evm import InstructionMetadata, TraceEVM
from traces_parser.parser.trace_evm.trace_evm import InstructionMetadata, TraceEVM


def test_delegatecall_with_persisten_storage_writes() -> None:
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/test_exceptional_halt.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
_test_push_steps,
assert_flow_dependencies,
)
from traces_analyzer.parser.environment.parsing_environment import (
from traces_parser.parser.environment.parsing_environment import (
InstructionOutputOracle,
ParsingEnvironment,
)
from traces_analyzer.parser.information_flow.information_flow_graph import (
from traces_parser.parser.information_flow.information_flow_graph import (
build_information_flow_graph,
)
from traces_analyzer.parser.instructions.instructions import STATICCALL, SWAP2
from traces_analyzer.parser.trace_evm.trace_evm import InstructionMetadata, TraceEVM
from traces_parser.parser.instructions.instructions import STATICCALL, SWAP2
from traces_parser.parser.trace_evm.trace_evm import InstructionMetadata, TraceEVM


def test_exceptional_halt_executes_instruction_in_correct_context():
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/test_persistent_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
_test_root,
assert_flow_dependencies,
)
from traces_analyzer.parser.environment.parsing_environment import (
from traces_parser.parser.environment.parsing_environment import (
InstructionOutputOracle,
ParsingEnvironment,
)
from traces_analyzer.parser.information_flow.constant_step_indexes import (
from traces_parser.parser.information_flow.constant_step_indexes import (
SPECIAL_STEP_INDEXES,
)
from traces_analyzer.parser.information_flow.information_flow_graph import (
from traces_parser.parser.information_flow.information_flow_graph import (
build_information_flow_graph,
)
from traces_analyzer.parser.instructions.instructions import (
from traces_parser.parser.instructions.instructions import (
CALL,
JUMPDEST,
POP,
SLOAD,
SSTORE,
STOP,
)
from traces_analyzer.parser.trace_evm.trace_evm import InstructionMetadata, TraceEVM
from traces_parser.parser.trace_evm.trace_evm import InstructionMetadata, TraceEVM


def test_persistent_storage_across_calls() -> None:
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/test_simple_data_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
_test_root,
assert_flow_dependencies,
)
from traces_analyzer.parser.environment.parsing_environment import (
from traces_parser.parser.environment.parsing_environment import (
InstructionOutputOracle,
ParsingEnvironment,
)
from traces_analyzer.parser.information_flow.information_flow_graph import (
from traces_parser.parser.information_flow.information_flow_graph import (
build_information_flow_graph,
)
from traces_analyzer.parser.instructions.instructions import (
from traces_parser.parser.instructions.instructions import (
KECCAK256,
LOG1,
MCOPY,
MSTORE,
)
from traces_analyzer.parser.trace_evm.trace_evm import InstructionMetadata, TraceEVM
from traces_parser.parser.trace_evm.trace_evm import InstructionMetadata, TraceEVM


def test_simple_information_flow() -> None:
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/test_staticcall.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
_test_push_steps,
_test_root,
)
from traces_analyzer.parser.environment.parsing_environment import (
from traces_parser.parser.environment.parsing_environment import (
InstructionOutputOracle,
ParsingEnvironment,
)
from traces_analyzer.parser.information_flow.information_flow_graph import (
from traces_parser.parser.information_flow.information_flow_graph import (
build_information_flow_graph,
)
from traces_analyzer.parser.instructions.instructions import (
from traces_parser.parser.instructions.instructions import (
STATICCALL,
CALLDATACOPY,
CALLVALUE,
Expand All @@ -28,7 +28,7 @@
SLOAD,
SSTORE,
)
from traces_analyzer.parser.trace_evm.trace_evm import InstructionMetadata, TraceEVM
from traces_parser.parser.trace_evm.trace_evm import InstructionMetadata, TraceEVM


def test_staticcall() -> None:
Expand Down
Loading

0 comments on commit 87e4be9

Please sign in to comment.