Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
joe bebel committed Sep 22, 2023
2 parents 1a68887 + f4f1ce1 commit 339ca85
Show file tree
Hide file tree
Showing 25 changed files with 309 additions and 795 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
run: echo "MASP_PARAMS=$(cargo run --release --example get-params-path --features directories)" >> $GITHUB_ENV
- name: Cache MASP parameters
id: cache-params
uses: actions/[email protected].1
uses: actions/[email protected].2
with:
path: ${{ env.MASP_PARAMS }}
key: ${{ runner.os }}-params
Expand Down Expand Up @@ -127,4 +127,4 @@ jobs:
- name: Install cargo-audit
run: cargo install cargo-audit
- name: Cargo Audit
run: cargo audit
run: cargo audit
4 changes: 2 additions & 2 deletions masp_note_encryption/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version = "0.2.0"
authors = [
"Jack Grigg <[email protected]>",
"Kris Nuttycombe <[email protected]>",
"[email protected]"
"[email protected]",
]
homepage = "https://github.com/anoma/masp"
repository = "https://github.com/anoma/masp"
Expand All @@ -24,7 +24,7 @@ chacha20 = { version = "0.9", default-features = false }
chacha20poly1305 = { version = "0.10", default-features = false }
rand_core = { version = "0.6", default-features = false }
subtle = { version = "2.3", default-features = false }
borsh = {version = "0.9", features = ["const-generics"]}
borsh = {version = "1.0.0-alpha.4", features = ["schema", "derive"]}

[features]
default = ["alloc"]
Expand Down
24 changes: 12 additions & 12 deletions masp_primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ authors = [
"Jack Grigg <[email protected]>",
"Kris Nuttycombe <[email protected]>",
"joe <[email protected]>",
"Murisi Tarusenga <[email protected]>",
"Murisi Tarusenga <[email protected]>",
"Heliax AG <[email protected]>",
]
homepage = "https://github.com/anoma/masp"
repository = "https://github.com/anoma/masp"
readme = "README.md"
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.65"
rust-version = "1.70"
categories = ["cryptography::cryptocurrencies"]

[package.metadata.docs.rs]
all-features = true

[dependencies]
zcash_encoding = { version = "0.0", git = "https://github.com/zcash/librustzcash", rev = "43c18d0" }
zcash_encoding = { version = "0.2", git = "https://github.com/zcash/librustzcash", rev = "bd7f9d7" }

# Dependencies exposed in a public API:
# (Breaking upgrades to these require a breaking upgrade to this crate.)
Expand All @@ -31,7 +31,7 @@ rand_core = "0.6"

# - Digests (output types exposed)
blake2b_simd = "1"
sha2 = "0.9"
sha2 = "0.10"

# - Metrics
memuse = "0.2.1"
Expand All @@ -43,11 +43,11 @@ num-traits = "0.2.14"
subtle = "2.2.3"

# - Shielded protocols
bls12_381 = "0.7"
ff = "0.12"
group = { version = "0.12.1", features = ["wnaf-memuse"] }
bls12_381 = "0.8"
ff = "0.13"
group = { version = "0.13", features = ["wnaf-memuse"] }
incrementalmerkletree = "0.3"
jubjub = "0.9"
jubjub = "0.10"
nonempty = "0.7"

# - Static constants
Expand All @@ -57,7 +57,7 @@ lazy_static = "1"
proptest = { version = "1.0.0", optional = true }

# - ZIP 339
bip0039 = { version = "0.9", features = ["std", "all-languages"] }
bip0039 = { version = "0.10", features = ["std", "all-languages"] }

# Dependencies used internally:
# (Breaking upgrades to these are usually backwards-compatible, but check MSRVs.)
Expand All @@ -70,10 +70,10 @@ bitvec = "1"
blake2s_simd = "1"

# - ZIP 32
aes = "0.7"
fpe = "0.5"
aes = "0.8"
fpe = "0.6"

