handshake-org / hsd

Handshake Daemon & Full Node
Other
1.91k stars 275 forks source link

Pay To Pubkey? Bare Pubkeys in Addresses #211

Open tynes opened 5 years ago

tynes commented 5 years ago

There are remnants of pay to pubkey in the codebase.

See here on the Script object: https://github.com/handshake-org/hsd/blob/cc1ef7ab8dfcadbcc1b18b934ccf2d2ec1776042/lib/script/script.js#L1368-L1383

Looking at the code right before the VM execution, an address can be 32 bytes (p2sh) or 20 bytes (p2pkh). Anything else will fail validation.

https://github.com/handshake-org/hsd/blob/4b04d9a2f9094b9c4c8e17346e7f24517f0a0336/lib/script/script.js#L2300-L2315

This means that the only way to do pay to pubkey is by wrapping it in p2sh which makes me feel like its just left over from bcoin. If pay to pubkey was truly supported, there would be a check here for address.hash.length === 33. This would be the bare pubkey in the address "hash" (data) field.

Pieter Wuille thinks that it is safe to put a bare pubkey in the address instead of the pubkey hash. I think that this could result in more interesting cryptographic schemes being developed since sharing an address will be the same as sharing a public key. It would make key aggregation easier, proof of reserves easier and stealth addresses easier.

Leaving standard p2pkh would decrease the anonymity set of users using p2pk and it would be a decent amount of work to change everything.

pinheadmz commented 4 years ago

There's fromPubkey() in the Address module as well, that is essentially unusable with the current address structure. Even if we add BIP-schnorr in a future soft fork, we'll likely copy the P2PK (address/witness v1) format which assumes an implicit OP_CHECKSIG.

I think we can leave this issue open since the unused code may be confusing, but I think it's also been decided that Schnorr will not roll out in hsd address v0 and bare pay to pubkey won't either.