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

Commit feafaad

Browse files
committed
Fixed STATICCALL bug, and changed modexp gas calculation
1 parent 492ce21 commit feafaad

File tree

11 files changed

+11534
-11526
lines changed

11 files changed

+11534
-11526
lines changed

ethereum/child_dao_list.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
# DAO extrabalance
88
L.append('0x807640a13483f8ac783c557fcdf27be11ea4ac7a')
99
# child DAOs (created by DAO creator)
10-
L.extend([b'0x' + encode_hex(mk_contract_address(source, i)) for i in range(1, 58)])
10+
L.extend(['0x' + encode_hex(mk_contract_address(source, i)) for i in range(1, 58)])
1111
# child extrabalances
12-
L.extend([b'0x' + encode_hex(mk_contract_address(mk_contract_address(source, i), 0)) for i in range(1, 58)])
12+
L.extend(['0x' + encode_hex(mk_contract_address(mk_contract_address(source, i), 0)) for i in range(1, 58)])

ethereum/messages.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from ethereum import opcodes
1717
from ethereum.transactions import Transaction
1818
from ethereum.consensus_strategy import get_consensus_strategy
19-
from ethereum import vm
19+
from ethereum import new_vm as vm
2020
from ethereum.specials import specials as default_specials
2121
from ethereum.config import Env, default_config
2222
from ethereum.db import BaseDB, EphemDB
@@ -323,7 +323,8 @@ def _apply_msg(ext, msg, code):
323323
log_msg.debug("MSG APPLY", sender=encode_hex(msg.sender), to=encode_hex(msg.to),
324324
gas=msg.gas, value=msg.value,
325325
data=encode_hex(msg.data.extract_all()) if msg.data.size < 2500 else ("data<%d>" % msg.data.size),
326-
pre_storage=ext.log_storage(msg.to))
326+
pre_storage=ext.log_storage(msg.to),
327+
static=msg.static, depth=msg.depth)
327328

328329
# Transfer value, instaquit if not enough
329330
snapshot = ext.snapshot()

ethereum/opcodes.py

Lines changed: 2 additions & 1 deletion
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+
0xfa: ['STATICCALL', 6, 1, 40],
7374
0xfd: ['REVERT', 2, 0, 0],
7475
0xff: ['SUICIDE', 1, 0, 0], # 5000 now
7576
}
@@ -125,7 +126,7 @@
125126
GSTORAGEMOD = 5000
126127
GSTORAGEADD = 20000
127128

128-
GMODEXPQUADDIVISOR = 20
129+
GMODEXPQUADDIVISOR = 100
129130
GECADD = 500
130131
GECMUL = 2000
131132

ethereum/specials.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def proc_ecrecover(ext, msg):
3030
return 1, msg.gas - opcodes.GECRECOVER, []
3131
try:
3232
pub = utils.ecrecover_to_pub(message_hash, v, r, s)
33-
except:
33+
except Exception as e:
3434
return 1, msg.gas - gas_cost, []
3535
o = [0] * 12 + [safe_ord(x) for x in utils.sha3(pub)[-20:]]
3636
return 1, msg.gas - gas_cost, o
@@ -78,7 +78,13 @@ def proc_modexp(ext, msg):
7878
baselen = msg.data.extract32(0)
7979
explen = msg.data.extract32(32)
8080
modlen = msg.data.extract32(64)
81-
gas_cost = (max(modlen, baselen) ** 2 * max(explen, 1)) // opcodes.GMODEXPQUADDIVISOR
81+
first_exp_bytes = msg.data.extract32(96 + baselen)
82+
bitlength = -1
83+
while first_exp_bytes:
84+
bitlength += 1
85+
first_exp_bytes >>= 1
86+
adjusted_explen = max(bitlength, 0) + 8 * max(explen - 32, 0)
87+
gas_cost = (max(modlen, baselen) ** 2 * max(adjusted_explen, 1)) // opcodes.GMODEXPQUADDIVISOR
8288
print(baselen, explen, modlen, 'expected gas cost', gas_cost)
8389
if msg.gas < gas_cost:
8490
return 0, 0, []

ethereum/tests/test_state.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717

1818
def test_state(filename, testname, testdata):
1919
logger.debug('running test:%r in %r' % (testname, filename))
20-
checker(testdata)
20+
try:
21+
checker(testdata)
22+
except new_statetest_utils.EnvNotFoundException:
23+
pass
2124

2225

2326
def pytest_generate_tests(metafunc):
@@ -49,7 +52,10 @@ def main():
4952
for testname, testdata in list(tests.items()):
5053
if len(sys.argv) < 3 or testname == sys.argv[2]:
5154
print("Testing: %s %s" % (filename, testname))
52-
checker(testdata)
55+
try:
56+
checker(testdata)
57+
except new_statetest_utils.EnvNotFoundException:
58+
pass
5359

5460

5561
if __name__ == '__main__':

ethereum/tools/new_statetest_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,13 @@ def init_state(env, pre):
135135
# state.commit()
136136
return state
137137

138+
class EnvNotFoundException(Exception):
139+
pass
140+
138141
def verify_state_test(test):
139142
print("Verifying state test")
143+
if "env" not in test:
144+
raise EnvNotFoundException("Env not found")
140145
_state = init_state(test["env"], test["pre"])
141146
for config_name, results in test["post"].items():
142147
# Old protocol versions may not be supported

ethereum/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
except ImportError:
55
import sha3 as _sha3
66
sha3_256 = lambda x: _sha3.keccak_256(x).digest()
7-
from bitcoin import privtopub
7+
from bitcoin import privtopub, ecdsa_raw_sign, ecdsa_raw_recover, encode_pubkey
88
import sys
99
import rlp
1010
from rlp.sedes import big_endian_int, BigEndianInt, Binary
1111
from rlp.utils import decode_hex, encode_hex, ascii_chr, str_to_bytes
1212
import random
1313

14+
1415
try:
1516
import secp256k1
1617
except ImportError:

ethereum/vm.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -602,14 +602,14 @@ def vm_execute(ext, msg, code):
602602
elif ext.post_homestead_hardfork() and op == 'DELEGATECALL':
603603
call_msg = Message(msg.sender, msg.to, msg.value, submsg_gas, cd,
604604
msg.depth + 1, code_address=to, transfers_value=False, static=msg.static)
605-
elif op == 'DELEGATECALL':
606-
return vm_exception('OPCODE INACTIVE')
605+
elif ext.post_metropolis_hardfork() and op == 'STATICCALL':
606+
call_msg = Message(msg.to, to, value, submsg_gas, cd,
607+
msg.depth + 1, code_address=to, static=True)
608+
elif op in ('DELEGATECALL', 'STATICCALL'):
609+
return vm_exception('OPCODE %s INACTIVE' % op)
607610
elif op == 'CALLCODE':
608611
call_msg = Message(msg.to, msg.to, value, submsg_gas, cd,
609612
msg.depth + 1, code_address=to, static=msg.static)
610-
elif op == 'STATICCALL':
611-
call_msg = Message(msg.to, to, value, submsg_gas, cd,
612-
msg.depth + 1, code_address=to, static=True)
613613
else:
614614
raise Exception("Lolwut")
615615
# Get result

fixtures

Submodule fixtures updated 2040 files

0 commit comments

Comments
 (0)