Skip to content

BIP458: Half-Aggregation of BIP 340 Signatures - #2205

Merged
jonatack merged 3 commits into
bitcoin:masterfrom
fjahr:halfagg
Nov 2, 2026
Merged

jonatack merged 3 commits into
bitcoin:masterfrom
fjahr:halfagg

Conversation

@fjahr

@fjahr fjahr commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

This is the BIP draft for half-aggregation of BIP340 Schnorr signatures, which has marinated at https://github.com/BlockstreamResearch/cross-input-aggregation/blob/master/half-aggregation.mediawiki long enough.

Mailing list discussion: https://gnusha.org/pi/bitcoindev/33f275c2-06b1-4b4a-2a75-cafe36836503@gmail.com/

Compared to the master version of the BIP linked above and the state of things at the time of sharing this on the mailing list, this version has a few minor typo fixes as well as three significant changes:

  1. Removal of a max signatures limit, see halfagg: Remove fixed limit BlockstreamResearch/cross-input-aggregation#16
  2. Replacement of the reference implementation in hacspec with one in Python, based on secp256k1lab. See halfagg: Add Python specification and extensive test vectors BlockstreamResearch/cross-input-aggregation#21 which also adds the test vectors

Given the Python reference implementation, I am vendoring the latest master of secp256k1lab with the BIP, as seems to be the standard with other BIPs (seen merged at 374 and in the pull for 445).

@jonatack jonatack left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks quite complete. Might be good to add a backward compatibility section (if not needed, that could be explicitly stated).

Comment thread bip-XXXX.mediawiki Resolved
Comment thread bip-0458.mediawiki Resolved
fjahr added a commit to fjahr/secp256k1 that referenced this pull request Jun 28, 2026
Code is based on the secp256k1-zkp implementation. Test vectors based on
the draft BIP: bitcoin/bips#2205

Co-authored-by: Benedikt <crypto@benedikt-wagner.dev>
fjahr added a commit to fjahr/secp256k1 that referenced this pull request Jun 28, 2026
Code is based on the secp256k1-zkp implementation. Test vectors based on
the draft BIP: bitcoin/bips#2205

Co-authored-by: Benedikt <crypto@benedikt-wagner.dev>
fjahr added a commit to fjahr/secp256k1 that referenced this pull request Jun 28, 2026
Code is based on the secp256k1-zkp implementation. Test vectors based on
the draft BIP: bitcoin/bips#2205

Co-authored-by: Benedikt <crypto@benedikt-wagner.dev>
@fjahr

fjahr commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

Addressed your comments @jonatack , thanks!

Might be good to add a backward compatibility section (if not needed, that could be explicitly stated).

I added a "section not needed" section ;)

@theStack theStack left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice! Left some notation and style nits below (mostly related to secp256k1lab usage).

Comment thread bip-XXXX/run_test_vectors.py Resolved
Comment thread bip-0458.mediawiki

==== Notation ====

