Skip to content

Commit

Permalink
Merge pull request #12 from hTrap/master
Browse files Browse the repository at this point in the history
 Fix header length check for 192_7 and update bubbles network branch id
  • Loading branch information
cryptoprofutonium authored Sep 7, 2019
2 parents ab2ba94 + d874102 commit 184558d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
11 changes: 8 additions & 3 deletions lib/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
from .bitcoin import *

HDR_LEN = 1487
HDR_EH_192_7_LEN = 543
CHUNK_LEN = 100
BUBBLES_ACTIVATION_HEIGHT = 585318

MAX_TARGET = 0x0007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
POW_AVERAGING_WINDOW = 17
Expand Down Expand Up @@ -65,7 +67,7 @@ def serialize_header(res):
def deserialize_header(s, height):
if not s:
raise Exception('Invalid header: {}'.format(s))
if len(s) != HDR_LEN:
if len(s) != HDR_LEN and len(s) != HDR_EH_192_7_LEN:
raise Exception('Invalid header length: {}'.format(len(s)))
hex_to_int = lambda s: int('0x' + bh2u(s[::-1]), 16)
h = {}
Expand All @@ -77,7 +79,10 @@ def deserialize_header(s, height):
h['bits'] = hex_to_int(s[104:108])
h['nonce'] = hash_encode(s[108:140])
h['sol_size'] = hash_encode(s[140:143])
h['solution'] = hash_encode(s[143:1487])
if height < BUBBLES_ACTIVATION_HEIGHT:
h['solution'] = hash_encode(s[143:HDR_LEN])
else:
h['solution'] = hash_encode(s[143:HDR_EH_192_7_LEN])
h['block_height'] = height
return h

Expand Down Expand Up @@ -275,7 +280,7 @@ def save_header(self, header):
delta = header.get('block_height') - self.checkpoint
data = bfh(serialize_header(header))
assert delta == self.size()
assert len(data) == HDR_LEN
assert len(data) == HDR_LEN or len(data) == HDR_EH_192_7_LEN
self.write(data, delta*HDR_LEN)
self.swap_with_parent()

Expand Down
6 changes: 3 additions & 3 deletions lib/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from . import util
from . import bitcoin
from .bitcoin import *
from .blockchain import HDR_LEN, CHUNK_LEN
from .blockchain import HDR_LEN, HDR_EH_192_7_LEN, CHUNK_LEN
from . import constants
from .interface import Connection, Interface
from . import blockchain
Expand Down Expand Up @@ -831,7 +831,7 @@ def on_get_header(self, interface, response, height):
self.connection_down(interface.server)
return

if len(hex_header) != HDR_LEN*2:
if len(hex_header) != HDR_LEN*2 and len(hex_header) != HDR_EH_192_7_LEN:
interface.print_error('wrong header length', interface.request)
self.connection_down(interface.server)
return
Expand Down Expand Up @@ -1013,7 +1013,7 @@ def on_notify_header(self, interface, header):
if not height or not hex_header:
return

if len(hex_header) != HDR_LEN*2:
if len(hex_header) != HDR_LEN*2 and len(hex_header) != HDR_EH_192_7_LEN*2:
interface.print_error('wrong header length', interface.request)
self.connection_down(interface.server)
return
Expand Down
3 changes: 2 additions & 1 deletion lib/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
OVERWINTER_BRANCH_ID = 0x5BA81B19
SAPLING_VERSION_GROUP_ID = 0x892F2085
SAPLING_BRANCH_ID = 0x76B809BB
BUBBLES_BRANCH_ID = 0x821A451C


class TransactionVersionError(Exception):
Expand Down Expand Up @@ -993,7 +994,7 @@ def sign(self, keypairs):
# add signature
if self.overwintered:
data = bfh(self.serialize_preimage(i))
person = b'ZcashSigHash' + SAPLING_BRANCH_ID.to_bytes(4, 'little')
person = b'ZcashSigHash' + BUBBLES_BRANCH_ID.to_bytes(4, 'little')
pre_hash = blake2b(data, digest_size=32, person=person).digest()
else:
pre_hash = Hash(bfh(self.serialize_preimage(i)))
Expand Down
2 changes: 1 addition & 1 deletion lib/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ELECTRUM_VERSION = 'v3.2.1a' # version of the client package
ELECTRUM_VERSION = 'v3.2.2' # version of the client package
PROTOCOL_VERSION = '1.2' # protocol version requested

# The hash of the mnemonic seed must begin with this
Expand Down

0 comments on commit 184558d

Please sign in to comment.