mythril.laser.ethereum.state package
Submodules
mythril.laser.ethereum.state.account module
This module contains account-related functionality.
This includes classes representing accounts and their storage.
mythril.laser.ethereum.state.annotation module
This module includes classes used for annotating trace information.
This includes the base StateAnnotation class, as well as an adaption, which will not be copied on every new state.
- class mythril.laser.ethereum.state.annotation.MergeableStateAnnotation[source]
Bases:
StateAnnotation
This class allows a base annotation class for annotations that can be merged.
- class mythril.laser.ethereum.state.annotation.NoCopyAnnotation[source]
Bases:
StateAnnotation
This class provides a base annotation class for annotations that shouldn’t be copied on every new state.
Rather the same object should be propagated. This is very useful if you are looking to analyze a property over multiple substates
- class mythril.laser.ethereum.state.annotation.StateAnnotation[source]
Bases:
object
The StateAnnotation class is used to persist information over traces.
This allows modules to reason about traces without the need to traverse the state space themselves.
- property persist_over_calls: bool
If this function returns true then laser will propagate the annotation between calls
The default is set to False
- property persist_to_world_state: bool
If this function returns true then laser will also annotate the world state.
If you want annotations to persist through different user initiated message call transactions then this should be enabled.
The default is set to False
- property search_importance: int
Used in estimating the priority of a state annotated with the corresponding annotation. Default is 1
mythril.laser.ethereum.state.calldata module
This module declares classes to represent call data.
- class mythril.laser.ethereum.state.calldata.BaseCalldata(tx_id: str)[source]
Bases:
object
Base calldata class This represents the calldata provided when sending a transaction to a contract.
- concrete(model: Model) list [source]
Returns a concrete version of the calldata using the provided model.
- Parameters:
model
- get_word_at(offset: int) Expression [source]
Gets word at offset.
- Parameters:
offset
- Returns:
- class mythril.laser.ethereum.state.calldata.BasicConcreteCalldata(tx_id: str, calldata: list)[source]
Bases:
BaseCalldata
A base class to represent concrete call data.
- property size: int
- Returns:
- class mythril.laser.ethereum.state.calldata.BasicSymbolicCalldata(tx_id: str)[source]
Bases:
BaseCalldata
A basic class representing symbolic call data.
- class mythril.laser.ethereum.state.calldata.ConcreteCalldata(tx_id: str, calldata: list)[source]
Bases:
BaseCalldata
A concrete call data representation.
- property size: int
- Returns:
mythril.laser.ethereum.state.constraints module
This module contains the class used to represent state-change constraints in the call graph.
- class mythril.laser.ethereum.state.constraints.Constraints(constraint_list: List[Bool] | None = None)[source]
Bases:
list
This class should maintain a solver and it’s constraints, This class tries to make the Constraints() object as a simple list of constraints with some background processing.
- append(constraint: bool | Bool) None [source]
- Parameters:
constraint – The constraint to be appended
- copy() Constraints [source]
Return a shallow copy of the list.
mythril.laser.ethereum.state.environment module
This module contains the representation for an execution state’s environment.
- class mythril.laser.ethereum.state.environment.Environment(active_account: Account, sender: ExprRef, calldata: BaseCalldata, gasprice: ExprRef, callvalue: ExprRef, origin: ExprRef, basefee: ExprRef, code=None, static=False)[source]
Bases:
object
The environment class represents the current execution environment for the symbolic executor.
- property as_dict: Dict
- Returns:
mythril.laser.ethereum.state.global_state module
This module contains a representation of the global execution state.
- class mythril.laser.ethereum.state.global_state.GlobalState(world_state: WorldState, environment: Environment, node: Node, machine_state=None, transaction_stack=None, last_return_data=None, annotations=None)[source]
Bases:
object
GlobalState represents the current globalstate.
- property accounts: Dict
- Returns:
- add_annotations(annotations: List[StateAnnotation])[source]
Function used to add annotations to global state :param annotations: :return:
- annotate(annotation: StateAnnotation) None [source]
- Parameters:
annotation
- property annotations: List[StateAnnotation]
- Returns:
- property current_transaction: MessageCallTransaction | ContractCreationTransaction | None
- Returns:
- get_annotations(annotation_type: type) Iterable[StateAnnotation] [source]
Filters annotations for the queried annotation type. Designed particularly for modules with annotations: globalstate.get_annotations(MySpecificModuleAnnotation)
- Parameters:
annotation_type – The type to filter annotations for
- Returns:
filter of matching annotations
- get_current_instruction() Dict [source]
Gets the current instruction for this GlobalState.
- Returns:
- property instruction: Dict
- Returns:
mythril.laser.ethereum.state.machine_state module
This module contains a representation of the EVM’s machine state and its stack.
- class mythril.laser.ethereum.state.machine_state.MachineStack(default_list=None)[source]
Bases:
list
Defines EVM stack, overrides the default list to handle overflows.
- STACK_LIMIT = 1024
- append(element: int | Expression) None [source]
- This function ensures the following properties when appending to a list:
Element appended to this list should be a BitVec
Ensures stack overflow bound
- Parameters:
element – element to be appended to the list
- Function:
appends the element to list if the size is less than STACK_LIMIT, else throws an error
- pop(index=-1) int | Expression [source]
This function ensures stack underflow bound :param index:index to be popped, same as the list() class. :returns popped value :function: same as list() class but throws StackUnderflowException for popping from an empty list
- class mythril.laser.ethereum.state.machine_state.MachineState(gas_limit: int, pc=0, stack=None, subroutine_stack=None, memory: Memory | None = None, constraints=None, depth=0, max_gas_used=0, min_gas_used=0)[source]
Bases:
object
MachineState represents current machine state also referenced to as mu.
- property as_dict: Dict
- Returns:
- mem_extend(start: int | BitVec, size: int | BitVec) None [source]
Extends the memory of this machine state.
- Parameters:
start – Start of memory extension
size – Size of memory extension
- property memory_size: int
- Returns:
mythril.laser.ethereum.state.memory module
This module contains a representation of a smart contract’s memory.
- class mythril.laser.ethereum.state.memory.Memory[source]
Bases:
object
A class representing contract memory with random access.
mythril.laser.ethereum.state.return_data module
This module declares classes to represent call data.
mythril.laser.ethereum.state.world_state module
This module contains a representation of the EVM’s world state.
- class mythril.laser.ethereum.state.world_state.WorldState(transaction_sequence=None, annotations: List[StateAnnotation] | None = None, constraints: Constraints | None = None)[source]
Bases:
object
The WorldState class represents the world state as described in the yellow paper.
- property accounts
- accounts_exist_or_load(addr, dynamic_loader: DynLoader) Account [source]
returns account if it exists, else it loads from the dynamic loader :param addr: address :param dynamic_loader: Dynamic Loader :return: The code
- annotate(annotation: StateAnnotation) None [source]
- Parameters:
annotation
- property annotations: List[StateAnnotation]
- Returns:
- create_account(balance=0, address=None, concrete_storage=False, dynamic_loader=None, creator=None, code=None, nonce=0) Account [source]
Create non-contract account.
- Parameters:
address – The account’s address
balance – Initial balance for the account
concrete_storage – Interpret account storage as concrete
dynamic_loader – used for dynamically loading storage from the block chain
creator – The address of the creator of the contract if it’s a contract
code – The code of the contract, if it’s a contract
nonce – Nonce of the account
- Returns:
The new account
- create_initialized_contract_account(contract_code, storage) None [source]
Creates a new contract account, based on the contract code and storage provided The contract code only includes the runtime contract bytecode.
- Parameters:
contract_code – Runtime bytecode for the contract
storage – Initial storage for the contract
- Returns:
The new account
- get_annotations(annotation_type: type) Iterator[StateAnnotation] [source]
Filters annotations for the queried annotation type. Designed particularly for modules with annotations: worldstate.get_annotations(MySpecificModuleAnnotation)
- Parameters:
annotation_type – The type to filter annotations for
- Returns:
filter of matching annotations