Skip to content
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

Add an OrderedUtxo type for transparent spend validation #2502

Merged
merged 3 commits into from
Jul 19, 2021
Merged

Conversation

teor2345
Copy link
Contributor

@teor2345 teor2345 commented Jul 16, 2021

Motivation

We need to track transaction order in each block, until we have validated transparent spends.

Specifications

Any input within this block can spend an output which also appears in this block (assuming the spend is otherwise valid).
However, the TXID corresponding to the output must be placed at some point before the TXID corresponding to the input.
This ensures that any program parsing block chain transactions linearly will encounter each output before it is used as an input.

https://developer.bitcoin.org/reference/block_chain.html#merkle-trees

Solution

  • Add an OrderedUtxo type which includes a Utxo and the transaction index in the block
  • Use this type instead of Utxo until the transaction is validated in the non-finalized chain

This PR is part of #2231, but it doesn't close that ticket.

Review

@jvff can review this PR.

I think it might conflict with some of @oxarbitrage's value pools work, so it might be good to get it in soon.

Reviewer Checklist

  • Code implements Specs and Designs

The tests will come in a future PR, as part of testing transparent spends.

@teor2345 teor2345 added A-consensus Area: Consensus rule updates NU Sprout Network Upgrade: Sprout specific tasks (before Overwinter) A-rust Area: Updates to Rust code C-enhancement Category: This is an improvement P-Medium labels Jul 16, 2021
@teor2345 teor2345 requested a review from jvff July 16, 2021 06:24
@teor2345 teor2345 self-assigned this Jul 16, 2021
@teor2345 teor2345 changed the base branch from sapling-orchard-duplicate-nullifiers to main July 16, 2021 06:25
@teor2345 teor2345 marked this pull request as ready for review July 16, 2021 06:25
jvff
jvff previously approved these changes Jul 16, 2021
Copy link
Contributor

@jvff jvff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! It can be merged as is, I just added one suggestion that's an optional optimization, and a tiny nit that can also be ignored.

zebra-chain/src/transparent/utxo.rs Outdated Show resolved Hide resolved
zebra-state/src/service/non_finalized_state/chain.rs Outdated Show resolved Hide resolved
teor2345 added 3 commits July 19, 2021 13:02
This change allows us to check that transparent spends use outputs from
earlier in their block. (But we don't actually do that check yet.)

We need to keep the order of UTXOs when we're contextually verifying
each new block that is added to a chain. But the block order is
irrelevant for UTXOs stored in the state.
@teor2345 teor2345 requested a review from jvff July 19, 2021 03:03
@jvff jvff merged commit bfc3e4a into main Jul 19, 2021
@jvff jvff deleted the ordered-utxo branch July 19, 2021 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-consensus Area: Consensus rule updates A-rust Area: Updates to Rust code C-enhancement Category: This is an improvement NU Sprout Network Upgrade: Sprout specific tasks (before Overwinter)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants