zcash_primitives: `impl DynamicUsage for sapling::Bundle<Authorized>`

This commit is contained in:
Jack Grigg 2023-04-26 15:33:48 +00:00
parent 26d95b4a0e
commit 8db7a071a0
2 changed files with 32 additions and 0 deletions

View File

@ -10,6 +10,10 @@ and this library adheres to Rust's notion of
- `zcash_primitives::transaction`:
- `Transaction::temporary_zcashd_read_v5_sapling`
- `Transaction::temporary_zcashd_write_v5_sapling`
- Implementations of `memuse::DynamicUsage` for the following types:
- `zcash_primitives::transaction::components::sapling`:
- `Bundle<Authorized>`
- `SpendDescription<Authorized>`
### Changed
- Bumped dependencies to `secp256k1 0.26`, `hdwallet 0.4`.

View File

@ -192,6 +192,24 @@ impl<A: Authorization> Bundle<A> {
}
}
impl DynamicUsage for Bundle<Authorized> {
fn dynamic_usage(&self) -> usize {
self.shielded_spends.dynamic_usage() + self.shielded_outputs.dynamic_usage()
}
fn dynamic_usage_bounds(&self) -> (usize, Option<usize>) {
let bounds = (
self.shielded_spends.dynamic_usage_bounds(),
self.shielded_outputs.dynamic_usage_bounds(),
);
(
bounds.0 .0 + bounds.1 .0,
bounds.0 .1.zip(bounds.1 .1).map(|(a, b)| a + b),
)
}
}
#[derive(Clone)]
pub struct SpendDescription<A: Authorization> {
cv: ValueCommitment,
@ -263,6 +281,16 @@ impl<A: Authorization> SpendDescription<A> {
}
}
impl DynamicUsage for SpendDescription<Authorized> {
fn dynamic_usage(&self) -> usize {
self.zkproof.dynamic_usage()
}
fn dynamic_usage_bounds(&self) -> (usize, Option<usize>) {
self.zkproof.dynamic_usage_bounds()
}
}
/// Consensus rules (§4.4) & (§4.5):
/// - Canonical encoding is enforced here.
/// - "Not small order" is enforced here.