Skip to content

Conversation

@theStack
Copy link
Contributor

This PR adds missing test coverage for the -bytespersigop option, which determines how pre-taproot signature operations (OP_CHECKSIG{VERIFY}, OP_CHECKMULTIGSIG{VERIFY}) affect fee handling calculations. The setting was introduced in PR #7081 for mitigating the sigop spam attack; the initial implementation rejected txs exceeding the limit, but was changed in #8365 later to account for higher sizes in the mempool (i.e. exceeding the sigop limit is possible, but has to be compensated by higher fees).

For each combination of -bytespersigop setting and sigops count, the test first creates a P2WSH spending transaction with a witness script that puts sigops in a non-executing branch (OP_FALSE OP_IF OP_CHECKMULTISIG ... OP_CHECKSIG ... OP_ENDIF). This tx is then bumped up to reach exactly the sig-op limit equivalent vsize by padding its datacarrier output. Based on that, increasing the tx's vsize should still reflect a vsize increase in the mempool, while a decrease of the tx's vsize should lead to the mempool treating the tx's vsize to be the sig-op limit equivalent vsize, since the limit was exceeded.

I assume that this parameter is almost never set explicitly by users (also it is not relevant for taproot spends), but it doesn't hurt to have a test for it. See also https://bitcoin.stackexchange.com/a/87958 for another explanation.

@DrahtBot
Copy link
Contributor

DrahtBot commented Feb 28, 2023

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK glozow, MarcoFalke

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

@DrahtBot DrahtBot added the Tests label Feb 28, 2023
@theStack theStack force-pushed the 202302-add_bytespersigop_test branch from 7ac70fa to 4ff0a26 Compare February 28, 2023 00:59
@fanquake fanquake requested a review from glozow February 28, 2023 09:29
Copy link
Member

@glozow glozow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