borsh = {version = "0.9", features = ["const-generics"]}
borsh = {version = "1.0.0-alpha.4", features = ["schema", "derive"]}
[dependencies.masp_note_encryption]
version = "0.2"
path = "../masp_note_encryption"
Expand Down
13 changes: 11 additions & 2 deletions masp_primitives/src/asset_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::{
#[derive(Debug, BorshSerialize, BorshDeserialize, Clone, Copy, Eq)]
pub struct AssetType {
identifier: [u8; ASSET_IDENTIFIER_LENGTH], //32 byte asset type preimage
#[borsh_skip]
#[borsh(skip)]
nonce: Option<u8>,
}

Expand Down Expand Up @@ -148,6 +148,15 @@ impl AssetType {
pub fn get_nonce(&self) -> Option<u8> {
self.nonce
}

/// Deserialize an AssetType object
pub fn read<R: std::io::Read>(reader: &mut R) -> std::io::Result<Self> {
let mut atype = [0; crate::constants::ASSET_IDENTIFIER_LENGTH];
reader.read_exact(&mut atype)?;
AssetType::from_identifier(&atype).ok_or_else(|| {
std::io::Error::new(std::io::ErrorKind::InvalidData, "invalid asset type")
})
}
}

impl PartialEq for AssetType {
Expand All @@ -170,7 +179,7 @@ impl Hash for AssetType {

impl PartialOrd for AssetType {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.get_identifier().partial_cmp(other.get_identifier())
Some(self.cmp(other))
}
}

Expand Down
8 changes: 4 additions & 4 deletions masp_primitives/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl From<I128Sum> for AllowedConversion {
}

impl BorshSerialize for AllowedConversion {
fn serialize<W: Write>(&self, writer: &mut W) -> borsh::maybestd::io::Result<()> {
fn serialize<W: Write>(&self, writer: &mut W) -> io::Result<()> {
self.assets.write(writer)?;
writer.write_all(&self.generator.to_bytes())?;
Ok(())
Expand All @@ -122,10 +122,10 @@ impl BorshDeserialize for AllowedConversion {
/// This deserialization is unsafe because it does not do the expensive
/// computation of checking whether the asset generator corresponds to the
/// deserialized amount.
fn deserialize(buf: &mut &[u8]) -> borsh::maybestd::io::Result<Self> {
let assets = I128Sum::read(buf)?;
fn deserialize_reader<R: io::Read>(reader: &mut R) -> io::Result<Self> {
let assets = I128Sum::read(reader)?;
let gen_bytes =
<<jubjub::ExtendedPoint as GroupEncoding>::Repr as BorshDeserialize>::deserialize(buf)?;
<<jubjub::ExtendedPoint as GroupEncoding>::Repr as BorshDeserialize>::deserialize_reader(reader)?;
let generator = Option::from(jubjub::ExtendedPoint::from_bytes(&gen_bytes))
.ok_or_else(|| io::Error::from(io::ErrorKind::InvalidData))?;
let allowed_conversion: AllowedConversion = assets.clone().into();
Expand Down
2 changes: 1 addition & 1 deletion masp_primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// Allow manual RangeIncludes for now
#![allow(clippy::manual_range_contains)]
// TODO
#![allow(clippy::derive_hash_xor_eq)]
#![allow(clippy::derived_hash_with_manual_eq)]

pub mod asset_type;
pub mod consensus;
Expand Down
9 changes: 2 additions & 7 deletions masp_primitives/src/memo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ impl Deref for TextMemo {
}

/// An unencrypted memo received alongside a shielded note in a Zcash transaction.
#[derive(Clone)]
#[derive(Clone, Default)]
pub enum Memo {
/// An empty memo field.
#[default]
Empty,
/// A memo field containing a UTF-8 string.
Text(TextMemo),
Expand All @@ -173,12 +174,6 @@ impl fmt::Debug for Memo {
}
}

impl Default for Memo {
fn default() -> Self {
Memo::Empty
}
}

impl PartialEq for Memo {
fn eq(&self, rhs: &Memo) -> bool {
match (self, rhs) {
Expand Down
32 changes: 16 additions & 16 deletions masp_primitives/src/merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,14 @@ impl<Node: Hashable> FrozenCommitmentTree<Node> {
}

impl<Node: BorshSerialize> BorshSerialize for FrozenCommitmentTree<Node> {
fn serialize<W: Write>(&self, writer: &mut W) -> borsh::maybestd::io::Result<()> {
fn serialize<W: Write>(&self, writer: &mut W) -> io::Result<()> {
(&self.0, self.1).serialize(writer)
}
}

impl<Node: BorshDeserialize> BorshDeserialize for FrozenCommitmentTree<Node> {
fn deserialize(buf: &mut &[u8]) -> borsh::maybestd::io::Result<Self> {
let tup: (Vec<Node>, usize) = BorshDeserialize::deserialize(buf)?;
fn deserialize_reader<R: Read>(reader: &mut R) -> io::Result<Self> {
let tup: (Vec<Node>, usize) = BorshDeserialize::deserialize_reader(reader)?;
Ok(Self(tup.0, tup.1))
}
}
Expand Down Expand Up @@ -303,7 +303,6 @@ impl<Node> CommitmentTree<Node> {
left,
right,
parents: (1..DEPTH)
.into_iter()
.map(|i| {
if upos & (1 << i) == 0 {
None
Expand Down Expand Up @@ -471,14 +470,14 @@ impl<Node: Hashable> CommitmentTree<Node> {
}

impl<Node: Hashable> BorshSerialize for CommitmentTree<Node> {
fn serialize<W: Write>(&self, writer: &mut W) -> borsh::maybestd::io::Result<()> {
fn serialize<W: Write>(&self, writer: &mut W) -> io::Result<()> {
self.write(writer)
}
}

impl<Node: Hashable> BorshDeserialize for CommitmentTree<Node> {
fn deserialize(buf: &mut &[u8]) -> borsh::maybestd::io::Result<Self> {
Self::read(buf)
fn deserialize_reader<R: Read>(reader: &mut R) -> io::Result<Self> {
Self::read(reader)
}
}

Expand Down Expand Up @@ -699,14 +698,14 @@ impl<Node: Hashable> IncrementalWitness<Node> {
}

impl<Node: Hashable> BorshSerialize for IncrementalWitness<Node> {
fn serialize<W: Write>(&self, writer: &mut W) -> borsh::maybestd::io::Result<()> {
fn serialize<W: Write>(&self, writer: &mut W) -> io::Result<()> {
self.write(writer)
}
}

impl<Node: Hashable> BorshDeserialize for IncrementalWitness<Node> {
fn deserialize(buf: &mut &[u8]) -> borsh::maybestd::io::Result<Self> {
Self::read(buf)
fn deserialize_reader<R: Read>(reader: &mut R) -> io::Result<Self> {
Self::read(reader)
}
}

Expand Down Expand Up @@ -762,17 +761,18 @@ impl<Node: Hashable> MerklePath<Node> {
}

impl<Node: Hashable> BorshDeserialize for MerklePath<Node> {
fn deserialize(witness: &mut &[u8]) -> Result<Self, std::io::Error> {
fn deserialize_reader<R: Read>(witness: &mut R) -> Result<Self, std::io::Error> {
// Skip the first byte, which should be "depth" to signify the length of
// the following vector of Pedersen hashes.
let depth = witness[0] as usize;
*witness = &witness[1..];
let depth = witness.read_u8()? as usize;

// Begin to construct the authentication path
// Do not use any data in the witness after the expected depth
let iter = witness[..33 * depth + 8].chunks_exact(33);
// Update the witness to its final position
*witness = &witness[33 * depth + 8..];
let mut iter = vec![];
let _ = witness
.take((33 * depth + 8usize) as u64)
.read_to_end(&mut iter)?;
let iter = iter.chunks_exact(33);
// Read the position from the witness
let position = iter.remainder().read_u64::<LittleEndian>()?;

Expand Down
Loading

0 comments on commit 339ca85

Please sign in to comment.