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

Commit cb05a95

Browse files
vubvub
authored andcommitted
Passing all vm and state tests again
1 parent 3841e9a commit cb05a95

File tree

6 files changed

+38
-22
lines changed

6 files changed

+38
-22
lines changed

ethereum/blocks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ def get_storage_data(self, address, index):
991991
if len(bytez) >= 32:
992992
return big_endian_to_int(bytez[-32:])
993993
else:
994-
return big_endian_to_int(bytez) * (1 << (8 * (32 - len(bytez))))
994+
return big_endian_to_int(bytez)
995995

996996
def set_storage_data(self, address, index, value):
997997
"""Set a specific item in the storage of an account.
@@ -1112,9 +1112,9 @@ def account_to_dict(self, address, with_storage_root=False,
11121112
v2 = subcache.get(utils.big_endian_to_int(k), None)
11131113
hexkey = b'0x' + encode_hex(utils.zunpad(k))
11141114
if v2 is not None:
1115-
if v2 != 0:
1115+
if v2 != '':
11161116
med_dict['storage'][hexkey] = \
1117-
b'0x' + encode_hex(utils.int_to_big_endian(v2))
1117+
b'0x' + encode_hex(v2)
11181118
elif v is not None:
11191119
med_dict['storage'][hexkey] = b'0x' + encode_hex(rlp.decode(v))
11201120

ethereum/processblock.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ def rp(what, actual, target):
146146
return '%r: %r actual:%r target:%r' % (tx, what, actual, target)
147147

148148
intrinsic_gas = tx.intrinsic_gas_used
149+
print 'b1', block.get_balance(tx.sender)
149150
if block.number >= block.config['HOMESTEAD_FORK_BLKNUM']:
150151
assert tx.s * 2 < transactions.secpk1n
151152
if not tx.to or tx.to == CREATE_CONTRACT_ADDRESS:
@@ -164,6 +165,7 @@ def rp(what, actual, target):
164165
message_data = vm.CallData([safe_ord(x) for x in tx.data], 0, len(tx.data))
165166
message = vm.Message(tx.sender, tx.to, tx.value, message_gas, message_data, code_address=tx.to)
166167

168+
print 'b2', block.get_balance(tx.sender)
167169
# MESSAGE
168170
ext = VMExt(block, tx)
169171
if tx.to and tx.to != CREATE_CONTRACT_ADDRESS:
@@ -213,6 +215,7 @@ def rp(what, actual, target):
213215
block.del_account(s)
214216
block.add_transaction_to_list(tx)
215217
block.logs = []
218+
print 'b3', block.get_balance(tx.sender), success
216219
return success, output
217220

218221

@@ -308,7 +311,7 @@ def create_contract(ext, msg):
308311
#print('CREATING WITH GAS', msg.gas)
309312
sender = decode_hex(msg.sender) if len(msg.sender) == 40 else msg.sender
310313
code = msg.data.extract_all()
311-
if ext._block.number >= ext._block.METROPOLIS_FORK_BLKNUM:
314+
if ext._block.number >= ext._block.config["METROPOLIS_FORK_BLKNUM"]:
312315
msg.to = mk_metropolis_contract_address(msg.sender, code)
313316
if ext.get_code(msg.to):
314317
if ext.get_nonce(msg.to) >= 2**40:

ethereum/specials.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def proc_ecrecover(ext, msg):
5555

5656
pub = pk.serialize(compressed=False)
5757
except:
58-
recovered_addr = bitcoin.ecdsa_raw_recover(h, (v, r, s))
58+
recovered_addr = bitcoin.ecdsa_raw_recover(message_hash, (v, r, s))
5959
if recovered_addr in (False, (0, 0)):
6060
return 1, msg.gas - gas_cost, []
6161
pub = bitcoin.encode_pubkey(recovered_addr, 'bin')

ethereum/testutils.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
}
3131

3232
# from ethereum.slogging import LogRecorder, configure_logging, set_level
33-
# config_string = ':info,eth.vm.log:trace,eth.vm.op:trace,eth.vm.stack:trace,eth.vm.exit:trace,eth.pb.msg:trace'
33+
# config_string = ':info,eth.vm.log:trace,eth.vm.op:trace,eth.vm.stack:trace,eth.vm.exit:trace,eth.pb.msg:trace,eth.pb.tx:debug'
3434
# configure_logging(config_string=config_string)
3535

3636
FILL = 1
@@ -157,7 +157,7 @@ def run_vm_test(params, mode, profiler=None):
157157
for k, v in h['storage'].items():
158158
blk.set_storage_data(address,
159159
utils.big_endian_to_int(decode_hex(k[2:])),
160-
zpad(decode_hex(v[2:]), 32))
160+
decode_hex(v[2:]))
161161

162162
# execute transactions
163163
sender = decode_hex(exek['caller']) # a party that originates a call
@@ -297,6 +297,7 @@ def run_state_test(params, mode):
297297
gas_limit=parse_int_or_hex(env['currentGasLimit']),
298298
timestamp=parse_int_or_hex(env['currentTimestamp']))
299299
blk = blocks.Block(header, env=db_env)
300+
blk.config['HOMESTEAD_FORK_BLKNUM'] = 1000000
300301

301302
# setup state
302303
for address, h in list(pre.items()):
@@ -309,7 +310,7 @@ def run_state_test(params, mode):
309310
for k, v in h['storage'].items():
310311
blk.set_storage_data(address,
311312
utils.big_endian_to_int(decode_hex(k[2:])),
312-
zpad(decode_hex(v[2:]), 32))
313+
decode_hex(v[2:]))
313314

314315
for address, h in list(pre.items()):
315316
address = decode_hex(address)
@@ -360,15 +361,22 @@ def blkhash(n):
360361
assert False
361362

362363
time_pre = time.time()
364+
blk.commit_state()
365+
snapshot = blk.snapshot()
363366
try:
364367
print('trying')
365368
success, output = pb.apply_transaction(blk, tx)
369+
assert success
366370
blk.commit_state()
367371
print('success', blk.get_receipts()[-1].gas_used)
368372
except InvalidTransaction:
369373
success, output = False, b''
370374
blk.commit_state()
371375
pass
376+
except AssertionError:
377+
success, output = False, b''
378+
blk.commit_state()
379+
pass
372380
time_post = time.time()
373381

374382
if tx.to == b'':
@@ -392,11 +400,13 @@ def blkhash(n):
392400
compare_post_states(shouldbe, reallyis)
393401
for k in ['pre', 'exec', 'env', 'callcreates',
394402
'out', 'gas', 'logs', 'postStateRoot']:
395-
shouldbe = params1.get(k, None)
396-
reallyis = params2.get(k, None)
397-
if shouldbe != reallyis:
403+
_shouldbe = params1.get(k, None)
404+
_reallyis = params2.get(k, None)
405+
if _shouldbe != _reallyis:
406+
print 's', shouldbe
407+
print 'r', reallyis
398408
raise Exception("Mismatch: " + k + ':\n shouldbe %r\n reallyis %r' %
399-
(shouldbe, reallyis))
409+
(_shouldbe, _reallyis))
400410

401411
elif mode == TIME:
402412
return time_post - time_pre

ethereum/transactions.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf8 -*-
22
import rlp
3-
from bitcoin import encode_pubkey, N, encode_privkey
3+
from bitcoin import encode_pubkey, N, encode_privkey, ecdsa_raw_sign
44
from rlp.sedes import big_endian_int, binary
55
from rlp.utils import encode_hex, str_to_bytes, ascii_chr
66
try:
@@ -133,14 +133,17 @@ def sign(self, key):
133133
# we need a binary key
134134
key = encode_privkey(key, 'bin')
135135

136-
pk = PrivateKey(key, raw=True)
137-
signature = pk.ecdsa_recoverable_serialize(
138-
pk.ecdsa_sign_recoverable(rawhash, raw=True)
139-
)
140-
signature = signature[0] + utils.bytearray_to_bytestr([signature[1]])
141-
self.v = utils.safe_ord(signature[64]) + 27
142-
self.r = big_endian_to_int(signature[0:32])
143-
self.s = big_endian_to_int(signature[32:64])
136+
try:
137+
pk = PrivateKey(key, raw=True)
138+
signature = pk.ecdsa_recoverable_serialize(
139+
pk.ecdsa_sign_recoverable(rawhash, raw=True)
140+
)
141+
signature = signature[0] + utils.bytearray_to_bytestr([signature[1]])
142+
self.v = utils.safe_ord(signature[64]) + 27
143+
self.r = big_endian_to_int(signature[0:32])
144+
self.s = big_endian_to_int(signature[32:64])
145+
except:
146+
self.v, self.r, self.s = ecdsa_raw_sign(rawhash, key)
144147

145148
self.sender = utils.privtoaddr(key)
146149
return self

ethereum/vm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ def vm_execute(ext, msg, code):
435435
return vm_exception('OUT OF GAS')
436436
compustate.gas -= gascost
437437
ext.add_refund(refund) # adds neg gascost as a refund if below zero
438-
ext.set_storage_data(msg.to, s0, zpad(encode_int(s1), 32))
438+
ext.set_storage_data(msg.to, s0, encode_int(s1))
439439
elif op == 'JUMP':
440440
compustate.pc = stk.pop()
441441
opnew = processed_code[compustate.pc][0] if \

0 commit comments

Comments
 (0)