Skip to content

Commit ad1d3bc

Browse files
authored
Merge pull request bitcoin#1647 from siv2r/minor-fixes
bip327: minor fixes
2 parents 511e670 + 26bb1d8 commit ad1d3bc

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

bip-0327.mediawiki

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ Algorithm ''DeterministicSign(sk, aggothernonce, pk<sub>1..u</sub>, tweak<sub>1.
619619
* Let ''keyagg_ctx<sub>0</sub> = KeyAgg(pk<sub>1..u</sub>)''; fail if that fails
620620
* For ''i = 1 .. v'':
621621
** Let ''keyagg_ctx<sub>i</sub> = ApplyTweak(keyagg_ctx<sub>i-1</sub>, tweak<sub>i</sub>, is_xonly_t<sub>i</sub>)''; fail if that fails
622-
* Let ''aggpk = GetPubkey(keyagg_ctx<sub>v</sub>)''
622+
* Let ''aggpk = GetXonlyPubkey(keyagg_ctx<sub>v</sub>)''
623623
* Let ''k<sub>i</sub> = int(hash<sub>MuSig/deterministic/nonce</sub>(sk' || aggothernonce || aggpk || bytes(8, len(m)) || m || bytes(1, i - 1))) mod n'' for ''i = 1,2''
624624
* Fail if ''k<sub>1</sub> = 0'' or ''k<sub>2</sub> = 0''
625625
* Let ''R<sub>⁎,1</sub> = k<sub>1</sub>⋅G, R<sub>⁎,2</sub> = k<sub>2</sub>⋅G''
@@ -782,6 +782,8 @@ An exception to this rule is <code>MAJOR</code> version zero (0.y.z) which is fo
782782
The <code>MINOR</code> version is incremented whenever the inputs or the output of an algorithm changes in a backward-compatible way or new backward-compatible functionality is added.
783783
The <code>PATCH</code> version is incremented for other changes that are noteworthy (bug fixes, test vectors, important clarifications, etc.).
784784
785+
* '''1.0.2''' (2024-07-22):
786+
** Fix minor bug in the specification of ''DeterministicSign'' and add small improvement to a ''PartialSigAgg'' test vector.
785787
* '''1.0.1''' (2024-05-14):
786788
** Fix minor issue in ''PartialSigVerify'' vectors.
787789
* '''1.0.0''' (2023-03-26):
@@ -825,4 +827,4 @@ The <code>PATCH</code> version is incremented for other changes that are notewor
825827
826828
== Acknowledgements ==
827829
828-
We thank Brandon Black, Riccardo Casatta, Lloyd Fournier, Russell O'Connor, and Pieter Wuille for their contributions to this document.
830+
We thank Brandon Black, Riccardo Casatta, Sivaram Dhakshinamoorthy, Lloyd Fournier, Russell O'Connor, and Pieter Wuille for their contributions to this document.

bip-0327/gen_vectors_helper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ def sig_agg_vectors():
153153
"psig_indices": [7, 8],
154154
"error": {
155155
"type": "invalid_contribution",
156-
"signer": 1
156+
"signer": 1,
157+
"contrib": "psig",
157158
},
158159
"comment": "Partial signature is invalid because it exceeds group size"
159160
}

bip-0327/reference.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def nonce_agg(pubnonces: List[bytes]) -> bytes:
317317
('is_xonly', List[bool]),
318318
('msg', bytes)])
319319

