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

ZSA integration (step 7): Modify zebra-consensus to support Orchard ZSA #28

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
50190a3
Introduce Nu7
dmidem Aug 18, 2024
2d3845d
Introduce Nu7 fo other crates of Zebra
dmidem Aug 19, 2024
7d79143
Merge branch 'switch-to-zsa-crates-nu6' into switch-to-zsa-crates-nu7
dmidem Sep 2, 2024
d659628
Merge branch 'switch-to-zsa-crates-nu6' into switch-to-zsa-crates-nu7
dmidem Sep 2, 2024
faec84b
Merge branch 'switch-to-zsa-crates-nu6' into switch-to-zsa-crates-nu7
dmidem Sep 9, 2024
509d525
Merge branch 'switch-to-zsa-crates-nu6' into switch-to-zsa-crates-nu7
dmidem Sep 22, 2024
0bcf59a
Merge branch 'switch-to-zsa-crates-nu6' into switch-to-zsa-crates-nu7
dmidem Sep 22, 2024
ab1838d
Merge branch 'main' into switch-to-zsa-crates-nu7
dmidem Oct 2, 2024
0a8cfe0
Merge branch 'switch-to-zsa-crates-nu6' into switch-to-zsa-crates-nu7
dmidem Oct 2, 2024
1b8e9e9
Merge branch 'zsa-integration-zsadeps' into zsa-integration-nu7
dmidem Oct 17, 2024
d8964e7
Fix of new_regtest call (as it additionally needs Nu7 arg now)
dmidem Oct 17, 2024
e8abddd
Fix of new_regtest call (as it additionally needs Nu7 arg now) (2)
dmidem Oct 17, 2024
23d9e77
Set Nu7 as a network update for testnet in zebra-chain network tests
dmidem Oct 17, 2024
e0adb4c
Fix serde names for NU7
dmidem Oct 17, 2024
0daf0ce
Update test snapshot in zebra-rpc to use NU7
dmidem Oct 17, 2024
24f5e85
Merge branch 'zsa-integration-zsadeps' into zsa-integration-nu7
dmidem Oct 29, 2024
d0ecf96
Merge branch 'zsa-integration-zsadeps' into zsa-integration-nu7
dmidem Oct 30, 2024
50680a6
Merge branch 'zsa-integration-nu7' into zsa-integration-block-test
dmidem Nov 11, 2024
3cce489
Refactor orchard_zsa modules to use IssueBundle serialization functio…
dmidem Nov 11, 2024
ce6c5c3
Fix the orchard::ShieldedData serialization/deserialization functions…
dmidem Nov 11, 2024
22349e5
Add ENABLE_ZSA flag to Flags for the orchard ShieldedData
dmidem Nov 11, 2024
46f81bc
Fix TX_V6_VERSION_GROUP_ID constant value to adjust it with the value…
dmidem Nov 11, 2024
408c155
Add a value for Nu7 to CONSENSUS_BRANCH_IDS (a placeholder values for…
dmidem Nov 11, 2024
c6a3dd4
Add a test vector with an issuance block to orchard_zsa module, also …
dmidem Nov 11, 2024
c3a8583
Add a method to return the inner value (IssueBundle) of IssueData wra…
dmidem Nov 11, 2024
4855c25
Add more checks after deserializing issuance block in issuance_block …
dmidem Nov 11, 2024
87e4a63
Rename orchard_zsa::tests::issuance_block to deserialize_blocks and a…
dmidem Nov 17, 2024
ffe49b7
Make zebra_chain::orchard_zsa::tests::vectors::BLOCKS visible for zeb…
dmidem Nov 17, 2024
697d38a
Add initial version of ZSA woirkflow tests to zebra-chain
dmidem Nov 17, 2024
fa948b8
Improve zebra-state/tests/zsa.rs code
dmidem Nov 18, 2024
1df822e
Modify zebra-consensus to use ItemVerifyingKey for Orchard ZSA (there…
dmidem Nov 19, 2024
e5d5dac
Temporary update get_blockchain_info@testnet_10 snapshot zebra-rpc to…
dmidem Nov 19, 2024
a18a456
Fix cargo fmt issue
dmidem Nov 19, 2024
215ec92
Add cargo clippy to ci-basic
dmidem Nov 19, 2024
d9c8720
Add temporary docs for pub test constants amd modules
dmidem Nov 19, 2024
90dac03
Fix zsa consensus tests
dmidem Nov 20, 2024
2bb599f
Add missed ZSA test modules in zebra-consensus
dmidem Nov 20, 2024
1faf196
Remove zebra-state zsa workflow tests (in favour of workflow tests in…
dmidem Nov 20, 2024
689e791
Fix cargo clippy issues
dmidem Nov 20, 2024
ab7c077
Modify Orchard ShieldedData binding_verification_key function to subt…
dmidem Nov 21, 2024
ada6a37
Update consensus ZSA workflow tests and test vectors
dmidem Nov 25, 2024
e0ee6c6
Add ZSA workflow test vectors
dmidem Nov 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci-basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ jobs:
run: cargo doc --all-features --document-private-items
- name: Run format check
run: cargo fmt -- --check
- name: Run clippy
run: cargo clippy --workspace --all-features --all-targets -- -D warnings
4 changes: 2 additions & 2 deletions zebra-chain/src/block/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl Commitment {
// NetworkUpgrade::current() returns the latest network upgrade that's activated at the provided height, so
// on Regtest for heights above height 0, it could return NU6, and it's possible for the current network upgrade
// to be NU6 (or Canopy, or any network upgrade above Heartwood) at the Heartwood activation height.
(Canopy | Nu5 | Nu6, activation_height)
(Canopy | Nu5 | Nu6 | Nu7, activation_height)
if height == activation_height
&& Some(height) == Heartwood.activation_height(network) =>
{
Expand All @@ -136,7 +136,7 @@ impl Commitment {
}
}
(Heartwood | Canopy, _) => Ok(ChainHistoryRoot(ChainHistoryMmrRootHash(bytes))),
(Nu5 | Nu6, _) => Ok(ChainHistoryBlockTxAuthCommitment(
(Nu5 | Nu6 | Nu7, _) => Ok(ChainHistoryBlockTxAuthCommitment(
ChainHistoryBlockTxAuthCommitmentHash(bytes),
)),
}
Expand Down
4 changes: 2 additions & 2 deletions zebra-chain/src/history_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl NonEmptyHistoryTree {
)?;
InnerHistoryTree::PreOrchard(tree)
}
NetworkUpgrade::Nu5 | NetworkUpgrade::Nu6 => {
NetworkUpgrade::Nu5 | NetworkUpgrade::Nu6 | NetworkUpgrade::Nu7 => {
let tree = Tree::<OrchardOnward>::new_from_cache(
network,
network_upgrade,
Expand Down Expand Up @@ -156,7 +156,7 @@ impl NonEmptyHistoryTree {
)?;
(InnerHistoryTree::PreOrchard(tree), entry)
}
NetworkUpgrade::Nu5 | NetworkUpgrade::Nu6 => {
NetworkUpgrade::Nu5 | NetworkUpgrade::Nu6 | NetworkUpgrade::Nu7 => {
let (tree, entry) = Tree::<OrchardOnward>::new_from_block(
network,
block,
Expand Down
11 changes: 11 additions & 0 deletions zebra-chain/src/orchard/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use halo2::{
use lazy_static::lazy_static;
use rand_core::{CryptoRng, RngCore};

use orchard::note::AssetBase;

use crate::{
amount::Amount,
error::RandError,
Expand Down Expand Up @@ -249,6 +251,15 @@ impl ValueCommitment {
let v = pallas::Scalar::from(value);
Self::from(*V * v + *R * rcv)
}

/// Generate a new `ValueCommitment` from an existing `rcv on a `value` (ZSA version).
#[cfg(feature = "tx-v6")]
#[allow(non_snake_case)]
pub fn with_asset(rcv: pallas::Scalar, value: Amount, asset: &AssetBase) -> Self {
let v = pallas::Scalar::from(value);
let V_zsa = asset.cv_base();
Self::from(V_zsa * v + *R * rcv)
}
}

lazy_static! {
Expand Down
14 changes: 11 additions & 3 deletions zebra-chain/src/orchard/orchard_flavor_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use proptest_derive::Arbitrary;

use orchard::{note_encryption::OrchardDomainCommon, orchard_flavor};

use crate::serialization::{ZcashDeserialize, ZcashSerialize};
use crate::{
orchard::ValueCommitment,
serialization::{ZcashDeserialize, ZcashSerialize},
};

#[cfg(feature = "tx-v6")]
use crate::orchard_zsa::{Burn, NoBurn};
Expand Down Expand Up @@ -50,7 +53,13 @@ pub trait OrchardFlavorExt: Clone + Debug {

/// A type representing a burn field for this protocol version.
#[cfg(feature = "tx-v6")]
type BurnType: Clone + Debug + Default + ZcashDeserialize + ZcashSerialize + TestArbitrary;
type BurnType: Clone
+ Debug
+ Default
+ ZcashDeserialize
+ ZcashSerialize
+ Into<ValueCommitment>
+ TestArbitrary;
}

/// A structure representing a tag for Orchard protocol variant used for the transaction version `V5`.
Expand Down Expand Up @@ -78,6 +87,5 @@ impl OrchardFlavorExt for OrchardZSA {
type Flavor = orchard_flavor::OrchardZSA;
type EncryptedNote = note::EncryptedNote<{ Self::ENCRYPTED_NOTE_SIZE }>;

#[cfg(feature = "tx-v6")]
type BurnType = Burn;
}
9 changes: 9 additions & 0 deletions zebra-chain/src/orchard/shielded_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@ impl<V: OrchardFlavorExt> ShieldedData<V> {
let cv_balance: ValueCommitment =
ValueCommitment::new(pallas::Scalar::zero(), self.value_balance);

#[cfg(not(feature = "tx-v6"))]
let key_bytes: [u8; 32] = (cv - cv_balance).into();

// FIXME: use asset to create ValueCommitment here for burns and above for value_balance?
#[cfg(feature = "tx-v6")]
let key_bytes: [u8; 32] = (cv - cv_balance - self.burn.clone().into()).into();

key_bytes.into()
}

Expand Down Expand Up @@ -313,6 +319,9 @@ bitflags! {
const ENABLE_SPENDS = 0b00000001;
/// Enable creating new non-zero valued Orchard notes.
const ENABLE_OUTPUTS = 0b00000010;
/// Enable ZSA transaction (otherwise all notes within actions must use native asset).
// FIXME: Should we use this flag explicitly anywhere in Zebra?
const ENABLE_ZSA = 0b00000100;
}
}

Expand Down
5 changes: 4 additions & 1 deletion zebra-chain/src/orchard_zsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
#[cfg(any(test, feature = "proptest-impl"))]
pub(crate) mod arbitrary;

mod common;
/// FIXME: feature = "proptest-impl" and pub are needed to access test vectors from another crates,
/// remove it then
#[cfg(any(test, feature = "proptest-impl"))]
pub mod tests;

mod burn;
mod issuance;
Expand Down
42 changes: 40 additions & 2 deletions zebra-chain/src/orchard_zsa/burn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,34 @@

use std::io;

use halo2::pasta::pallas;

use crate::{
amount::Amount,
block::MAX_BLOCK_BYTES,
serialization::{SerializationError, TrustedPreallocate, ZcashDeserialize, ZcashSerialize},
orchard::ValueCommitment,
serialization::{
ReadZcashExt, SerializationError, TrustedPreallocate, ZcashDeserialize, ZcashSerialize,
},
};

use orchard::{note::AssetBase, value::NoteValue};

use super::common::ASSET_BASE_SIZE;
// The size of the serialized AssetBase in bytes (used for TrustedPreallocate impls)
pub(super) const ASSET_BASE_SIZE: u64 = 32;

impl ZcashSerialize for AssetBase {
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), io::Error> {
writer.write_all(&self.to_bytes())
}
}

impl ZcashDeserialize for AssetBase {
fn zcash_deserialize<R: io::Read>(mut reader: R) -> Result<Self, SerializationError> {
Option::from(AssetBase::from_bytes(&reader.read_32_bytes()?))
.ok_or_else(|| SerializationError::Parse("Invalid orchard_zsa AssetBase!"))
}
}

// Sizes of the serialized values for types in bytes (used for TrustedPreallocate impls)
const AMOUNT_SIZE: u64 = 8;
Expand Down Expand Up @@ -93,6 +112,13 @@ impl<'de> serde::Deserialize<'de> for BurnItem {
#[derive(Default, Clone, Debug, PartialEq, Eq, Serialize)]
pub struct NoBurn;

impl From<NoBurn> for ValueCommitment {
fn from(_burn: NoBurn) -> ValueCommitment {
// FIXME: is there a simpler way to get zero ValueCommitment?
ValueCommitment::new(pallas::Scalar::zero(), Amount::zero())
}
}

impl ZcashSerialize for NoBurn {
fn zcash_serialize<W: io::Write>(&self, mut _writer: W) -> Result<(), io::Error> {
Ok(())
Expand All @@ -115,6 +141,18 @@ impl From<Vec<BurnItem>> for Burn {
}
}

// FIXME: consider conversion from reference to Burn instead, to avoid using `clone` when it's called
impl From<Burn> for ValueCommitment {
fn from(burn: Burn) -> ValueCommitment {
burn.0
.into_iter()
.map(|BurnItem(asset, amount)| {
ValueCommitment::with_asset(pallas::Scalar::zero(), amount, &asset)
})
.sum()
}
}

impl ZcashSerialize for Burn {
fn zcash_serialize<W: io::Write>(&self, writer: W) -> Result<(), io::Error> {
self.0.zcash_serialize(writer)
Expand Down
23 changes: 0 additions & 23 deletions zebra-chain/src/orchard_zsa/common.rs

This file was deleted.

Loading
Loading