Skip to content

Commit 183fe3d

Browse files
committed
Fix the code to support compilation with tx-v6 feature flag disabled, make this flag non-default in Cargo.toml files and enable it by default in .cargo/config.toml
1 parent b9f7083 commit 183fe3d

15 files changed

Lines changed: 86 additions & 33 deletions

File tree

.cargo/config.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# Flags that apply to all Zebra crates and configurations
44
[target.'cfg(all())']
55
rustflags = [
6+
# Enable tx-v6 everywhere by default
7+
"--cfg", 'feature="tx-v6"',
8+
69
# TODO: Consider removing this line later (it's needed for the ZSA version of librustzcash crates)
710
"--cfg", "zcash_unstable=\"nu6\"",
811

@@ -85,6 +88,9 @@ rustflags = [
8588

8689
[build]
8790
rustdocflags = [
91+
# Enable tx-v6 everywhere by default
92+
"--cfg", 'feature="tx-v6"',
93+
8894
# TODO: Consider removing this line later (it's needed for the ZSA version of librustzcash crates)
8995
"--cfg", "zcash_unstable=\"nu6\"",
9096

zebra-chain/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ keywords = ["zebra", "zcash"]
1515
categories = ["asynchronous", "cryptography::cryptocurrencies", "encoding"]
1616

1717
[features]
18-
#default = []
19-
default = ["tx-v6"]
18+
default = []
2019

2120
# Production features that activate extra functionality
2221

zebra-chain/src/orchard/note/ciphertexts.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,13 @@ impl ZcashDeserialize for WrappedNoteKey {
109109
#[cfg(test)]
110110
mod tests {
111111
use crate::{
112-
orchard::{OrchardVanilla, OrchardZSA, ShieldedDataFlavor, WrappedNoteKey},
112+
orchard::{OrchardVanilla, ShieldedDataFlavor, WrappedNoteKey},
113113
serialization::{ZcashDeserialize, ZcashSerialize},
114114
};
115115

116+
#[cfg(feature = "tx-v6")]
117+
use crate::orchard::OrchardZSA;
118+
116119
use proptest::prelude::*;
117120

118121
fn roundtrip_encrypted_note<EncryptedNote>(note: &EncryptedNote) -> EncryptedNote
@@ -135,6 +138,7 @@ mod tests {
135138
}
136139

137140

141+
#[cfg(feature = "tx-v6")]
138142
#[test]
139143
fn encrypted_ciphertext_roundtrip_orchard_zsa(ec in any::<<OrchardZSA as ShieldedDataFlavor>::EncryptedNote>()) {
140144
let _init_guard = zebra_test::init();

zebra-chain/src/orchard/shielded_data.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,17 @@ use super::{OrchardVanilla, ShieldedDataFlavor};
2727

2828
/// A bundle of [`Action`] descriptions and signature data.
2929
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
30-
#[serde(bound(
31-
serialize = "Flavor::EncryptedNote: serde::Serialize, Flavor::BurnType: serde::Serialize",
32-
deserialize = "Flavor::BurnType: serde::Deserialize<'de>"
33-
))]
30+
#[cfg_attr(
31+
not(feature = "tx-v6"),
32+
serde(bound(serialize = "Flavor::EncryptedNote: serde::Serialize"))
33+
)]
34+
#[cfg_attr(
35+
feature = "tx-v6",
36+
serde(bound(
37+
serialize = "Flavor::EncryptedNote: serde::Serialize, Flavor::BurnType: serde::Serialize",
38+
deserialize = "Flavor::BurnType: serde::Deserialize<'de>"
39+
))
40+
)]
3441
pub struct ShieldedData<Flavor: ShieldedDataFlavor> {
3542
/// The orchard flags for this transaction.
3643
/// Denoted as `flagsOrchard` in the spec.

zebra-chain/src/orchard/shielded_data_flavor.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ use orchard::{domain::OrchardDomainCommon, orchard_flavor::OrchardFlavor};
99
pub use orchard::orchard_flavor::OrchardVanilla;
1010

1111
#[cfg(feature = "tx-v6")]
12-
pub use orchard::orchard_flavor::OrchardZSA;
12+
pub use orchard::{note::AssetBase, orchard_flavor::OrchardZSA, value::NoteValue};
1313

14+
use crate::serialization::{ZcashDeserialize, ZcashSerialize};
15+
16+
#[cfg(feature = "tx-v6")]
1417
use crate::{
1518
orchard::ValueCommitment,
16-
serialization::{ZcashDeserialize, ZcashSerialize},
19+
orchard_zsa::{Burn, BurnItem, NoBurn},
1720
};
1821

19-
#[cfg(feature = "tx-v6")]
20-
use crate::orchard_zsa::{Burn, BurnItem, NoBurn};
21-
2222
use super::note;
2323

2424
// When testing or with the proptest-impl feature, enforce Arbitrary.
@@ -62,6 +62,7 @@ pub trait ShieldedDataFlavor: OrchardFlavor {
6262
+ ZcashSerialize
6363
+ Into<ValueCommitment>
6464
+ AsRef<[BurnItem]>
65+
+ for<'a> From<&'a [(AssetBase, NoteValue)]>
6566
+ test_arbitrary::TestArbitrary;
6667
}
6768

zebra-chain/src/transaction.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub use unmined::{
4040

4141
use crate::{
4242
amount::{Amount, Error as AmountError, NegativeAllowed, NonNegative},
43-
block, orchard, orchard_zsa,
43+
block, orchard,
4444
parameters::{ConsensusBranchId, NetworkUpgrade},
4545
primitives::{ed25519, Bctv14Proof, Groth16Proof},
4646
sapling,
@@ -53,6 +53,9 @@ use crate::{
5353
value_balance::{ValueBalance, ValueBalanceError},
5454
};
5555

56+
#[cfg(feature = "tx-v6")]
57+
use crate::orchard_zsa;
58+
5659
/// A Zcash transaction.
5760
///
5861
/// A transaction is an encoded data structure that facilitates the transfer of

zebra-chain/src/transaction/arbitrary.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -880,13 +880,25 @@ impl Arbitrary for Transaction {
880880
Self::v5_strategy(ledger_state)
881881
]
882882
.boxed(),
883-
#[cfg(feature = "tx-v6")]
884-
NetworkUpgrade::Nu7 => prop_oneof![
885-
Self::v4_strategy(ledger_state.clone()),
886-
Self::v5_strategy(ledger_state.clone()),
887-
Self::v6_strategy(ledger_state)
888-
]
889-
.boxed(),
883+
NetworkUpgrade::Nu7 => {
884+
#[cfg(not(feature = "tx-v6"))]
885+
{
886+
prop_oneof![
887+
Self::v4_strategy(ledger_state.clone()),
888+
Self::v5_strategy(ledger_state.clone()),
889+
]
890+
.boxed()
891+
}
892+
#[cfg(feature = "tx-v6")]
893+
{
894+
prop_oneof![
895+
Self::v4_strategy(ledger_state.clone()),
896+
Self::v5_strategy(ledger_state.clone()),
897+
Self::v6_strategy(ledger_state),
898+
]
899+
.boxed()
900+
}
901+
}
890902
}
891903
}
892904

zebra-chain/src/transaction/serialize.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@ use reddsa::{orchard::Binding, orchard::SpendAuth, Signature};
1010

1111
use crate::{
1212
block::MAX_BLOCK_BYTES,
13-
orchard::{OrchardVanilla, OrchardZSA, ShieldedDataFlavor},
14-
orchard_zsa::NoBurn,
13+
orchard::{OrchardVanilla, ShieldedDataFlavor},
1514
parameters::{OVERWINTER_VERSION_GROUP_ID, SAPLING_VERSION_GROUP_ID, TX_V5_VERSION_GROUP_ID},
1615
primitives::{Halo2Proof, ZkSnarkProof},
1716
serialization::{
1817
zcash_deserialize_external_count, zcash_serialize_empty_list,
19-
zcash_serialize_external_count, AtLeastOne, CompactSizeMessage, ReadZcashExt,
20-
SerializationError, TrustedPreallocate, ZcashDeserialize, ZcashDeserializeInto,
21-
ZcashSerialize,
18+
zcash_serialize_external_count, AtLeastOne, ReadZcashExt, SerializationError,
19+
TrustedPreallocate, ZcashDeserialize, ZcashDeserializeInto, ZcashSerialize,
2220
},
2321
};
2422

2523
#[cfg(feature = "tx-v6")]
26-
use crate::parameters::TX_V6_VERSION_GROUP_ID;
24+
use crate::{
25+
orchard::OrchardZSA, orchard_zsa::NoBurn, parameters::TX_V6_VERSION_GROUP_ID,
26+
serialization::CompactSizeMessage,
27+
};
2728

2829
use super::*;
2930
use crate::sapling;
@@ -503,6 +504,7 @@ impl ZcashDeserialize for Option<orchard::ShieldedData<OrchardVanilla>> {
503504
Ok(Some(orchard::ShieldedData::<OrchardVanilla> {
504505
flags,
505506
value_balance,
507+
#[cfg(feature = "tx-v6")]
506508
burn: NoBurn,
507509
shared_anchor,
508510
proof,

zebra-consensus/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ keywords = ["zebra", "zcash"]
1515
categories = ["asynchronous", "cryptography::cryptocurrencies"]
1616

1717
[features]
18-
#default = []
19-
default = ["tx-v6"]
18+
default = []
2019

2120
# Production features that activate extra dependencies, or extra features in dependencies
2221

zebra-consensus/src/primitives/halo2.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ use tower::{util::ServiceFn, Service};
1919
use tower_batch_control::{Batch, BatchControl};
2020
use tower_fallback::Fallback;
2121

22-
use zebra_chain::orchard::{OrchardVanilla, OrchardZSA, ShieldedData, ShieldedDataFlavor};
22+
use zebra_chain::orchard::{OrchardVanilla, ShieldedData, ShieldedDataFlavor};
23+
24+
#[cfg(feature = "tx-v6")]
25+
use zebra_chain::orchard::OrchardZSA;
2326

2427
use crate::BoxError;
2528

@@ -78,7 +81,10 @@ pub type ItemVerifyingKey = VerifyingKey;
7881
lazy_static::lazy_static! {
7982
/// The halo2 proof verifying key for Orchard Vanilla
8083
pub static ref VERIFYING_KEY_VANILLA: ItemVerifyingKey = ItemVerifyingKey::build::<OrchardVanilla>();
84+
}
8185

86+
#[cfg(feature = "tx-v6")]
87+
lazy_static::lazy_static! {
8288
/// The halo2 proof verifying key for OrchardZSA
8389
pub static ref VERIFYING_KEY_ZSA: ItemVerifyingKey = ItemVerifyingKey::build::<OrchardZSA>();
8490
}
@@ -241,6 +247,7 @@ pub static VERIFIER_VANILLA: Lazy<VerificationContext> =
241247
Lazy::new(create_verification_context::<OrchardVanilla>);
242248

243249
/// FIXME: copy a doc from VERIFIER_VANILLA or just refer to its doc?
250+
#[cfg(feature = "tx-v6")]
244251
pub static VERIFIER_ZSA: Lazy<VerificationContext> =
245252
Lazy::new(create_verification_context::<OrchardZSA>);
246253

@@ -256,6 +263,7 @@ impl OrchardVerifier for OrchardVanilla {
256263
}
257264
}
258265

266+
#[cfg(feature = "tx-v6")]
259267
impl OrchardVerifier for OrchardZSA {
260268
const ZSA_ENABLED: bool = true;
261269

0 commit comments

Comments
 (0)