Commit graph

5021 commits

Author SHA1 Message Date
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
Glenn Willen
06070070a3 ci: Temporarily suppress leak-detection of wallet objects loaded at startup 2022-05-25 11:48:35 -07: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