Skip to content

Commit

Permalink
Renaming: "transaction reordering" -> "transaction displacement"
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Jun 3, 2020
1 parent 62c1a88 commit 64a262f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion manticore/ethereum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
DetectUninitializedStorage,
DetectRaceCondition,
DetectManipulableBalance,
DetectTransactionReordering,
DetectTransactionDisplacement,
)
from .account import EVMAccount, EVMContract
from .solidity import SolidityMetadata
Expand Down
4 changes: 2 additions & 2 deletions manticore/ethereum/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
DetectRaceCondition,
DetectorClassification,
DetectManipulableBalance,
DetectTransactionReordering,
DetectTransactionDisplacement,
)
from ..core.plugin import Profiler
from .manticore import ManticoreEVM
Expand Down Expand Up @@ -56,7 +56,7 @@ def get_detectors_classes():
DetectExternalCallAndLeak,
DetectEnvInstruction,
DetectManipulableBalance,
DetectTransactionReordering,
DetectTransactionDisplacement,
# The RaceCondition detector has been disabled for now as it seems to collide with IntegerOverflow detector
# DetectRaceCondition
]
Expand Down
13 changes: 6 additions & 7 deletions manticore/ethereum/detectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,15 +884,15 @@ def did_evm_execute_instruction_callback(self, state, instruction, arguments, re
REPLAYING = "replaying"


class DetectTransactionReordering(Detector):
class DetectTransactionDisplacement(Detector):
"""
Detects cases where:
* transaction Y returns successfully
* for some transaction X from a different account, when X precedes Y, Y reverts
"""

ARGUMENT = "transaction-reordering"
HELP = "Susceptible to transaction reordering attacks"
ARGUMENT = "transaction-displacement"
HELP = "Susceptible to transaction displacement attacks"
IMPACT = DetectorClassification.MEDIUM
CONFIDENCE = DetectorClassification.HIGH

Expand Down Expand Up @@ -920,16 +920,15 @@ def will_run_callback(self, states: Iterable[State]):
consts = config.get_group("evm")
if consts.sha3 is consts.sha3.symbolicate:
logger.warn(
"Unsound symbolication can cause the transaction reordering attack"
"Unsound symbolication can cause the transaction displacement attack"
+ " detector to produce false positives"
)
context[WARNED] = True

if not context.get(TROUBLEMAKER):
# sam.moelius: Use same initial balance as in ManticoreEVM.multi_tx_analysis.
troublemaker = self.manticore.create_account(
balance=10000000000000000000,
name="troublemaker",
balance=10000000000000000000, name="troublemaker",
)
context[TROUBLEMAKER] = troublemaker.address
self.debug("troublemaker = %s", hex(troublemaker.address))
Expand Down Expand Up @@ -987,7 +986,7 @@ def did_close_transaction_callback(self, state: State, tx: Transaction):
state,
tx.address,
0,
f"{tx.result} following transaction reordering",
f"{tx.result} caused by transaction displacement",
False,
)

Expand Down
22 changes: 11 additions & 11 deletions tests/ethereum/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
State,
DetectExternalCallAndLeak,
DetectIntegerOverflow,
DetectTransactionReordering,
DetectTransactionDisplacement,
Detector,
NoAliveStates,
ABI,
Expand All @@ -46,7 +46,7 @@ def disposable_mevm(*args, **kwargs):
try:
yield mevm
finally:
shutil.rmtree(mevm.workspace)
pass # shutil.rmtree(mevm.workspace)


class EthDetectorsIntegrationTest(unittest.TestCase):
Expand All @@ -63,39 +63,39 @@ def test_int_ovf(self):
self.assertIn("Unsigned integer overflow at MUL instruction", all_findings)


class EthDetectorsTransactionReordering(unittest.TestCase):
def test_transaction_reordering_basic(self):
class EthDetectorsTransactionDisplacement(unittest.TestCase):
def test_transaction_displacement_basic(self):
# log.set_verbosity(5)
consts = config.get_group("evm")
consts.sha3 = consts.sha3.concretize
mevm = ManticoreEVM()
mevm.register_detector(DetectTransactionReordering())
mevm.register_detector(DetectTransactionDisplacement())
filename = os.path.join(THIS_DIR, "contracts/basic.sol")
mevm.multi_tx_analysis(filename, tx_limit=1)
mevm.finalize()
self.assertEqual(len(mevm.global_findings), 1)
all_findings = "".join([x[2] for x in mevm.global_findings])
self.assertIn("REVERT following transaction reordering", all_findings)
self.assertIn("REVERT caused by transaction displacement", all_findings)

def test_transaction_reordering_sqrt(self):
def test_transaction_displacement_sqrt(self):
# log.set_verbosity(5)
consts = config.get_group("evm")
consts.sha3 = consts.sha3.concretize
mevm = ManticoreEVM()
mevm.register_detector(DetectTransactionReordering())
mevm.register_detector(DetectTransactionDisplacement())
filename = os.path.join(THIS_DIR, "contracts/sqrt.sol")
mevm.multi_tx_analysis(filename, tx_limit=1)
mevm.finalize()
self.assertEqual(len(mevm.global_findings), 1)
all_findings = "".join([x[2] for x in mevm.global_findings])
self.assertIn("REVERT following transaction reordering", all_findings)
self.assertIn("REVERT caused by transaction displacement", all_findings)

def test_transaction_reordering_sqrt_better(self):
def test_transaction_displacement_sqrt_better(self):
# log.set_verbosity(5)
consts = config.get_group("evm")
consts.sha3 = consts.sha3.concretize
mevm = ManticoreEVM()
mevm.register_detector(DetectTransactionReordering())
mevm.register_detector(DetectTransactionDisplacement())
filename = os.path.join(THIS_DIR, "contracts/sqrt_better.sol")
mevm.multi_tx_analysis(filename, tx_limit=2)
mevm.finalize()
Expand Down

0 comments on commit 64a262f

Please sign in to comment.