mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 07:28:10 +00:00
src/apps/wallet/sign_tx: correct processing of block_height in bip115
This commit is contained in:
parent
13c659c202
commit
622eb001a6
@ -42,21 +42,18 @@ def output_script_p2sh(scripthash: bytes) -> bytearray:
|
|||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
def script_replay_protection_bip115(block_hash: bytes, block_height: bytes) -> bytearray:
|
def script_replay_protection_bip115(block_hash: bytes, block_height: int) -> bytearray:
|
||||||
if block_hash is None or block_height is None:
|
if block_hash is None or block_height is None:
|
||||||
return bytearray()
|
return bytearray()
|
||||||
block_height_size = len(block_height) # size in bytes of block_height (should be 3)
|
assert len(block_hash) == 32
|
||||||
s = bytearray(38)
|
s = bytearray(33)
|
||||||
s[0] = 0x20 # 32 bytes for block hash
|
s[0] = 0x20 # 32 bytes for block hash
|
||||||
s[1:33] = block_hash # block hash
|
s[1:33] = block_hash # block hash
|
||||||
s[33] = 0x03 # 3 bytes for block height
|
write_scriptnum(s, block_height)
|
||||||
if block_height_size == 3:
|
s.append(0xB4) # OP_CHECKBLOCKATHEIGHT
|
||||||
s[34:37] = block_height
|
|
||||||
else:
|
|
||||||
s[34:37] = block_height[:3 - block_height_size] # must be only 3 bytes
|
|
||||||
s[37] = 0xB4 # OP_CHECKBLOCKHIGHT
|
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
# SegWit: Native P2WPKH or P2WSH
|
# SegWit: Native P2WPKH or P2WSH
|
||||||
# ===
|
# ===
|
||||||
# https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#p2wpkh
|
# https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#p2wpkh
|
||||||
|
@ -59,7 +59,7 @@ def write_varint(w, n: int):
|
|||||||
assert n >= 0 and n <= 0xFFFFFFFF
|
assert n >= 0 and n <= 0xFFFFFFFF
|
||||||
if n < 253:
|
if n < 253:
|
||||||
w.append(n & 0xFF)
|
w.append(n & 0xFF)
|
||||||
elif n < 65536:
|
elif n < 0x10000:
|
||||||
w.append(253)
|
w.append(253)
|
||||||
w.append(n & 0xFF)
|
w.append(n & 0xFF)
|
||||||
w.append((n >> 8) & 0xFF)
|
w.append((n >> 8) & 0xFF)
|
||||||
@ -71,6 +71,28 @@ def write_varint(w, n: int):
|
|||||||
w.append((n >> 24) & 0xFF)
|
w.append((n >> 24) & 0xFF)
|
||||||
|
|
||||||
|
|
||||||
|
def write_scriptnum(w, n: int):
|
||||||
|
assert n >= 0 and n <= 0xFFFFFFFF
|
||||||
|
if n < 0x100:
|
||||||
|
w.append(1)
|
||||||
|
w.append(n & 0xFF)
|
||||||
|
elif n < 0x10000:
|
||||||
|
w.append(2)
|
||||||
|
w.append(n & 0xFF)
|
||||||
|
w.append((n >> 8) & 0xFF)
|
||||||
|
elif n < 0x1000000:
|
||||||
|
w.append(3)
|
||||||
|
w.append(n & 0xFF)
|
||||||
|
w.append((n >> 8) & 0xFF)
|
||||||
|
w.append((n >> 16) & 0xFF)
|
||||||
|
elif:
|
||||||
|
w.append(4)
|
||||||
|
w.append(n & 0xFF)
|
||||||
|
w.append((n >> 8) & 0xFF)
|
||||||
|
w.append((n >> 16) & 0xFF)
|
||||||
|
w.append((n >> 24) & 0xFF)
|
||||||
|
|
||||||
|
|
||||||
def write_uint32(w, n: int):
|
def write_uint32(w, n: int):
|
||||||
assert n >= 0 and n <= 0xFFFFFFFF
|
assert n >= 0 and n <= 0xFFFFFFFF
|
||||||
w.append(n & 0xFF)
|
w.append(n & 0xFF)
|
||||||
|
@ -22,7 +22,7 @@ class TxInputType(p.MessageType):
|
|||||||
9: ('decred_tree', p.UVarintType, 0),
|
9: ('decred_tree', p.UVarintType, 0),
|
||||||
10: ('decred_script_version', p.UVarintType, 0),
|
10: ('decred_script_version', p.UVarintType, 0),
|
||||||
11: ('prev_block_hash_bip115', p.BytesType, 0),
|
11: ('prev_block_hash_bip115', p.BytesType, 0),
|
||||||
12: ('prev_block_height_bip115', p.BytesType, 0),
|
12: ('prev_block_height_bip115', p.UVarintType, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -38,7 +38,7 @@ class TxInputType(p.MessageType):
|
|||||||
decred_tree: int = None,
|
decred_tree: int = None,
|
||||||
decred_script_version: int = None,
|
decred_script_version: int = None,
|
||||||
prev_block_hash_bip115: bytes = None,
|
prev_block_hash_bip115: bytes = None,
|
||||||
prev_block_height_bip115: bytes = None,
|
prev_block_height_bip115: int = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.address_n = address_n if address_n is not None else []
|
self.address_n = address_n if address_n is not None else []
|
||||||
self.prev_hash = prev_hash
|
self.prev_hash = prev_hash
|
||||||
|
@ -19,7 +19,7 @@ class TxOutputType(p.MessageType):
|
|||||||
6: ('op_return_data', p.BytesType, 0),
|
6: ('op_return_data', p.BytesType, 0),
|
||||||
7: ('decred_script_version', p.UVarintType, 0),
|
7: ('decred_script_version', p.UVarintType, 0),
|
||||||
8: ('block_hash_bip115', p.BytesType, 0),
|
8: ('block_hash_bip115', p.BytesType, 0),
|
||||||
9: ('block_height_bip115', p.BytesType, 0),
|
9: ('block_height_bip115', p.UVarintType, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -32,7 +32,7 @@ class TxOutputType(p.MessageType):
|
|||||||
op_return_data: bytes = None,
|
op_return_data: bytes = None,
|
||||||
decred_script_version: int = None,
|
decred_script_version: int = None,
|
||||||
block_hash_bip115: bytes = None,
|
block_hash_bip115: bytes = None,
|
||||||
block_height_bip115: bytes = None,
|
block_height_bip115: int = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.address = address
|
self.address = address
|
||||||
self.address_n = address_n if address_n is not None else []
|
self.address_n = address_n if address_n is not None else []
|
||||||
|
2
vendor/trezor-common
vendored
2
vendor/trezor-common
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 1b9b7d6c8ed44b24a7f105a83dc10ea7cc796ed9
|
Subproject commit 5eae03131c89dabaa4caa8c5cb96742707206541
|
Loading…
Reference in New Issue
Block a user