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

Commit c713195

Browse files
NerdNerd
authored andcommitted
Updated the signature S value checks in accordance with the recent yello paper.
1 parent fe283ab commit c713195

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

ethereum/processblock.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from ethereum.exceptions import *
1111
from ethereum.utils import safe_ord, normalize_address, mk_contract_address
1212
from ethereum import transactions
13+
import ethereum.config as config
1314

1415
sys.setrecursionlimit(100000)
1516

@@ -80,6 +81,8 @@ def rp(what, actual, target):
8081
# (1) The transaction signature is valid;
8182
if not tx.sender: # sender is set and validated on Transaction initialization
8283
raise UnsignedTransaction(tx)
84+
if block.number >= config.default_config["HOMESTEAD_FORK_BLKNUM"]:
85+
tx.check_low_s()
8386

8487
# (2) the transaction nonce is valid (equivalent to the
8588
# sender account's current nonce);

ethereum/tests/test_transactions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from rlp.utils import decode_hex, encode_hex, str_to_bytes
55
import ethereum.testutils as testutils
66
from ethereum.testutils import fixture_to_bytes
7+
import ethereum.config as config
78
import sys
89
import json
910
import os
@@ -24,6 +25,9 @@ def run_test(filename, testname, testdata):
2425
rlpdata = decode_hex(testdata["rlp"][2:])
2526
o = {}
2627
tx = rlp.decode(rlpdata, transactions.Transaction)
28+
blknum = int(testdata["blocknumber"])
29+
if blknum >= config.default_config["HOMESTEAD_FORK_BLKNUM"]:
30+
tx.check_low_s()
2731
o["sender"] = tx.sender
2832
o["transaction"] = {
2933
"data": b'0x' * (len(tx.data) > 0) + encode_hex(tx.data),

ethereum/transactions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ def __repr__(self):
170170
def __structlog__(self):
171171
return encode_hex(self.hash)
172172

173+
# This method should be called for block numbers >= HOMESTEAD_FORK_BLKNUM only.
174+
# The >= operator is replaced by > because the integer division N/2 always produces the value
175+
# which is by 0.5 less than the real N/2
176+
def check_low_s(self):
177+
if self.s > N/2 or self.s == 0:
178+
raise InvalidTransaction("Invalid signature S value!")
179+
173180

174181
UnsignedTransaction = Transaction.exclude(['v', 'r', 's'])
175182

fixtures

Submodule fixtures updated 31 files

0 commit comments

Comments
 (0)