test: add test for decoding PSBT with MuSig2 PSBT key types (BIP 373) #32305

pull theStack wants to merge 2 commits into bitcoin:master from theStack:202504-test-add_musig2_decodepsbt_tests changing 2 files +79 −0
  1. theStack commented at 9:35 pm on April 18, 2025: contributor
    This PR is a follow-up to #31247 (see #31247#pullrequestreview-2427834909) and adds a functional test for decoding PSBTs (using the decodepsbt RPC) with MuSig2 per-input and per-output types. The first commit adds the new MuSig2 key types to the test frameworks and extends the PSBT serialization to cope with lists of bytestrings.
  2. test: add constants for MuSig2 PSBT key types (BIP 373)
    Also, support serialization of lists of byte-strings as PSBTMap values,
    which will be simply concatenated without any compact-size prefixes
    (neither for the individual items nor for the size of the list).
    e5537de0ab
  3. test: add test for decoding PSBT with MuSig2 PSBT key types (BIP 373) 23ee07dd0f
  4. DrahtBot commented at 9:35 pm on April 18, 2025: contributor

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

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32305.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK rkrux

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

  5. DrahtBot added the label Tests on Apr 18, 2025
  6. maflcko commented at 12:06 pm on April 21, 2025: member
    (fresh CI)
  7. maflcko closed this on Apr 21, 2025

  8. maflcko reopened this on Apr 21, 2025

  9. in test/functional/test_framework/psbt.py:96 in e5537de0ab outdated
    91@@ -88,6 +92,9 @@ def serialize(self):
    92         for k,v in self.map.items():
    93             if isinstance(k, int) and 0 <= k and k <= 255:
    94                 k = bytes([k])
    95+            if isinstance(v, list):
    96+                assert any(type(elem) is bytes for elem in v)
    


    rkrux commented at 1:33 pm on April 21, 2025:
    Since this is a new check that has been added & the current use case is of a list of only bytes (in participant pubkeys), maybe we can assert this on all instead of any to keep the checking strict to start with that can be eased in the future if needed?
  10. in test/functional/rpc_psbt.py:1020 in 23ee07dd0f
    1015+
    1016+        assert "musig2_participant_pubkeys" in res_input
    1017+        in_participant_pks = res_input["musig2_participant_pubkeys"][0]
    1018+        assert "aggregate_pubkey" in in_participant_pks
    1019+        assert_equal(in_participant_pks["aggregate_pubkey"], in_fake_agg_pubkey.hex())
    1020+        assert "participant_pubkeys" in in_participant_pks
    


    rkrux commented at 1:34 pm on April 21, 2025:
    Are asserts like on this line really needed? If the decoded psbt is malformed then the test would fail in the following assert anyway.
  11. in test/functional/rpc_psbt.py:984 in 23ee07dd0f
    980@@ -977,6 +981,74 @@ def test_psbt_input_keys(psbt_input, keys):
    981             assert hash.hex() in res_input[preimage_key]
    982             assert_equal(res_input[preimage_key][hash.hex()], preimage.hex())
    983 
    984+        self.log.info("Test decoding PSBT with MuSig2 per-input and per-output types")
    


    rkrux commented at 1:35 pm on April 21, 2025:
    Nit: Maybe consider putting this in a separate subtest as the current run_test is quite long already.
  12. in test/functional/rpc_psbt.py:1050 in 23ee07dd0f
    1045+        assert "musig2_participant_pubkeys" in res_output
    1046+        out_participant_pks = res_output["musig2_participant_pubkeys"][0]
    1047+        assert "aggregate_pubkey" in out_participant_pks
    1048+        assert_equal(out_participant_pks["aggregate_pubkey"], out_fake_agg_pubkey.hex())
    1049+        assert "participant_pubkeys" in out_participant_pks
    1050+        assert_equal(out_participant_pks["participant_pubkeys"], [out_pubkey1.hex(), out_pubkey2.hex()])
    


    rkrux commented at 1:38 pm on April 21, 2025:
    Fine for now but maybe we can consider making an assert_musig2_fields() later when more musig2 specific tests are added - if needed though.
  13. rkrux approved
  14. rkrux commented at 1:41 pm on April 21, 2025: contributor

    tACK 23ee07dd0f81930f46d2f4910cc92cb0eab61cc3

    I believe this is a value add as it sets the base for the MuSig2 functional testing. I left few minor suggestions, I would be quick to re-ack if they are implemented.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-05-05 15:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me