ZcashFoundation / zebra

Zcash - Financial Privacy in Rust 🦓
https://zfnd.org/zebra/
Apache License 2.0
404 stars 96 forks source link

Track the provenance of UTXOs #1342

Closed hdevalence closed 3 years ago

hdevalence commented 3 years ago

Is your feature request related to a problem? Please describe.

One of the transaction consensus rules, whose previous implementation was removed in https://github.com/ZcashFoundation/zebra/pull/1340/commits/f607c9840aa2e37a14cb595fd6e9b9a1fa478850 , requires that transactions with transparent inputs which are the outputs of coinbase transactions must have no transparent outputs. (The previous implementation did not actually check this).

This requires tracking the provenance of UTXOs to some extent, which may require changing the data we store in our database. It might be worth checking what Zcashd does here.

Describe the solution you'd like

Rather than just tracking raw transparent::Outputs, we should track Utxos, a new structure that includes a transparent::Output as well as metadata:

pub struct Utxo {
    pub output: transparent::Output,
    pub height: block::Height,
    pub from_coinbase: bool,
}

This requires:

Then, in subsequent PRs, we can use this information to implement the relevant consensus rules.

hdevalence commented 3 years ago

Here's the relevant structure in Zcashd (thanks @str4d for the pointer): https://github.com/zcash/zcash/blob/877212414ad40e37cf8e49884a90767c54d59ba2/src/coins.h#L23-L79