Skip to content

Commit 59cc43d

Browse files
theStackjosibake
andcommitted
BIP-352: scanning: add step to skip tx if input pubkeys sum A is point at infinity
The input data for the test vector is taken from the signet transaction fe788cf6578d547819def43d79e6c8f0153d4885f5a343d12bd03f34507aabd6 which spends two P2WPKH inputs with negated pubkeys (x, y) and (x, -y) from the funding transaction 3a286147b25e16ae80aff406f2673c6e565418c40f45c071245cdebc8a94174e (see also bitcoin-core/secp256k1#1519 (comment) and the output from the script in the previous commit message). Co-authored-by: josibake <[email protected]>
1 parent 47033c6 commit 59cc43d

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

bip-0352.mediawiki

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ A scan and spend key pair using BIP32 derivation are defined (taking inspiration
335335
If each of the checks in ''[[#scanning-silent-payment-eligible-transactions|Scanning silent payment eligible transactions]]'' passes, the receiving wallet must:
336336

337337
* Let ''A = A<sub>1</sub> + A<sub>2</sub> + ... + A<sub>n</sub>'', where each ''A<sub>i</sub>'' is the public key of an input from the ''[[#inputs-for-shared-secret-derivation|Inputs For Shared Secret Derivation]]'' list
338+
** If ''A'' is the point at infinity, skip the transaction
338339
* Generate the ''input_hash'' with the smallest outpoint lexicographically and ''A'', using the method described above
339340
* Let ''ecdh_shared_secret = input_hash·b<sub>scan</sub>·A''
340341
* Check for outputs:

bip-0352/reference.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ def scanning(b_scan: ECKey, B_spend: ECPubKey, A_sum: ECPubKey, input_hash: byte
300300
add_to_wallet = []
301301
if (len(input_pub_keys) > 0):
302302
A_sum = reduce(lambda x, y: x + y, input_pub_keys)
303+
if A_sum.get_bytes() is None:
304+
# Input pubkeys sum is point at infinity -> skip tx
305+
assert expected["outputs"] == []
306+
continue
303307
input_hash = get_input_hash([vin.outpoint for vin in vins], A_sum)
304308
pre_computed_labels = {
305309
(generate_label(b_scan, label) * G).get_bytes(False).hex(): generate_label(b_scan, label).hex()

bip-0352/send_and_receive_test_vectors.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2713,6 +2713,48 @@
27132713
}
27142714
],
27152715
"receiving": [
2716+
{
2717+
"given": {
2718+
"vin": [
2719+
{
2720+
"txid": "3a286147b25e16ae80aff406f2673c6e565418c40f45c071245cdebc8a94174e",
2721+
"vout": 0,
2722+
"scriptSig": "",
2723+
"txinwitness": "024730440220085003179ce1a3a88ce0069aa6ea045e140761ab88c22a26ae2a8cfe983a6e4602204a8a39940f0735c8a4424270ac8da65240c261ab3fda9272f6d6efbf9cfea366012102557ef3e55b0a52489b4454c1169e06bdea43687a69c1f190eb50781644ab6975",
2724+
"prevout": {
2725+
"scriptPubKey": {
2726+
"hex": "00149d9e24f9fab4e35bf1a6df4b46cb533296ac0792"
2727+
}
2728+
}
2729+
},
2730+
{
2731+
"txid": "3a286147b25e16ae80aff406f2673c6e565418c40f45c071245cdebc8a94174e",
2732+
"vout": 1,
2733+
"scriptSig": "",
2734+
"txinwitness": "0247304402204586a68e1d97dd3c6928e3622799859f8c3b20c3c670cf654cc905c9be29fdb7022043fbcde1689f3f4045e8816caf6163624bd19e62e4565bc99f95c533e599782c012103557ef3e55b0a52489b4454c1169e06bdea43687a69c1f190eb50781644ab6975",
2735+
"prevout": {
2736+
"scriptPubKey": {
2737+
"hex": "00149860538b5575962776ed0814ae222c7d60c72d7b"
2738+
}
2739+
}
2740+
}
2741+
],
2742+
"outputs": [
2743+
"0000000000000000000000000000000000000000000000000000000000000000"
2744+
],
2745+
"key_material": {
2746+
"spend_priv_key": "0000000000000000000000000000000000000000000000000000000000000001",
2747+
"scan_priv_key": "0000000000000000000000000000000000000000000000000000000000000002"
2748+
},
2749+
"labels": []
2750+
},
2751+
"expected": {
2752+
"addresses": [
2753+
"sp1qqtrqglu5g8kh6mfsg4qxa9wq0nv9cauwfwxw70984wkqnw2uwz0w2qnehen8a7wuhwk9tgrzjh8gwzc8q2dlekedec5djk0js9d3d7qhnq6lqj3s"
2754+
],
2755+
"outputs": []
2756+
}
2757+
}
27162758
]
27172759
}
27182760
]

0 commit comments

Comments
 (0)