* Add foundry command support

* Add foundry support

* Add a hotfix

* Fix cheat codes

* misc fixes

* misc fixes

* Black

* switch equality
pull/1750/head
Nikhil Parasaram 2 years ago committed by GitHub
parent e38502f35d
commit 4af3b1d98f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      mythril/laser/ethereum/call.py
  2. 56
      mythril/laser/ethereum/cheat_code.py
  3. 10
      mythril/laser/ethereum/util.py
  4. 1
      mythril/solidity/soliditycontract.py

@ -8,7 +8,9 @@ from typing import Union, List, cast, Optional
from eth.constants import GAS_CALLSTIPEND
import mythril.laser.ethereum.util as util
from mythril.laser.ethereum.util import insert_ret_val
from mythril.laser.ethereum import natives
from mythril.laser.ethereum.cheat_code import handle_cheat_codes, hevm_cheat_code
from mythril.laser.ethereum.instruction_data import calculate_native_gas
from mythril.laser.ethereum.state.account import Account
from mythril.laser.ethereum.natives import PRECOMPILE_COUNT, PRECOMPILE_FUNCTIONS
@ -194,14 +196,6 @@ def get_call_data(
return SymbolicCalldata(transaction_id)
def insert_ret_val(global_state: GlobalState):
retval = global_state.new_bitvec(
"retval_" + str(global_state.get_current_instruction()["address"]), 256
)
global_state.mstate.stack.append(retval)
global_state.world_state.constraints.append(retval == 1)
def native_call(
global_state: GlobalState,
callee_address: Union[str, BitVec],
@ -210,11 +204,17 @@ def native_call(
memory_out_size: Union[int, Expression],
) -> Optional[List[GlobalState]]:
if (
isinstance(callee_address, BitVec)
or not 0 < int(callee_address, 16) <= PRECOMPILE_COUNT
if isinstance(callee_address, BitVec) or not (
0 < int(callee_address, 16) <= PRECOMPILE_COUNT
or hevm_cheat_code.is_cheat_address(callee_address)
):
return None
if hevm_cheat_code.is_cheat_address(callee_address):
log.info("HEVM cheat code address triggered")
handle_cheat_codes(
global_state, callee_address, call_data, memory_out_offset, memory_out_size
)
return [global_state]
log.debug("Native contract called: " + callee_address)
try:

@ -0,0 +1,56 @@
import logging
import re
from typing import Union, List, cast, Optional
from eth.constants import GAS_CALLSTIPEND
import mythril.laser.ethereum.util as util
from mythril.laser.ethereum.util import insert_ret_val
from mythril.laser.ethereum import natives
from mythril.laser.ethereum.instruction_data import calculate_native_gas
from mythril.laser.ethereum.state.account import Account
from mythril.laser.ethereum.natives import PRECOMPILE_COUNT, PRECOMPILE_FUNCTIONS
from mythril.laser.ethereum.state.calldata import (
BaseCalldata,
SymbolicCalldata,
ConcreteCalldata,
)
from mythril.laser.ethereum.state.global_state import GlobalState
from mythril.laser.smt import BitVec, If
from mythril.laser.smt import simplify, Expression, symbol_factory
from mythril.support.loader import DynLoader
class hevm_cheat_code:
# https://github.com/dapphub/ds-test/blob/cd98eff28324bfac652e63a239a60632a761790b/src/test.sol
address = 0x7109709ECFA91A80626FF3989D68F67F5B1DD12D
fail_payload = int(
"70ca10bb"
+ "0000000000000000000000007109709ecfa91a80626ff3989d68f67f5b1dd12d"
+ "6661696c65640000000000000000000000000000000000000000000000000000"
+ "0000000000000000000000000000000000000000000000000000000000000001",
16,
)
assume_sig = 0x4C63E562
@staticmethod
def is_cheat_address(address):
if int(address, 16) == int("0x7109709ECfa91a80626fF3989D68f67F5b1DD12D", 16):
return True
if int(address, 16) == int("0x72c68108a82e82617b93d1be0d7975d762035015", 16):
return True
return False
def handle_cheat_codes(
global_state: GlobalState,
callee_address: Union[str, BitVec],
call_data: BaseCalldata,
memory_out_offset: Union[int, Expression],
memory_out_size: Union[int, Expression],
):
insert_ret_val(global_state)
pass

@ -5,7 +5,7 @@ from typing import Dict, List, Union, TYPE_CHECKING, cast
if TYPE_CHECKING:
from mythril.laser.ethereum.state.machine_state import MachineState
from mythril.laser.ethereum.state.global_state import GlobalState
from mythril.laser.smt import BitVec, Bool, Expression, If, simplify, symbol_factory
TT256 = 2**256
@ -25,6 +25,14 @@ def safe_decode(hex_encoded_string: str) -> bytes:
return bytes.fromhex(hex_encoded_string)
def insert_ret_val(global_state: "GlobalState"):
retval = global_state.new_bitvec(
"retval_" + str(global_state.get_current_instruction()["address"]), 256
)
global_state.mstate.stack.append(retval)
global_state.world_state.constraints.append(retval == 1)
def to_signed(i: int) -> int:
"""

@ -286,7 +286,6 @@ class SolidityContract(EVMContract):
:param ast: AST of the contract
:return: The source maps
"""
print
source_maps = set()
if ast.node_type == "SourceUnit":
for child in ast.nodes:

Loading…
Cancel
Save