Compare commits

...

1 Commits

Author SHA1 Message Date
likho 44bdc35a17 WIP: Remove transparent transactions 2024-04-24 17:08:00 +02:00
8 changed files with 36 additions and 128 deletions

View File

@ -161,8 +161,7 @@ impl TryFrom<&Transaction> for zp_tx::Transaction {
Transaction::V5 {
network_upgrade, ..
} => network_upgrade,
Transaction::V1 { .. }
| Transaction::V2 { .. }
Transaction::V2 { .. }
| Transaction::V3 { .. }
| Transaction::V4 { .. } => panic!("Zebra only uses librustzcash for V5 transactions"),
};

View File

@ -68,16 +68,6 @@ use crate::{
derive(Serialize)
)]
pub enum Transaction {
/// A fully transparent transaction (`version = 1`).
V1 {
/// The transparent inputs to the transaction.
inputs: Vec<transparent::Input>,
/// The transparent outputs from the transaction.
outputs: Vec<transparent::Output>,
/// The earliest time or block height that this transaction can be added to the
/// chain.
lock_time: LockTime,
},
/// A Sprout transaction (`version = 2`).
V2 {
/// The transparent inputs to the transaction.
@ -232,8 +222,7 @@ impl Transaction {
/// [ZIP-244]: https://zips.z.cash/zip-0244.
pub fn auth_digest(&self) -> Option<AuthDigest> {
match self {
Transaction::V1 { .. }
| Transaction::V2 { .. }
Transaction::V2 { .. }
| Transaction::V3 { .. }
| Transaction::V4 { .. } => None,
Transaction::V5 { .. } => Some(AuthDigest::from(self)),
@ -308,7 +297,7 @@ impl Transaction {
/// Return if the `fOverwintered` flag of this transaction is set.
pub fn is_overwintered(&self) -> bool {
match self {
Transaction::V1 { .. } | Transaction::V2 { .. } => false,
Transaction::V2 { .. } => false,
Transaction::V3 { .. } | Transaction::V4 { .. } | Transaction::V5 { .. } => true,
}
}
@ -316,7 +305,6 @@ impl Transaction {
/// Return the version of this transaction.
pub fn version(&self) -> u32 {
match self {
Transaction::V1 { .. } => 1,
Transaction::V2 { .. } => 2,
Transaction::V3 { .. } => 3,
Transaction::V4 { .. } => 4,
@ -327,8 +315,7 @@ impl Transaction {
/// Get this transaction's lock time.
pub fn lock_time(&self) -> Option<LockTime> {
let lock_time = match self {
Transaction::V1 { lock_time, .. }
| Transaction::V2 { lock_time, .. }
Transaction::V2 { lock_time, .. }
| Transaction::V3 { lock_time, .. }
| Transaction::V4 { lock_time, .. }
| Transaction::V5 { lock_time, .. } => *lock_time,
@ -385,7 +372,7 @@ impl Transaction {
/// Get this transaction's expiry height, if any.
pub fn expiry_height(&self) -> Option<block::Height> {
match self {
Transaction::V1 { .. } | Transaction::V2 { .. } => None,
Transaction::V2 { .. } => None,
Transaction::V3 { expiry_height, .. }
| Transaction::V4 { expiry_height, .. }
| Transaction::V5 { expiry_height, .. } => match expiry_height {
@ -406,8 +393,8 @@ impl Transaction {
#[cfg(any(test, feature = "proptest-impl"))]
pub fn expiry_height_mut(&mut self) -> &mut block::Height {
match self {
Transaction::V1 { .. } | Transaction::V2 { .. } => {
panic!("v1 and v2 transactions are not supported")
Transaction::V2 { .. } => {
panic!("v2 transactions are not supported")
}
Transaction::V3 {
ref mut expiry_height,
@ -430,8 +417,7 @@ impl Transaction {
/// [7.1]: https://zips.z.cash/protocol/nu5.pdf#txnencodingandconsensus
pub fn network_upgrade(&self) -> Option<NetworkUpgrade> {
match self {
Transaction::V1 { .. }
| Transaction::V2 { .. }
Transaction::V2 { .. }
| Transaction::V3 { .. }
| Transaction::V4 { .. } => None,
Transaction::V5 {
@ -445,7 +431,6 @@ impl Transaction {
/// Access the transparent inputs of this transaction, regardless of version.
pub fn inputs(&self) -> &[transparent::Input] {
match self {
Transaction::V1 { ref inputs, .. } => inputs,
Transaction::V2 { ref inputs, .. } => inputs,
Transaction::V3 { ref inputs, .. } => inputs,
Transaction::V4 { ref inputs, .. } => inputs,
@ -457,7 +442,6 @@ impl Transaction {
#[cfg(any(test, feature = "proptest-impl"))]
pub fn inputs_mut(&mut self) -> &mut Vec<transparent::Input> {
match self {
Transaction::V1 { ref mut inputs, .. } => inputs,
Transaction::V2 { ref mut inputs, .. } => inputs,
Transaction::V3 { ref mut inputs, .. } => inputs,
Transaction::V4 { ref mut inputs, .. } => inputs,
@ -475,7 +459,6 @@ impl Transaction {
/// Access the transparent outputs of this transaction, regardless of version.
pub fn outputs(&self) -> &[transparent::Output] {
match self {
Transaction::V1 { ref outputs, .. } => outputs,
Transaction::V2 { ref outputs, .. } => outputs,
Transaction::V3 { ref outputs, .. } => outputs,
Transaction::V4 { ref outputs, .. } => outputs,
@ -487,9 +470,6 @@ impl Transaction {
#[cfg(any(test, feature = "proptest-impl"))]
pub fn outputs_mut(&mut self) -> &mut Vec<transparent::Output> {
match self {
Transaction::V1 {
ref mut outputs, ..
} => outputs,
Transaction::V2 {
ref mut outputs, ..
} => outputs,
@ -542,8 +522,7 @@ impl Transaction {
} => Box::new(joinsplit_data.joinsplits()),
// No JoinSplits / JoinSplits with BCTV14 proofs
Transaction::V1 { .. }
| Transaction::V2 { .. }
Transaction::V2 { .. }
| Transaction::V3 { .. }
| Transaction::V4 {
joinsplit_data: None,
@ -571,8 +550,7 @@ impl Transaction {
..
} => joinsplit_data.joinsplits().count(),
// No JoinSplits
Transaction::V1 { .. }
| Transaction::V2 {
Transaction::V2 {
joinsplit_data: None,
..
}
@ -610,8 +588,7 @@ impl Transaction {
..
} => Box::new(joinsplit_data.nullifiers()),
// No JoinSplits
Transaction::V1 { .. }
| Transaction::V2 {
Transaction::V2 {
joinsplit_data: None,
..
}
@ -646,8 +623,7 @@ impl Transaction {
..
} => Some(joinsplit_data.pub_key),
// No JoinSplits
Transaction::V1 { .. }
| Transaction::V2 {
Transaction::V2 {
joinsplit_data: None,
..
}
@ -667,7 +643,7 @@ impl Transaction {
pub fn has_sprout_joinsplit_data(&self) -> bool {
match self {
// No JoinSplits
Transaction::V1 { .. } | Transaction::V5 { .. } => false,
Transaction::V5 { .. } => false,
// JoinSplits-on-BCTV14
Transaction::V2 { joinsplit_data, .. } | Transaction::V3 { joinsplit_data, .. } => {
@ -713,7 +689,6 @@ impl Transaction {
joinsplit_data: None,
..
}
| Transaction::V1 { .. }
| Transaction::V5 { .. } => Box::new(std::iter::empty()),
}
}
@ -737,8 +712,7 @@ impl Transaction {
} => Box::new(sapling_shielded_data.anchors()),
// No Spends
Transaction::V1 { .. }
| Transaction::V2 { .. }
Transaction::V2 { .. }
| Transaction::V3 { .. }
| Transaction::V4 {
sapling_shielded_data: None,
@ -775,8 +749,7 @@ impl Transaction {
} => Box::new(sapling_shielded_data.spends_per_anchor()),
// No Spends
Transaction::V1 { .. }
| Transaction::V2 { .. }
Transaction::V2 { .. }
| Transaction::V3 { .. }
| Transaction::V4 {
sapling_shielded_data: None,
@ -803,8 +776,7 @@ impl Transaction {
} => Box::new(sapling_shielded_data.outputs()),
// No Outputs
Transaction::V1 { .. }
| Transaction::V2 { .. }
Transaction::V2 { .. }
| Transaction::V3 { .. }
| Transaction::V4 {
sapling_shielded_data: None,
@ -833,8 +805,7 @@ impl Transaction {
} => Box::new(sapling_shielded_data.nullifiers()),
// No Spends
Transaction::V1 { .. }
| Transaction::V2 { .. }
Transaction::V2 { .. }
| Transaction::V3 { .. }
| Transaction::V4 {
sapling_shielded_data: None,
@ -863,8 +834,7 @@ impl Transaction {
} => Box::new(sapling_shielded_data.note_commitments()),
// No Spends
Transaction::V1 { .. }
| Transaction::V2 { .. }
Transaction::V2 { .. }
| Transaction::V3 { .. }
| Transaction::V4 {
sapling_shielded_data: None,
@ -880,7 +850,7 @@ impl Transaction {
/// Return if the transaction has any Sapling shielded data.
pub fn has_sapling_shielded_data(&self) -> bool {
match self {
Transaction::V1 { .. } | Transaction::V2 { .. } | Transaction::V3 { .. } => false,
Transaction::V2 { .. } | Transaction::V3 { .. } => false,
Transaction::V4 {
sapling_shielded_data,
..
@ -905,8 +875,7 @@ impl Transaction {
} => orchard_shielded_data.as_ref(),
// No Orchard shielded data
Transaction::V1 { .. }
| Transaction::V2 { .. }
Transaction::V2 { .. }
| Transaction::V3 { .. }
| Transaction::V4 { .. } => None,
}
@ -922,8 +891,7 @@ impl Transaction {
..
} => Some(orchard_shielded_data),
Transaction::V1 { .. }
| Transaction::V2 { .. }
Transaction::V2 { .. }
| Transaction::V3 { .. }
| Transaction::V4 { .. }
| Transaction::V5 {
@ -1042,8 +1010,7 @@ impl Transaction {
.map(|joinsplit| &joinsplit.vpub_old),
),
// No JoinSplits
Transaction::V1 { .. }
| Transaction::V2 {
Transaction::V2 {
joinsplit_data: None,
..
}
@ -1091,8 +1058,7 @@ impl Transaction {
.map(|joinsplit| &mut joinsplit.vpub_old),
),
// No JoinSplits
Transaction::V1 { .. }
| Transaction::V2 {
Transaction::V2 {
joinsplit_data: None,
..
}
@ -1138,8 +1104,7 @@ impl Transaction {
.map(|joinsplit| &joinsplit.vpub_new),
),
// No JoinSplits
Transaction::V1 { .. }
| Transaction::V2 {
Transaction::V2 {
joinsplit_data: None,
..
}
@ -1187,8 +1152,7 @@ impl Transaction {
.map(|joinsplit| &mut joinsplit.vpub_new),
),
// No JoinSplits
Transaction::V1 { .. }
| Transaction::V2 {
Transaction::V2 {
joinsplit_data: None,
..
}
@ -1228,8 +1192,7 @@ impl Transaction {
joinsplit_data: Some(joinsplit_data),
..
} => joinsplit_data.joinsplit_value_balances(),
Transaction::V1 { .. }
| Transaction::V2 {
Transaction::V2 {
joinsplit_data: None,
..
}
@ -1284,8 +1247,7 @@ impl Transaction {
..
} => sapling_shielded_data.value_balance,
Transaction::V1 { .. }
| Transaction::V2 { .. }
Transaction::V2 { .. }
| Transaction::V3 { .. }
| Transaction::V4 {
sapling_shielded_data: None,
@ -1315,8 +1277,7 @@ impl Transaction {
sapling_shielded_data: Some(sapling_shielded_data),
..
} => Some(&mut sapling_shielded_data.value_balance),
Transaction::V1 { .. }
| Transaction::V2 { .. }
Transaction::V2 { .. }
| Transaction::V3 { .. }
| Transaction::V4 {
sapling_shielded_data: None,

View File

@ -35,21 +35,6 @@ pub const MAX_ARBITRARY_ITEMS: usize = 4;
// TODO: if needed, fixup transaction outputs
// (currently 0..=9 outputs, consensus rules require 1..)
impl Transaction {
/// Generate a proptest strategy for V1 Transactions
pub fn v1_strategy(ledger_state: LedgerState) -> BoxedStrategy<Self> {
(
transparent::Input::vec_strategy(&ledger_state, MAX_ARBITRARY_ITEMS),
vec(any::<transparent::Output>(), 0..MAX_ARBITRARY_ITEMS),
any::<LockTime>(),
)
.prop_map(|(inputs, outputs, lock_time)| Transaction::V1 {
inputs,
outputs,
lock_time,
})
.boxed()
}
/// Generate a proptest strategy for V2 Transactions
pub fn v2_strategy(ledger_state: LedgerState) -> BoxedStrategy<Self> {
(
@ -760,7 +745,6 @@ impl Arbitrary for Transaction {
fn arbitrary_with(ledger_state: Self::Parameters) -> Self::Strategy {
match ledger_state.transaction_version_override() {
Some(1) => return Self::v1_strategy(ledger_state),
Some(2) => return Self::v2_strategy(ledger_state),
Some(3) => return Self::v3_strategy(ledger_state),
Some(4) => return Self::v4_strategy(ledger_state),
@ -770,9 +754,8 @@ impl Arbitrary for Transaction {
}
match ledger_state.network_upgrade() {
NetworkUpgrade::Genesis | NetworkUpgrade::BeforeOverwinter => {
Self::v1_strategy(ledger_state)
}
//TODO - LOOK AT network_upgrade see where NetworkUpgrade::Genesis and
// NetworkUpgrade::BeforeOverwinterare used
NetworkUpgrade::Overwinter => Self::v2_strategy(ledger_state),
NetworkUpgrade::Sapling => Self::v3_strategy(ledger_state),
NetworkUpgrade::Blossom | NetworkUpgrade::Heartwood | NetworkUpgrade::Canopy => {
@ -783,6 +766,7 @@ impl Arbitrary for Transaction {
Self::v5_strategy(ledger_state)
]
.boxed(),
_ => {}
}
}
@ -859,19 +843,6 @@ pub fn transaction_to_fake_v5(
let block_nu = NetworkUpgrade::current(network, height);
match trans {
V1 {
inputs,
outputs,
lock_time,
} => V5 {
network_upgrade: block_nu,
inputs: inputs.to_vec(),
outputs: outputs.to_vec(),
lock_time: *lock_time,
expiry_height: height,
sapling_shielded_data: None,
orchard_shielded_data: None,
},
V2 {
inputs,
outputs,

View File

@ -481,20 +481,6 @@ impl ZcashSerialize for Transaction {
writer.write_u32::<LittleEndian>(version)?;
match self {
Transaction::V1 {
inputs,
outputs,
lock_time,
} => {
// Denoted as `tx_in_count` and `tx_in` in the spec.
inputs.zcash_serialize(&mut writer)?;
// Denoted as `tx_out_count` and `tx_out` in the spec.
outputs.zcash_serialize(&mut writer)?;
// Denoted as `lock_time` in the spec.
lock_time.zcash_serialize(&mut writer)?;
}
Transaction::V2 {
inputs,
outputs,
@ -732,14 +718,6 @@ impl ZcashDeserialize for Transaction {
//
// https://zips.z.cash/protocol/protocol.pdf#txnconsensus
match (version, overwintered) {
(1, false) => Ok(Transaction::V1 {
// Denoted as `tx_in_count` and `tx_in` in the spec.
inputs: Vec::zcash_deserialize(&mut limited_reader)?,
// Denoted as `tx_out_count` and `tx_out` in the spec.
outputs: Vec::zcash_deserialize(&mut limited_reader)?,
// Denoted as `lock_time` in the spec.
lock_time: LockTime::zcash_deserialize(&mut limited_reader)?,
}),
(2, false) => {
// Version 2 transactions use Sprout-on-BCTV14.
type OptV2Jsd = Option<JoinSplitData<Bctv14Proof>>;

View File

@ -24,8 +24,7 @@ impl<'a> TxIdBuilder<'a> {
/// Compute the Transaction ID for the previously specified transaction.
pub(super) fn txid(self) -> Result<Hash, io::Error> {
match self.trans {
Transaction::V1 { .. }
| Transaction::V2 { .. }
Transaction::V2 { .. }
| Transaction::V3 { .. }
| Transaction::V4 { .. } => self.txid_v1_to_v4(),
Transaction::V5 { .. } => self.txid_v5(),

View File

@ -139,7 +139,7 @@ impl From<Transaction> for UnminedTxId {
impl From<&Transaction> for UnminedTxId {
fn from(transaction: &Transaction) -> Self {
match transaction {
V1 { .. } | V2 { .. } | V3 { .. } | V4 { .. } => Legacy(transaction.into()),
V2 { .. } | V3 { .. } | V4 { .. } => Legacy(transaction.into()),
V5 { .. } => Witnessed(transaction.into()),
}
}

View File

@ -385,7 +385,7 @@ where
tracing::trace!(?tx_id, "got state UTXOs");
let mut async_checks = match tx.as_ref() {
Transaction::V1 { .. } | Transaction::V2 { .. } | Transaction::V3 { .. } => {
Transaction::V2 { .. } | Transaction::V3 { .. } => {
tracing::debug!(?tx, "got transaction with wrong version");
return Err(TransactionError::WrongVersion);
}

View File

@ -1510,7 +1510,7 @@ impl Chain {
sapling_shielded_data,
orchard_shielded_data,
),
V1 { .. } | V2 { .. } | V3 { .. } => unreachable!(
V2 { .. } | V3 { .. } => unreachable!(
"older transaction versions only exist in finalized blocks, because of the mandatory canopy checkpoint",
),
};
@ -1671,7 +1671,7 @@ impl UpdateWith<ContextuallyVerifiedBlock> for Chain {
sapling_shielded_data,
orchard_shielded_data,
),
V1 { .. } | V2 { .. } | V3 { .. } => unreachable!(
V2 { .. } | V3 { .. } => unreachable!(
"older transaction versions only exist in finalized blocks, because of the mandatory canopy checkpoint",
),
};