Skip to content

Commit

Permalink
core: allow spending coins from Bitcoin paths if the coin ...
Browse files Browse the repository at this point in the history
has implemented strong replay protection via SIGHASH_FORKID
  • Loading branch information
prusnak committed Aug 16, 2020
1 parent f6be9eb commit 6def758
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
2 changes: 2 additions & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed
- Print inverted question mark for non-printable characters.
- Remove pre-fill bar from text rendering functions. [#1173]
- Allow spending coins from Bitcoin paths if the coin has implemented strong replay protection via `SIGHASH_FORKID`. [#1188]

### Deprecated

Expand Down Expand Up @@ -264,3 +265,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
[#1139]: https://github.com/trezor/trezor-firmware/issues/1139
[#1165]: https://github.com/trezor/trezor-firmware/pull/1165
[#1173]: https://github.com/trezor/trezor-firmware/pull/1173
[#1188]: https://github.com/trezor/trezor-firmware/issues/1188
10 changes: 10 additions & 0 deletions core/src/apps/bitcoin/keychain.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ def get_namespaces_for_coin(coin: coininfo.CoinInfo):
# m/0x4741b11e/6/pointer
namespaces.append([0x4741B11E])

# some wallets such as Electron-Cash (BCH) store coins on Bitcoin paths
# we can allow spending these coins from Bitcoin paths if the coin has
# implemented strong replay protection via SIGHASH_FORKID
if coin.fork_id is not None:
namespaces.append([44 | HARDENED, 0 | HARDENED])
namespaces.append([48 | HARDENED, 0 | HARDENED])
if coin.segwit:
namespaces.append([49 | HARDENED, 0 | HARDENED])
namespaces.append([84 | HARDENED, 0 | HARDENED])

return namespaces


Expand Down
34 changes: 33 additions & 1 deletion core/tests/test_apps.wallet.keychain.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,46 @@ def test_bcash(self):
self.assertFalse(coin.segwit)
valid_addresses = (
[44 | HARDENED, 145 | HARDENED],
[44 | HARDENED, 0 | HARDENED],
[45 | HARDENED, 123456],
[48 | HARDENED, 145 | HARDENED],
[48 | HARDENED, 0 | HARDENED],
)
invalid_addresses = (
[43 | HARDENED, 145 | HARDENED],
[44 | HARDENED, 0 | HARDENED],
[43 | HARDENED, 0 | HARDENED],
[49 | HARDENED, 145 | HARDENED],
[49 | HARDENED, 0 | HARDENED],
[84 | HARDENED, 145 | HARDENED],
[84 | HARDENED, 0 | HARDENED],
)

for addr in valid_addresses:
keychain.derive(addr)

for addr in invalid_addresses:
self.assertRaises(wire.DataError, keychain.derive, addr)

def test_litecoin(self):
keychain, coin = await_result(
get_keychain_for_coin(wire.DUMMY_CONTEXT, "Litecoin")
)
self.assertEqual(coin.coin_name, "Litecoin")

self.assertTrue(coin.segwit)
valid_addresses = (
[44 | HARDENED, 2 | HARDENED],
[45 | HARDENED, 123456],
[48 | HARDENED, 2 | HARDENED],
[49 | HARDENED, 2 | HARDENED],
[84 | HARDENED, 2 | HARDENED],
)
invalid_addresses = (
[43 | HARDENED, 2 | HARDENED],
[44 | HARDENED, 0 | HARDENED],
[48 | HARDENED, 0 | HARDENED],
[49 | HARDENED, 0 | HARDENED],
[84 | HARDENED, 0 | HARDENED],
)

for addr in valid_addresses:
Expand Down

0 comments on commit 6def758

Please sign in to comment.