Skip to content

Replace device libraries with stripped down versions#120

Merged
achow101 merged 6 commits into
bitcoin-core:masterfrom
achow101:minilibs
Feb 14, 2019
Merged

Replace device libraries with stripped down versions#120
achow101 merged 6 commits into
bitcoin-core:masterfrom
achow101:minilibs

Conversation

@achow101
Copy link
Copy Markdown
Member

This PR replaces all of the device libraries (trezor, keepkey, ckcc-protocol, and btchip-python) with stripped down versions of them directly in the source tree. These stripped down versions have several unused functions removed, including support for outdated hardware (e.g. Ledger HW.1) and altcoins. Some additional modifications have been made to them in order to make our implementations cleaner and easier to understand.

One major part of this change is replacing the Keepkey implementation with the Trezor implementation entirely. I found during testing that the Keepkey and Trezor use largely the same protocol. Some parts were different but those did not affect our usage of the Keepkey and the Trezor, so those differences were removed and reconciled. This allows us to have only one library which serves both the Trezor and Keepkey and have just one implementation that works for both Trezor and Keepkey.

Overall, by replacing the vendor provided libraries with our own versions of them, we are able to reduce the total number of dependencies required, and reduce some possible implementation errors (e.g. it would be a simple mistake to let Trezor or Keepkey do their default behavior of phoning home to fetch previous transactions). We can also make changes to the lower level implementations as needed instead of waiting on changes and fixes to be merged into upstream libraries.

This PR is based on #118 so that everything that was changed could be tested.

@Sjors
Copy link
Copy Markdown
Member

Sjors commented Feb 10, 2019

Concept ACK. I am a bit concerned about long term maintainability. I'd have to review the code get a better sense of how many moving parts we're dealing with. Ideally though we'd upstream these lighter libraries back to the manufactures (and then pin them by hash, like Bitcoin Core /depends).

I'll review Ledger and Trezor stuff some time after Bitcoin Core 0.18 feature freeze.

@achow101
Copy link
Copy Markdown
Member Author

I am a bit concerned about long term maintainability

I don't really think that will be a problem. The changes that we are concerned about are limited to a specific set of files. After looking through the commit history of python-trezor and python-keepkey, it seems like many of the changes happening to these libraries have been for supporting altcoins or changes to their tests, neither of which are things we need here. And btchip-python and ckcc-protocol haven't really been changed in several months, so I don't expect those to change very much or frequently. Any changes that are made are things we should be able to easily pull in here.

Ideally though we'd upstream these lighter libraries back to the manufactures

I don't think that is possible. The manufacturers have obligations to support older hardware, altcoins, and other functionality that we don't use or care about. These lighter libraries are just versions of the original ones with all of that stuff deleted.

@instagibbs
Copy link
Copy Markdown
Collaborator

concept ACK. Updating these stripped down libraries should be pretty easy even in the case of them being updated upstream. Some tests are failing.

@achow101
Copy link
Copy Markdown
Member Author

Test failure caused by bad hww branch. Should be fixed now.

@instagibbs
Copy link
Copy Markdown
Collaborator

With #122 Ledger tests still pass for me, without the ledger python library installed.

@instagibbs
Copy link
Copy Markdown
Collaborator

light tACK 681a52d for ledger

@achow101 achow101 merged commit 7c0fd1e into bitcoin-core:master Feb 14, 2019
achow101 added a commit that referenced this pull request Feb 14, 2019
7c0fd1e Update dependencies in the readme (Andrew Chow)
681a52d Replace btchip-python with our own stripped down version of it (Andrew Chow)
f7d04ff Replace ckcc dependency with our own version of the library itself (Andrew Chow)
f0c5aa7 Add Keepkey to Trezorlib and have KeepkeyClient use TrezorClient (Andrew Chow)
2693ae3 Change TrezorClient to do what TrezorNoInit did (Andrew Chow)
aa3665c Replace trezorlib with our own stripped down version (Andrew Chow)

Pull request description:

  This PR replaces all of the device libraries (`trezor`, `keepkey`, `ckcc-protocol,` and `btchip-python`) with stripped down versions of them directly in the source tree. These stripped down versions have several unused functions removed, including support for outdated hardware (e.g. Ledger HW.1) and altcoins. Some additional modifications have been made to them in order to make our implementations cleaner and easier to understand.

  One major part of this change is replacing the Keepkey implementation with the Trezor implementation entirely. I found during testing that the Keepkey and Trezor use largely the same protocol. Some parts were different but those did not affect our usage of the Keepkey and the Trezor, so those differences were removed and reconciled. This allows us to have only one library which serves both the Trezor and Keepkey and have just one implementation that works for both Trezor and Keepkey.

  Overall, by replacing the vendor provided libraries with our own versions of them, we are able to reduce the total number of dependencies required, and reduce some possible implementation errors (e.g. it would be a simple mistake to let Trezor or Keepkey do their default behavior of phoning home to fetch previous transactions). We can also make changes to the lower level implementations as needed instead of waiting on changes and fixes to be merged into upstream libraries.

  This PR is based on #118 so that everything that was changed could be tested.

Tree-SHA512: 2e8e581ebf533a9306d76edfff607d6c5fe85f3764e80015b03638abb15edc76f174b013a64604d3b3e70dacf8b70d00c5a1484702d4fbb7c26625dd18da54dc
achow101 added a commit that referenced this pull request Mar 8, 2019
… distribution archives

8931ae0 Run tests using the binary distribution (Andrew Chow)
39a6fc9 Fixes for Windows (Andrew Chow)
a229de0 Update .travis.yml to use poetry for build (Andrew Chow)
77257a1 Add build scripts and documentation for building releases (Andrew Chow)
9e04d1a Add a hwi.spec file for pyinstaller to build standalone binaries (Andrew Chow)
d6b24b8 Add pyproject.toml and poetry.lock for poetry dependency manager (Andrew Chow)

Pull request description:

  This PR adds several scripts and tools for making standalone binaries of the `hwi.py` script and for creating distribution archives that will go on pypi.org.

  To achieve deterministic builds, the dependencies used must be locked to specific versions and hashes. To do this, I have added configuration files for using the [Poetry dependency manager](https://github.com/sdispater/poetry). Because Poetry uses a `pyproject.toml` file instead of `setup.py`, I have created a helper script which will automatically generate the proper `setup.py` file from `pyproject.toml`. The reason I chose Poetry instead of Pipenv for this task is because it has the ability to do deterministic builds of the distribution archives (python wheel and source tar for pypi.org) which Pipenv does not have.

  Additionally scripts have been added to the newly created `contrib/` folder which will perform the deterministic builds of the binaries and distribution archives. The builds of the binaries are done using [pyinstaller](http://www.pyinstaller.org/). In order to build for different platforms, the `contrib/build_bin.sh` script needs to be run on each of the platforms we wish to release for. It can also be run in wine to do windows builds (see `contrib/build_wine.sh`). The configuration file that pyinstaller needs has also been added.

  Lastly the pyenv version for this project has been bumped to 3.6.8 since using python 3.5.x produced standalone binaries that did not work.

  This PR is built on #120 as reducing the number of dependencies fixed several issues with the standalone binary builds.

Tree-SHA512: abc1a6ac06d663b1316cde254980b0b1e8c392a6ffe478710df7c8e48a344cd57105e83555ec8fdcdc30e2b7d6d9cd6464367afda80653cb3cbc3acaf6119f48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants