-
Notifications
You must be signed in to change notification settings - Fork 992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] coinbase outputs with lock_height in switch commitments #215
Conversation
I'm pretty sure there's no way you can put any restriction on outputs that isn't somehow hidden inside the Pedersen commitments (e.g. you can do multisig this way). There is nothing in MW signing the exact output, except perhaps some p2p-level things to prevent noninteractive merging that would then require miner cooperation to work around, so the recipient is free to replace it with anything else that adds up to the same Pedersen commitment. Cut-through is just one instance of this, where the recipient makes another transaction spending the would-be locktimed output. Typical uses of locktimed outputs involve the creation of refund transactions, where the original output isn't even broadcast until the refund transaction has been created. In this situation, by sending both the funding transaction and the refund transaction to a malicious miner, somebody can completely override the locktime in a non-consensus-detectable way. |
31088a1
to
d49cb3b
Compare
7b88081
to
a30ce26
Compare
Is this ready for review now (wish github would tell me when you added reviewers to the PR)? |
@ignopeverell I think so yes. I'm not 100% convinced this is the right approach right now but I'm keen on getting your feedback. We're increasing the size of each Input to cover the "revealed" switch commit and lock_height. I guess the question is - is the increased complexity and larger inputs worth it to allow us to encode lock_heights in coinbase outputs like this? |
I haven't forgotten this, but I'm still pondering. |
No rush - I'm totally happy to close this for now and we can revisit later if that makes more sense. |
439dca9
to
ad47d12
Compare
Alternative approach to "coinbase maturity validation needs to to be fork aware" here - #580, maintain heights in a sumtree pmmr, keep lock_heights out of the inputs/outputs themselves. |
c369a0e
to
94f70f5
Compare
switch commit hash key encodes lock_height cleanup output by commit index (currently broken...)
utxos come from the sumtrees (and only the sumtrees, limited info) outputs come from blocks (and we need to look them up via block height)
restore is not working fully refresh refreshes heights correctly (at least appears to)
Going to be saving a fair bit of disk space like this if we're no longer storing outputs (+ rangeproofs) in the index. |
@ignopeverell - this is ready for review/discussion. |
|
||
hashable_ord!(Input); | ||
|
||
/// Implementation of Writeable for a transaction Input, defines how to write | ||
/// an Input as binary. | ||
impl Writeable for Input { | ||
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ser::Error> { | ||
writer.write_fixed_bytes(&self.0) | ||
writer.write_fixed_bytes(&self.commit)?; | ||
writer.write_fixed_bytes(&self.switch_commit)?; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
SwitchCommitHashKey::from_lock_height(self.lock_height), | ||
); | ||
|
||
if switch_commit_hash != *output_switch_commit_hash { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
…et keys) for coinbase outputs where lock_height is _very_ important
Writing down what I understand to be the proposed approach here based on feedback - We modify
Then on tx pool and block validation -
We can implement (1) as a separate PR and build on what we have done in this PR. I'm concerned about (2) though - is my thinking correct here or am I missing something simple? There is nothing in the sumtree that shows an output is coinbase or not. |
Overall I agree but I have a couple remarks that may make things easier:
|
Closing - replaced with #615. |
TODO -
Old info (needs revisiting).
Coinbase outputs use
(output_features || lock_height)
as the secret key to the blake2 hash in the switch commitment hash.This allows us to timelock coinbase outputs in a self-contained way (does not rely on retrieving the originating block header for the block that generated the coinbase output).
The height h must be revealed to spend the coinbase output.
Normal tx outputs use
zero
array as the secret key - this way we can still leverage the switch commitment hash to identify out own outputs when recovering a wallet.rJ
blake2(rJ)
blake2(h, rJ)
whereh
the lock_height is used as the secret key to the hash function.Proposal: to spend an output timelocked with a lock_height (currently only applies to coinbase outputs) you need to reveal
rJ
andh
.We can verify an input based on the switch commitment and lock_height from the output.
The hash function ensures nobody is lying about the lock_height as the switch commit hash needs to match the one on the output itself.
This assumes every verifier has the output - this is fine for coinbase outputs.
I don't believe we know how to do this for the general case due to possible cut-through of outputs.