tradecraftio / tradecraft

Tradecraft integration/staging tree https://tradecraft.io/download
Other
13 stars 9 forks source link

Alter segwit script hashes to permit a Merkle tree of alternative script pathways #63

Closed maaku closed 4 years ago

maaku commented 4 years ago

In segwit P2WSH, the scriptPubKey payload is the hash the script to be used at time of redemption. This means that only one script can be used, and that script must be committed to at the time the output is created. This PR uses the fast Merkle tree code to have all segwit scriptPubKey simultaneously commit to N scripts, where N >= 1, and then select which script is to be used at time of redemption. In other words this makes all segwit outputs MAST outputs (MAST = Merklized alternative script tree).

The code has been updated to make P2WSH outputs contain a Merkle root hash, and an extra witness element is required at redemption which contains the proof. For traditional outputs which contain only one script, the proof is the empty string, but it must be present. The hash of scripts is changed from SHA256 to double-SHA256.

maaku commented 4 years ago

The 20-byte P2WPKH output type is now a MAST output. Since it is no longer a "pay to pubkey hash" output, I've adopted the new terminology of "short hash" and "long hash" to differentiate the two pay-to-witness-script-hash output types.

maaku commented 4 years ago

I'm now considering this ready for merge. The only thing from the original specification that is not implemented is supporting multiple spend pathways. It turns out that implementing this correctly is actually rather complicated. I'm not sure what the best approach is, and I don't want to delay the segwit feature any further while sorting out what is ultimately a rather trivial feature that doesn't affect consensus.