Skip to content

Commit

Permalink
Add IssueData::note_commitments and use it in Transaction::orchard_no…
Browse files Browse the repository at this point in the history
…te_commitments to merge Orchard ZSA issuance note commitments for V6 transactions
  • Loading branch information
dmidem committed Nov 3, 2024
1 parent 7447d45 commit 714e631
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 15 deletions.
2 changes: 1 addition & 1 deletion zebra-chain/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl Block {
}

/// Access the [orchard note commitments](pallas::Base) from all transactions in this block.
pub fn orchard_note_commitments(&self) -> impl Iterator<Item = &pallas::Base> {
pub fn orchard_note_commitments(&self) -> impl Iterator<Item = pallas::Base> + '_ {
self.transactions
.iter()
.flat_map(|transaction| transaction.orchard_note_commitments())
Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/block/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ impl Block {
sapling_tree.append(*sapling_note_commitment).unwrap();
}
for orchard_note_commitment in transaction.orchard_note_commitments() {
orchard_tree.append(*orchard_note_commitment).unwrap();
orchard_tree.append(orchard_note_commitment).unwrap();
}
}
new_transactions.push(Arc::new(transaction));
Expand Down
38 changes: 29 additions & 9 deletions zebra-chain/src/orchard_zsa/issuance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,35 @@

use std::{fmt::Debug, io};

use crate::{
block::MAX_BLOCK_BYTES,
serialization::{
zcash_serialize_bytes, zcash_serialize_empty_list, ReadZcashExt, SerializationError,
TrustedPreallocate, ZcashDeserialize, ZcashDeserializeInto, ZcashSerialize,
},
};

use nonempty::NonEmpty;

// FIXME: needed for "as_bool" only - consider to implement as_bool locally
use bitvec::macros::internal::funty::Fundamental;

use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};

use halo2::pasta::pallas;

// For pallas::Base::from_repr only
use group::ff::PrimeField;

use orchard::{
issuance::{IssueAction, IssueBundle, Signed},
keys::IssuanceValidatingKey,
note::{RandomSeed, Rho},
note::{ExtractedNoteCommitment, RandomSeed, Rho},
primitives::redpallas::{SigType, Signature, SpendAuth},
value::NoteValue,
Address, Note,
};

use crate::{
block::MAX_BLOCK_BYTES,
serialization::{
zcash_serialize_bytes, zcash_serialize_empty_list, ReadZcashExt, SerializationError,
TrustedPreallocate, ZcashDeserialize, ZcashDeserializeInto, ZcashSerialize,
},
};

use super::common::ASSET_BASE_SIZE;

/// Wrapper for `IssueBundle` used in the context of Transaction V6. This allows the implementation of
Expand All @@ -39,6 +44,21 @@ impl From<IssueBundle<Signed>> for IssueData {
}
}

impl IssueData {
pub(crate) fn note_commitments(&self) -> impl Iterator<Item = pallas::Base> + '_ {
self.0.actions().iter().flat_map(|action| {
action.notes().iter().map(|note| {
// FIXME: Make `ExtractedNoteCommitment::inner` public in `orchard` (this would
// eliminate the need for the workaround of converting `pallas::Base` from bytes
// here), or introduce a new public method in `orchard::issuance::IssueBundle` to
// retrieve note commitments directly from `orchard`.
pallas::Base::from_repr(ExtractedNoteCommitment::from(note.commitment()).to_bytes())
.unwrap()
})
})
}
}

// Sizes of the serialized values for types in bytes (used for TrustedPreallocate impls)
// FIXME: are those values correct (43, 32 etc.)?
//const ISSUANCE_VALIDATING_KEY_SIZE: u64 = 32;
Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/parallel/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl NoteCommitmentTrees {

let sprout_note_commitments: Vec<_> = block.sprout_note_commitments().cloned().collect();
let sapling_note_commitments: Vec<_> = block.sapling_note_commitments().cloned().collect();
let orchard_note_commitments: Vec<_> = block.orchard_note_commitments().cloned().collect();
let orchard_note_commitments: Vec<_> = block.orchard_note_commitments().collect();

let mut sprout_result = None;
let mut sapling_result = None;
Expand Down
28 changes: 26 additions & 2 deletions zebra-chain/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,8 +1046,32 @@ impl Transaction {

/// Access the note commitments in this transaction, if there are any,
/// regardless of version.
pub fn orchard_note_commitments(&self) -> Box<dyn Iterator<Item = &pallas::Base> + '_> {
orchard_shielded_data_iter!(self, orchard::ShieldedData::note_commitments)
pub fn orchard_note_commitments(&self) -> Box<dyn Iterator<Item = pallas::Base> + '_> {
match_orchard_shielded_data!(
self,
Box::new(std::iter::empty()),
{ orchard_shielded_data },
Box::new(
orchard_shielded_data
.iter()
.flat_map(orchard::ShieldedData::note_commitments)
.cloned()
),
{ orchard_shielded_data, orchard_zsa_issue_data },
{
Box::new(
orchard_shielded_data
.iter()
.flat_map(orchard::ShieldedData::note_commitments)
.cloned()
.chain(
orchard_zsa_issue_data
.iter()
.flat_map(orchard_zsa::IssueData::note_commitments)
)
)
}
)
}

/// Access the [`orchard::Flags`] in this transaction, if there is any,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,6 @@ fn calculate_orchard_subtree(
let orchard_note_commitments = block
.orchard_note_commitments()
.take(prev_remaining_notes)
.cloned()
.collect();

// This takes less than 1 second per tree, so we don't need to make it cancellable.
Expand Down

0 comments on commit 714e631

Please sign in to comment.