1
0
mirror of https://github.com/lightning/bolts.git synced 2024-11-19 10:00:04 +01:00
Commit Graph

155 Commits

Author SHA1 Message Date
pm47
557db43378 make htlc outputs of the commitment tx spendable with revocation key
(Merge conflict in test vectors fixed by selecting Pierre's, will have to
 be re-evaluated).

Closes: #105
2017-03-07 09:21:40 +10:30
Rusty Russell
034c234829 BOLT 2,3: SHOULD NOT create malleable funding tx.
But note that our funding transaction example is.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-07 06:39:28 +10:30
Rusty Russell
dc0b529161 BOLT 3: update test vectors for ec99f893f3
The weights of HTLCs were corrected by Pierre in "fixed htlc weight
calculation": this adjusts the test vectors to match.

This also means that the feerate thresholds change.

In addition, this fixes feerate on "maximum feerate" tests,
and corrects the fee for the htlc-timeout tx.

Reported-by: Fabrice Drouin <fabrice.drouin@acinq.fr>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-02-22 09:59:37 +10:30
Rusty Russell
0801f05795 BOLT 3: Note the HTLC number when annotating witness scripts.
This is more distinctive than amount.

No normative changes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-02-22 09:59:37 +10:30
Rusty Russell
394da29189 BOLT 3: fix test vector derivation.
The test vectors themselves were fine, but they're supposed to be derived
from known basepoints (and I was actually testing this with some new code).

I accidentally used the *remote* per-commitment-point, instead of the *local*
per-commitment-point to derive the remotekey/remote_privkey; since we are
generating the local transaction, this is wrong.  We don't need to know
the remote per-commitment-point at all, in fact.

