Commit graph

4299 commits

Author SHA1 Message Date
Pablo Greco
380660016a
Merge pull request #1258 from goatpig/spend_fix
KnapsackSolver fix
2023-10-18 10:59:41 -03:00
Pablo Greco
defeec2b8c Merge branch 'master' into elements-22.1.2-rc1-prep 2023-08-24 15:12:55 -07:00
Byron Hambly
a8b0ed6f96
test: add functional test for issue #1259
Adds a functional test to cover the issue uncovered in #1259, where
calling fundrawtransaction with many non-policy inputs and no policy
recipients results in an assertion failure and a crash.

Fixed in #1258.
2023-08-18 16:19:34 +02:00
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
roconnor-blockstream
f8bf7c6269 test: Replace 0xC0 constant
Instead it should be the named constant `LEAF_VERSION_TAPSCRIPT`.

Github-Pull: #27143
Rebased-From: c3b4b5a142
(cherry picked from commit c3b4b5a142)
2023-02-24 14:22:36 -03:00
Pablo Greco
5bbdb64af8 Fix tests after backport of #26275 2022-12-07 20:13:57 +00:00
muxator
7ffaf1b573 rpc: add non-regression test about deriveaddresses crash when index is 2147483647
This test would cause a crash in bitcoind (see #26274) if the fix given in the
previous commit was not applied.

Github-Pull: #26275
Rebased-From: 9153ff3e27
(cherry picked from commit 403de22119f5c65a9fd43a665c469512b967ed38)
2022-12-07 20:13:57 +00:00
Martin Zumsande
856ba34e21 test: Call ceildiv helper with integer
It returns an incorrect result when called with a Decimal,
for which the "//" operator works differently.
Also drop unnecessary call to satoshi_round.

Github-Pull: #24239
Rebased-From: d1fab9d5d2
(cherry picked from commit 269553fe73b17f8acda3071a48836c66092d31d0)

NB: This code is commented out in elements and the cherry-pick is done
commenting out the code too.
2022-12-07 20:08:16 +00:00
Pablo Greco
e528b34ed8 Fix tests after backport of #22949 2022-12-07 11:11:30 +00:00
Andrew Chow
2c72896bb3 tests: Calculate fees more similarly to CFeeRate::GetFee
Because of floating point precision issues, not all of the rounding done
is always correct. To fix this, the fee calculation for
assert_fee_amount is changed to better reflect how CFeeRate::GetFee does
it.

First the feerate is converted to an int representing sat/kvb. Then this
is multiplied by the transaction size, divivided by 1000, and rounded up
to the nearest sat. The result is then converted back to BTC (divided by
1e8) and then rounded down to the nearest sat to avoid precision errors.

Github-Pull: #22949
Rebased-From: 80dc829be7
(cherry picked from commit c768bfa08af034c744402d4294cc323d653b97b8)
2022-12-07 11:11:30 +00:00
Andrew Chow
66d12ce52d tests: Test for assertion when feerate is rounded down
When calculating a txs absolute fee, if the fee is rounded down to the
nearest satoshi, it is possible for the coin selection algorithms to
undercalculate the fee needed. This can lead to an assertion error in
some situations. One such scenario is added to
rpc_fundrawtransaction.py.

Github-Pull: #22949
Rebased-From: ce2cc44afd
(cherry picked from commit f66bc42957ad2e86982c8c487f821683d3009b43)
2022-12-07 11:11:30 +00:00
Andrew Chow
5f376a3588 fees: Always round up fee calculated from a feerate
When calculating the fee for a given tx size from a fee rate, we should
always round up to the next satoshi. Otherwise, if we round down (via
truncation), the calculated fee may result in a fee with a feerate
slightly less than targeted.

This is particularly important for coin selection as a slightly lower
feerate than expected can result in a variety of issues.

Github-Pull: #22949
Rebased-From: 0fbaef9676
(cherry picked from commit bd7e08e36bf2e1238ddf8cc01433f8db82f848c9)
2022-12-07 11:11:30 +00:00
MarcoFalke
df09befb2f Fix (inverse) meaning of -persistmempool
Github-Pull: #23061
Rebased-From: faff17bbde
(cherry picked from commit db76db7329f6357c5226cd08611fe0f669c002af)
2022-12-07 11:11:30 +00:00
Pablo Greco
dff0e8202b Merge branch 'master' into elements_22_1_rc1 2022-12-07 10:47:10 +00:00
Andrew Chow
42cbdc81a6 test: Test for explicit values and assets and their proofs 2022-10-18 16:52:31 -04:00
Pablo Greco
6624455ec2 Merge branch 'master' into elements-22_0_2rc1 2022-10-16 10:05:35 -03:00
Glenn Willen
d0625e1ed5 Add taproot address parsing test case, regression test for #1181. 2022-10-11 17:02:34 -07:00
Pablo Greco
fd9a1b67b9 Fix lint
(cherry picked from commit 90c4bf99f6)
2022-09-26 14:11:31 -03:00
Andrew Poelstra
005a27cac7 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.

(cherry picked from commit e5e3ec2700)
2022-09-26 14:11:31 -03:00
Andrew Poelstra
a1e1afcda1 test: rename elements_regression_1172 to follow naming convention
(cherry picked from commit 3c896b11e0)
2022-09-26 14:11:31 -03:00
Andrew Poelstra
ce496535c4 wallet: extend fix to "dropped change is the last blinded output" case
(cherry picked from commit 79fd90f064)
2022-09-26 14:11:31 -03:00
Andrew Poelstra
4553496c44 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.

(cherry picked from commit fac694be4c)
2022-09-26 14:11:31 -03: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
Pieter Wuille
069bec11b3 Swap out hashlib.ripemd160 for own implementation
Github-Pull: 23716
Rebased-From: 5b559dc7ec
2022-09-07 14:13:27 +00:00
Pieter Wuille
0f6967033d Add pure Python RIPEMD-160
Github-Pull: 23716
Rebased-From: ad3e9e1f21
2022-09-07 14:13:13 +00:00
Pablo Greco
ddeb7b99d8 Merge branch 'master' into elements-22-rc6 2022-09-07 14:09:17 +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
Andrew Chow
5629cae32b fs: Make compatible with boost 1.78
backport of https://github.com/bitcoin/bitcoin/pull/24104
2022-09-01 14:36:37 -03:00
Pablo Greco
a531cf5f77 Merge branch 'master' into elements-22-rc5 2022-09-01 14:35:09 -03: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
Glenn Willen
0229b2c277 Bring in Elements #1121 and #1131 for elements 22rc3. 2022-08-09 12:38:02 -07: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
Andrew Poelstra
7286cdc3b5 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-08-05 16:32:52 +00: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
S3RK
c9d0d0cbe4 test: fix bug in 22686
Github-Pull: bitcoin/bitcoin#22742
Rebased-From: 8dcbbbea64
2022-08-01 15:35:06 -07:00
Andrew Chow
58deead9b9 test: Test for ApproximateBestSubset edge case with too little fees
ApproximateBestSubset had an edge case (due to not using
GetSelectionAmount) where it was possible for it to return success but
fail to select enough to cover transaction fees. A test is added that
could trigger this failure prior to the fix being implemented.

Github-Pull: bitcoin/bitcoin#22686
Rebased-From: 92885c4f69
2022-08-01 15:35:06 -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