Commit graph

4271 commits

Author SHA1 Message Date
Byron Hambly
49c3ea309e
fix: getnewaddress - don't blind bech32 addresses
fixes #1245
2023-07-19 12:40:22 +02:00
Pablo Greco
cfc10a5dd6
Merge pull request #1232 from delta1/script-assets-test
test: re-enable and fix script assets test
2023-06-05 14:14:27 -03:00
Byron Hambly
5cbd44f1c8
test: re-enable and fix script assets test
Re-enables and fixes the script_assets_test by changing feature_taproot.py to include the genesis block hash when dumping the json tests.

Requires the json file from https://github.com/ElementsProject/qa-assets/pull/1

Co-authored-by: Andrew Poelstra <apoelstra@wpsoftware.net>
2023-06-05 16:43:06 +02:00
Andrea Bonel
d856ef2e6c Add test for dynafed cpe root 2023-04-03 18:03:59 -03:00
Andrew Chow
42cbdc81a6 test: Test for explicit values and assets and their proofs 2022-10-18 16:52:31 -04:00
Glenn Willen
d0625e1ed5 Add taproot address parsing test case, regression test for #1181. 2022-10-11 17:02:34 -07:00
Pablo Greco
90c4bf99f6 Fix lint 2022-09-26 12:09:28 -03:00
Andrew Poelstra
e5e3ec2700
wallet: account for issuances during coin selection
Prior to coin selection we need to indicate that the issuances will take
extra space, otherwise we may fail to select enough coins to cover our
fees, triggering the new "fee needed exceeds fees available" assertion.
2022-09-22 13:20:29 +00:00
Andrew Poelstra
3c896b11e0
test: rename elements_regression_1172 to follow naming convention 2022-09-20 21:17:50 +00:00
Andrew Poelstra
79fd90f064
wallet: extend fix to "dropped change is the last blinded output" case 2022-09-20 21:17:47 +00:00
Andrew Poelstra
fac694be4c
wallet: don't clear out all the blinding data when dropping change
The Elements 22 blinding logic has an edge case where when we drop change,
leaving only a single blinded output, we recompute a bunch of blinding
data to handle the potential for us to have 0 inputs and 1 output to blind.
(BlindTransaction will fail in this case because it cannot make the
transaction balance with only one output to mess with.)

