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

Commit dc77771

Browse files
vubvub
authored andcommitted
Added revert opcode declaration
1 parent 6af2dbe commit dc77771

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

ethereum/new_statetest_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from ethereum.slogging import LogRecorder, configure_logging, set_level
1212
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'
1313

14-
# configure_logging(config_string=config_string)
14+
configure_logging(config_string=config_string)
1515

1616
fake_headers = {}
1717

@@ -128,6 +128,10 @@ def verify_state_test(test):
128128
continue
129129
print("Testing for %s" % config_name)
130130
for result in results:
131+
print("Checking for values: g %d v %d d %s" % (
132+
parse_int_or_hex(test["transaction"]['gasLimit'][result["indexes"]["gas"]]),
133+
parse_int_or_hex(test["transaction"]['value'][result["indexes"]["value"]]),
134+
test["transaction"]['data'][result["indexes"]["data"]]))
131135
computed = compute_state_test_unit(_state, test["transaction"], result["indexes"], configs[config_name])
132136
if computed["hash"] != result["hash"]:
133137
raise Exception("Hash mismatch, computed: %s, supplied: %s" % (computed["hash"], result["hash"]))

ethereum/opcodes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
0xf3: ['RETURN', 2, 0, 0],
7171
0xf4: ['DELEGATECALL', 6, 1, 40], # 700 now
7272
0xf5: ['CALLBLACKBOX', 7, 1, 40],
73+
0xfd: ['REVERT', 2, 0, 0],
7374
0xff: ['SUICIDE', 1, 0, 0], # 5000 now
7475
}
7576

ethereum/state_transition.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,16 +262,18 @@ def rp(what, actual, target):
262262
log_tx.debug("TX APPLIED", result=result, gas_remained=gas_remained,
263263
data=data)
264264

265+
gas_used = tx.startgas - gas_remained
266+
265267
if not result: # 0 = OOG failure in both cases
266268
log_tx.debug('TX FAILED', reason='out of gas',
267269
startgas=tx.startgas, gas_remained=gas_remained)
268270
state.gas_used += tx.startgas
269-
state.delta_balance(state.block_coinbase, tx.gasprice * tx.startgas)
271+
state.delta_balance(tx.sender, tx.gasprice * gas_remained)
272+
state.delta_balance(state.block_coinbase, tx.gasprice * gas_used)
270273
output = b''
271274
success = 0
272275
else:
273276
log_tx.debug('TX SUCCESS', data=data)
274-
gas_used = tx.startgas - gas_remained
275277
state.refunds += len(set(state.suicides)) * opcodes.GSUICIDEREFUND
276278
if state.refunds > 0:
277279
log_tx.debug('Refunding', gas_refunded=min(state.refunds, gas_used // 2))

ethereum/vm.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ def peaceful_exit(cause, gas, data, **kargs):
163163
log_vm_exit.trace('EXIT', cause=cause, **kargs)
164164
return 1, gas, data
165165

166+
def revert(gas, data, **kargs):
167+
log_vm_exit.trace('REVERT', **kargs)
168+
return 0, gas, data
169+
166170
code_cache = {}
167171

168172

@@ -571,7 +575,7 @@ def vm_execute(ext, msg, code):
571575
compustate.gas = compustate.gas - ingas + gas
572576
else:
573577
stk.append(0)
574-
compustate.gas -= ingas
578+
compustate.gas = compustate.gas - ingas + gas
575579
else:
576580
stk.append(0)
577581
elif op == 'CALL':
@@ -689,6 +693,13 @@ def vm_execute(ext, msg, code):
689693
if not mem_extend(mem, compustate, op, s0, s1):
690694
return vm_exception('OOG EXTENDING MEMORY')
691695
return peaceful_exit('RETURN', compustate.gas, mem[s0: s0 + s1])
696+
elif op == 'REVERT':
697+
if not ext.post_metropolis_hardfork():
698+
return vm_exception('Opcode not yet enabled')
699+
s0, s1 = stk.pop(), stk.pop()
700+
if not mem_extend(mem, compustate, op, s0, s1):
701+
return vm_exception('OOG EXTENDING MEMORY')
702+
return revert(compustate.gas, mem[s0: s0 + s1])
692703
elif op == 'SUICIDE':
693704
to = utils.encode_int(stk.pop())
694705
to = ((b'\x00' * (32 - len(to))) + to)[12:]
@@ -701,7 +712,6 @@ def vm_execute(ext, msg, code):
701712
ext.set_balance(to, ext.get_balance(to) + xfer)
702713
ext.set_balance(msg.to, 0)
703714
ext.add_suicide(msg.to)
704-
print('suiciding %s %s %d' % (msg.to, to, xfer))
705715
return 1, compustate.gas, []
706716

707717
# assert utils.is_numeric(compustate.gas)

0 commit comments

Comments
 (0)