Skip to content

Conversation

kallewoof
Copy link
Contributor

@kallewoof kallewoof commented Jan 26, 2022

This

  • adds test vectors to the BIP-322 (signmessage) proposal (more needed, but better than nothing)
  • clarifies how messages are serialized as this was slightly ambiguous
  • clarifies that the to_sign transaction must have version, locktime, and sequence all set to 0 for the SIMPLE format (signature only)

@kallewoof kallewoof force-pushed the 202201-bip322-testvecs branch 2 times, most recently from 6c82ed6 to aeeda30 Compare January 26, 2022 10:22
@benthecarman
Copy link
Contributor

Wasn't able to find any problems with my tagged hashes, @kallewoof are you sure yours are correct?

@kallewoof
Copy link
Contributor Author

@benthecarman Will investigate. I assume your tagged hashes / BIP 340 stuff passes the test vectors in https://github.com/bitcoin/bips/blob/master/bip-0340/test-vectors.csv ?

@benthecarman
Copy link
Contributor

@benthecarman Will investigate. I assume your tagged hashes / BIP 340 stuff passes the test vectors in https://github.com/bitcoin/bips/blob/master/bip-0340/test-vectors.csv ?

Yes

@kallewoof
Copy link
Contributor Author

kallewoof commented Jan 31, 2022

I realize the message serialization into the hasher is a little ambiguous. That's probably where the difference is happening.

Edit: this is how it is done in Core:

/**
 * string
 */
template<typename Stream, typename C>
void Serialize(Stream& os, const std::basic_string<C>& str)
{
    WriteCompactSize(os, str.size());
    if (!str.empty())
        os.write((char*)str.data(), str.size() * sizeof(C));
}

So for the empty string case, it would result in 0x00 (the length 0), and for the string "Hello World" it would be 0x0B + "Hello World", i.e. it prefixes the compact size of the string.

@kallewoof kallewoof force-pushed the 202201-bip322-testvecs branch from aeeda30 to aa92d9c Compare January 31, 2022 10:07
@kallewoof
Copy link
Contributor Author

Updated BIP to clarify that the message serialization is done without length prefix and without null terminator.

@kallewoof kallewoof changed the title add test vectors to BIP-322 clarify message serialization and add test vectors to BIP-322 Jan 31, 2022
@kallewoof
Copy link
Contributor Author

I mistakenly thought the signatures were the same but looking closer they aren't. So, hashes are now identical but the signatures are different (and only mine pass the verifymessage call).

@kallewoof
Copy link
Contributor Author

I added a clarification to the to_sign transaction that version must be 0 for SIMPLE (signature only) format.

If the spent destination turns out to have locktimes and/or such, they need to use FULL format. (Half-hearted ping @apoelstra who's probably too busy to look at this.)

@kallewoof kallewoof force-pushed the 202201-bip322-testvecs branch from d06762b to f52e047 Compare February 3, 2022 03:11
@kallewoof
Copy link
Contributor Author

Since it's all guess-work for SIMPLE format, I've changed the spec to require version, locktime, and sequence to all be 0 for the to_sign transaction. Will convert this to a non-draft if no one objects.

@kallewoof kallewoof marked this pull request as ready for review February 4, 2022 04:50
@kallewoof
Copy link
Contributor Author

kallewoof commented Feb 4, 2022

Self-ACK f52e047

Ping @luke-jr -- I will merge this soon unless you have reservations; I don't think there's anything controversial in here, but better safe than sorry.

@benthecarman
Copy link
Contributor

ack f52e047

@kallewoof kallewoof merged commit 97e02b2 into bitcoin:master Feb 7, 2022
@kallewoof kallewoof deleted the 202201-bip322-testvecs branch February 7, 2022 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants