docs: Fix various typos and formatting issues
What changed, and why it matters
This commit only corrects typos, grammar, formatting, and documentation wording across nine Markdown files. No code, build scripts, tests, or security-sensitive behavior were changed. It is a documentation cleanup with no security impact.
No security action required. Treat as routine documentation maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff touches only documentation files under doc/. Changes include typo fixes (e.g., ‘a1c65727bacabf0’ -> ‘a1c65727bacabf0’ is not present; examples are ‘typos and formatting issues’), grammar corrections, Markdown heading normalization, and clarification of wording such as ‘bitcoin’ -> ‘Bitcoin’, ‘doc’ -> ‘docs’, and table formatting. No source code, configuration, CI, cryptographic, or protocol implementation changes are present.
Changed components
doc/bitcoin.mddoc/debugging.mddoc/features.mddoc/integration.mddoc/merkle.mddoc/musig.mddoc/v0/bitcoin.mddoc/v0/wallet.mddoc/wallet.mdInspect captured patch +109 / −102
### doc/bitcoin.md
@@ -2,7 +2,7 @@
This page details the protocol implemented since version 2.1.0 of the app.
-The protocol documentation for version from 2.0.0 and before 2.1.0 is [here](./v0/bitcoin.md) and is now deprecated.
+The protocol documentation for versions from 2.0.0 and before 2.1.0 is [here](./v0/bitcoin.md) and is now deprecated.
## Framework
@@ -19,44 +19,48 @@ The main commands use `CLA = 0xE1`, unlike the legacy Bitcoin application that u
| E1 | 03 | GET_WALLET_ADDRESS | Return and show on screen an address for a registered or default wallet |
| E1 | 04 | SIGN_PSBT | Sign a PSBT with a registered or default wallet |
| E1 | 05 | GET_MASTER_FINGERPRINT | Return the fingerprint of the master public key |
-| E1 | 10 | SIGN_MESSAGE | Sign a message with a key from a BIP32 path (Bitcoin Message Signing) |
+| E1 | 10 | SIGN_MESSAGE | Sign a message with a key from a BIP-32 path (Bitcoin Message Signing) |
The `CLA = 0xF8` is used for framework-specific (rather than app-specific) APDUs; at this time, only one command is present.
| CLA | INS | COMMAND NAME | DESCRIPTION |
|-----|-----|--------------|-------------|
| F8 | 01 | CONTINUE | Respond to an interruption and continue processing a command |
-The `CONTINUE` command is sent as a response to a client command from the Hardware Wallet; the format and content on the response depends on the client command, and is documented below for each client command.
+The `CONTINUE` command is sent as a response to a client command from the Hardware Wallet; the format and content of the response depend on the client command, and is documented below for each client command.
### Interactive commands
-Several commands are executed via an interactive protocol that requires multiple rounds. At any time after receiving the command and before returning the commands final response (which is status word `0x9000` in case of success), the Hardware Wallet can respond with a special status word `SW_INTERRUPTED_EXECUTION` (`0xE000`), containing a request for the client in the response data. The first byte of the response is the *client command code*, identified what kind of request the Hardware Wallet is asking the client to perform. The client *must* comply with the request and send a special *CONTINUE* command `CLA = 0xF8` and `INS = 0x01`, with the appropriate response.
+Several commands are executed via an interactive protocol that requires multiple rounds. At any time after receiving the command and before returning the command's final response (which is status word `0x9000` in case of success), the Hardware Wallet can respond with a special status word `SW_INTERRUPTED_EXECUTION` (`0xE000`), containing a request for the client in the response data. The first byte of the response is the *client command code*, identifying what kind of request the Hardware Wallet is asking the client to perform. The client *must* comply with the request and send a special *CONTINUE* command `CLA = 0xF8` and `INS = 0x01`, with the appropriate response.
The specs for the client commands are detailed below.
## Descriptors and wallet policies
The Bitcoin app uses a language similar to [output script descriptors](https://github.com/bitcoin/bitcoin/blob/master/doc/descriptors.md) in order to represent the wallets that can be used to sign transactions.
-Wallet policies need to be registered on the device, with an interactive process that requires user's approval.
+Wallet policies need to be registered on the device, with an interactive process that requires the user's approval.
-See [here](wallet.md) for detailed information on the wallet policy language.
+See [wallet.md](wallet.md) for detailed information on the wallet policy language.
## Wallet registration flow
-In order to use a wallet policy that is not one of the default ones, the policy must first be registered on the wallet, which is a protocol that requires explicit approval from the user.
+In order to use a wallet policy that is not one of the default ones, the policy must first be registered on the device, which is a protocol that requires explicit approval from the user.
-A wallet policy is initiated using the `REGISTER_WALLET` command. The screen of the hardware wallet will ask the user to inspect the wallet descriptor template, followed by each of the keys of the cosigners that are part of the wallet policy.
+The registration is initiated using the `REGISTER_WALLET` command. The screen of the hardware wallet will ask the user to inspect the wallet descriptor template, followed by each of the keys of the cosigners that are part of the wallet policy.
Once the user approves, the `REGISTER_WALLET` returns to the client a 32-byte HMAC-SHA256. This will be provided to any future command that makes use of the wallet policy; therefore, the HMAC should be permanently stored on the client. In case of loss of the HMAC, the registration flow must be repeated from scratch.
## Status Words
| SW | SW name | Description |
|--------|------------------------------|-------------|
+| 0x6982 | `SW_SECURITY_STATUS_NOT_SATISFIED` | Command not allowed for security reasons (for example, a feature disabled in the settings) |
| 0x6985 | `SW_DENY` | Rejected by user |
+| 0x6A80 | `SW_INCORRECT_DATA` | Invalid data in the request |
+| 0x6A82 | `SW_NOT_SUPPORTED` | Request not currently supported (but not otherwise invalid) |
| 0x6A86 | `SW_WRONG_P1P2` | Either `P1` or `P2` is incorrect |
| 0x6A87 | `SW_WRONG_DATA_LENGTH` | `Lc` or minimum APDU length is incorrect |
+| 0x6B00 | `SW_FAIL_SWAP` | Failure during a swap (when started from the Exchange app) |
| 0x6D00 | `SW_INS_NOT_SUPPORTED` | No command exists with `INS` |
| 0x6E00 | `SW_CLA_NOT_SUPPORTED` | Bad `CLA` used for this application |
| 0xB000 | `SW_WRONG_RESPONSE_LENGTH` | Wrong response length (buffer size problem) |
@@ -100,9 +104,9 @@ Returns an extended public key at the given derivation path, serialized as per B
#### Description
-This command returns the extended public key for the given BIP 32 path.
+This command returns the extended public key for the given BIP-32 path.
-The paths defined in [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki), [BIP-48](https://github.com/bitcoin/bips/blob/master/bip-0048.mediawiki), [BIP-49](https://github.com/bitcoin/bips/blob/master/bip-0049.mediawiki), [BIP-84](https://github.com/bitcoin/bips/blob/master/bip-0084.mediawiki), [BIP-86](https://github.com/bitcoin/bips/blob/master/bip-0086.mediawiki) and [BIP-87](https://github.com/bitcoin/bips/blob/master/bip-0087.mediawiki), either in full or are at the deepest hardened level (excluding `change` and `address_index`), are considered standard.
+The paths defined in [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki), [BIP-48](https://github.com/bitcoin/bips/blob/master/bip-0048.mediawiki), [BIP-49](https://github.com/bitcoin/bips/blob/master/bip-0049.mediawiki), [BIP-84](https://github.com/bitcoin/bips/blob/master/bip-0084.mediawiki), [BIP-86](https://github.com/bitcoin/bips/blob/master/bip-0086.mediawiki) and [BIP-87](https://github.com/bitcoin/bips/blob/master/bip-0087.mediawiki), either in full or truncated at the deepest hardened level (excluding `change` and `address_index`), are considered standard.
If the `display` parameter is `0` and the path is not standard, an error is returned.
@@ -140,19 +144,19 @@ The `policy` is serialized as described [here](wallet.md). At this time, no poli
This command allows to register a wallet policy on the device. The wallet's name, descriptor template and each of the keys information is shown to the user.
-After user's validation is completed successfully, the application returns the `wallet_id` (sha256 of the wallet serialization), and the `hmac` for this wallet.
+After user's validation is completed successfully, the application returns the `wallet_id` (SHA-256 of the wallet serialization), and the `hmac` for this wallet.
#### Client commands
-`GET_PREIMAGE` must know and respond for the full serialized wallet policy whose sha256 hash is `wallet_id`; moreover, it must know and respond for the sha256 hash of its descriptor template.
+`GET_PREIMAGE` must know and respond for the full serialized wallet policy whose SHA-256 hash is `wallet_id`; moreover, it must know and respond for the SHA-256 hash of its descriptor template.
The client must respond to the `GET_PREIMAGE`, `GET_MERKLE_LEAF_PROOF` and `GET_MERKLE_LEAF_INDEX` queries related to the Merkle tree of the list of keys information.
The `GET_MORE_ELEMENTS` command must be handled.
### GET_WALLET_ADDRESS
-Get a receive or change a address for a registered or default wallet, after validating it with the user using the trusted screen.
+Get a receive or change address for a registered or default wallet, after validating it with the user using the trusted screen.
#### Encoding
@@ -172,12 +176,11 @@ Get a receive or change a address for a registered or default wallet, after vali
| `1` | `change` | `0` for a receive address, `1` for a change address |
| `4` | `address_index` | The desired address index (big-endian) |
-
**Output data**
-| Length | Description |
-|-------------|-----------------|
-| <variable> | The wallet address for the given change/address_index |
+| Length | Description |
+|--------------|-----------------|
+| `<variable>` | The wallet address for the given change/address_index |
#### Description
@@ -189,7 +192,7 @@ If the `display` parameter is `1`, the resulting wallet address is also shown on
#### Client commands
-`GET_PREIMAGE` must know and respond for the full serialized wallet policy whose sha256 hash is `wallet_id`; moreover, it must know and respond for the sha256 hash of its descriptor template.
+`GET_PREIMAGE` must know and respond for the full serialized wallet policy whose SHA-256 hash is `wallet_id`; moreover, it must know and respond for the SHA-256 hash of its descriptor template.
The client must respond to the `GET_PREIMAGE`, `GET_MERKLE_LEAF_PROOF` and `GET_MERKLE_LEAF_INDEX` queries related to the Merkle tree of the list of keys information.
@@ -211,19 +214,19 @@ Given a PSBTv2 and a registered wallet (or a standard one), sign all the inputs
| Length | Name | Description |
|---------|------------------------|-------------|
-| `<var>` | `global_map_size` | The number of key/value pairs of the global map of the psbt |
+| `<var>` | `global_map_size` | The number of key/value pairs of the global map of the PSBT |
| `32` | `global_map_keys_root` | The Merkle root of the keys of the global map |
| `32` | `global_map_vals_root` | The Merkle root of the values of the global map |
-| `<var>` | `n_inputs` | The number of inputs of the psbt |
+| `<var>` | `n_inputs` | The number of inputs of the PSBT |
| `32` | `inputs_maps_root` | The Merkle root of the vector of Merkleized map commitments for the input maps |
-| `<var>` | `n_outputs` | The number of outputs of the psbt |
+| `<var>` | `n_outputs` | The number of outputs of the PSBT |
| `32` | `outputs_maps_root` | The Merkle root of the vector of Merkleized map commitments for the output maps |
| `32` | `wallet_id` | The id of the wallet |
| `32` | `wallet_hmac` | The hmac of a registered wallet, or exactly 32 0 bytes |
**Output data**
-No output data; the signature are returned using the YIELD client command.
+No output data; the signatures are returned using the `YIELD` client command.
#### Description
@@ -237,10 +240,10 @@ The data yielded begins with `<tag_or_input_index>`, represented as a bitcoin-st
##### If `<tag_or_input_index>` is at most 65535
-If `<tag_or_input index>` is at most 65535, then it is an `<input_index>` and a partial_signature is being yielded.
+If `<tag_or_input_index>` is at most 65535, then it is an `<input_index>` and a signature is being yielded.
The results yielded via the YIELD command respect the following format: `<input_index> <pubkey_augm_len> <pubkey_augm> <signature>`, where:
-- `input_index` is a Bitcoin style varint, the index input of the input being signed (starting from 0);
+- `input_index` is a Bitcoin-style varint, the index of the input being signed (starting from 0);
- `pubkey_augm_len` is an unsigned byte equal to the length of `pubkey_augm`;
- `pubkey_augm` is the `pubkey` used for signing for legacy, segwit or taproot keypath spends (a compressed pubkey if non-taproot, a 32-byte x-only pubkey if taproot); for taproot script path spends, it is the concatenation of the `x-only` pubkey and the 32-byte *tapleaf hash* as defined in [BIP-0341](https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki);
- `signature` is the returned signature, possibly concatenated with the sighash byte (as it would be pushed on the stack).
@@ -249,16 +252,16 @@ The results yielded via the YIELD command respect the following format: `<input_
In this case `<tag_or_input_index>` is a `<tag>` that specifies what the rest of the data contains.
-- If `<tag>` equals `0xFFFFFFFF`: a pubnonce is being yielded during Round 1 of the MuSig2 protocol. The format is: `<tag> <input_index: varint)> <pubnonce: 66 bytes> <participant_pk: 33 bytes> <aggregate_pubkey: 33 bytes> <tapleaf_hash: 0 or 32 bytes>`.
-- If `<tag>` equals `0xFFFFFFFE`: a partial signature is being yielded, completing Round 2 of the MuSig2 protocol. The format is: `<tag> <input_index: varint)> <partial_signature: 32 bytes> <participant_pk: 33 bytes> <aggregate_pubkey: 33 bytes> <tapleaf_hash: 0 or 32 bytes>`
+- If `<tag>` equals `0xFFFFFFFF`: a pubnonce is being yielded during Round 1 of the MuSig2 protocol. The format is: `<tag> <input_index: varint> <pubnonce: 66 bytes> <participant_pk: 33 bytes> <aggregate_pubkey: 33 bytes> <tapleaf_hash: 0 or 32 bytes>`.
+- If `<tag>` equals `0xFFFFFFFE`: a partial signature is being yielded, completing Round 2 of the MuSig2 protocol. The format is: `<tag> <input_index: varint> <partial_signature: 32 bytes> <participant_pk: 33 bytes> <aggregate_pubkey: 33 bytes> <tapleaf_hash: 0 or 32 bytes>`.
-In both cases, the `tapleaf_hash` is only present for a Script path spend.
+In both cases, the `tapleaf_hash` is only present for a script path spend.
Other values of the `<tag>` are undefined and reserved for future use.
#### BIP-322 message signing
-If the PSBT contains the `PSBT_GLOBAL_GENERIC_SIGNED_MESSAGE` global field (`0x09`, defined in [BIP-0322](https://github.com/bitcoin/bips/blob/master/bip-0322.mediawiki), version 2.0.0), the PSBT is treated as a request to sign the BIP-322 *to_sign* virtual transaction for the message contained in the field, and is reviewed on-screen as a **message signature** (account, address whose ownership is being proven, and the message), never as a transaction. If the message is too long (more than 640 bytes) or not printable ASCII (which includes any UTF-8 text with non-ASCII characters), its plain sha256 hash is shown instead, matching the behavior of the legacy `SIGN_MESSAGE` command (note that this display hash is *not* the BIP-322 tagged hash that the signature commits to).
+If the PSBT contains the `PSBT_GLOBAL_GENERIC_SIGNED_MESSAGE` global field (`0x09`, defined in [BIP-0322](https://github.com/bitcoin/bips/blob/master/bip-0322.mediawiki), version 2.0.0), the PSBT is treated as a request to sign the BIP-322 *to_sign* virtual transaction for the message contained in the field, and is reviewed on-screen as a **message signature** (account, address whose ownership is being proven, and the message), never as a transaction. If the message is too long (more than 640 bytes) or not printable ASCII (which includes any UTF-8 text with non-ASCII characters), its plain SHA-256 hash is shown instead, matching the behavior of the legacy `SIGN_MESSAGE` command (note that this display hash is *not* the BIP-322 tagged hash that the signature commits to).
Before showing the message, the app enforces the exact structure mandated by BIP-322, and refuses to sign otherwise:
@@ -281,13 +284,13 @@ As an optimization for proofs of funds, BIP-322 allows omitting the non-witness
#### Client commands
-`GET_PREIMAGE` must know and respond for the full serialized wallet policy whose sha256 hash is `wallet_id`; moreover, it must know and respond for the sha256 hash of its descriptor template.
+`GET_PREIMAGE` must know and respond for the full serialized wallet policy whose SHA-256 hash is `wallet_id`; moreover, it must know and respond for the SHA-256 hash of its descriptor template.
-The client must respond to the `GET_PREIMAGE`, `GET_MERKLE_LEAF_PROOF` and `GET_MERKLE_LEAF_INDEX` queries for all the Merkle trees in the input, including each of the Merkle trees for keys and values of the Merkleized map commitments of each of the inputs/outputs maps of the psbt.
+The client must respond to the `GET_PREIMAGE`, `GET_MERKLE_LEAF_PROOF` and `GET_MERKLE_LEAF_INDEX` queries for all the Merkle trees in the input, including each of the Merkle trees for keys and values of the Merkleized map commitments of each of the inputs/outputs maps of the PSBT.
The `GET_MORE_ELEMENTS` command must be handled.
-The `YIELD` command must be processed in order to receive the signatures, or the MuSig2 partial nonces or partial signatures.
+The `YIELD` command must be processed in order to receive the signatures, or the MuSig2 pubnonces or partial signatures.
### GET_MASTER_FINGERPRINT
@@ -317,14 +320,13 @@ The fingerprint is necessary to fill the key origin information for some PSBT fi
User interaction is not required for this command.
-
### SIGN_MESSAGE
Signs a message, according to the standard Bitcoin Message Signing.
The device shows on its secure screen the BIP-32 path used for signing and the message information:
- either the content of the message (if its length does not exceed 640 bytes in current version and contains only ASCII printable characters (`0x20-0x7E` range) plus Line Feed (`0x0A`));
-- or the SHA256 hash of the message (the hash should be verified by the user using an external tool if the client is untrusted).
+- or the SHA-256 hash of the message (the hash should be verified by the user using an external tool if the client is untrusted).
#### Encoding
@@ -360,7 +362,7 @@ The signature is returned as a 65-byte binary string (1 byte equal to 32 or 33,
#### Description
-The digest being signed is the double-SHA256 of the message, after prefixing the message with:
+The digest being signed is the double-SHA-256 of the message, after prefixing the message with:
- the magic string `"\x18Bitcoin Signed Message:\n"` (equal to `18426974636f696e205369676e6564204d6573736167653a0a` in hexadecimal)
- the length of the message, encoded as a Bitcoin-style variable length integer.
@@ -376,9 +378,9 @@ This section documents the commands that the Hardware Wallet can request to the
| CMD | COMMAND NAME | DESCRIPTION |
|-----|-----------------------|-------------|
| 10 | YIELD | Receive some elements during command execution |
-| 40 | GET_PREIMAGE | Return the preimage corresponding to the given sha256 hash |
-| 41 | GET_MERKLE_LEAF_PROOF | Returns the Merkle proof for a given leaf |
-| 42 | GET_MERKLE_LEAF_INDEX | Returns the index of a leaf in a Merkle tree |
+| 40 | GET_PREIMAGE | Return the preimage corresponding to the given SHA-256 hash |
+| 41 | GET_MERKLE_LEAF_PROOF | Return the Merkle proof for a given leaf |
+| 42 | GET_MERKLE_LEAF_INDEX | Return the index of a leaf in a Merkle tree |
| A0 | GET_MORE_ELEMENTS | Receive more data that could not fit in the previous responses |
### YIELD
@@ -397,14 +399,14 @@ The `GET_PREIMAGE` command requests the client to reveal a SHA-256 preimage.
The request contains:
- `1` byte: must equal 0, reserved for future usage. (The client should abort if non-zero);
-- `32` bytes: a sha-256 hash.
+- `32` bytes: a SHA-256 hash.
The response must contain:
- `<var>`: the length of the preimage, encoded as a Bitcoin-style varint;
-- `1` byte: a 1-byte unsigned integer `b`, the length of the prefix of the pre-image that is part of the response;
+- `1` byte: a 1-byte unsigned integer `b`, the length of the prefix of the preimage that is part of the response;
- `b` bytes: corresponding to the first `b` bytes of the preimage.
-If the pre-image is too long to be contained in a single response, the client should choose `b` to be as large as possible; subsequent bytes are enqueued as single-byte elements that the Hardware Wallet will request with one or more `GET_MORE_ELEMENTS` requests.
+If the preimage is too long to be contained in a single response, the client should choose `b` to be as large as possible; subsequent bytes are enqueued as single-byte elements that the Hardware Wallet will request with one or more `GET_MORE_ELEMENTS` requests.
### GET_MERKLE_LEAF_PROOF
@@ -420,23 +422,23 @@ The request contains:
The client must respond with:
- `32` bytes: the hash of the leaf with index `i` in the requested Merkle tree;
- `1` byte: the length of the Merkle proof;
-- `1` byte: the amount `p` of hashes of the proof that are contained in the response;
+- `1` byte: the number `p` of hashes of the proof that are contained in the response;
- `32 * p` bytes: the concatenation of the first `p` hashes in the Merkle proof.
-If the proof is too long to be contained in a single response, the client should choose `p` to be as large as possible; subsequent bytes are enqueued as 32-byte elements that the Hardware Wallet will request with one or more `GET_MORE_ELEMENTS` requests.
+If the proof is too long to be contained in a single response, the client should choose `p` to be as large as possible; subsequent hashes are enqueued as 32-byte elements that the Hardware Wallet will request with one or more `GET_MORE_ELEMENTS` requests.
### GET_MERKLE_LEAF_INDEX
**Command code**: 0x42
-The `GET_MERKLE_LEAF_INDEX` requests the index of a leaf with a certain hash. if multiple leafs have the same hash, the client could respond with either.
+The `GET_MERKLE_LEAF_INDEX` requests the index of a leaf with a certain hash. If multiple leaves have the same hash, the client could respond with either.
The request contains:
- `32` bytes: the Merkle root hash;
- `32` bytes: the leaf hash.
The response contains:
-- `1` byte: `1` if the leaf is found, `0` if matching leaf exists;
+- `1` byte: `1` if the leaf is found, `0` if no matching leaf exists;
- `<var>`: the index of the leaf, encoded as a Bitcoin-style varint.
### GET_MORE_ELEMENTS
@@ -445,16 +447,15 @@ The response contains:
The `GET_MORE_ELEMENTS` command requests the client to return more elements that were enqueued by previous client commands (like `GET_PREIMAGE` and `GET_MERKLE_LEAF_PROOF`).
-All of the elements in the queue must all be byte strings of the same length; the command fails otherwise. The client should return as many elements as it is possible to fit in the response, while leaving the remaining ones (if any) in the queue.
+All of the elements in the queue must be byte strings of the same length; the command fails otherwise. The client should return as many elements as it is possible to fit in the response, while leaving the remaining ones (if any) in the queue.
The request is empty.
The response contains:
-- `1` byte: the number `n` of returned element;
+- `1` byte: the number `n` of returned elements;
- `1` byte: the size `s` of each returned element;
- `n * s` bytes: the concatenation of the `n` returned elements.
-
## Security considerations
Some of the client commands are used to allow the client to reveal some information that is not known to the hardware wallet. This approach allows to create protocols that work with an amount of data that is too large to fit in a single APDU, or even in the limited RAM of a device like a Ledger Nano S.
@@ -464,6 +465,6 @@ In designing the interactive protocol, care is taken to avoid security risks ass
All the current commands use a commit-and-reveal approach: the APDU that starts the protocol (first message) commits to all the relevant data (for example, the entirety of the PSBT), by using hashes and/or Merkle trees. Any time the client is asked to reveal some committed information, the app does not consider it trusted:
- If a preimage is asked via `GET_PREIMAGE`, the hash is computed to validate that the correct preimage is returned by the client.
- If a Merkle proof is asked via `GET_MERKLE_LEAF_PROOF`, the proof is verified.
-- If the index of a leaf is asked `GET_MERKLE_LEAF_INDEX`, the proof for that element is requested via `GET_MERKLE_LEAF_PROOF` and the proof verified, *even if the leaf value is known*.
+- If the index of a leaf is asked via `GET_MERKLE_LEAF_INDEX`, the proof for that element is requested via `GET_MERKLE_LEAF_PROOF` and the proof verified, *even if the leaf value is known*.
Care needs to be taken in designing protocols, as the client might lie by omission (for example, fail to reveal that a leaf of a Merkle tree is present during a call to `GET_MERKLE_LEAF_INDEX`).
### doc/debugging.md
@@ -1,23 +1,25 @@
+# Debugging
+
This page contains some information for developers on how to debug failures of the commands of the Ledger Bitcoin app.
-# Status Words
+## Status Words
Failures in the app's commands are always reported by a corresponding Status Word; see [bitcoin.md](bitcoin.md#status-words) for the currently defined Status Words. Client libraries generally return structured versions of the same Status Words.
The Status Word is contained in the last 2 bytes of the APDU Response, interpreted as a big-endian 16-bit constant.
-# Error codes
+## Error codes
In addition to the Status Word, some errors provide further details as an _error code_, contained in the first two bytes of the _data_ portion of the reply.
Integrations can ignore the error codes and should not rely on them in production (as they are not guaranteed to be consistent across versions of the app); however, they can provide valuable debugging information for developers working on an integration.
You can see the list of the currently defined error codes in [error_codes.h](../src/error_codes.h).
-# Running on Speculos with semihosting
+## Running on Speculos with semihosting
-When running the bitcoin app on the [speculos](https://github.com/LedgerHQ/speculos) emulator, additional debugging information can be printed on the command line (on the same terminal where speculos is running) by defining the `DEBUG=10` constant when running the `make` command. See the [ledger-app-builder](https://github.com/LedgerHQ/ledger-app-builder?tab=readme-ov-file#compile-your-app-in-the-container) for instructions on how to build the app for speculos.
+When running the Bitcoin app on the [Speculos](https://github.com/LedgerHQ/speculos) emulator, additional debugging information can be printed on the command line (on the same terminal where Speculos is running) by defining the `DEBUG=10` variable when running the `make` command. See the [ledger-app-builder](https://github.com/LedgerHQ/ledger-app-builder?tab=readme-ov-file#compile-your-app-in-the-container) for instructions on how to build the app for Speculos.
-Binaries produced in this way _will_ crash if sideloading on a real device.
+Binaries produced in this way _will_ crash if sideloaded on a real device.
Note: `DEBUG=10` is a feature of the Bitcoin app, and is not used in other Ledger apps.
### doc/features.md
@@ -114,7 +114,7 @@ build is named **Bitcoin Test**. They are ***separate applications***.
The **Bitcoin Test** app can be used for all test networks, including Bitcoin Core's regtest.
Note, however, that SegWit (and taproot) addresses are shown on-screen and returned to the
-host using the human readable part `tb1`, while bitcoin-core uses `bcrt`.
+host using the human-readable part `tb`, while Bitcoin Core's regtest uses `bcrt`.
## Version and feature compatibility
### doc/integration.md
@@ -82,7 +82,7 @@ This guarantees the following security property (except on default accounts):
inform the user about the involved account.
This is particularly important for accounts involving multiple parties (multisig,
-miniscript, etc).
+miniscript, etc.).
## Registration and the HMAC
### doc/merkle.md
@@ -1,17 +1,18 @@
+# Merkle trees and Merkleized maps
-The apps makes extensive usage of [Merkle trees](https://en.wikipedia.org/wiki/Merkle_tree) in order to commit to (possibly large) sets of data that is stored on the client and revealed to the Hardware Wallet when needed. This allows to safely operate on sets of data that are too large to be stored on the limited device memory.
+The app makes extensive usage of [Merkle trees](https://en.wikipedia.org/wiki/Merkle_tree) in order to commit to (possibly large) sets of data that are stored on the client and revealed to the Hardware Wallet when needed. This allows to safely operate on sets of data that are too large to be stored on the limited device memory.
By checking a Merkle proof to a previously committed-to Merkle tree, the Hardware Wallet is certain that a compromised client cannot do anything unexpected (e.g.: lie on some data, or maliciously choose what data to reveal based on the previous interaction of a multi-step protocol, etc.).
Operations on Merkle trees are composed to create commitments to more complex data structures like maps.
-# Data structures
-## Merkle trees
-### Definition
+## Data structures
+### Merkle trees
+#### Definition
-A Merkle tree allows to create a commitment to an arbitrarily large list of values; short membership proofs can be provided that can be verified solely with the knowledge of a single hash (the Merkle tree root)
+A Merkle tree allows to create a commitment to an arbitrarily large list of values; short membership proofs can be provided that can be verified solely with the knowledge of a single hash (the Merkle tree root).
-Our implementation of Merkle trees loosely follow the structure defined in [RFC 6962](https://www.rfc-editor.org/rfc/pdfrfc/rfc6962.txt.pdf), using SHA-256 as the hash function. We refer to the linked document for a more detailed description. Only one difference (the hash of the empty list) is defined below.
+Our implementation of Merkle trees loosely follows the structure defined in [RFC 6962](https://www.rfc-editor.org/rfc/pdfrfc/rfc6962.txt.pdf), using SHA-256 as the hash function. We refer to the linked document for a more detailed description. Only one difference (the hash of the empty list) is defined below.
We call a *byte string* an arbitrary array of bytes, where each byte is a value between `0` and `255`. A *hash function* takes as input an arbitrary length byte string, and produces a fixed-length output. Outputs of SHA-256 are 32 bytes long.
@@ -25,29 +26,29 @@ The hash of a 1-element list (*leaf node*) is:
MTH({d(0)}) = SHA-256(0x00 || d(0))
-For `n > 1`, let k be the largest power of `2` strictly smaller than `n`. Then the hash of a list `D[n]` (*internal node*) is:
+For `n > 1`, let `k` be the largest power of `2` strictly smaller than `n`. Then the hash of a list `D[n]` (*internal node*) is:
MTH(D[n]) = SHA-256(0x01 || MTH(D[0:k]) || MTH(D[k:n]))
Note that the 1-byte prefix `0x00` is prepended when computing the leaf hashes, while `0x01` is prepended for internal nodes; this domain separation prevents collision attacks where different trees with the same Merkle Tree hash could be produced.
-### Merkle proofs
+#### Merkle proofs
-The Merkle proof (called *Merkle audit path* in the language for RFC 6962) for a leaf node is the minimal set of additional nodes that is necessary to compute the Merkle Tree Hash. See section 2.1.3. of RFC 6962 for some examples.
+The Merkle proof (called *Merkle audit path* in the language of RFC 6962) for a leaf node is the minimal set of additional nodes that is necessary to compute the Merkle Tree Hash. See section 2.1.3. of RFC 6962 for some examples.
For any non-root node of the tree (either internal or leaf), let the *brother* be the unique other node sharing the same parent, that is the unique other node whose hash is combined together to compute an internal node.
-In the typical tree-like representation of the Merkle tree, the Merkle proof for a leaf is the list of the brothers of all the internal nodes
+In the typical tree-like representation of the Merkle tree, the Merkle proof for a leaf is the list of the brothers of all the nodes on the path from that leaf to the root (excluding the root itself).
-### Remarks
+#### Remarks
- As long as the size `n` of a Merkle tree is known, the exact structure of the tree (the sequence of hashes necessary to compute each internal node, and the Merkle Tree Hash) is deterministic.
- For any internal node, the left sub-tree is a complete binary tree.
- Assuming collision-resistance of SHA-256, it is intractable to find two trees with the same Merkle root.
<!-- TODO: Size and leaf index in Merkle proof; how we use Merkle proofs -->
-## Merkleized maps
+### Merkleized maps
A *map* of size `n` is an arbitrary set of key-value pairs `{(k(0), v(0)), (k(1), v(1)), ..., (k(n-1), v(n-1))}`, where each `k(i)` and each `v(j)` is a byte string, and all the keys are different. Without loss of generality, we assume that the list `{k(0), k(1), ..., k(n-1)}` is sorted lexicographically.
@@ -59,56 +60,56 @@ and
values_root = MTH({v(0), v(1), ..., v(n - 1)})
-### Serialization
+#### Serialization
-A Merklelized Map commitment is serialized as a string of bytes containing, in sequence:
+A Merkleized map commitment is serialized as a string of bytes containing, in sequence:
- the number of key-value pairs, encoded as a Bitcoin-style varint;
-- the 32 bytes `keys_root`
-- the 32 bytes `values_root`
+- the 32 bytes `keys_root`;
+- the 32 bytes `values_root`.
Therefore, the length of a serialized Merkleized map commitment is between `65` and `73` bytes long.
-# Client side operations
+## Client side operations
-In this section we describe the operations that might be performed in a protocol where a hardware wallets (HWW) knows some hashes, Merkle tree hashes or Merkleized map commitments, while the client knows the corresponding preimages, leaf values and maps.
+In this section we describe the operations that might be performed in a protocol where a hardware wallet (HWW) knows some hashes, Merkle tree hashes or Merkleized map commitments, while the client knows the corresponding preimages, leaf values and maps.
-## get_preimage
+### get_preimage
-Given a 32-byte hash `el_hash`, the HWW asks the client to provide its pre-image.
+Given a 32-byte hash `el_hash`, the HWW asks the client to provide its preimage.
***Security considerations***:
Once the client responds with a byte string `el`, the hardware wallet must verify that indeed `SHA-256(el) == el_hash`.
-## get_merkle_leaf_proof
+### get_merkle_leaf_proof
-Given a 32-byte hash `mth` and an index `i`, the HWW asks the client to provide the proof the hash of the leaf with index `i`, together with its Merkle proof in the Merkle tree whose root is `mth`.
+Given a 32-byte hash `mth` and an index `i`, the HWW asks the client to provide the hash of the leaf with index `i`, together with its Merkle proof in the Merkle tree whose root is `mth`.
***Security considerations***:
The HWW must verify that the proof provided by the client is valid.
-## get_merkle_leaf_index
+### get_merkle_leaf_index
-Given a 32 byte hash `leaf_hash` of a and a 32-byte hash `mth`, the HWW asks the client what is the index of the leaf whose hash is `leaf_hash` in the Merkle tree whose root is `mth`.
+Given a 32-byte hash `leaf_hash` of a leaf and a 32-byte hash `mth`, the HWW asks the client what is the index of the leaf whose hash is `leaf_hash` in the Merkle tree whose root is `mth`.
***Security considerations***:
The HWW cannot trust that the answer is truthful. Therefore, this should only be used as a step in a more complex protocol (for example, once the response is given, the HWW asks and verifies the Merkle proof for that element).
-## Get the value corresponding to a key in the map
+### Get the value corresponding to a key in the map
Once the HWW knows a Merkleized map commitment, a common step in a protocol might be "retrieve the value `v` in the map corresponding to the key `k`". This can be achieved by composing a number of elementary operations on the Merkle trees of keys and values.
-### Validate the tree of keys
+#### Validate the tree of keys
The map is valid only if the list of keys is indeed sorted in strict lexicographical order. Therefore, before using a client-provided Merkleized map commitment, the HWW must check that the list of keys is valid. Otherwise, a malicious client might provide different values for the same keys, therefore being able to choose which one to reveal later in the protocol.
Therefore, the HWW should iterate in order over the `n` keys, and retrieve each key (using the protocols for `get_merkle_leaf_proof` and `get_preimage`), while checking that the returned keys are indeed in strict lexicographical order.
*Remark: the protocol described above has communication and computational cost O(n log n). A more efficient protocol with cost O(n) to verify the integrity of the Merkle tree is possible, but it does not rely on the existing primitives and is left as a possible future improvement*.
-### Get the value corresponding to key `k`
+#### Get the value corresponding to key `k`
Once the integrity of a Merkleized map commitment `(keys_root, values_root)` is verified, the HWW can request the client to provide the value corresponding to a certain key `k` as follows:
@@ -121,12 +122,12 @@ It is crucial that step 2 is not skipped, or the client might provide the value
***Security considerations***:
-Unless the HWW keeps trackt of the fact that a key is present (which is possible during validation if the key is know), the client can always lie by omission (refuse to provide a certain value). Protocols in the HWW must take this possibility into account.
+Unless the HWW keeps track of the fact that a key is present (which is possible during validation if the key is known), the client can always lie by omission (refuse to provide a certain value). Protocols in the HWW must take this possibility into account.
-# Future use cases
+## Future use cases
At this time, all of the Merkle trees are built on top of a static list or map. For future applications, a useful property of the construction chosen is that:
-- it is not difficult to compute `MTH(D[n+1])` given the knowledge of the Merkle tree for `D[n]` and the additional element `d(n+1)`;
+- it is not difficult to compute `MTH(D[n+1])` given the knowledge of the Merkle tree for `D[n]` and the additional element `d(n)`;
- similarly, it is not difficult to compute `MTH(D'[n])` for a list `D'[n]` that is identically equal to `D[n]` except for one element.
-This can allow future constructions and protocols where the client is responsible for maintaining dynamic data structures , while guaranteeing integrity with Merkle proofs. One example is the outsourcing of storage/memory on the client side.
+This can allow future constructions and protocols where the client is responsible for maintaining dynamic data structures, while guaranteeing integrity with Merkle proofs. One example is the outsourcing of storage/memory on the client side.
### doc/musig.md
@@ -17,7 +17,7 @@ MuSig2 is a 2-round multi-signature scheme compatible with the public keys and s
## State minimization
-This section describes implementation details that allow to minimize the amount of statefor each MuSig2 signing session, allowing secure support for multiple parallel MuSig2 on embedded device with limited storage.
+This section describes implementation details that allow to minimize the amount of state for each MuSig2 signing session, allowing secure support for multiple parallel MuSig2 signing sessions on embedded devices with limited storage.
### Introduction
@@ -27,7 +27,7 @@ In the typical signing flow of a wallet, it's more logical to consider a _sessio
Therefore, in the flow of BIP-0327, you would expect at least _one MuSig2 signing session per input_ to be active at the same time. In the context of hardware signing device support, that's somewhat problematic: it would require to persist state for an unbounded number of signing sessions, for example for a wallet that received a large number of small UTXOs. Persistent storage is often a scarce resource in embedded signing devices, and a naive approach would likely impose a maximum limit on the number of inputs of the transactions, depending on the hardware limitations.
-This document describes an approach that is compatible with and builds on top of BIP-0327 to define a _psbt-level session_ with only a small amount of state persisted on the device. Each psbt-level session allows to manage in parallel all the MuSig2 sessions involved in signing a transaction (typically, at least one for each input). Each psbt-level session only requires 64 bytes of storage for the entire transaction, regardless of the amount of inputs.
+This document describes an approach that is compatible with and builds on top of BIP-0327 to define a _psbt-level session_ with only a small amount of state persisted on the device. Each psbt-level session allows to manage in parallel all the MuSig2 sessions involved in signing a transaction (typically, at least one for each input). Each psbt-level session only requires 64 bytes of storage for the entire transaction, regardless of the number of inputs.
### Signing flow with synthetic randomness
@@ -37,11 +37,11 @@ This section presents the core idea, while the next section makes it more precis
In BIP-0327, the internal state that is kept by the signing device is essentially the *secnonce*, which in turn is computed from a random number _rand'_, and optionally from other parameters of _NonceGen_ which depend on the transaction being signed.
-The core idea for state minimization is to compute a global random `rand_root`; then, for the *i*-th input and for the *j*-th `musig()` key that the device is signing for in the [wallet policy](https://github.com/bitcoin/bips/blob/master/bip-0388.mediawiki), one defines the *rand'* in _NonceGen_ as:
+The core idea for state minimization is to compute a global random `rand_root`; then, for the *i*-th input and for the *j*-th `musig()` key that the device is signing for in the [wallet policy](https://github.com/bitcoin/bips/blob/master/bip-0388.mediawiki), one defines the *rand'* in _NonceGen_ as:
-$\qquad rand_{i,j} = SHA256(rand\_{root} \| i \| j)$
+$`\qquad rand_{i,j} = SHA256(rand\_{root} \| i \| j)`$
-In the concatenation, a fixed-length encoding of $i$ and $j$ is used in order to avoid collisions. That is used as the *rand'* value in the *NonceGen* algorithm for that input/KEY pair.
+In the concatenation, a fixed-length encoding of $i$ and $j$ is used in order to avoid collisions. That is used as the *rand'* value in the *NonceGen* algorithm for that input/key pair.
The *j* parameter allows to handle wallet policies that contain more than one `musig()` key expression involving the signing device.
@@ -65,10 +65,10 @@ The term *persistent memory* refers to secure storage that is not wiped out when
**Phase 1: pubnonce generation:** A PSBT is sent to the signing device, and it does not contain any pubnonce.
- If a session already exists, it is deleted from the persistent memory.
- A new session is created in volatile memory.
-- The device produces a fresh random number $rand\_{root}$, and saves it in the current session.
-- The device generates the randomness for the $i$-th input and for the $j$-th key as: $rand_{i,j} = SHA256(rand\_{root} \| i \| j)$.
+- The device produces a fresh random number $`rand\_{root}`$, and saves it in the current session.
+- The device generates the randomness for the $i$-th input and for the $j$-th key as: $`rand_{i,j} = SHA256(rand\_{root} \| i \| j)`$.
- Compute each *(secnonce, pubnonce)* as per the `NonceGen` algorithm, with the arguments described above.
-- At completion (after all the pubnonces are returned), the session secret $rand\_{root}$ is copied into the persistent memory.
+- At completion (after all the pubnonces are returned), the session secret $`rand\_{root}`$ is copied into the persistent memory.
**Phase 2: partial signature generation:** A PSBT containing all the pubnonces is sent to the device.
- *A copy of the session is stored in the volatile memory, and the session is deleted from the persistent memory*.
@@ -78,27 +78,30 @@ The term *persistent memory* refers to secure storage that is not wiped out when
- Continue the signing flow as per BIP-0327, generating the partial signature.
### Security considerations
+
#### State reuse avoidance
+
Storing the session in persistent memory only at the end of Phase 1, and deleting it before beginning Phase 2 simplifies auditing and making sure that there is no reuse of state across signing sessions.
#### Security of synthetic randomness
-Generating $rand_{i, j}$ synthetically is not a problem, since the $rand\_{root}$ value is kept secret and never leaves the device. This ensures that all the values produced for different $i$ and $j$ are not predictable for an attacker.
+Generating $rand_{i, j}$ synthetically is not a problem, since the $`rand\_{root}`$ value is kept secret and never leaves the device. This ensures that all the values produced for different $i$ and $j$ are not predictable for an attacker.
#### Optional arguments of NonceGen
-In BIP-0327, *aggpk*, *msg* and *extra_in* are optional arguments of _NonceGen_. They only add entropy, as a defense in depth against a faulty source of randomness. They are not needed for the uniqueness of the nonces, which comes from $rand\_{root}$ being generated by the hardware RNG, and from the $(i, j)$ domain separation in $rand_{i,j}$.
+
+In BIP-0327, *aggpk*, *msg* and *extra_in* are optional arguments of _NonceGen_. They only add entropy, as a defense in depth against a faulty source of randomness. They are not needed for the uniqueness of the nonces, which comes from $`rand\_{root}`$ being generated by the hardware RNG, and from the $(i, j)$ domain separation in $rand_{i,j}$.
BIP-0327 suggests using the tweaked aggregate key as *aggpk*. Using the untweaked one instead is what makes the pubnonces independent of the transaction, and of the (change, address index) of the UTXO being spent. Since none of the arguments depend on the PSBT, a malicious software wallet can't affect the _secnonce_/_pubnonce_ pairs in any way. A PSBT whose pubnonces were not produced by the current session makes Phase 2 fail, as the recomputed _pubnonce_ does not match the one in the PSBT.
### Generalization to multiple PSBT signing sessions
The approach described above assumes that no attempt to sign a PSBT for a wallet policy containing `musig()` keys is initiated while a session is already in progress.
-In order to generalize this to multiple parallel signing sessions, each signing session is identified by a `psbt_session_id`, which must be identical between Round 1 and Round 2 of the protocol. The device computes it as:
+In order to generalize this to multiple parallel signing sessions, each signing session is identified by a `psbt_session_id`, which must be identical between Phase 1 and Phase 2 of the protocol. The device computes it as:
-$\qquad psbt\_session\_id = H_{PsbtSessionId}(descriptor\_template\_hash \| keys\_info\_merkle\_root \| len(session\_id) \| session\_id)$
+$`\qquad psbt\_session\_id = H_{PsbtSessionId}(descriptor\_template\_hash \| keys\_info\_merkle\_root \| len(session\_id) \| session\_id)`$
-where $H_{tag}$ is the BIP-0340 tagged hash, the first two arguments are the hash of the descriptor template and the root of the Merkle tree of the keys information of the wallet policy, $session\_id$ is the value of the [`MUSIG2_SESSION_ID`](#the-musig2_session_id-psbt-field) field (empty if the PSBT does not contain the field), and $len(session\_id)$ is its length as a single byte (`0x00` if the field is absent). The name of the wallet policy is not committed to, as it plays no role in signing.
+where $H_{tag}$ is the BIP-0340 tagged hash, the first two arguments are the hash of the descriptor template and the root of the Merkle tree of the keys information of the wallet policy, $`session\_id`$ is the value of the [`MUSIG2_SESSION_ID`](#the-musig2_session_id-psbt-field) field (empty if the PSBT does not contain the field), and $`len(session\_id)`$ is its length as a single byte (`0x00` if the field is absent). The name of the wallet policy is not committed to, as it plays no role in signing.
The `psbt_session_id` deliberately depends only on the wallet policy and on the `MUSIG2_SESSION_ID`, and not on the transaction; together with the transaction-independent arguments of _NonceGen_, this is what allows [pre-generating the pubnonces](#pre-generating-the-pubnonces). The tradeoff is that, without a `MUSIG2_SESSION_ID`, at most one session can be pending for each wallet policy.
### doc/v0/bitcoin.md
@@ -172,7 +172,7 @@ Get a receive or change a address for a registered or default wallet, after vali
| Length | Description |
|-------------|-----------------|
-| <variable> | The wallet address for the given change/address_index |
+| `<variable>` | The wallet address for the given change/address_index |
#### Description
### doc/v0/wallet.md
@@ -1,5 +1,5 @@
-This page described the wallet plicies used in the _deprecated_ version 0 of the protocol, as implemented in the v2.0.0 of the Bitcoin app. This protocol is still supported at this time, but we encourage integrations to switch to the [wallet policies in version 1 of the protocol](../wallet.md).
+This page describes the wallet policies used in the _deprecated_ version 0 of the protocol, as implemented in the v2.0.0 of the Bitcoin app. This protocol is still supported at this time, but we encourage integrations to switch to the [wallet policies in version 1 of the protocol](../wallet.md).
# Wallet policy
### doc/wallet.md
@@ -13,7 +13,7 @@ is a pair of:
The key origin information is compulsory for xpubs controlled by the device. Without it, the xpub
will be considered external, and the device will not sign for any key derived by it.
-Wallet policies are registered with a short readable *account name* provided by the host wallet, which is shown on-screen.
+Wallet policies are registered with a short readable *wallet name* provided by the host wallet, which is shown on-screen.
For a higher-level explanation of wallet policies, registration, and the security model,
see [integration.md](integration.md).Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.