-
Notifications
You must be signed in to change notification settings - Fork 37.7k
test: MiniWallet: fix fee calculation for P2PK and check tx vsize #22089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: MiniWallet: fix fee calculation for P2PK and check tx vsize #22089
Conversation
Thanks for the explanation in the PR. I like your approach, but I'm wondering if this will still be accurate about So it seems like the fee rate won't be exact anymore unless i'm missing something. I feel like it might be a problem for some tests if It's probably not an issue when no fee rate has been specified, but perhaps in the case where the user does specify a fee rate then the signature could be restricted to 71 bytes? |
@DariusParvin: Thanks for reviewing, you brought up an interesting point here. Indeed, the promise "
Good question, I don't know enough of the "big picture" of all tests to know whether having exact fees is something that is really needed (and if it really is, if the anyone-can-spend modes are not sufficient then?). I could generally think of two possible solutions:
Since the |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last run. |
I think that's a reasonable compromise. The only thing is I think it might be better to have the default be True instead, mainly because the fee rate is quite important for a few tests (e.g. getting included in a block, replaced in the mempool, fee limits) and it could be very hard to debug if the fee rate is random between test runs. |
In order to enable exact fee calculation for transactions that spend P2PK outputs in the MiniWallet, we enforce the created signatures to have a fixed length (>49.89% probability) by default. With that it is easier to check the created transactions vsize and avoid flaky tests that would appear whenever the signatures R- or S-values are smaller (due to leading zero bytes). Note that to get the total scriptSig size one has to add another 2 bytes, as there is also the OP_PUSHx instruction on the front and the sighash type byte on the back, leading to a final scriptSig size of 73 bytes.
9bef494
to
d6d2ab9
Compare
Rebased on master, changed
@DariusParvin: After repeatedly executing the test |
Concept ACK d6d2ab9 |
…nd check tx vsize d6d2ab9 test: MiniWallet: fix fee calculation for P2PK and check tx vsize (Sebastian Falbesoner) ce024b1 test: MiniWallet: force P2PK signature to have fixed size (71 bytes) (Sebastian Falbesoner) Pull request description: This PR is a follow-up to bitcoin#21945. It aims to both fix the fee calculation for P2PK mode transactions and enable its vsize check. Currently, the latter assumes a fixed tx length, which is fine for anyone-can-spend txs but doesn't apply to P2PK output spends due to varying DER signature size; the vsize check is therefore disabled for P2PK mode on master branch. Creating one million DER signatures with MiniWallet shows the following distribution of sizes (smart people with better math skills probably could deduce the ratios without trying, but hey): | DER signature size [bytes] | #occurences (ratio) | | ------------- | ------------- | | 71 | 498893 (49.89%) | | 70 | 497244 (49.72%) | | 69 | 3837 (0.38%) | | 68 | 22 (0.0022%) | Note that even smaller signatures are possible (for smaller R and S values with leading zero bytes), it's just that the probability decreases exponentially. Instead of choosing a large vsize check range and hoping that smaller signatures are never created (potentially leading to flaky tests), the proposed solution is ~~to limit the signature size to the two most common sizes 71 and 70 (>99.6% probability) and then accordingly only check for two vsize values; the value to be used for fee calculation is a decimal right between the two possible sizes (167.5 vbytes) and for the vsize check it's rounded down/up integer values are used.~~ to simply grind the signature to a fixed size of 71 bytes (49.89% probability, i.e. on average each call to `sign_tx()`, on average two ECC signing operations are needed). ~~The idea of grinding signatures to a fixed size (similar to bitcoin#13666 which grinds to low-R values) would be counter-productive, as the signature creation in the test suite is quite expensive and this would significantly slow down tests that calculate hundreds of signatures (like e.g. feature_csv_activation.py).~~ For more about transaction sizes on different input/output types, see the following interesting article: https://medium.com/coinmonks/on-bitcoin-transaction-sizes-97e31bc9d816 ACKs for top commit: MarcoFalke: Concept ACK d6d2ab9 Tree-SHA512: 011c70ee0e4adf9ba12902e4b6c411db9ae96bdd8bc810bf1d67713367998e28ea328394503371fc1f5087a819547ddaea56c073b28db893ae1c0031d7927f32
This PR is a follow-up to #21945. It aims to both fix the fee calculation for P2PK mode transactions and enable its vsize check. Currently, the latter assumes a fixed tx length, which is fine for anyone-can-spend txs but doesn't apply to P2PK output spends due to varying DER signature size; the vsize check is therefore disabled for P2PK mode on master branch.
Creating one million DER signatures with MiniWallet shows the following distribution of sizes (smart people with better math skills probably could deduce the ratios without trying, but hey):
Note that even smaller signatures are possible (for smaller R and S values with leading zero bytes), it's just that the probability decreases exponentially. Instead of choosing a large vsize check range and hoping that smaller signatures are never created (potentially leading to flaky tests), the proposed solution is
to limit the signature size to the two most common sizes 71 and 70 (>99.6% probability) and then accordingly only check for two vsize values; the value to be used for fee calculation is a decimal right between the two possible sizes (167.5 vbytes) and for the vsize check it's rounded down/up integer values are used.to simply grind the signature to a fixed size of 71 bytes (49.89% probability, i.e. on average each call tosign_tx()
, on average two ECC signing operations are needed).The idea of grinding signatures to a fixed size (similar to #13666 which grinds to low-R values) would be counter-productive, as the signature creation in the test suite is quite expensive and this would significantly slow down tests that calculate hundreds of signatures (like e.g. feature_csv_activation.py).For more about transaction sizes on different input/output types, see the following interesting article: https://medium.com/coinmonks/on-bitcoin-transaction-sizes-97e31bc9d816