Commit graph

34650 commits

Author SHA1 Message Date
Andrew Poelstra
b64ca7f411 Merge 6eed792d43 into merged_master (Elements PR ElementsProject/elements#1050)
Conflicts were mostly obvious, except for those in CreateTransactionInternal.
(This function was moved from wallet.cpp to spend.cpp, and substantially
rewritten, between 0.21 and 22.0.) For those I manually applied the changes
from the diff, which wound up taking a slightly different form.

Also had to update the new test because the `addresses` field of the RPC
output was removed.
2021-10-04 15:13:47 +00:00
Andrew Poelstra
6eed792d43
Merge ElementsProject/elements#1050: wallet: fix a pile of bugs in transaction funding logic
a67a2df330 pset: remove one more intermediate-zero check from the blinding logic (Andrew Poelstra)
9eb285c19d test: add test for confidential non-wallet-owned change (Andrew Poelstra)
185d473fe8 walletcreatefundedpsbt: add functional test for blinding edge cases (Andrew Poelstra)
533da12c2c wallet: make sure extra OP_RETURN output is blinded when called from fundraw (Andrew Poelstra)
b09b63bd1b pset: allow input blinding factors to sum to zero, or value to be 0 (Andrew Poelstra)
9afcb83baf wallet: correctly handle blinding of manually-set change addresses (Andrew Poelstra)
9813c3e74a wallet: fix "cannot unblind IsMine output" check in SignPSBT (Andrew Poelstra)
7103471fd5 walletcreatefundedpsbt: signal blinding data correctly to `FundTransaction` (Andrew Poelstra)

Pull request description:

  Fixes #1049

  Needs backport to 0.21 (and a new rc).

  Although there are several bugs here, none affect the functionaries. There is a more thorough summary in the second-to-last commit message.

ACKs for top commit:
  achow101:
    ACK a67a2df330

Tree-SHA512: 25066c29f080e43cd00c5b33c60a986a8cb5bbf4ca01ceb3b4182c5b8f61979a1d6d946b8f28fa871ec90f44bdb6fc22014b5c11280cf081181db102cd588cdf
2021-10-02 15:13:45 +00:00
Andrew Poelstra
ea62009330 Merge 4798e8ee2c into merged_master (Elements PR ElementsProject/elements#1052) 2021-10-02 14:06:41 +00:00
Andrew Poelstra
7b69a940eb Merge 846ab81794 into merged_master (Elements PR ElementsProject/elements#1051) 2021-10-02 13:27:49 +00:00
Andrew Poelstra
4798e8ee2c
Merge ElementsProject/elements#1052: chainparams: change magic bytes for liquidv1test
0628311b53 chainparams: change magic bytes for liquidv1test (Andrew Poelstra)

Pull request description:

  This is basically a Liquid-prod-ish version of regtest. Its default magic should not collide with that for Liquid prod.

ACKs for top commit:
  psgreco:
    UTACK 0628311b53

Tree-SHA512: 50c387ffeb62d42ffd0b42d0f43335966feb64a50140159c615474b9c864222e2a7510bb3b07aa95f62a977d0e7472d905bc97a06a3ace80aae0a519031c446e
2021-10-02 13:23:55 +00:00
Andrew Poelstra
a67a2df330 pset: remove one more intermediate-zero check from the blinding logic 2021-10-01 23:30:58 +00:00
Andrew Poelstra
846ab81794
Merge ElementsProject/elements#1051: combinepsbt: do safety checks that explicit values are only used if they are proven
fec0b59112 pset: make sure combinepsbt doesn't crash when explicit values are missing (Andrew Poelstra)
187c8094bb combinepsbt: only use explicit values if the corresponding proofs pass (Andrew Poelstra)
c873a78ff4 pset tutorial: add `combinepsbt` safety checks, expand comments (Andrew Poelstra)
57ea7e8a59 pset tutorial: expand a couple of comments, fix numbering (Andrew Poelstra)

Pull request description:

  Also update the PSET tutorial

ACKs for top commit:
  achow101:
    ACK fec0b59112

Tree-SHA512: 48a98932d62657f2eeb904cd77b59046edebaf79323bd1223bf1e7b5212308d2cdb60a0e4d2e42407d97d8ac1c4ac04bfda454361854edea6b123cd4014926d2
2021-10-01 23:30:27 +00:00
Andrew Poelstra
fec0b59112 pset: make sure combinepsbt doesn't crash when explicit values are missing
I accidentally dropped this check (and its test) in the previous
commits. Restore both.
2021-10-01 20:10:27 +00:00
Andrew Poelstra
187c8094bb combinepsbt: only use explicit values if the corresponding proofs pass 2021-10-01 17:17:41 +00:00
Andrew Poelstra
c873a78ff4 pset tutorial: add combinepsbt safety checks, expand comments 2021-10-01 00:54:00 +00:00
Andrew Poelstra
57ea7e8a59 pset tutorial: expand a couple of comments, fix numbering 2021-10-01 00:54:00 +00:00
Andrew Poelstra
9eb285c19d test: add test for confidential non-wallet-owned change 2021-09-30 22:58:14 +00:00
Andrew Poelstra
185d473fe8 walletcreatefundedpsbt: add functional test for blinding edge cases
This test actually hits almost all of the edge cases covered by the
previous commits.

  1. The "`walletcreatefundedpsbt` does not propagate blinding factors"
     issue is actually covered by several existing tests, which did not
     fail, but which revealed other bugs as soon as I fixed the issue.

  2. Similarly, the "properly blind (or don't blind) explicit change
     addresses" issue was covered by existing tests, but was revealed
     upon fixing the issue with verifying unblindability in SignPSBT,
     since it resulted in using the wrong blinding key to produce
     rangeproofs for change.

  2a. (While addressing this, I was able to test the SignPSBT checks
      extensively, because the code was producing bad rangeproofs. But
      in the final result this is *not* covered, since it is hard, or
      hopefully impossible, to cajole the wallet into producing outputs
      that can't be unblinded now.)

  3. Once that was fixed, the existing tests create an output whose
     total blinding factor (`v_b + v*a_b`) is zero, which it does by
     having no blinded inputs, explicit change/fee, and a single
     blinded output. This output is spent in the new test. This tests
     one of the "blinding may fail due to zero intermediate values"
     cases.

  4. The new test then intentionally tests that `walletcreatefundedpsbt`
     creates OP_RETURN outputs only when it is legitimately given a
     "blinded inputs, no blinded outputs" transaction, which tests the
     original bug (that blinding factors were propagated correctly from
     `walletfundpsbt`).

  5. In doing so, it hit the "OP_RETURN outputs are not blinded when
     called from fundrawtransaction" bug.

  6. And once this was fixed, `BlindPSBT` has to blind a zero-valued
     output, which triggers the other "blinding may fail due to zero
     intermediate values" case.

For purposes of assigning blame, I'd say that half of this omnibug came
from the new PSET logic and half was latent in Elements for years. The
most concerning thing, I'd say, is the "explicit change addresses cause
outputs to be blinded to the wrong key" bug, which I believe has been
around for the entire history of Elements.
2021-09-30 22:46:33 +00:00
Andrew Poelstra
533da12c2c wallet: make sure extra OP_RETURN output is blinded when called from fundraw
This is a followup to https://github.com/ElementsProject/elements/pull/588
2021-09-30 21:54:40 +00:00
Andrew Poelstra
b09b63bd1b pset: allow input blinding factors to sum to zero, or value to be 0
There are a number of special cases (and inconsistencies with wallet.cpp)
in the blinding logic that can prevent blinding from succeeding when various
intermediate values are zero. This fixes two of them.

A proper fix would involve adding new APIs to secp-zkp and then overhauling
all of the wallet blinding code. But for now let's get the tests working.
2021-09-30 21:54:40 +00:00
Andrew Poelstra
9afcb83baf wallet: correctly handle blinding of manually-set change addresses
When the user specifies a change address manually, use the change address
to obtain blinding parameters (either extract the blinding key from the
address or don't blind the change).

The previous behavior would assume that the change address was owned by
the wallet and always generate a blinding key internally. If the user
were to pass a non-wallet-owned change address, the result would be an
output that could not be unblinded by its owner.
2021-09-30 21:54:40 +00:00
Andrew Poelstra
9813c3e74a wallet: fix "cannot unblind IsMine output" check in SignPSBT 2021-09-30 21:54:40 +00:00
Andrew Poelstra
7103471fd5 walletcreatefundedpsbt: signal blinding data correctly to FundTransaction 2021-09-30 21:54:10 +00:00
Andrew Poelstra
0628311b53 chainparams: change magic bytes for liquidv1test
This is basically a Liquid-prod-ish version of regtest. Its default magic
should not collide with that for Liquid prod.
2021-09-28 17:29:13 +00:00
Andrew Poelstra
daa471ddd2 Merge 4c7dc0620a into merged_master (Elements PR ElementsProject/elements#1046) 2021-09-22 02:26:13 +00:00
Andrew Poelstra
4c7dc0620a
Merge ElementsProject/elements#1046: PSET: change sanity checks for blinding
d1a1d19113 test: add decodepsbt and analyzepsbt tests for blinding proofs (Andrew Poelstra)
03b835c887 PSET: output warnings in decodepsbt and analyzepsbt about blinding status (Andrew Poelstra)
694ec795e4 PSET: fix asset proof generation and verification (Andrew Poelstra)
c6f801d4ce PSET: encapsulate blind proof checks into one method (Andrew Poelstra)
35cfda73b9 PSET: do not assume in GetUnsignedTx that explicit amounts/assets are available (Andrew Poelstra)
c88eb96e74 pset: check that we can get the blinding factors from any IsMine outputs before signing (Andrew Poelstra)
9c55d0a175 pset: only check asset/amount proofs in case both explicit+blinded values are provided (Andrew Poelstra)

Pull request description:

  After conversation with @stepansnigirev in #1026 I realize we need to adjust our sanity checks on asset proofs. In particular,

  * Rather than enforcing that all confidential values have corresponding explicit values with proofs, we should only check that **if** both confidential and explicit values are present, they are connected by a proof.
  * Further, the wallet should check before signing that any `IsMine` scripts have confidential values that we are actually able to spend (i.e. rewinding works).

  This PR implements these two things, and also extends the `analyzepsbt` and `decodepsbt` RPC calls to provide more information if the amount/asset proofs are missing or invalid. It adds tests for these and also demonstrates that `combinepsbt` does not really work without explicit data present.

  `walletprocesspsbt`, when blinding, will still produce these proofs and there is currently no way to disable this behavior.

ACKs for top commit:
  achow101:
    ACK d1a1d19113

Tree-SHA512: 472ee0fe285308e803cbc3f5885e513ec91d1b3f18a2973772cd5a88d29fa4dba9441d9b3bd58847564e43d9a7478bbc75af62d9326c727709b5ff2dc646714a
2021-09-22 02:01:39 +00:00
Andrew Poelstra
d1a1d19113 test: add decodepsbt and analyzepsbt tests for blinding proofs 2021-09-21 21:59:16 +00:00
Andrew Poelstra
03b835c887 PSET: output warnings in decodepsbt and analyzepsbt about blinding status 2021-09-21 21:59:16 +00:00
Andrew Poelstra
694ec795e4 PSET: fix asset proof generation and verification
A couple issues with this -- one is that it was verifying the asset
commitment against itself, rather than against the explicit asset,
and the other is that the verification logic had an extra `== 0` at
the end which inverted the verification check.

Both pretty embarassing to have not caught in review..
2021-09-21 21:59:10 +00:00
Andrew Poelstra
c6f801d4ce PSET: encapsulate blind proof checks into one method 2021-09-21 20:33:31 +00:00
Andrew Poelstra
35cfda73b9 PSET: do not assume in GetUnsignedTx that explicit amounts/assets are available 2021-09-21 20:33:31 +00:00
Andrew Poelstra
c88eb96e74 pset: check that we can get the blinding factors from any IsMine outputs before signing
Arguably we should do this for signrawtransaction too but it'd be a
lot of duplicated code for a deprecated workflow.
2021-09-21 20:33:31 +00:00
Andrew Poelstra
9c55d0a175 pset: only check asset/amount proofs in case both explicit+blinded values are provided 2021-09-21 20:33:28 +00:00
Andrew Poelstra
6c368ab1a3 Merge a1726c555b into merged_master (Elements PR ElementsProject/elements#1045) 2021-09-21 20:32:03 +00:00
Andrew Poelstra
a1726c555b
Merge ElementsProject/elements#1045: Fix SIGHASH_RANGEPROOF bugs
71c9e90fa0 test: add another functional test for rangeproofs in issuances (Andrew Poelstra)
cf4136b3b0 SIGHASH_RANGEPROOF and asset issuance rangeproofs (Andrew Poelstra)
d4a0b6285a test: check asset issuances with SIGHASH_RANGEPROOF (Andrew Poelstra)
1b23ad7093 pset: fix encoding of blinded asset issuances (Andrew Poelstra)
0907fa0f6f test: support asset issuance in test framework sighashes (Andrew Poelstra)
34eafaf761 test: sign using the PSET interface and SIGHASH_RANGEPROOF (Andrew Poelstra)
9c3c61aa0a psbt: make sure rangeproofs are present in the confidential version of the unsigned tx (Andrew Poelstra)
7d39e430c7 test: check that `signrawtransaction` does not erase RANGEPROOF signatures (Andrew Poelstra)
7a3cbda848 sign.cpp: turn on SIGHASH_SCRIPT_RANGEPROOF when checking already-existing signatures (Andrew Poelstra)
ac54a2f765 test: check that signing with the RANGEPROOF flag works (Andrew Poelstra)
ab5b376b72 SignatureHash: fix rangeproof hash for SIGHASH_RANGEPROOF (Andrew Poelstra)

Pull request description:

  Fixes #1026

  Supercedes #932

ACKs for top commit:
  achow101:
    ACK 71c9e90fa0

Tree-SHA512: ddc8074b6783344aa8b04de9e0a3d9320f70aa5f2bccd05d7e329110d861e46b2730b230a1b89ddb414dec8e9d31d04ab66e589d3f9648692fd990d03c369e81
2021-09-21 12:32:03 +00:00
Andrew Poelstra
71c9e90fa0 test: add another functional test for rangeproofs in issuances 2021-09-20 22:10:50 +00:00
Andrew Poelstra
cf4136b3b0 SIGHASH_RANGEPROOF and asset issuance rangeproofs 2021-09-20 22:10:47 +00:00
Andrew Poelstra
d4a0b6285a test: check asset issuances with SIGHASH_RANGEPROOF
Asset issuance rangeproofs are not actually covered by SIGHASH_RANGEPROOF
so this test serves more as a sanity check that our various signing
mechanisms still work with issuances. Sure enough, it uncovered a PSET
bug (fixed) and a blindrawtransaction bug (left a FIXME).
2021-09-19 20:58:07 +00:00
Andrew Poelstra
1b23ad7093 pset: fix encoding of blinded asset issuances 2021-09-19 20:58:07 +00:00
Andrew Poelstra
0907fa0f6f test: support asset issuance in test framework sighashes
Replaces #932
2021-09-19 20:58:07 +00:00
Andrew Poelstra
34eafaf761 test: sign using the PSET interface and SIGHASH_RANGEPROOF 2021-09-19 14:52:47 +00:00
Andrew Poelstra
9c3c61aa0a psbt: make sure rangeproofs are present in the confidential version of the unsigned tx
These rangeproofs are covered by signature in both Taproot and
SIGHASH_RANGEPROOF signatures, so they need to be present.
2021-09-19 14:52:47 +00:00
Andrew Poelstra
7d39e430c7 test: check that signrawtransaction does not erase RANGEPROOF signatures 2021-09-19 14:18:13 +00:00
Andrew Poelstra
7a3cbda848 sign.cpp: turn on SIGHASH_SCRIPT_RANGEPROOF when checking already-existing signatures
Currently when a user uses `signrawtransaction` on a transaction that is
already partially signed with SIGHASH_RANGEPROOF signatures, the existing
signatures will be deleted because they are not recognized as valid. This
makes it impossible to collabratively sign transactions using this RPC.
Fix this.
2021-09-19 14:18:13 +00:00
Andrew Poelstra
ac54a2f765 test: check that signing with the RANGEPROOF flag works 2021-09-19 14:10:21 +00:00
Andrew Poelstra
ab5b376b72 SignatureHash: fix rangeproof hash for SIGHASH_RANGEPROOF
The logic for computing the uncached version of the sighash changed during
the 0.21 rebase, such that it no longer matched the cached version. As the
changed hash is used during signing (not verification!), this was not a
forking change (and our existing functional test would have caught such a
forking change since it uses Python to independently compute the hash).
But it still broke signing.

Test in next commit.
2021-09-19 14:08:56 +00:00
Andrew Poelstra
5d8b55ce47 Merge f7f9555792 into merged_master (Elements PR ElementsProject/elements#1044) 2021-09-18 23:15:14 +00:00
Andrew Poelstra
c55db47277 Merge ade32378c1 into merged_master (Elements PR ElementsProject/elements#1041) 2021-09-18 16:37:33 +00:00
Andrew Poelstra
92d6f321b8 Merge 388d47f9a3 into merged_master (Elements PR ElementsProject/elements#1010)
Basically just reconstructed the diff since so much code had been moved.
2021-09-18 15:46:10 +00:00
Andrew Poelstra
dc31deacff Merge bc0494cc39 into merged_master (Elements PR ElementsProject/elements#1040) 2021-09-18 14:58:14 +00:00
Andrew Poelstra
7da9e74a39 Merge b456b72353 into merged_master (Elements PR ElementsProject/elements#1039) 2021-09-18 14:20:58 +00:00
Andrew Poelstra
6c38123ae4 Merge 787ee1e91f into merged_master (Elements PR ElementsProject/elements#1043) 2021-09-18 13:43:13 +00:00
Andrew Poelstra
541d18a8e7 Merge 27f9f0beab into merged_master (Elements PR ElementsProject/elements#1042) 2021-09-18 03:56:00 +00:00
Andrew Poelstra
f7f9555792
Merge ElementsProject/elements#1044: Define Taproot activation parameters for Liquid
3cb9612faa test: add test for Taproot activation (Andrew Poelstra)
5291c0d9d9 chainparams: add undocumented regtest/testnet only -con_taproot_signal_start option (Andrew Poelstra)
cc6b933478 add missing taproot activation params for Liquid v1 (Andrew Poelstra)
bec6bcf31b versionbits: allow specific deployments to override the signalling/threshold values (Andrew Poelstra)

Pull request description:

  Sets Taproot to start signalling around noon (California time) on Nov 1, 2021, assuming 95% of blocks are produced between now and then.

  Will activate after one week of 100% signalling. If we can pull this off on the first or second try, we will beat Bitcoin which currently looks like it will activate on Nov 16.

  **Edit:** actually, even without Speedy Trial, there is one full period (week) where Taproot will be "locked in" but not "active". So it will activate on Nov 15 at the earliest.

ACKs for top commit:
  achow101:
    ACK 3cb9612faa

Tree-SHA512: c3a80d39ba86a0d762a3057cb9c45e379c70c2daee8ff2e54978a4c32118c935c8909d872ac9f873e283441c52c1974c06268f10dc7bf9e9e000c21063ac84d7
2021-09-18 03:22:30 +00:00
Andrew Poelstra
e4c9cc06dc Merge 250c8e59d5 into merged_master (Elements PR ElementsProject/elements#1030) 2021-09-18 03:17:06 +00:00