Comment on lines 102 to 103
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if I'm misunderstanding this comment but afaik the reason is that txsize is max(serialized size, "sigop" size), not that fees have any impact?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intention was to express the implication of exceeding the sig-op limit from a user's perspective (tx is treated as larger than it's serialized vsize => more fees needed to reach the same fee-rate; or as PR desc of #8365 put it "high-sigop transactions [...] need to pay a fee corresponding to the maximally-used resource."). Agree that the comment is rather misleading and not very helpful for the test, replaced it.

Generally struggled a bit with terminology for this PR (not even sure if talking about a "limit" is proper, usually we reject txs from mempool if limits are exceeded), suggestions of course very welcome.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see where that comes from, thanks for clarifying! Comment does look better to me now.

@theStack theStack force-pushed the 202302-add_bytespersigop_test branch from 4ff0a26 to 89cd20c Compare March 7, 2023 03:24
Copy link
Member

@glozow glozow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

light review ACK 89cd20c

(Doesn't need to be in this PR) it could be worth checking that this vsize calculation is used for anc/desc limits as well?

@fanquake fanquake requested a review from maflcko March 8, 2023 17:47
Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice ACK 89cd20c 📁

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: nice ACK 89cd20cbedbba344bab92dd1d71dac9c84320a70  📁
B5cwOnNBzAlwwLnU0zkxGtximOvhWc70b8b8cIBDwmGXl+th6o29WfVzP4QXUU+NEdze0Yl8uHyok7mzdst1AQ==

num_singlesigops = num_sigops % 20
witness_script = CScript(
[OP_FALSE, OP_IF] +
[OP_CHECKMULTISIG]*num_multisigops +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for reference, usually fAccurate is set for witness scripts sigop counts, but omitting the k and n in the CMS imitates fAccurate=false.

@fanquake fanquake merged commit 3e7dd4f into bitcoin:master Mar 10, 2023
@fanquake
Copy link
Member

@theStack could open a followup addressing anything here?

(Doesn't need to be in this PR) it could be worth checking that this vsize calculation is used for anc/desc limits as well?

for reference, usually fAccurate is set for witness scripts sigop counts, but omitting the k and n in the CMS imitates fAccurate=false.

@maflcko
Copy link
Member

maflcko commented Mar 10, 2023

My comment was only meant for reviewers. A unit test may be more appropriate if someone wants to check the behavior of the sigop counting function itself.

@theStack theStack deleted the 202302-add_bytespersigop_test branch March 10, 2023 14:31
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Mar 10, 2023
…espersigop` setting)

89cd20c test: add coverage for sigop limit policy (`-bytespersigop` setting) (Sebastian Falbesoner)

Pull request description:

  This PR adds missing test coverage for the `-bytespersigop` option, which determines how pre-taproot signature operations (OP_CHECKSIG{VERIFY}, OP_CHECKMULTIGSIG{VERIFY}) affect fee handling calculations. The setting was introduced in PR bitcoin#7081 for mitigating the [sigop spam attack](https://bitcointalk.org/index.php?topic=1166928.0); the initial implementation rejected txs exceeding the limit, but was changed in bitcoin#8365 later to account for higher sizes in the mempool (i.e. exceeding the sigop limit is possible, but has to be compensated by higher fees).

  For each combination of `-bytespersigop` setting and sigops count, the test first creates a P2WSH spending transaction with a witness script that puts sigops in a non-executing branch (OP_FALSE OP_IF OP_CHECKMULTISIG ... OP_CHECKSIG ... OP_ENDIF). This tx is then bumped up to reach exactly the _sig-op limit equivalent vsize_ by padding its datacarrier output. Based on that, increasing the tx's vsize should still reflect a vsize increase in the mempool, while a decrease of the tx's vsize should lead to the mempool treating the tx's vsize to be the _sig-op limit equivalent vsize_, since the limit was exceeded.

  I assume that this parameter is almost never set explicitly by users (also it is not relevant for taproot spends), but it doesn't hurt to have a test for it. See also https://bitcoin.stackexchange.com/a/87958 for another explanation.

ACKs for top commit:
  glozow:
    light review ACK 89cd20c
  MarcoFalke:
    nice ACK 89cd20c  📁

Tree-SHA512: 06998ce93bf9d5ce6143db2996a43f13990c415f97afe684227ad469349e73952bf4f6c871c1e6349e07606f4d45db64408848873a86a89481cdca5a134e5e60
@theStack
Copy link
Contributor Author

@theStack could open a followup addressing anything here?

(Doesn't need to be in this PR) it could be worth checking that this vsize calculation is used for anc/desc limits as well?

for reference, usually fAccurate is set for witness scripts sigop counts, but omitting the k and n in the CMS imitates fAccurate=false.

Yes, I'm planning to do a follow-up next week, extending the checks on ancestor/descendant limits is definitely a good idea! Regarding Marco's explanation w.r.t. fAccurate, will consider adding a small explanation comment (something like e.g. "if k and n are omitted, the sig-ops costs of OP_CMS are 20 even in witness spends").

fanquake added a commit to bitcoin-core/gui that referenced this pull request Mar 19, 2023
…s ancestor/descendant size (27171 follow-up)

6d24d1e test: check that sigop limit also affects ancestor/descendant size (Sebastian Falbesoner)

Pull request description:

  This is a follow-up to #27171, adding a check that the sigop-limit vsize logic is also respected for {ancestor,descendant}size calculation (as suggested in bitcoin/bitcoin#27171 (review)). For simplicity, we use a one-parent-one-child cluster here and only check for the case that the sigop-limit equivalent size is larger than the serialized vsize.

ACKs for top commit:
  glozow:
    code review ACK 6d24d1e, thanks for taking!

Tree-SHA512: dc65e455d06cfef1f1d6a53b959f99ec1ca3fe51c98dc1ed5826614b5619773d34aff0171c43a0ede4fd45605b2eb7a9278e027196128bb7ad8586b859f1cf70
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Mar 19, 2023
…or/descendant size (27171 follow-up)

6d24d1e test: check that sigop limit also affects ancestor/descendant size (Sebastian Falbesoner)

Pull request description:

  This is a follow-up to bitcoin#27171, adding a check that the sigop-limit vsize logic is also respected for {ancestor,descendant}size calculation (as suggested in bitcoin#27171 (review)). For simplicity, we use a one-parent-one-child cluster here and only check for the case that the sigop-limit equivalent size is larger than the serialized vsize.

ACKs for top commit:
  glozow:
    code review ACK 6d24d1e, thanks for taking!

Tree-SHA512: dc65e455d06cfef1f1d6a53b959f99ec1ca3fe51c98dc1ed5826614b5619773d34aff0171c43a0ede4fd45605b2eb7a9278e027196128bb7ad8586b859f1cf70
@bitcoin bitcoin locked and limited conversation to collaborators Mar 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants