-
Notifications
You must be signed in to change notification settings - Fork 112
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
Reject UTXO double spends #2511
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far. There's only one optional suggestion that I'm not sure if it's valid, but if so it might affect the API of the function in the check
module.
3859a5a
to
76fbce1
Compare
Check that transparent spends use unspent outputs from: * earlier transaction in the same block, * earlier blocks in the parent non-finalized chain, or * the finalized state.
Co-authored-by: Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com>
- split each error case into a separate check - combine `contains` and `insert` - add a missing check against the non-finalized unspent UTXOs - rename arguments and edit error strings for clarity
385211c
to
8a411d2
Compare
- accept output and spend in the same block - accept output and spend in a later block - reject output and double-spend all in the same block - reject output then double-spend in a later block - reject output, spend, then double-spend all in different blocks
a90dfd1
to
5377fd0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still haven't finished reviewing the tests, I apologize for that :/
Co-authored-by: Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com>
19fac23
to
c44c17e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I just added some optional comments.
That was a lot of tests. If we end up having to write more tests like these, it might make sense to look into writing some more abstractions 🤔
Honestly I tried, there's already a lot of abstractions in there. |
Thinking about this a bit more, we could use something like the But I think the tests are good enough for now. |
* ZIPs were updated to remove ambiguity, this was tracked in #1267. * #2105 was fixed by #3039 and #2379 was closed by #3069 * #2230 was a duplicate of #2231 which was closed by #2511 * #3235 was obsoleted by #2156 which was fixed by #3505 * #1850 was fixed by #2944, #1851 was fixed by #2961 and #2902 was fixed by #2969 * We migrated to Rust 2021 edition in Jan 2022 with #3332 * #1631 was closed as not needed * #338 was fixed by #3040 and #1162 was fixed by #3067 * #2079 was fixed by #2445 * #4794 was fixed by #6122 * #1678 stopped being an issue * #3151 was fixed by #3934 * #3204 was closed as not needed * #1213 was fixed by #4586 * #1774 was closed as not needed * #4633 was closed as not needed * Clarify behaviour of difficulty spacing Co-authored-by: teor <teor@riseup.net> * Update comment to reflect implemented behaviour Co-authored-by: teor <teor@riseup.net> * Update comment to reflect implemented behaviour when retrying block downloads Co-authored-by: teor <teor@riseup.net> * Update `TODO` to remove closed issue and clarify when we might want to fix Co-authored-by: teor <teor@riseup.net> * Update `TODO` to remove closed issue and clarify what we might want to change in future Co-authored-by: teor <teor@riseup.net> * Clarify benefits of how we do block verification Co-authored-by: teor <teor@riseup.net> * Fix rustfmt errors --------- Co-authored-by: teor <teor@riseup.net>
Motivation
We don't want users to be able to create new coins by spending transparent outputs more than once.
Specifications
https://zips.z.cash/protocol/protocol.pdf#transactions
https://developer.bitcoin.org/devguide/block_chain.html#introduction
https://developer.bitcoin.org/reference/block_chain.html#merkle-trees
Designs
https://github.com/ZcashFoundation/zebra/blob/main/book/src/dev/rfcs/0005-state-updates.md#pub-fn-pushmut-self-block-arcblock
Solution
Closes #2231.
Testing
Review
I'd like a review from @jvff.
This PR will conflict with a bunch of other recent/upcoming state PRs, but the conflicts should be easy enough to resolve.
Reviewer Checklist