320-
def key_agg_and_tweak(pubkeys: List[PlainPk], tweaks: List[bytes], is_xonly: List[bool]):
320+
def key_agg_and_tweak(pubkeys: List[PlainPk], tweaks: List[bytes], is_xonly: List[bool]) -> KeyAggContext:
321321
if len(tweaks) != len(is_xonly):
322322
raise ValueError('The `tweaks` and `is_xonly` arrays must have the same length.')
323323
keyagg_ctx = key_agg(pubkeys)
@@ -440,8 +440,6 @@ def partial_sig_verify_internal(psig: bytes, pubnonce: bytes, pk: bytes, session
440440
Re_s_ = point_add(R_s1, point_mul(R_s2, b))
441441
Re_s = Re_s_ if has_even_y(R) else point_negate(Re_s_)
442442
P = cpoint(pk)
443-
if P is None:
444-
return False
445443
a = get_session_key_agg_coeff(session_ctx, P)
446444
g = 1 if has_even_y(Q) else n - 1
447445
g_ = g * gacc % n
@@ -523,7 +521,7 @@ def test_key_agg_vectors() -> None:
523521

524522
assert get_xonly_pk(key_agg(pubkeys)) == expected
525523

526-
for i, test_case in enumerate(error_test_cases):
524+
for test_case in error_test_cases:
527525
exception, except_fn = get_error_details(test_case)
528526

529527
pubkeys = [X[i] for i in test_case["key_indices"]]
@@ -572,7 +570,7 @@ def test_nonce_agg_vectors() -> None:
572570
expected = bytes.fromhex(test_case["expected"])
573571
assert nonce_agg(pubnonces) == expected
574572

575-
for i, test_case in enumerate(error_test_cases):
573+
for test_case in error_test_cases:
576574
exception, except_fn = get_error_details(test_case)
577575
pubnonces = [pnonce[i] for i in test_case["pnonce_indices"]]
578576
assert_raises(exception, lambda: nonce_agg(pubnonces), except_fn)
@@ -598,7 +596,10 @@ def test_sign_verify_vectors() -> None:
598596

599597
aggnonces = fromhex_all(test_data["aggnonces"])
600598
# The aggregate of the first three elements of pnonce is at index 0
601-
assert(aggnonces[0] == nonce_agg([pnonce[0], pnonce[1], pnonce[2]]))
599+
assert (aggnonces[0] == nonce_agg([pnonce[0], pnonce[1], pnonce[2]]))
600+
# The aggregate of the first and fourth elements of pnonce is at index 1,
601+
# which is the infinity point encoded as a zeroed 33-byte array
602+
assert (aggnonces[1] == nonce_agg([pnonce[0], pnonce[3]]))
602603

603604
msgs = fromhex_all(test_data["msgs"])
604605

@@ -626,7 +627,7 @@ def test_sign_verify_vectors() -> None:
626627
assert sign(secnonce_tmp, sk, session_ctx) == expected
627628
assert partial_sig_verify(expected, pubnonces, pubkeys, [], [], msg, signer_index)
628629

629-
for i, test_case in enumerate(sign_error_test_cases):
630+
for test_case in sign_error_test_cases:
630631
exception, except_fn = get_error_details(test_case)
631632

632633
pubkeys = [X[i] for i in test_case["key_indices"]]
@@ -646,7 +647,7 @@ def test_sign_verify_vectors() -> None:
646647

647648
assert not partial_sig_verify(sig, pubnonces, pubkeys, [], [], msg, signer_index)
648649

649-
for i, test_case in enumerate(verify_error_test_cases):
650+
for test_case in verify_error_test_cases:
650651
exception, except_fn = get_error_details(test_case)
651652

652653
sig = bytes.fromhex(test_case["sig"])
@@ -702,7 +703,7 @@ def test_tweak_vectors() -> None:
702703
assert sign(secnonce_tmp, sk, session_ctx) == expected
703704
assert partial_sig_verify(expected, pubnonces, pubkeys, tweaks, is_xonly, msg, signer_index)
704705

705-
for i, test_case in enumerate(error_test_cases):
706+
for test_case in error_test_cases:
706707
exception, except_fn = get_error_details(test_case)
707708

708709
pubkeys = [X[i] for i in test_case["key_indices"]]
@@ -747,7 +748,7 @@ def test_det_sign_vectors() -> None:
747748
session_ctx = SessionContext(aggnonce, pubkeys, tweaks, is_xonly, msg)
748749
assert partial_sig_verify_internal(psig, pubnonce, pubkeys[signer_index], session_ctx)
749750

750-
for i, test_case in enumerate(error_test_cases):
751+
for test_case in error_test_cases:
751752
exception, except_fn = get_error_details(test_case)
752753

753754
pubkeys = [X[i] for i in test_case["key_indices"]]
@@ -796,7 +797,7 @@ def test_sig_agg_vectors() -> None:
796797
aggpk = get_xonly_pk(key_agg_and_tweak(pubkeys, tweaks, is_xonly))
797798
assert schnorr_verify(msg, aggpk, sig)
798799

799-
for i, test_case in enumerate(error_test_cases):
800+
for test_case in error_test_cases:
800801
exception, except_fn = get_error_details(test_case)
801802

802803
pubnonces = [pnonce[i] for i in test_case["nonce_indices"]]

bip-0327/vectors/sig_agg_vectors.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@
143143
],
144144
"error": {
145145
"type": "invalid_contribution",
146-
"signer": 1
146+
"signer": 1,
147+
"contrib": "psig"
147148
},
148149
"comment": "Partial signature is invalid because it exceeds group size"
149150
}

0 commit comments

Comments
 (0)