Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Murisi/box impl build params #88

Merged
merged 8 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 53 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions masp_note_encryption/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ chacha20poly1305 = { version = "0.10", default-features = false }
rand_core = { version = "0.6", default-features = false }
subtle = { version = "2.3", default-features = false }
borsh = {version = "1.2.0", features = ["unstable__schema", "derive"]}
arbitrary = {version = "1.3", features = ["derive"], optional = true }

[features]
default = ["alloc"]
alloc = []
pre-zip-212 = []
arbitrary = ["dep:arbitrary"]

[lib]
bench = false
4 changes: 2 additions & 2 deletions masp_note_encryption/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! [in-band secret distribution scheme]: https://zips.z.cash/protocol/protocol.pdf#saplingandorchardinband
//! [`masp_primitives`]: https://github.com/anoma/masp

#![no_std]
#![cfg_attr(not(feature = "arbitrary"), no_std)]
#![cfg_attr(docsrs, feature(doc_cfg))]
// Catch documentation errors caused by code changes.
#![deny(rustdoc::broken_intra_doc_links)]
Expand Down Expand Up @@ -75,10 +75,10 @@ impl AsRef<[u8]> for OutgoingCipherKey {
&self.0
}
}

/// Newtype representing the byte encoding of an [`EphemeralPublicKey`].
///
/// [`EphemeralPublicKey`]: Domain::EphemeralPublicKey
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(
BorshSerialize,
BorshDeserialize,
Expand Down
9 changes: 7 additions & 2 deletions masp_primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ num-traits = { version = "0.2.19", git = "https://github.com/heliaxdev/num-trait
subtle = "2.2.3"

# - Shielded protocols
bls12_381 = "0.8"
# branch "tomas/arbitrary"
bls12_381 = { git = "https://github.com/heliaxdev/bls12_381.git", rev = "d3ebe9dd6488fac1923db120a7498079e55dd838" }
ff = "0.13"
group = { version = "0.13", features = ["wnaf-memuse"] }
incrementalmerkletree = "0.3"
jubjub = "0.10"
# branch "tomas/arbitrary"
jubjub = { git = "https://github.com/heliaxdev/jubjub.git", rev = "a373686962f4e9d0edb3b4716f86ff6bbd9aa86c" }
nonempty = "0.7"

# - Static constants
Expand All @@ -74,6 +76,8 @@ aes = "0.8"
fpe = "0.6"

borsh = {version = "1.2.0", features = ["unstable__schema", "derive"]}
arbitrary = {version = "1.3", features = ["derive"], optional = true }

[dependencies.masp_note_encryption]
version = "1.0.0"
path = "../masp_note_encryption"
Expand All @@ -90,6 +94,7 @@ rand_xorshift = "0.3"
transparent-inputs = []
test-dependencies = ["proptest"]
default = ["transparent-inputs"]
arbitrary = ["dep:arbitrary", "masp_note_encryption/arbitrary", "bls12_381/arbitrary", "jubjub/arbitrary"]

[badges]
maintenance = { status = "actively-developed" }
1 change: 1 addition & 0 deletions masp_primitives/src/asset_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use std::{
hash::{Hash, Hasher},
};

#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, BorshSerialize, BorshDeserialize, Clone, Copy, Eq, BorshSchema)]
pub struct AssetType {
identifier: [u8; ASSET_IDENTIFIER_LENGTH], //32 byte asset type preimage
Expand Down
2 changes: 2 additions & 0 deletions masp_primitives/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::ops::{Add, Bound, RangeBounds, Sub};

/// A wrapper type representing blockchain heights. Safe conversion from
/// various integer types, as well as addition and subtraction, are provided.
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[repr(transparent)]
#[derive(
Clone, Copy, Debug, PartialEq, Eq, Hash, BorshSerialize, BorshDeserialize, BorshSchema,
Expand Down Expand Up @@ -244,6 +245,7 @@ pub const ZIP212_GRACE_PERIOD: u32 = 0;
/// See [ZIP 200](https://zips.z.cash/zip-0200) for more details.
///
/// [`signature_hash`]: crate::transaction::sighash::signature_hash
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum BranchId {
/// The consensus rules deployed by [`NetworkUpgrade::MASP`].
Expand Down
12 changes: 12 additions & 0 deletions masp_primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,15 @@ pub use num_traits;

#[cfg(test)]
mod test_vectors;

#[cfg(not(feature = "arbitrary"))]
pub trait MaybeArbitrary<'a> {}

#[cfg(not(feature = "arbitrary"))]
impl<'a, T> MaybeArbitrary<'a> for T {}

#[cfg(feature = "arbitrary")]
pub trait MaybeArbitrary<'a>: arbitrary::Arbitrary<'a> {}

#[cfg(feature = "arbitrary")]
impl<'a, T: for<'b> arbitrary::Arbitrary<'b>> MaybeArbitrary<'a> for T {}
1 change: 1 addition & 0 deletions masp_primitives/src/merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ impl<Node: Hashable> BorshDeserialize for IncrementalWitness<Node> {
}

/// A path from a position in a particular commitment tree to the root of that tree.
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct MerklePath<Node> {
pub auth_path: Vec<(Node, bool)>,
Expand Down
7 changes: 7 additions & 0 deletions masp_primitives/src/sapling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub fn merkle_hash(depth: usize, lhs: &[u8; 32], rhs: &[u8; 32]) -> [u8; 32] {
}

/// A node within the Sapling commitment tree.
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Clone, Copy, Debug, PartialEq, Eq, BorshSerialize, BorshDeserialize, Default)]
pub struct Node {
repr: [u8; 32],
Expand Down Expand Up @@ -261,6 +262,7 @@ impl BorshSchema for ProofGenerationKey {

/// A key used to derive the nullifier for a Sapling note.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub struct NullifierDerivingKey(pub jubjub::SubgroupPoint);

impl BorshSerialize for NullifierDerivingKey {
Expand Down Expand Up @@ -301,6 +303,7 @@ impl BorshSchema for NullifierDerivingKey {
}

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub struct ViewingKey {
pub ak: jubjub::SubgroupPoint,
pub nk: NullifierDerivingKey,
Expand Down Expand Up @@ -450,6 +453,7 @@ impl SaplingIvk {
}
}

#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(
Copy, Clone, Debug, PartialEq, Eq, Hash, BorshSerialize, BorshDeserialize, BorshSchema,
)]
Expand Down Expand Up @@ -624,6 +628,7 @@ impl BorshSchema for PaymentAddress {
/// Before ZIP 212, the note commitment trapdoor `rcm` must be a scalar value.
/// After ZIP 212, the note randomness `rseed` is a 32-byte sequence, used to derive
/// both the note commitment trapdoor `rcm` and the ephemeral private key `esk`.
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Copy, Clone, Debug)]
pub enum Rseed {
BeforeZip212(jubjub::Fr),
Expand Down Expand Up @@ -686,6 +691,7 @@ impl BorshDeserialize for Rseed {
}

/// Typesafe wrapper for nullifier values.
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(
Copy,
Clone,
Expand Down Expand Up @@ -743,6 +749,7 @@ impl From<NoteValue> for u64 {
}
}

#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Clone, Debug, Copy)]
pub struct Note<R = Rseed> {
/// The asset type that the note represents
Expand Down
3 changes: 3 additions & 0 deletions masp_primitives/src/sapling/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ pub enum DecodingError {
}

/// An outgoing viewing key
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(
Clone, Copy, Debug, PartialEq, Eq, Hash, BorshSerialize, BorshDeserialize, BorshSchema,
)]
pub struct OutgoingViewingKey(pub [u8; 32]);

/// A Sapling expanded spending key
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Clone, PartialEq, Eq, Copy)]
pub struct ExpandedSpendingKey {
pub ask: jubjub::Fr,
Expand Down Expand Up @@ -128,6 +130,7 @@ impl ExpandedSpendingKey {

/// A Sapling key that provides the capability to view incoming and outgoing transactions.
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub struct FullViewingKey {
pub vk: ViewingKey,
pub ovk: OutgoingViewingKey,
Expand Down
2 changes: 2 additions & 0 deletions masp_primitives/src/sapling/redjubjub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ fn h_star(a: &[u8], b: &[u8]) -> jubjub::Fr {
hash_to_scalar(b"MASP__RedJubjubH", a, b)
}

#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Copy, Clone, Debug, PartialOrd, PartialEq, Ord, Eq, Hash, BorshSchema)]
pub struct Signature {
rbar: [u8; 32],
Expand All @@ -46,6 +47,7 @@ pub struct Signature {

pub struct PrivateKey(pub jubjub::Fr);

#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, Clone, PartialEq, Eq, Copy)]
pub struct PublicKey(pub ExtendedPoint);

Expand Down
Loading
Loading