In this recomputation, we dropped more data than we meant to, causing us
to incorrectly blind an output.
2022-09-20 17:40:47 +00:00
Andrew Poelstra
23e91d0ef8
wallet: fix some fee calculation bugs
First, this reverts commit ca2d72ae8b to reinstate
an assertion that was added in Bitcoin #22686. It did not compile because our
`change_and_fee` variable is a map rather than number; I changed it to use
`map_change_and_fee.at(policyAsset)` to match the equivalent change 2 lines down
from a5d97b363b (merge of Bitcoin #22008).

Then fix the following bugs:

1. Change the new test in rpc_fundrawtransaction.py to bump the -maxtxfee value,
   which we'd otherwise exceed, failing the test and masking actual failures.
   (This was just caused by the extreme fee settings of the test combined with
   Elements' large transactions.)
2. Change the fee-output size estimation for `tx_noinputs_size` to be 46 rather
   than 44 bytes; we forgot that even null surjection/rangeproofs need a 0 byte
   when output witnesses are present. This mistake triggered the new assertion.
3. Correct the logic in which change outputs are sometimes dropped even when
   they are the only blinded output in a transaction with blinded inputs. This
   would cause the new test to fail with `bad-txn-inputs-ne-outputs`; I'm very
   surprised that no existing tests hit this.

   (I have an existing comment block in this code where I "promise" that I had
   a good reason for doing something mysterious related to blinding. I was not
   able to reverse-engineer my intention here, though I think it is related to
   this, but since I couldn't understand it I just left this block intact and
   worked around it.)
4. This then triggered the assertion again since the coin selection code
   assumes that sufficiently-small change will always be dropped. If we prevent
   this drop we will have under-funded the transaction.

   To fix this we add Yet Another Flag `may_need_blinded_dummy` in which we add
   extra weight to `tx_noinputs_size` in the case that we're doing a blinded tx
   but have no blind destinations. We turn this off after coin selection if it
   turns out that we don't have any blinded inputs, though ofc at that point
   much of the damage/inefficiency has already been done..
5. Fix some constants in other functional tests which assumed precise fee
   calculations; these precise values changed because of fixes (2) and (4).

There is one new FIXME, which is that the "dummy change" value will now be a
zero-valued OP_RETURN but we still put a full-size rangeproof and surjection
proof on it. There is some plausible privacy benefit to this but not much,
and wasting 5000+ bytes rather than the ~65 needed for an exact-value proof
is not worth it. We will fix this in the future when we overhaul the wallet
blinding logic.
2022-09-20 17:39:24 +00:00
Byron Hambly
661c6c7094
feat: change getnewblockhex to take multiple commitments
Modifies the getnewblockhex json rpc call to accept an array of
commitments instead of a single commitment.

Backwards compatibility is maintained by first attempting to parse as a
string for a singular commitment.
2022-09-07 14:43:10 +02:00
Andrew Chow
66290e60cf tests: Tests for pset input explicit value, asset, and proofs 2022-09-06 16:26:49 -04:00
Allen Piscitello
2da7d75ee9 removing test that fails due to blinded issuances, which results in incorrect reissuance token ids 2022-08-24 13:36:08 -05:00
Pablo Sebastian Greco
6132c01d60
Merge pull request #1121 from jgriffiths/pset_updates
PSET: Various fixes
2022-08-09 16:16:02 -03:00
Jon Griffiths
1462492553
PSET: Use the current serialization format in PSET tests
This allows these test cases to be re-used by alternate implementations
for round-trip serialization testing.
2022-08-09 09:36:02 +12:00
Jon Griffiths
46c49c09b6
PSET: Allow reading of correctly serialized empty vectors
A single 0x00 byte indicates a zero length field; we must skip parsing
that field otherwise the length will be expected to be read again for
the vector that is passed in to revieve the value.

This allows PSBT_ELEMENTS_GLOBAL_SCALAR to be parsed when it is
serialized according to the spec, i.e. both of the following cases
will correctly parse to the same representation:

$cli decodepsbt 'cHNldP8B+wQCAAAAAQIEAgAAAAEEAQABBQEAJ/wEcHNldAABAgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhscHR4fIAEAAA=='

and

$cli decodepsbt 'cHNldP8B+wQCAAAAAQIEAgAAAAEEAQABBQEAJ/wEcHNldAABAgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhscHR4fIAAA'

PSBT_ELEMENTS_GLOBAL_SCALAR is the only PSBT/PSET field that contains
key data but no value data and so is the only field that currently hits
this special case.
2022-08-09 09:35:54 +12:00
sanket1729
a142232384 Allow dumpblinding key to accept non-CT address
This facilitates the following workflow:
1) Obtain an updated psbt with in_witness_utxo and in_utxo_rangeproof
2) Get the blinding key from the input utxo address obtained from input
script pubkey without revealing master blinding key
3) Rewind the proof to obtain blinding factors and implement stateless
blinding
2022-08-02 13:29:05 -07:00
Glenn Willen
87028135ad
Merge pull request #1107 from gwillen/test-fix-1058
Bring Elements up to date with Bitcoin Core 22.0 (Updated)
2022-06-28 16:27:30 -07:00
Glenn Willen
7754db44e4 Merge 03b8b0cb91 into merged_master (Elements PR ElementsProject/elements#1111) 2022-06-27 13:11:53 -07:00
Steven Roose
3e77addbd2
Improve the JSON representation of dynafed parameters 2022-06-07 10:00:35 +01:00
James Dorfman
efdb2f4df3 getblockchaininfo: remove incorrect fields 'signblock_asm' and 'signblock_hex' from rpc response 2022-04-28 10:14:03 -04:00
Glenn Willen
5889a844db Merge 2dda79cf61 into merged_master (Elements PR ElementsProject/elements#1094) 2022-04-21 15:54:34 -07:00
Glenn Willen
f035196ceb Merge 586e5c7dd7 into merged_master (Elements PR ElementsProject/elements#1062) 2022-04-20 21:51:53 -07:00
Glenn Willen
bf7f050aeb Raise max P2P message size to account for larger elements dynafed header size 2022-03-01 14:21:52 -08:00
Pablo Greco
85c3c2b819 Deprecate con_dyna_deploy_start in favor of evbparams 2021-11-23 14:36:03 +00:00
Pablo Greco
24cafa50cf Implement vbparams for Elements (evbparams) 2021-11-23 14:36:03 +00:00
Andrew Poelstra
242586cea6 lint: fix pylint issues 2021-10-15 00:20:23 +00:00
Andrew Poelstra
ba8273ac94 lint: fix non-pylint linter errors
Includes fixing all the spelling mistakes that are our fault,
but not those present upstream in Core.
2021-10-15 00:20:20 +00:00
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
7b69a940eb Merge 846ab81794 into merged_master (Elements PR ElementsProject/elements#1051) 2021-10-02 13:27:49 +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
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
daa471ddd2 Merge 4c7dc0620a into merged_master (Elements PR ElementsProject/elements#1046) 2021-09-22 02:26:13 +00:00
Andrew Poelstra
d1a1d19113 test: add decodepsbt and analyzepsbt tests for blinding proofs 2021-09-21 21:59:16 +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
71c9e90fa0 test: add another functional test for rangeproofs in issuances 2021-09-20 22:10:50 +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
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
7d39e430c7 test: check that signrawtransaction does not erase RANGEPROOF signatures 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
5d8b55ce47 Merge f7f9555792 into merged_master (Elements PR ElementsProject/elements#1044) 2021-09-18 23:15:14 +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