Thus, the remotekey (and signatures) in the test vectors change.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-02-22 09:59:37 +10:30
pm47
ec99f893f3 fixed htlc weight calculation 2017-02-10 11:33:41 +10:30
Rusty Russell
fb5e8667bb bolt3 fix and enhance tx testvectors (#99)
This is a smerge of Fabrice Drouin and my work: he update them, I updated them and enhanced them, he found bugs, I re-derived them, etc.

- rename keys properly
- fix fees
- sign all transactions
- Derive test transaction vectors from minimal subset of parameters.
- rewrite test vectors to test edge cases for trimming.
- add funding tx test vector, make testable on regtest.

This adds a funding transaction test (really, we only specify the output), but importantly adds enough information to duplicate a blockchain with that particular funding tx:

$ rm -rf ~/.bitcoin/regtest/
$ bitcoind -regtest=1 &
$ bitcoin-cli -regtest=1 submitblock  0000002006226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910fadbb20ea41a8423ea937e76e8151636bf6093b70eaff942930d20576600521fdc30f9858ffff7f20000000000101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03510101ffffffff0100f2052a010000001976a9143ca33c2e4446f4a305f23c80df8ad1afdcf652f988ac00000000
$ bitcoin-cli -regtest=1 generate 431
$ bitcoin-cli -regtest=1 sendrawtransaction 0200000001adbb20ea41a8423ea937e76e8151636bf6093b70eaff942930d20576600521fd000000006b48304502210090587b6201e166ad6af0227d3036a9454223d49a1f11839c1a362184340ef0240220577f7cd5cca78719405cbf1de7414ac027f0239ef6e214c90fcaab0454d84b3b012103535b32d5eb0a6ed0982a0479bbadc9868d9836f6ba94dd5a63be16d875069184ffffffff028096980000000000220020c015c4a6be010e21657068fc2e6a9d02b27ebe4d490a25846f7237f104d1a3cd20256d29010000001600143ca33c2e4446f4a305f23c80df8ad1afdcf652f900000000

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-02-07 11:15:33 +10:30
Rusty Russell
0dd1d383ed BOLT 3: fix trimming typo.
If the htlc amount, after htlc fee is *subtracted*, is less than the dust limit,
trim it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-02-01 12:42:04 +10:30
Rusty Russell
d907eacbac BOLT 3: use P2WPKH instead of P2PKH.
Not only is it shorter and cheaper, but the rest of the document (including
test vectors and weight calculation) assumed it already.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-31 13:09:53 +10:30
Rusty Russell
76937db387 BOLT 3: minor cleanup.
Remove redundant sentence about commitment txin; it's specified exactly
3 lines later.

Refer to the Commitment Transaction section in "Commitment Transaction
Construction".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-25 16:05:11 +10:30
Rusty Russell
de8be3072d BOLT 3: Spell out how to construct the commitment transaction.
* I add the term "trimmed outputs" for sub-dust outputs; this matters
  for both fee calculation and transaction construction.

* Introduce the concept of "base fee": this is what needs to be
  extracted from the funder.

* The requirements are spread between the different sections, let's
  tie it together in a new section at the end.

* Spell out all the steps in the example which calculates fees.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-25 06:23:28 +10:30
Rusty Russell
1819ff9355 BOLT 3: dust-limit should be dust-limit-satoshis
That's the name of the field in BOLT 2.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-25 06:23:28 +10:30
Rusty Russell
b29269419a BOLT 3: Fix amounts in example.
Since we changed from / 1024 to / 1000 in fddc992b2d, the example is
out-of-date.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-25 06:23:28 +10:30
Rusty Russell
30e0cc6782 BOLT 3: Fix one-letter URL typo.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-24 06:55:45 +10:30
Rusty Russell
6aaa9322a1 BOLT 3: Add test vectors for key derivation. (#83)
* BOLT 3: Add test vectors for key derivation.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-24 06:52:29 +10:30
Rusty Russell
fddc992b2d BOLT 2, BOLT 3: fee-per-kw kilo == 1000, not 1024.
I checked the bitcoin source to be sure, too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-22 16:17:30 -08:00
Christopher Jämthagen
f1eaa25446 BOLT 3: Use 0x20 as high byte for locktime in commitment transaction
The most significant byte of the locktime in a commitment transaction
must be set to 0x20. This is to make sure that the locktime value
is always higher than 500,000,000, making it interpreted as a Unix
epoch timestamp, and not a block height. It also makes sure that the
locktime is below the current time, allowing the commitment transaction
to be included in a block.

Since the sequence field in the input of the commitment transaction is
used for the other half of the obscured commitment transaction number,
it will never assume the maxInt value (0xFFFFFFFF) which would disable
locktime checking.
2017-01-13 22:57:14 +01:00
Christopher Jämthagen
2045d6d632 witnessScript is part of witness + null dummy for OP_CHECKMULTISIG (#70)
* Add null dummy consumed by OP_CHECKMULTISIG
* scriptsig -> witness.
* witness script -> witness.
2017-01-04 16:09:18 +10:30
pm47
7751ee11f2 added test vectors for transactions 2017-01-04 15:55:41 +10:30
pm47
2c4cd03b4c added a section about who pays the fee 2017-01-04 15:55:41 +10:30
pm47
4339f033e6 moved weight computation to Appendix section, fixed index 2017-01-04 15:55:41 +10:30
Pierre-Marie Padiou
856331e347 fixed numbering 2016-12-21 11:44:15 +01:00
Fabrice Drouin
d02681a53b BOLT 3: fix fee computations
1. HTLC must be able to pay for their HTLC success/timeout transaction fees
2. add examples
2016-12-21 14:55:26 +10:30
Pierre-Marie Padiou
bf68c6253e fixed typo 2016-12-20 19:00:58 +01:00
pm47
951fe14775 added a table of contents to bolt3 2016-12-20 16:43:08 +01:00
fivepiece
66ffc6c624 BOLT 3: Fix funding output script
remove `0` from the funding output script as it is not part of a normal 2-of-2 multisig script
2016-12-18 10:36:49 +10:30
pm47
93f948cbd9 typos and consistency 2016-12-13 15:44:14 +01:00
Rusty Russell
125b9a3657 BOLT 3: Fix commitment transaction input sequence number.
From BIP 68:

	If bit (1 << 31) of the sequence number is set, then no consensus
	meaning is applied to the sequence number and can be included in any
	block under all currently possible circumstances.

Which is what we want.

Reported-by: Olaoluwa Osuntokun <laolu32@gmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-12-12 11:13:29 +10:30
Rusty Russell
2f998f3741 BOLT 3: make upper bits of commit tx locktime and sequence explicit.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-12-12 10:38:10 +10:30
Christopher Jämthagen
f8f5fa6312 Make it clear that lower 24 bits of locktime is lower 24 bits of the obscured commitment transaction number 2016-12-12 10:37:45 +10:30
Christian Decker
3378afe028 trivial: Consolidating inline code
Now using `<>` on inline code only when part of a script and extra
emphasis is warranted. Outside of scripts the variable names are
already highlighted, so no need to add further emphasis.
2016-12-11 11:08:53 +10:30
Christian Decker
71514b92df trivial: Minor markup fixes 2016-12-11 11:08:53 +10:30
Christopher Jämthagen
6e4f7f0cc2 Consistently use 'transaction' instead of 'tx' 2016-12-09 10:41:48 +01:00
Rusty Russell
e6faf71c30 BOLT 3: Add test vectors for per-commitment-secret generation
These were generated (and recovery tested) by the command-line tool at:

	https://github.com/rustyrussell/ccan/tree/master/ccan/crypto/shachain/tools

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-12-08 11:00:05 +10:30
Christopher Jämthagen
6750398c97 Some spelling and language fixes in BOLTs 3,4,5 2016-12-07 10:04:57 +01:00
Rusty Russell
aa594c2608 BOLT 3: per-commitment not per-commit.
Be consistent.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-12-02 11:45:01 +10:30
Rusty Russell
10f49ecb84 BOLT 3: Fix incorrect secret derivation.
There was talk of using a simple increment, but it was removed after
Tadge educated me.  Somehow this didn't get updated.

Reported-by: Tadge Dryja <tdryja@gmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-12-01 11:53:29 +10:30
Rusty Russell
e88dd27d12 BOLT 3: expand and correct HTLC transaction weights.
Inspired by Andrew Shvv's work, this expands the HTLC weight calculation
and fixes the gross errors (the witness program itself wasn't counted in
the weights!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-30 06:58:27 +10:30
Rusty Russell
970b39a40d BOLT 3: Note assumption about to-remote output existing.
Commit a0c4f7cfd1 "BOLT 3: add more detailed commitment transaction
estimation (#26)" simplified the weight formula to assume there was a
to-remote output.

This worst-case 18% error, but it's simple.  Document it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-30 06:58:27 +10:30
andrew.shvv
a0c4f7cfd1 BOLT 3: add more detailed commitment transaction estimation (#26)
* add more detailed estimation
* fix miscalculations
2016-11-30 06:50:05 +10:30
Rusty Russell
1a1dc1e70f Merge pull request #22 from lightningnetwork/fix-fee-calc
BOLT 3: Fix fee calculation.
2016-11-28 13:17:29 +10:30
Fabrice Drouin
de87eaa147 BOLT 3: fix witness scripts
1. Add a short paragraph on P2WSH (the witness script is omitted for brevity in all descriptions) and fix witness scripts for spending the different tx outputs.
2. use CHECK(MULTI)SIG instead of CHECK(MULTI)SIGVERIFY
3. Fix order and nulldummy for witness in HTLC transactions
4. Fix a minor typo (if -> it)

(Commits rebased and squashed together by Rusty)
2016-11-24 11:05:31 +10:30
Rusty Russell
1e7e21b5c6 BOLT 3: Fix fee calculation.
I forgot to add in the amount+scriptsize overhead for each HTLC.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-24 10:56:13 +10:30
Christian Decker
4dde8e6a26 Merge pull request #18 from lightningnetwork/license
Add CC-BY.
2016-11-23 15:49:46 +01:00
Rusty Russell
5f5f87d124 Merge pull request #10 from lightningnetwork/feerate
BOLT 02/03: Add fee calculation details.
2016-11-23 06:27:50 +10:30
Rusty Russell
193bbef972 Add CC-BY.
Closes: #2
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-23 06:22:59 +10:30
Fabrice Drouin
f51f5c8690 'to-local output': add revocation key
The 'to local' output in the commit tx should be spendable without delay if you know the revocation key.
2016-11-22 15:33:07 +01:00
Rusty Russell
bf80e07df0 BOLT 02/03: Add fee calculation details.
Make the fee amount by kiloweight, not by kilobyte, and spell out how
to calculate it.  Note that we have to trim HTLCs outputs whose second-stage
would also fall below dust limit, and we also make some reasonable
approximations on transaction size (which is unknowable before signatures
anyway).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-21 13:43:42 +10:30
Rusty Russell
77afd570af BOLT #3: re-add XORing to obscure the commitment index.
I missed this somehow from the spec.

Reported-by: Olaoluwa Osuntokun <laolu32@gmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-19 10:39:30 +10:30
Rusty Russell
32779962b5 BOLT 2/3: watcher-compatible key derivation.
After much discussion with Tadge and Laolu, I think we have something
which is nicely outsourcable, and yetnot insanely complex.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-17 14:33:22 +10:30
Olaoluwa Osuntokun
17060cbf9d BOLT 3: use code block for multi-sig script
This commit modifies BOLT 3 slightly to use a code block for the multi-sig script. Without this change, the script doesn't display correctly, as the angle brackets are interpreted as markdown syntax.
2016-11-16 17:13:48 -08:00
Rusty Russell
ab15a6e427 BOLT #3: document how to efficiently derive shachain, fix refs to it.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-15 16:30:38 +10:30
Rusty Russell
99b8888827 BOLT #3: Fix typo 2016-11-15 14:07:07 +10:30
Rusty Russell
3c612dd229 03-transactions: fix script formatting.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-15 13:56:45 +10:30
Rusty Russell
76dfd378ff Transfer from google doc.
Minimal markdown and consistency fixes, more to come.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-15 11:53:20 +10:30