Published on: 2014-03-12T19:42:44+00:00
Alan Reiner suggests using parallel trees to generate P2SH addresses after sorting the public keys lexicographically as strings. This means that the keys should be sorted based on their string representation. The writer of the discussion implemented sorting in JavaScript, sorting the keys as big endian numbers and filling in any leading zeros. However, the writer emphasizes that the specific method used is not important, as long as there is a standard way that everyone in the Bitcoin world agrees upon.In a P2SH multisig transaction, the serialized script includes multiple public keys and an OP_CHECKMULTISIG operation. The order of the public keys is crucial because it affects the resulting P2SH address. To ensure consistency, a standard sorting method needs to be established. There are two types of public keys: compressed and uncompressed. Compressed keys are shorter than uncompressed ones. Different sorting methods can be employed, such as treating the keys as strings, big endian numbers, or little endian numbers.Sorting the keys as strings may lead to unexpected results, as the length of the keys can influence the sorting order. For example, a compressed key could be ranked higher than an uncompressed one solely due to its shorter length. On the other hand, sorting the keys as big endian numbers would provide the correct order, ensuring that the uncompressed keys come before the compressed ones. The writer's implementation uses this method, sorting the keys as big endian numbers, and filling in any leading zeros to maintain consistency.In conclusion, establishing a standard way of sorting public keys for p2sh multisig transactions is crucial to ensure consistency and avoid potential issues. Sorting the keys as big endian numbers appears to be a suitable method, as it preserves the correct ordering regardless of the key type. It is vital for the Bitcoin community to agree on a standardized sorting approach to maintain compatibility and prevent any discrepancies.
Updated on: 2023-08-01T07:57:04.333383+00:00