Skip to content

Commit

Permalink
Blacken
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Hennenfent committed Aug 26, 2020
1 parent 2c4471d commit c26f291
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 50 deletions.
11 changes: 7 additions & 4 deletions manticore/ethereum/manticore.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,13 @@ def _compile(source_code, contract_name, libraries=None, crytic_compile_args=Non
if isinstance(source_code, io.IOBase):
source_code = source_code.name

if (isinstance(source_code, str) and
not is_supported(source_code) and
# Until https://github.com/crytic/crytic-compile/issues/103 is implemented
"ignore_compile" not in crytic_compile_args):
if (
isinstance(source_code, str)
and not is_supported(source_code)
and
# Until https://github.com/crytic/crytic-compile/issues/103 is implemented
"ignore_compile" not in crytic_compile_args
):
with tempfile.NamedTemporaryFile("w+", suffix=".sol") as temp:
temp.write(source_code)
temp.flush()
Expand Down
2 changes: 1 addition & 1 deletion manticore/ethereum/verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,5 +500,5 @@ def main():
psender=psender,
timeout=args.timeout,
propre=args.propre,
compile_args=vars(parsed)
compile_args=vars(parsed),
)
62 changes: 17 additions & 45 deletions tests/ethereum/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -1779,21 +1779,20 @@ def test_selfdestruct(self):
self.assertEqual(m.count_ready_states(), 1)

def test_call_gas(self):
GCALLSTATIC = 21721 # 21000 + (3 * 7 push ops) + 700 static cost for call
GCALLVALUE = 9000 # cost added for nonzero callvalue
GCALLNEW = 25000 # cost added for forcing new acct creation
GCALLSTIPEND = 2300 # additional gas sent with a call if value > 0
GCALLSTATIC = 21721 # 21000 + (3 * 7 push ops) + 700 static cost for call
GCALLVALUE = 9000 # cost added for nonzero callvalue
GCALLNEW = 25000 # cost added for forcing new acct creation
GCALLSTIPEND = 2300 # additional gas sent with a call if value > 0

with disposable_mevm() as m:
# nonempty call target
m.create_account(
address=0x111111111111111111111111111111111111111,
nonce=1 # nonempty account
address=0x111111111111111111111111111111111111111, nonce=1 # nonempty account
)

# call(gas, target, value, in_offset, in_size, out_offset, out_size)
# call to empty acct with value = 0
asm_call_empty_no_val = """ PUSH1 0x0
asm_call_empty_no_val = """ PUSH1 0x0
PUSH1 0X0
PUSH1 0x0
PUSH1 0X0
Expand All @@ -1804,7 +1803,7 @@ def test_call_gas(self):
STOP
"""
# call to existing acct with value > 0
asm_call_nonempty_w_val = """ PUSH1 0x0
asm_call_nonempty_w_val = """ PUSH1 0x0
PUSH1 0X0
PUSH1 0x0
PUSH1 0X0
Expand All @@ -1815,7 +1814,7 @@ def test_call_gas(self):
STOP
"""
# call to empty acct with value > 0, forcing addition to state trie
asm_call_empty_w_val = """ PUSH1 0x0
asm_call_empty_w_val = """ PUSH1 0x0
PUSH1 0X0
PUSH1 0x0
PUSH1 0X0
Expand All @@ -1826,31 +1825,20 @@ def test_call_gas(self):
STOP
"""

call_empty_no_val = m.create_account(
code=EVMAsm.assemble(asm_call_empty_no_val)
)
call_empty_no_val = m.create_account(code=EVMAsm.assemble(asm_call_empty_no_val))
call_nonempty_w_val = m.create_account(
balance=100,
code=EVMAsm.assemble(asm_call_nonempty_w_val)
balance=100, code=EVMAsm.assemble(asm_call_nonempty_w_val)
)
call_empty_w_val = m.create_account(
balance=100,
code=EVMAsm.assemble(asm_call_empty_w_val)
balance=100, code=EVMAsm.assemble(asm_call_empty_w_val)
)

caller = m.create_account(
address=0x222222222222222222222222222222222222222,
balance=1000000000000000000
address=0x222222222222222222222222222222222222222, balance=1000000000000000000
)

# call to empty acct with value = 0
m.transaction(
caller=caller,
address=call_empty_no_val,
data=b'',
value=0,
gas=50000000
)
m.transaction(caller=caller, address=call_empty_no_val, data=b"", value=0, gas=50000000)
self.assertEqual(m.count_ready_states(), 1)
state = next(m.ready_states)
txs = state.platform.transactions
Expand All @@ -1861,41 +1849,25 @@ def test_call_gas(self):

# call to existing acct with value > 0
m.transaction(
caller=caller,
address=call_nonempty_w_val,
data=b'',
value=0,
gas=50000000
caller=caller, address=call_nonempty_w_val, data=b"", value=0, gas=50000000
)
self.assertEqual(m.count_ready_states(), 1)
state = next(m.ready_states)
txs = state.platform.transactions
# call stipend should be sent with call
self.assertEqual(txs[-2].gas, GCALLSTIPEND)
# cost of call should include value cost, but not new acct cost
self.assertEqual(
txs[-1].used_gas,
GCALLSTATIC + GCALLVALUE - GCALLSTIPEND
)
self.assertEqual(txs[-1].used_gas, GCALLSTATIC + GCALLVALUE - GCALLSTIPEND)

# call to empty acct with value > 0, forcing addition to state trie
m.transaction(
caller=caller,
address=call_empty_w_val,
data=b'',
value=0,
gas=50000000
)
m.transaction(caller=caller, address=call_empty_w_val, data=b"", value=0, gas=50000000)
self.assertEqual(m.count_ready_states(), 1)
state = next(m.ready_states)
txs = state.platform.transactions
# call stipend should be sent with call
self.assertEqual(txs[-2].gas, GCALLSTIPEND)
# cost of call should include value cost and new acct cost
self.assertEqual(
txs[-1].used_gas,
GCALLSTATIC + GCALLVALUE + GCALLNEW - GCALLSTIPEND
)
self.assertEqual(txs[-1].used_gas, GCALLSTATIC + GCALLVALUE + GCALLNEW - GCALLSTIPEND)


class EthPluginTests(unittest.TestCase):
Expand Down

0 comments on commit c26f291

Please sign in to comment.