The following conventions are used, with constants as defined for [https://www.secg.org/sec2-v2.pdf secp256k1]. We note that adapting this specification to other elliptic curves is not straightforward and can result in an insecure scheme<ref>Among other pitfalls, using the specification with a curve whose order is not close to the size of the range of the nonce derivation function is insecure.</ref>.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fwiw, in BIP-445 a different notation is used (for the first time, as far as I'm aware) that leans more to secp256k1lab, with a table showing how the notation maps to the lab functions: https://github.com/siv2r/bips/blob/bip-frost-signing/bip-0445.md?plain=1#L255

(I found that quite a nice idea for improved readability and hopefully easier navigation through the reference implementation; but that's of course more a nit than a requirement; ultimately it's up to the BIP authors).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I didn't quite pick up on this despite looking at the BIP445 draft for some inspiration. But I am not sure it's the best idea to adapt this notation fully here. I think there is also some value in having the notation closer to BIP340 which is a prerequisite to this BIP here while BIP445 is not directly related. I did steal the idea of the mapping table though, please let me know if you agree with this decision and think the mapping table on it's own is helpful.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah good point, keeping the notation intentionally close to BIP340 seems reasonable. I think the small mapping table you added is definitely helpful for (reference implementation) readers.

Comment thread bip-XXXX/halfagg.py Resolved
Comment thread bip-XXXX/halfagg.py Resolved
Comment thread bip-XXXX/halfagg.py Resolved
@fjahr

fjahr commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

Addressed feedback from @theStack , thanks a lot!

@murchandamus murchandamus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, that was a splendid read. I especially enjoyed the ventilated prose. Looks like you have all the sections covered, already have a reference implementation, and the text is very polished already. I don’t have any improvement suggestions at this time, so let’s just go right ahead: assigned BIP454. Please move the document and auxiliary files to the corresponding file paths, update the BIP and Assigned headers, and add a table entry to the README.mediawiki.

@murchandamus murchandamus changed the title BIP draft: Half-Aggregation of BIP 340 Signatures BIP454: Half-Aggregation of BIP 340 Signatures Jul 1, 2026
@fjahr

fjahr commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

that was a splendid read

Nice, 99% of that praise goes to @jonasnick and @real-or-random !

assigned BIP454

Thanks! I applied the necessary changes.

@murchandamus murchandamus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Changes LGTM. Since this just got opened, I suggest we let it simmer for at least a couple weeks to see if there is any more useful review, but otherwise, this seems pretty much ready for publication to me. What do you think?

@fjahr

fjahr commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

Since this just got opened, I suggest we let it simmer for at least a couple weeks to see if there is any more useful review, but otherwise, this seems pretty much ready for publication to me. What do you think?

Yeah, that sounds good for me. I will publish the draft for fullagg shortly and maybe there will be some additional feedback here from having the two side by side.

@murchandamus murchandamus changed the title BIP454: Half-Aggregation of BIP 340 Signatures BIP458: Half-Aggregation of BIP 340 Signatures Jul 6, 2026
@murchandamus

Copy link
Copy Markdown
Member

Assigned new number per request of @fjahr. Let’s refer to this as 458 instead of 454. Please update the table and preamble accordingly.

@fjahr

fjahr commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Assigned new number per request of @fjahr. Let’s refer to this as 458 instead of 454. Please update the table and preamble accordingly.

Done! Thanks and sorry for the inconvenience.

@murchandamus

Copy link
Copy Markdown
Member

Since the Full-Aggregation BIP has just been out for a few days, I’ll hold off on merging this. Are you also expecting to submit the CISA BIP soon or will that be much later?

@fjahr

fjahr commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

Are you also expecting to submit the CISA BIP soon or will that be much later?

I hope to do it very soon, a couple of days

@murchandamus

Copy link
Copy Markdown
Member

Great, let’s aim to publish them together, when they all have been open for a bit.

Comment thread bip-0458.mediawiki Outdated
Status: Draft
Type: Specification
Assigned: 2026-07-02
License: BSD-3-Clause

@real-or-random real-or-random Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
License: BSD-3-Clause
License: CC0-1.0 or MIT

It may not matter at all in the future, but let's change this if we all agree here (cc @jonasnick).

I helped with the Licensing section in BIP3, and there's a reason why this has License: CC0-1.0 or MIT as an example:

  • When it comes to the text, CC0 is made with documents in mind and not just code, and works internationally. Plus, it's great to have the test vectors in CC0, so people can copy them to their repos without any legal obligation.
  • When it comes to code, MIT is just the more natural choice given that Bitcoin Core and most of the ecosystem is MIT-licensed. (For some reason, people started licensing BIPs under BSD3 licenses... There's nothing wrong with mixing MIT and BSD, but the ability to distribute all your code under a single license makes things a tiny bit easier.)

And with the OR we just give readers/users the best of both worlds.

(The same comment applies to the full-agg BIP modulo that you can decide on your own there.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds good to me! I will push the change but I can revert if @jonasnick has any objections! I will make the same change in BIP459.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No objection, sounds good.

jonasnick added a commit to SHRINCS/shrincs-bip that referenced this pull request Jul 27, 2026
@fjahr

fjahr commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Added a small note on how to avoid quadratic hashing in implementation code

Comment thread bip-0458/halfagg.py Resolved
Comment thread bip-0458.mediawiki Resolved
@fjahr

fjahr commented Sep 12, 2026

Copy link
Copy Markdown
Contributor Author

Addressed feedback from @theStack , thanks a lot!

@baslabofhd777-lab

This comment was marked as spam.

@fjahr

fjahr commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

Applied the latest comments from #2210 here as well: the randomizer tag is now BIP0458/randomizer and the test vectors are regenerated. I also dropped the point-to-bytes notation instead of renaming it, since this BIP never converts a point to bytes, and fixed the challenge line in VerifyAggregate to hash r_i directly.

Note that the tag change means the spec now diverges from the schnorrsig_halfagg module in secp256k1-zkp. Its aggregates and test vectors are no longer valid under this BIP.

Comment thread bip-0458/halfagg.py Resolved
Comment thread bip-0458.mediawiki Resolved

@PeterXMR PeterXMR left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice work. One gap: the 32/32/64-byte input sizes are stated in the Input sections but never enforced, in either the spec or halfagg.py. On the current head, Aggregate + VerifyAggregate accept 0-, 31-, 33- and 100-byte messages and a 65-byte sig. A 31-byte pk hits an AssertionError instead of failing. Suggestions inline. Happy to add a FALSE verify vector for a 33-byte message (aggsig valid over that message) if useful.

Comment thread bip-0458.mediawiki Resolved
Comment thread bip-0458/halfagg.py Resolved
Add a vendored copy of the secp256k1lab library (master branch, commit
a265da139aea27386085a2a8760f8698e1bda64e) that the half-aggregation
reference implementation and test vector scripts depend on.
@fjahr

fjahr commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Addressed feedback from @PeterXMR and @theStack , thanks for the review!

@fametrano fametrano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment: the size checks are in halfagg.py but not yet in the pseudocode, and the vectors miss two of the sizes. I wrote an independent implementation from the pseudocode on btclib-ecc to check the size limits PeterXMR raised. All 47 vectors pass at the current head, and halfagg.py now refuses each wrong size I tried.

The pseudocode only says "32-byte" in the Input lists. It has no fail step for the key, message or signature sizes, though it has one for aggsig. Copying the line PeterXMR suggested into IncAggregate and VerifyAggregate would close that. The vectors only test messages that are too long and keys that are too short. A check of len(m) > 32 alone, or len(pk) < 32 alone, passes all 47. Two FALSE verify vectors catch both, each a valid signature over the wrong-size input. The first is vector 23 built with create_signature(0, 31), a 31-byte message. The second is vector 1 with its key prefixed by 02, a 33-byte key that a library accepting SEC keys verifies as true. I ran the vectors through my implementation and halfagg.py, and the weakened check through mine. I can share the code.

pmazzocchi pushed a commit to btclib-org/ecc that referenced this pull request Oct 28, 2026
* Add BIP458 half-aggregation of BIP340 signatures (issue #365)

ecc.ecc.ssa_halfagg aggregates BIP340 signatures into one signature of
32*(u+1) bytes, adds signatures to an existing aggregate, and verifies
an aggregate against its (public key, message) pairs: aggregate,
inc_aggregate, verify and assert_as_valid.

It is written from the pseudocode of bitcoin/bips#2205 at 2f436b02f60b,
without reading the reference code. The draft's three vector files are
vendored under tests/schemes/_data/ and run, and every vector agrees but
the empty aggregate described below.

verify follows the tree's bool contract: a key, a message or an
aggregate of the wrong size raises, and an empty list of pairs raises
where BIP458 accepts an empty aggregate with s = 0, as ssa.batch_verify
refuses an empty batch, and CONTRIBUTING.md's paragraph on that
exception names both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Ferdinando Ametrano <ferdinando@ametrano.net>

* Answer review of the BIP458 half-aggregation (issue #365)

- curve.py: name the callers of _multi_mult_x_only_var without counting them.
- curve.py: multi_mult_var's docstring names the verifications, not "those last two".
- tests/_data/README.md: link ISS 365.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Ferdinando Ametrano <ferdinando@ametrano.net>

* Raise EccValueError for a tuple of the wrong arity in ssa_halfagg (issue #365)

A pair where a triple belongs, and the converse, is a wrong value, as
for a Point in tests/input_validation_test.py, not a wrong type.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Ferdinando Ametrano <ferdinando@ametrano.net>

* Answer review of the wrong-arity decision (issue #365)

- CONTRIBUTING.md: a tuple of the wrong arity is a wrong value.
- tests/input_validation_test.py: _WRONG_VALUE's header names that exception.
- ssa_halfagg.py: inc_aggregate and verify name the wrong arity among what raises.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Ferdinando Ametrano <ferdinando@ametrano.net>

* Rewrap the verify docstring to 80 columns (issue #365)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Ferdinando Ametrano <ferdinando@ametrano.net>

* Cut the _WRONG_VALUE header to the arity exception (issue #365)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Ferdinando Ametrano <ferdinando@ametrano.net>

* Narrow the wrong-arity paragraph to what the tree keeps (issue #365)

negate and negate_jac raise EccTypeError for a tuple of the wrong length,
and tests/curves/curve_test.py pins it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Ferdinando Ametrano <ferdinando@ametrano.net>

* Name negate and negate_jac as the wrong-arity exception (issue #365)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Ferdinando Ametrano <ferdinando@ametrano.net>

* Call the negate EccTypeError a leftover (issue #365)

negate and negate_jac raise EccTypeError for a tuple of the wrong
length. That is a leftover, not a choice: #377 moves them
to EccValueError. CONTRIBUTING.md says so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Ferdinando Ametrano <ferdinando@ametrano.net>

---------

Signed-off-by: Ferdinando Ametrano <ferdinando@ametrano.net>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@fjahr

fjahr commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

The pseudocode only says "32-byte" in the Input lists. It has no fail step for the key, message or signature sizes, though it has one for aggsig.

This is intentional. The pseudocode follows the examples of BIP 340 and BIP 327, which have fixed sizes on the input and use fail steps only for value checks. aggsig gets a fail step because its input is a byte array of variable length. Otherwise it seems enough to have the reference code enforce the sizes, and the rationale mention why messages must be exactly 32 bytes. Maybe my earlier response was not clear enough about this.

The vectors only test messages that are too long and keys that are too short. A check of len(m) > 32 alone, or len(pk) < 32 alone, passes all 47.

I added a 31-byte message and your 02-prefix key suggestion as fail vectors to each of the vector files.

@fametrano

Copy link
Copy Markdown
Contributor

You are right, and I am sorry for the extra round. BIP 340 and BIP 327 give the sizes only in their input lists, so the fail steps I asked for in the pseudocode would break that pattern. I withdraw that part of my earlier review.

Thank you for the new vectors. I ran all 53 at fe78361 against btclib-ecc, an independent implementation I maintain: 52 pass. The other is verify vector 0, the empty aggregate, which btclib-ecc refuses on purpose. Verify vector 24 verifies as TRUE if its 02 prefix is dropped, as a library accepting 33-byte keys would do. Vector 25 verifies as TRUE if its 31-byte message goes unchecked. Both now catch the weakened checks. The script, the command and the output are in https://gist.github.com/fametrano/8a91810a284958d5ef56ca906478654a/b46e508ba94fc699e7c29971ad9c6ab153ed7eae.

@jonatack jonatack left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACK

@jonatack
jonatack merged commit ada3419 into bitcoin:master Nov 2, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants