Skeleton for notes and values

This commit is contained in:
Jack Grigg 2021-01-20 20:09:09 +00:00
parent 5285737bf0
commit d65968ed38
3 changed files with 71 additions and 0 deletions

View File

@ -9,12 +9,17 @@
mod address;
pub mod keys;
mod note;
pub mod value;
pub use address::Address;
pub use note::{EncryptedNote, Note, NoteCommitment, Nullifier};
/// Chain-specific constants and constraints for Orchard.
///
/// The purpose of this trait is to encapsulate things like the human-readable prefixes
/// for encoded addresses, or the range of allowable values for notes.
pub trait Chain {
/// Constraints on values within this chain.
type Value: value::Constraint;
}

34
src/note.rs Normal file
View File

@ -0,0 +1,34 @@
use crate::{keys::FullViewingKey, value::NoteValue, Address, Chain};
/// A discrete amount of funds received by an address.
#[derive(Debug)]
pub struct Note<C: Chain> {
/// The recipient of the funds.
recipient: Address<C>,
/// The value of this note.
value: NoteValue<C::Value>,
}
impl<C: Chain> Note<C> {
/// Derives the commitment to this note.
pub fn commitment(&self) -> NoteCommitment {
todo!()
}
/// Derives the nullifier for this note.
pub fn nullifier(&self, _: &FullViewingKey<C>) -> Nullifier {
todo!()
}
}
/// An encrypted note.
#[derive(Debug)]
pub struct EncryptedNote;
/// A commitment to a note.
#[derive(Debug)]
pub struct NoteCommitment;
/// A unique nullifier for a note.
#[derive(Debug)]
pub struct Nullifier;

32
src/value.rs Normal file
View File

@ -0,0 +1,32 @@
//! Monetary values within the Orchard shielded pool.
//!
//! Values are represented in two places within Orchard:
//! - The value of an individual note, which is unsigned.
//! - The sum of note values within an Orchard [`Action`] or [`Bundle`], which is signed.
//!
//! We give these separate types within this crate. Users should map these types to their
//! own general "amount" type as appropriate.
//!
//! Inside the circuit, values are constrained to be 63-bit integers.
//! - TODO: Should this be constrained further to 53 bits? To Zcash's MAX_MONEY?
//!
//! [`Action`]: crate::bundle::Action
//! [`Bundle`]: crate::bundle::Bundle
use std::fmt;
use std::marker::PhantomData;
/// The constraints applied to Orchard values.
pub trait Constraint: fmt::Debug {}
/// The value of an individual Orchard note.
#[derive(Debug)]
pub struct NoteValue<C: Constraint>(u64, PhantomData<C>);
/// A sum of Orchard note values.
#[derive(Debug)]
pub struct ValueSum<C: Constraint>(i64, PhantomData<C>);
/// A commitment to a [`ValueSum`].
#[derive(Debug)]
pub struct ValueCommitment;