Skip to content

Commit

Permalink
Rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeykoren committed Jul 10, 2023
1 parent 83fb98f commit 3ba6146
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@ debug = true
debug = true

[patch.crates-io]
zcash_note_encryption = { version = "0.4", git = "https://github.com/QED-it/librustzcash.git", tag = "orchard_zsa_0.5.0_compatible" }
zcash_note_encryption = { version = "0.4", git = "https://github.com/QED-it/librustzcash.git", branch = "zsa-bundle-in-v5-vector-serialization" }
58 changes: 58 additions & 0 deletions src/issuance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use nonempty::NonEmpty;
use rand::{CryptoRng, RngCore};
use std::collections::HashSet;
use std::fmt;
use memuse::DynamicUsage;

use crate::bundle::commitments::{hash_issue_bundle_auth_data, hash_issue_bundle_txid_data};
use crate::issuance::Error::{
Expand Down Expand Up @@ -49,6 +50,29 @@ pub struct IssueAction {
finalize: bool,
}

impl DynamicUsage for IssueAction {
#[inline(always)]
fn dynamic_usage(&self) -> usize {
self.asset_desc.dynamic_usage() + self.notes.dynamic_usage()
}

#[inline(always)]
fn dynamic_usage_bounds(&self) -> (usize, Option<usize>) {
let bounds = (
self.asset_desc.dynamic_usage_bounds(),
self.notes.dynamic_usage_bounds(),
);
(
bounds.0 .0 + bounds.1 .0,
bounds
.0
.1
.zip(bounds.1 .1)
.map(|(a, b)| a + b),
)
}
}

/// The parameters required to add a Note into an IssueAction.
#[derive(Debug)]
pub struct IssueInfo {
Expand Down Expand Up @@ -197,6 +221,15 @@ impl IssueAuth for Unauthorized {}
impl IssueAuth for Prepared {}
impl IssueAuth for Signed {}

impl DynamicUsage for Signed {
fn dynamic_usage(&self) -> usize {
0
}
fn dynamic_usage_bounds(&self) -> (usize, Option<usize>) {
(0, Some(0))
}
}

impl<T: IssueAuth> IssueBundle<T> {
/// Returns the issuer verification key for the bundle.
pub fn ik(&self) -> &IssuanceValidatingKey {
Expand Down Expand Up @@ -455,6 +488,31 @@ impl IssueBundle<Signed> {
}
}

impl DynamicUsage for IssueBundle<Signed> {
fn dynamic_usage(&self) -> usize {
self.actions.dynamic_usage()
+ self.ik.dynamic_usage()
+ self.authorization.dynamic_usage()
}

fn dynamic_usage_bounds(&self) -> (usize, Option<usize>) {
let bounds = (
self.actions.dynamic_usage_bounds(),
self.ik.dynamic_usage_bounds(),
self.authorization.dynamic_usage_bounds(),
);
(
bounds.0 .0 + bounds.1 .0 + bounds.2 .0,
bounds
.0
.1
.zip(bounds.1 .1)
.zip(bounds.2 .1)
.map(|((a, b), c)| a + b + c),
)
}
}

/// Validation for Orchard IssueBundles
///
/// A set of previously finalized asset types must be provided in `finalized` argument.
Expand Down
13 changes: 13 additions & 0 deletions src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use group::{
prime::PrimeCurveAffine,
Curve, GroupEncoding,
};
use memuse::DynamicUsage;
use pasta_curves::{pallas, pallas::Scalar};
use rand::{CryptoRng, RngCore};
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
Expand Down Expand Up @@ -349,6 +350,18 @@ impl PartialEq for IssuanceValidatingKey {

impl Eq for IssuanceValidatingKey {}

impl DynamicUsage for IssuanceValidatingKey {
#[inline(always)]
fn dynamic_usage(&self) -> usize {
0
}

#[inline(always)]
fn dynamic_usage_bounds(&self) -> (usize, Option<usize>) {
(0, Some(0))
}
}

impl IssuanceValidatingKey {
/// Converts this spend validating key to its serialized form,
/// I2LEOSP_256(ik).
Expand Down
13 changes: 13 additions & 0 deletions src/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use core::fmt;

use group::GroupEncoding;
use memuse::DynamicUsage;
use pasta_curves::pallas;
use rand::RngCore;
use subtle::{Choice, ConditionallySelectable, CtOption};
Expand Down Expand Up @@ -306,6 +307,18 @@ impl Note {
}
}

impl DynamicUsage for Note {
#[inline(always)]
fn dynamic_usage(&self) -> usize {
0
}

#[inline(always)]
fn dynamic_usage_bounds(&self) -> (usize, Option<usize>) {
(0, Some(0))
}
}

/// An encrypted note.
#[derive(Clone)]
pub struct TransmittedNoteCiphertext {
Expand Down

0 comments on commit 3ba6146

Please sign in to comment.