Add `memuse::DynamicUsage` impls for types used for batch scanning

This commit is contained in:
Jack Grigg 2022-10-15 23:29:06 +00:00
parent 0b4d7bc9c6
commit 050b2f231e
6 changed files with 40 additions and 2 deletions

View File

@ -16,6 +16,9 @@ and this project adheres to Rust's notion of
- `orchard::note`:
- `RandomSeed`
- `Note::{from_parts, rseed}`
- `impl memuse::DynamicUsage for Nullifier`
- `orchard::note_encryption`:
- `impl memuse::DynamicUsage for OrchardDomain`
- `orchard::builder::SpendInfo::new`
- `orchard::circuit::Circuit::from_action_context`

View File

@ -28,12 +28,12 @@ bitvec = "1"
blake2b_simd = "1"
ff = "0.12"
fpe = "0.5"
group = "0.12.1"
group = { version = "0.12.1", features = ["wnaf-memuse"] }
halo2_gadgets = "0.2"
halo2_proofs = "0.2"
hex = "0.4"
lazy_static = "1"
memuse = { version = "0.2", features = ["nonempty"] }
memuse = { version = "0.2.1", features = ["nonempty"] }
pasta_curves = "0.4"
proptest = { version = "1.0.0", optional = true }
rand = "0.8"

View File

@ -710,6 +710,16 @@ impl IncomingViewingKey {
#[derive(Clone, Debug)]
pub struct PreparedIncomingViewingKey(PreparedNonZeroScalar);
impl memuse::DynamicUsage for PreparedIncomingViewingKey {
fn dynamic_usage(&self) -> usize {
self.0.dynamic_usage()
}
fn dynamic_usage_bounds(&self) -> (usize, Option<usize>) {
self.0.dynamic_usage_bounds()
}
}
impl PreparedIncomingViewingKey {
/// Performs the necessary precomputations to use an `IncomingViewingKey` for note
/// decryption.

View File

@ -1,5 +1,6 @@
use group::{ff::PrimeField, Group};
use halo2_proofs::arithmetic::CurveExt;
use memuse::DynamicUsage;
use pasta_curves::pallas;
use rand::RngCore;
use subtle::CtOption;
@ -14,6 +15,9 @@ use crate::{
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct Nullifier(pub(crate) pallas::Base);
// We know that `pallas::Base` doesn't allocate internally.
memuse::impl_no_dynamic_usage!(Nullifier);
impl Nullifier {
/// Generates a dummy nullifier for use as $\rho$ in dummy spent notes.
///

View File

@ -85,6 +85,16 @@ pub struct OrchardDomain {
rho: Nullifier,
}
impl memuse::DynamicUsage for OrchardDomain {
fn dynamic_usage(&self) -> usize {
self.rho.dynamic_usage()
}
fn dynamic_usage_bounds(&self) -> (usize, Option<usize>) {
self.rho.dynamic_usage_bounds()
}
}
impl OrchardDomain {
/// Constructs a domain that can be used to trial-decrypt this action's output note.
pub fn for_action<T>(act: &Action<T>) -> Self {

View File

@ -7,6 +7,7 @@ use ff::{Field, PrimeField, PrimeFieldBits};
use group::{Curve, Group, GroupEncoding, WnafBase, WnafScalar};
use halo2_gadgets::{poseidon::primitives as poseidon, sinsemilla::primitives as sinsemilla};
use halo2_proofs::arithmetic::{CurveAffine, CurveExt, FieldExt};
use memuse::DynamicUsage;
use pasta_curves::pallas;
use subtle::{ConditionallySelectable, CtOption};
@ -153,6 +154,16 @@ impl PreparedNonIdentityBase {
#[derive(Clone, Debug)]
pub(crate) struct PreparedNonZeroScalar(WnafScalar<pallas::Scalar, PREPARED_WINDOW_SIZE>);
impl DynamicUsage for PreparedNonZeroScalar {
fn dynamic_usage(&self) -> usize {
self.0.dynamic_usage()
}
fn dynamic_usage_bounds(&self) -> (usize, Option<usize>) {
self.0.dynamic_usage_bounds()
}
}
impl PreparedNonZeroScalar {
pub(crate) fn new(scalar: &NonZeroPallasScalar) -> Self {
PreparedNonZeroScalar(WnafScalar::new(scalar))