Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit c44fc46

Browse files
committed
rm: very slow stack verification
1 parent bcc1ea5 commit c44fc46

File tree

4 files changed

+49
-44
lines changed

4 files changed

+49
-44
lines changed

ethereum/blocks.py

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# ####### dev hack flags ###############
2+
3+
dump_block_on_failed_verification = False
4+
5+
# ######################################
16
import time
27
from itertools import count
38
import sys
@@ -93,33 +98,6 @@ def calc_difficulty(parent, timestamp):
9398
return int(max(parent.difficulty + offset * sign, min(parent.difficulty, MIN_DIFF)))
9499

95100

96-
# Auxiliary value for must_* error messages
97-
aux = [None]
98-
99-
100-
def set_aux(auxval):
101-
aux[0] = auxval
102-
103-
104-
def must(what, f, symb, a, b):
105-
if not f(a, b):
106-
if aux[0]:
107-
sys.stderr.write('%r' % aux[0])
108-
raise VerificationFailed(what, a, symb, b)
109-
110-
111-
def must_equal(what, a, b):
112-
return must(what, lambda x, y: x == y, "==", a, b)
113-
114-
115-
def must_ge(what, a, b):
116-
return must(what, lambda x, y: x >= y, ">=", a, b)
117-
118-
119-
def must_le(what, a, b):
120-
return must(what, lambda x, y: x <= y, "<=", a, b)
121-
122-
123101
class Account(rlp.Serializable):
124102
"""An Ethereum account.
125103
@@ -523,8 +501,23 @@ def __init__(self, header, transaction_list=[], uncles=[], db=None,
523501
# (it doesn't know intermediate states), so reset it
524502
self.receipts = Trie(self.db, header.receipts_root)
525503

526-
# checks
527-
set_aux(self.to_dict())
504+
# checks ##############################
505+
506+
def must(what, f, symb, a, b):
507+
if not f(a, b):
508+
if dump_block_on_failed_verification:
509+
sys.stderr.write('%r' % self.to_dict())
510+
raise VerificationFailed(what, a, symb, b)
511+
512+
def must_equal(what, a, b):
513+
return must(what, lambda x, y: x == y, "==", a, b)
514+
515+
def must_ge(what, a, b):
516+
return must(what, lambda x, y: x >= y, ">=", a, b)
517+
518+
def must_le(what, a, b):
519+
return must(what, lambda x, y: x <= y, "<=", a, b)
520+
528521
if parent:
529522
must_equal('prev_hash', self.prevhash, parent.hash)
530523
must_ge('gas_limit', self.gas_limit,
@@ -540,7 +533,6 @@ def __init__(self, header, transaction_list=[], uncles=[], db=None,
540533
must_equal('tx_list_root', self.transactions.root_hash, header.tx_list_root)
541534
must_equal('receipts_root', self.receipts.root_hash, header.receipts_root)
542535
must_equal('bloom', self.bloom, original_values['bloom'])
543-
set_aux(None)
544536

545537
# from now on, trie roots refer to block instead of header
546538
header.block = self

ethereum/testutils.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def mktest(code, language, data=None, fun=None, args=None,
110110

111111

112112
# Fills up a vm test without post data, or runs the test
113-
def run_vm_test(params, mode):
113+
def run_vm_test(params, mode, profiler=None):
114114
pre = params['pre']
115115
exek = params['exec']
116116
env = params['env']
@@ -144,13 +144,14 @@ def run_vm_test(params, mode):
144144
# execute transactions
145145
sender = decode_hex(exek['caller']) # a party that originates a call
146146
recvaddr = decode_hex(exek['address'])
147-
tx = transactions.Transaction(
148-
nonce=blk._get_acct_item(decode_hex(exek['caller']), 'nonce'),
149-
gasprice=parse_int_or_hex(exek['gasPrice']),
150-
startgas=parse_int_or_hex(exek['gas']),
151-
to=recvaddr,
152-
value=parse_int_or_hex(exek['value']),
153-
data=decode_hex(exek['data'][2:]))
147+
nonce = blk._get_acct_item(sender, 'nonce')
148+
gasprice = parse_int_or_hex(exek['gasPrice'])
149+
startgas = parse_int_or_hex(exek['gas'])
150+
value = parse_int_or_hex(exek['value'])
151+
data = decode_hex(exek['data'][2:])
152+
153+
tx = transactions.Transaction(nonce=nonce, gasprice=gasprice, startgas=startgas,
154+
to=recvaddr, value=value, data=data)
154155
tx.sender = sender
155156

156157
# capture apply_message calls
@@ -191,9 +192,13 @@ def blkhash(n):
191192

192193
msg = vm.Message(tx.sender, tx.to, tx.value, tx.startgas,
193194
vm.CallData([safe_ord(x) for x in tx.data]))
195+
code = decode_hex(exek['code'][2:])
194196
time_pre = time.time()
195-
success, gas_remained, output = \
196-
vm.vm_execute(ext, msg, decode_hex(exek['code'][2:]))
197+
if profiler:
198+
profiler.enable()
199+
success, gas_remained, output = vm.vm_execute(ext, msg, code)
200+
if profiler:
201+
profiler.disable()
197202
pb.apply_msg = orig_apply_msg
198203
blk.commit_state()
199204
for s in blk.suicides:

ethereum/vm.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# ####### dev hack flags ###############
2+
3+
verify_stack_after_op = False
4+
5+
# ######################################
16
from ethereum import utils
27
from ethereum.abi import is_numeric
38
import copy
@@ -548,9 +553,12 @@ def vm_execute(ext, msg, code):
548553
ext.add_suicide(msg.to)
549554
# print('suiciding %s %s %d' % (msg.to, to, xfer))
550555
return 1, compustate.gas, []
551-
for a in stk:
552-
assert is_numeric(a)
553-
assert a >= 0 and a < 2**256, (a, op, stk)
556+
557+
# this is slow!
558+
if verify_stack_after_op:
559+
for a in stk:
560+
assert is_numeric(a)
561+
assert a >= 0 and a < 2**256, (a, op, stk)
554562

555563

556564
class VmExtBase():

fixtures

Submodule fixtures updated 54 files

0 commit comments

Comments
 (0)