From d8741024880915249763d6e8bc560bf210d93ec2 Mon Sep 17 00:00:00 2001 From: Parth Oberoi Date: Sun, 8 Sep 2019 02:18:10 +0530 Subject: [PATCH] Fix header length check for 192_7 and update bubbles network upgrade branch --- lib/blockchain.py | 11 ++++++++--- lib/network.py | 6 +++--- lib/transaction.py | 3 ++- lib/version.py | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/blockchain.py b/lib/blockchain.py index 6ddbd39b1..132fbcdb8 100644 --- a/lib/blockchain.py +++ b/lib/blockchain.py @@ -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 @@ -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 = {} @@ -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 @@ -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() diff --git a/lib/network.py b/lib/network.py index 48b9ee61d..6f75437a6 100644 --- a/lib/network.py +++ b/lib/network.py @@ -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 @@ -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 @@ -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 diff --git a/lib/transaction.py b/lib/transaction.py index 190a5e083..85dbfdac4 100644 --- a/lib/transaction.py +++ b/lib/transaction.py @@ -46,6 +46,7 @@ OVERWINTER_BRANCH_ID = 0x5BA81B19 SAPLING_VERSION_GROUP_ID = 0x892F2085 SAPLING_BRANCH_ID = 0x76B809BB +BUBBLES_BRANCH_ID = 0x821A451C class TransactionVersionError(Exception): @@ -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))) diff --git a/lib/version.py b/lib/version.py index 542ca1020..158f08de1 100644 --- a/lib/version.py +++ b/lib/version.py @@ -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