Musig Key Generation - Taproot Workshop - 1.2 Musig: 1.2.1 Programming Exercise: Compute 3-of-3 MuSig public key

I am finding it difficult to figure out how to properly multiply the key-pairs with the challenges.

privkey1, pubkey1 = generate_key_pair(sha256(b'key0'))
privkey2, pubkey2 = generate_key_pair(sha256(b'key1'))
privkey3, pubkey3 = generate_key_pair(sha256(b'key2'))
pubkeys = [pubkey1, pubkey2, pubkey3]

# Compute key challenges
# Method: use generate_musig_key() on the list of pubkeys.
# generate_musig_key() returns a challenge map and the aggregate public key.
c_map, pubkey_agg =  generate_musig_key(pubkeys)# TODO: implement
print("Aggregated Public Key is {}\n".format(pubkey_agg.get_bytes().hex()))

# Multiply key pairs by challenge factor

The diagram shows that tweaked private key di' = ci * di

musig keygen

This made me think to do something like:

privkey1_c = int.from_bytes(c_map[pubkey1], "big") * int.from_bytes(privkey1.get_bytes(), "big")

(cant multiply bytes directly) But this results in a number far too large and since SECP256K1_ORDER was not imported (for modulo operations) I figured that is a mistake on my part. I also tried to just set it like this:

privkey1_c = ECKey().set(c_map[pubkey1])

Which results in a valid key but is not the expected values that are checked at the assertions at the bottom of the code:

assert privkey1_c.secret == 104717570570407299858230629579807834166658508605015363884161538594382975780625
assert privkey2_c.secret == 65554880484297966965546994775376394861215085064604177497808278620612854069980
assert privkey3_c.secret == 106998690642216524894360365246223287721822845133760006050846956016514597569168

I feel like I'm misunderstanding how the challenge map relates to the challenge factor in the diagram. I assume it outputs ci for each pubkey but if that's the case, multiplying that number by the original privkey will result in a value too large for SECP256K1_ORDER.

There is also this part:

# Determine if the private and public keys need to be negated. 
# Hint: The aggregate public key is the one that needs to be valid.
if pubkey_agg.get_y() % 2 != 0:
    pubkey_agg.negate()
    # TODO: implement

Since the key generation is not random this has the same result every time which is that the if statement returns false (even value) and will not get used, so unless I am misunderstanding that this part seems to be a red herring (irrelevant to the issue).



from Recent Questions - Bitcoin Stack Exchange https://ift.tt/ynKJTNI
via IFTTT

Comments

Popular posts from this blog

Do Kwon’s Detention Prolonged Until 2024 As Montenegro Responds To Extradition Requests

Sam Bankman-Fried Trial Begins Tomorrow: 3 Reasons Ex-SEC Official Foresees Conviction

Ethereum Price Plummets 9% As Fed Chair Passes Hawkish Remarks