mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-21 23:18:13 +00:00
src/apps/wallet/sign_tx: implement tx.branch_id field
This commit is contained in:
parent
178d4fe598
commit
6974d037a9
@ -644,6 +644,26 @@ COINS = [
|
||||
decred=False,
|
||||
curve_name='secp256k1-groestl',
|
||||
),
|
||||
CoinInfo(
|
||||
coin_name="Komodo",
|
||||
coin_shortcut="KMD",
|
||||
address_type=60,
|
||||
address_type_p2sh=85,
|
||||
maxfee_kb=1000000,
|
||||
signed_message_header="Komodo Signed Message:\n",
|
||||
xpub_magic=0x0488b21e,
|
||||
xpub_magic_segwit_p2sh=None,
|
||||
xpub_magic_segwit_native=None,
|
||||
bech32_prefix=None,
|
||||
cashaddr_prefix=None,
|
||||
slip44=141,
|
||||
segwit=False,
|
||||
fork_id=None,
|
||||
force_bip143=False,
|
||||
bip115=False,
|
||||
decred=False,
|
||||
curve_name='secp256k1',
|
||||
),
|
||||
CoinInfo(
|
||||
coin_name="Koto",
|
||||
coin_shortcut="KOTO",
|
||||
|
@ -66,9 +66,9 @@ async def check_tx_fee(tx: SignTx, keychain: seed.Keychain):
|
||||
tx_ser = TxRequestSerializedType()
|
||||
elif tx.overwintered:
|
||||
if tx.version == 3:
|
||||
hash143 = zcash.Zip143() # ZIP-0143 transaction hashing
|
||||
hash143 = zcash.Zip143(tx.branch_id) # ZIP-0143 transaction hashing
|
||||
elif tx.version == 4:
|
||||
hash143 = zcash.Zip243() # ZIP-0243 transaction hashing
|
||||
hash143 = zcash.Zip243(tx.branch_id) # ZIP-0243 transaction hashing
|
||||
else:
|
||||
raise SigningError(
|
||||
FailureType.DataError,
|
||||
|
@ -1,3 +1,4 @@
|
||||
import ustruct as struct
|
||||
from micropython import const
|
||||
|
||||
from trezor.crypto.hashlib import blake2b
|
||||
@ -45,7 +46,8 @@ def derive_script_code(txi: TxInputType, pubkeyhash: bytes) -> bytearray:
|
||||
|
||||
|
||||
class Zip143:
|
||||
def __init__(self):
|
||||
def __init__(self, branch_id):
|
||||
self.branch_id = branch_id
|
||||
self.h_prevouts = HashWriter(blake2b(outlen=32, personal=b"ZcashPrevoutHash"))
|
||||
self.h_sequence = HashWriter(blake2b(outlen=32, personal=b"ZcashSequencHash"))
|
||||
self.h_outputs = HashWriter(blake2b(outlen=32, personal=b"ZcashOutputsHash"))
|
||||
@ -78,8 +80,10 @@ class Zip143:
|
||||
sighash: int,
|
||||
) -> bytes:
|
||||
h_preimage = HashWriter(
|
||||
blake2b(outlen=32, personal=b"ZcashSigHash\x19\x1b\xa8\x5b")
|
||||
) # BRANCH_ID = 0x5ba81b19 / Overwinter
|
||||
blake2b(
|
||||
outlen=32, personal=b"ZcashSigHash" + struct.pack("<I", self.branch_id)
|
||||
)
|
||||
)
|
||||
|
||||
ensure(tx.overwintered)
|
||||
ensure(tx.version == 3)
|
||||
@ -111,8 +115,8 @@ class Zip143:
|
||||
|
||||
|
||||
class Zip243(Zip143):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def __init__(self, branch_id):
|
||||
super().__init__(branch_id)
|
||||
|
||||
def preimage_hash(
|
||||
self,
|
||||
@ -123,8 +127,10 @@ class Zip243(Zip143):
|
||||
sighash: int,
|
||||
) -> bytes:
|
||||
h_preimage = HashWriter(
|
||||
blake2b(outlen=32, personal=b"ZcashSigHash\xbb\x09\xb8\x76")
|
||||
) # BRANCH_ID = 0x76b809bb / Sapling
|
||||
blake2b(
|
||||
outlen=32, personal=b"ZcashSigHash" + struct.pack("<I", self.branch_id)
|
||||
)
|
||||
)
|
||||
|
||||
ensure(tx.overwintered)
|
||||
ensure(tx.version == 4)
|
||||
|
@ -17,6 +17,7 @@ class SignTx(p.MessageType):
|
||||
overwintered: bool = None,
|
||||
version_group_id: int = None,
|
||||
timestamp: int = None,
|
||||
branch_id: int = None,
|
||||
) -> None:
|
||||
self.outputs_count = outputs_count
|
||||
self.inputs_count = inputs_count
|
||||
@ -27,6 +28,7 @@ class SignTx(p.MessageType):
|
||||
self.overwintered = overwintered
|
||||
self.version_group_id = version_group_id
|
||||
self.timestamp = timestamp
|
||||
self.branch_id = branch_id
|
||||
|
||||
@classmethod
|
||||
def get_fields(cls):
|
||||
@ -40,4 +42,5 @@ class SignTx(p.MessageType):
|
||||
7: ('overwintered', p.BoolType, 0),
|
||||
8: ('version_group_id', p.UVarintType, 0),
|
||||
9: ('timestamp', p.UVarintType, 0),
|
||||
10: ('branch_id', p.UVarintType, 0),
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ class TransactionType(p.MessageType):
|
||||
overwintered: bool = None,
|
||||
version_group_id: int = None,
|
||||
timestamp: int = None,
|
||||
branch_id: int = None,
|
||||
) -> None:
|
||||
self.version = version
|
||||
self.inputs = inputs if inputs is not None else []
|
||||
@ -44,6 +45,7 @@ class TransactionType(p.MessageType):
|
||||
self.overwintered = overwintered
|
||||
self.version_group_id = version_group_id
|
||||
self.timestamp = timestamp
|
||||
self.branch_id = branch_id
|
||||
|
||||
@classmethod
|
||||
def get_fields(cls):
|
||||
@ -61,4 +63,5 @@ class TransactionType(p.MessageType):
|
||||
11: ('overwintered', p.BoolType, 0),
|
||||
12: ('version_group_id', p.UVarintType, 0),
|
||||
13: ('timestamp', p.UVarintType, 0),
|
||||
14: ('branch_id', p.UVarintType, 0),
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ class TestZcashZip143(unittest.TestCase):
|
||||
overwintered=(v["version"] >= 3),
|
||||
version_group_id=v["version_group_id"],
|
||||
)
|
||||
zip143 = Zip143()
|
||||
zip143 = Zip143(0x5ba81b19) # Overwinter
|
||||
for i in v["inputs"]:
|
||||
txi = TxInputType()
|
||||
txi.amount = i["amount"]
|
||||
|
@ -185,7 +185,7 @@ class TestZcashZip243(unittest.TestCase):
|
||||
overwintered=(v["version"] >= 3),
|
||||
version_group_id=v["version_group_id"],
|
||||
)
|
||||
zip243 = Zip243()
|
||||
zip243 = Zip243(0x76b809bb) # Sapling
|
||||
for i in v["inputs"]:
|
||||
txi = TxInputType()
|
||||
txi.amount = i["amount"]
|
||||
|
2
vendor/trezor-common
vendored
2
vendor/trezor-common
vendored
@ -1 +1 @@
|
||||
Subproject commit ee25c4a6f4d8e36770b4bc2d6b962076547260aa
|
||||
Subproject commit 4b41d2e63841517bf701618434c018acf4f1bca2
|
2
vendor/trezor-crypto
vendored
2
vendor/trezor-crypto
vendored
@ -1 +1 @@
|
||||
Subproject commit d1c52401e4c76c74a10455682ace0655b7aa644c
|
||||
Subproject commit 21391dc5be9917bc32a518cf98376f79103727af
|
Loading…
Reference in New Issue
Block a user