Skip to content

Commit 5bd93cf

Browse files
authored
Merge pull request #1019 from dfinity/alex/update-motoko-basic-bitcoin-readme
update motoko basic_bitcoin readme
2 parents 94b2d62 + a1ea280 commit 5bd93cf

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

motoko/basic_bitcoin/README.md

+12-19
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,8 @@ Candid:
8585

8686
Your canister is live and ready to use! You can interact with it using either the command line or the Candid UI, which is the link you see in the output above.
8787

88-
In the output above, to see the Candid Web UI for your bitcoin canister, you would use the URL `https://a4gq6-oaaaa-aaaab-qaa4q-cai.raw.icp0.io/?id=<YOUR-CANISTER-ID>`. Here are the two methods you will see:
89-
90-
* `public_key`
91-
* `sign`
88+
In the output above, to see the Candid Web UI for your bitcoin canister, you would use the URL `https://a4gq6-oaaaa-aaaab-qaa4q-cai.raw.icp0.io/?id=<YOUR-CANISTER-ID>`. Candid
89+
Web UI will contain all methods implemented by the canister.
9290

9391
## Step 2: Generating a Bitcoin address
9492

@@ -99,7 +97,7 @@ if you are interested in a high-level comparison of different address types.
9997
These addresses can be generated from an ECDSA public key or a Schnorr
10098
([BIP340](https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki))
10199
public key. The example code showcases how your canister can generate and spend
102-
from two types of addresses:
100+
from three types of addresses:
103101
1. A [P2PKH address](https://en.bitcoin.it/wiki/Transaction#Pay-to-PubkeyHash)
104102
using the
105103
[ecdsa_public_key](https://internetcomputer.org/docs/current/references/ic-interface-spec/#ic-method-ecdsa_public_key)
@@ -110,13 +108,19 @@ from two types of addresses:
110108
(so-called P2TR key path spend, but untweaked). The advantage of this
111109
approach compared to P2TR script spends is its significantly smaller fee per
112110
transaction because checking the transaction signature is analogous to P2PK
113-
but uses Schnorr instead of ECDSA. IMPORTANT: Note that
111+
but uses Schnorr instead of ECDSA. The limitation of untweaked P2TR addresses
112+
is that they cannot be used with scripts. IMPORTANT: Note that
114113
[BIP341](https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#cite_note-23)
115114
advises against using taproot addresses that can be spent with an untweaked
116115
key. This precaution is to prevent attacks that can occur when creating
117116
taproot multisigner addresses using specific multisignature schemes. However,
118117
the Schnorr API of the internet computer does not support Schnorr
119118
multisignatures.
119+
3. A [P2TR
120+
address](https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki)
121+
where the funds can be spent using the provided public key with the script
122+
path, where the Merkelized Alternative Script Tree (MAST) consists of a
123+
single script allowing to spend funds by exactly one key.
120124

121125
Note that P2TR *key path* spending with a tweaked key is currently not available
122126
on the IC because the threshold Schnorr signing interface does not allow
@@ -128,7 +132,7 @@ post](https://bitcoin.stackexchange.com/a/111100) by Pieter Wuille.
128132

129133
On the Candid UI of your canister, click the "Call" button under
130134
`get_${type}_address` to generate a `${type}` Bitcoin address, where `${type}`
131-
is one of `[p2pkh, p2tr_raw_key_spend]`.
135+
is one of `[p2pkh, p2tr_raw_key_spend, p2tr_script_spend]`.
132136

133137
Or, if you prefer the command line:
134138

@@ -173,7 +177,7 @@ Checking the balance of a Bitcoin address relies on the [bitcoin_get_balance](ht
173177
## Step 5: Sending bitcoin
174178

175179
You can send bitcoin using the `send_from_${type}` endpoint on your canister, where
176-
`${type}` is on of `[p2pkh, p2tr_raw_key_spend]`.
180+
`${type}` is on of `[p2pkh, p2tr_raw_key_spend, p2tr_script_spend]`.
177181

178182
In the Candid UI, add a destination address and an amount to send. In the example
179183
below, we're sending 4'321 Satoshi (0.00004321 BTC) back to the testnet faucet.
@@ -226,15 +230,4 @@ For example, the following aspects are particularly relevant for this app:
226230
* [Certify query responses if they are relevant for security](https://internetcomputer.org/docs/current/references/security/general-security-best-practices#certify-query-responses-if-they-are-relevant-for-security), since the app e.g. offers a method to read balances.
227231
* [Use a decentralized governance system like SNS to make a canister have a decentralized controller](https://internetcomputer.org/docs/current/developer-docs/security/security-best-practices/overview)
228232

229-
## Taproot transactions
230-
In addition to P2PKH transactions, this example now also suppots P2TR
231-
transactions, namely the so-called untweaked key path P2TR transactions, which
232-
is the most efficient way of performing a P2TR transaction. The limitation of
233-
this type of transactions is that it cannot be used in combination with scripts.
234-
IMPORTANT: Note that BIP341 advises against using taproot addresses that can be
235-
spent with an untweaked key. This precaution is to prevent attacks that can
236-
occur when creating taproot multisigner addresses using specific multisignature
237-
schemes. However, the Schnorr API of the internet computer does not support
238-
Schnorr multisignatures.
239-
240233
This implementation has only been tested locally with regtest.

0 commit comments

Comments
 (0)