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

Commit ab9079e

Browse files
vubvub
authored andcommitted
Proposed homestead changes v0.1
1 parent 2d62ac7 commit ab9079e

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

ethereum/blocks.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@
3939
def calc_difficulty(parent, timestamp):
4040
config = parent.config
4141
offset = parent.difficulty // config['BLOCK_DIFF_FACTOR']
42-
sign = 1 if timestamp - parent.timestamp < config['DIFF_ADJUSTMENT_CUTOFF'] else -1
42+
if parent.number < config['HOMESTEAD_FORK_BLKNUM']:
43+
sign = 1 if timestamp - parent.timestamp < config['DIFF_ADJUSTMENT_CUTOFF'] else -1
44+
else:
45+
sign = max(1 - 2 * ((timestamp - parent.timestamp) // config['HOMESTEAD_DIFF_ADJUSTMENT_CUTOFF']), -99)
4346
# If we enter a special mode where the genesis difficulty starts off below
4447
# the minimal difficulty, we allow low-difficulty blocks (this will never
4548
# happen in the official protocol)

ethereum/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
EXPDIFF_FREE_PERIODS=2,
4444
# Blank account initial nonce
4545
ACCOUNT_INITIAL_NONCE=0,
46+
# Homestead fork (500k on livenet?)
47+
HOMESTEAD_FORK_BLKNUM=2**100,
48+
HOMESTEAD_DIFF_ADJUSTMENT_CUTOFF=16,
4649
)
4750
assert default_config['NEPHEW_REWARD'] == \
4851
default_config['BLOCK_REWARD'] // 32

ethereum/processblock.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,18 @@ def apply_transaction(block, tx):
124124
block.increment_nonce(tx.sender)
125125
# print block.get_nonce(tx.sender), '@@@'
126126

127+
intrinsic_gas = intrinsic_gas_used(tx)
128+
if block.number >= block.config['HOMESTEAD_FORK_BLKNUM']:
129+
assert tx.s * 2 < transactions.secpk1n
130+
if not tx.to or tx.to == CREATE_CONTRACT_ADDRESS:
131+
intrinsic_gas += opcodes.CREATE[3]
132+
if tx.startgas < intrinsic_gas:
133+
raise InsufficientStartGas(rp('startgas', tx.startgas, intrinsic_gas))
134+
127135
# buy startgas
128136
assert block.get_balance(tx.sender) >= tx.startgas * tx.gasprice
129137
block.delta_balance(tx.sender, -tx.startgas * tx.gasprice)
130-
message_gas = tx.startgas - intrinsic_gas_used(tx)
138+
message_gas = tx.startgas - intrinsic_gas
131139
message_data = vm.CallData([safe_ord(x) for x in tx.data], 0, len(tx.data))
132140
message = vm.Message(tx.sender, tx.to, tx.value, message_gas, message_data, code_address=tx.to)
133141

@@ -293,6 +301,8 @@ def create_contract(ext, msg):
293301
else:
294302
dat = []
295303
#print('CONTRACT CREATION OOG', 'have', gas, 'want', gcost)
304+
if ext._block.number >= ext._block.config['HOMESTEAD_FORK_BLKNUM']:
305+
return 0, 0, b''
296306
log_msg.debug('CONTRACT CREATION OOG', have=gas, want=gcost)
297307
ext._block.set_code(msg.to, b''.join(map(ascii_chr, dat)))
298308
return 1, gas, msg.to

ethereum/transactions.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ class Transaction(rlp.Serializable):
5353
_sender = None
5454

5555
def __init__(self, nonce, gasprice, startgas, to, value, data, v=0, r=0, s=0):
56-
if len(to) in (40, 48):
57-
to = decode_hex(to)
58-
if len(to) == 24:
59-
to = utils.check_and_strip_checksum(to)
56+
to = utils.normalize_address(to, allow_blank=True)
6057
assert len(to) == 20 or len(to) == 0
6158
super(Transaction, self).__init__(nonce, gasprice, startgas, to, value, data, v, r, s)
6259
self.logs = []

0 commit comments

Comments
 (0)