Skip to content

Commit

Permalink
Merge branch 'main' into mariari/bump-borsh
Browse files Browse the repository at this point in the history
  • Loading branch information
joe authored Sep 21, 2023
2 parents 87cf808 + 22288a9 commit 4eebd81
Show file tree
Hide file tree
Showing 19 changed files with 34 additions and 51 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
2 changes: 1 addition & 1 deletion masp_primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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]
Expand Down
2 changes: 1 addition & 1 deletion masp_primitives/src/asset_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,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
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
1 change: 0 additions & 1 deletion masp_primitives/src/merkle_tree.rs
Original file line number Diff line number Diff line change
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
12 changes: 6 additions & 6 deletions masp_primitives/src/sapling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ impl BorshDeserialize for ViewingKey {

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

Expand Down Expand Up @@ -462,7 +462,7 @@ impl FromStr for PaymentAddress {

impl PartialOrd for PaymentAddress {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.to_bytes().partial_cmp(&other.to_bytes())
Some(self.cmp(other))
}
}
impl Ord for PaymentAddress {
Expand Down Expand Up @@ -536,7 +536,7 @@ impl TryFrom<u64> for NoteValue {
type Error = ();

fn try_from(value: u64) -> Result<Self, Self::Error> {
if value <= MAX_MONEY as u64 {
if value <= MAX_MONEY {
Ok(NoteValue(value))
} else {
Err(())
Expand Down Expand Up @@ -757,15 +757,15 @@ pub mod testing {
};

prop_compose! {
pub fn arb_note_value()(value in 0u64..=MAX_MONEY as u64) -> NoteValue {
pub fn arb_note_value()(value in 0u64..=MAX_MONEY) -> NoteValue {
NoteValue::try_from(value).unwrap()
}
}

prop_compose! {
/// The
pub fn arb_positive_note_value(bound: u64)(
value in 1u64..=(min(bound, MAX_MONEY as u64))
value in 1u64..=(min(bound, MAX_MONEY))
) -> NoteValue {
NoteValue::try_from(value).unwrap()
}
Expand Down Expand Up @@ -824,7 +824,7 @@ mod tests {
proptest! {
#![proptest_config(ProptestConfig::with_cases(10))]
#[test]
fn note_serialization(note in arb_positive_note_value(MAX_MONEY as u64).prop_flat_map(arb_note)) {
fn note_serialization(note in arb_positive_note_value(MAX_MONEY).prop_flat_map(arb_note)) {
// BorshSerialize
let borsh = borsh::to_vec(&note).unwrap();
// BorshDeserialize
Expand Down
4 changes: 2 additions & 2 deletions masp_primitives/src/sapling/note_encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ impl<P: consensus::Parameters> BatchDomain for SaplingDomain<P> {
shared_secrets
.into_iter()
.map(|s| s.and_then(|_| secrets_affine.next()))
.zip(ephemeral_keys.into_iter())
.zip(ephemeral_keys)
.map(|(secret, ephemeral_key)| {
secret.map(|dhsecret| {
Blake2bParams::new()
Expand All @@ -389,7 +389,7 @@ impl<P: consensus::Parameters> BatchDomain for SaplingDomain<P> {
let ephemeral_keys: Vec<_> = ephemeral_keys.collect();
let epks = jubjub::AffinePoint::batch_from_bytes(ephemeral_keys.iter().map(|b| b.0));
epks.into_iter()
.zip(ephemeral_keys.into_iter())
.zip(ephemeral_keys)
.map(|(epk, ephemeral_key)| {
(
epk.map(jubjub::ExtendedPoint::from)
Expand Down
5 changes: 1 addition & 4 deletions masp_primitives/src/sapling/pedersen_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ pub fn pedersen_hash<I>(personalization: Personalization, bits: I) -> jubjub::Su
where
I: IntoIterator<Item = bool>,
{
let mut bits = personalization
.get_bits()
.into_iter()
.chain(bits.into_iter());
let mut bits = personalization.get_bits().into_iter().chain(bits);

let mut result = jubjub::SubgroupPoint::identity();
let mut generators = PEDERSEN_HASH_EXP_TABLE.iter();
Expand Down
4 changes: 2 additions & 2 deletions masp_primitives/src/sapling/redjubjub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ pub struct BatchEntry<'a> {

// TODO: #82: This is a naive implementation currently,
// and doesn't use multiexp.
pub fn batch_verify<'a, R: RngCore>(
pub fn batch_verify<R: RngCore>(
mut rng: &mut R,
batch: &[BatchEntry<'a>],
batch: &[BatchEntry<'_>],
p_g: SubgroupPoint,
) -> bool {
let mut acc = ExtendedPoint::identity();
Expand Down
10 changes: 3 additions & 7 deletions masp_primitives/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,7 @@ impl Transaction {

let shielded_spends = sd_v5s
.into_iter()
.zip(
v_spend_proofs
.into_iter()
.zip(v_spend_auth_sigs.into_iter()),
)
.zip(v_spend_proofs.into_iter().zip(v_spend_auth_sigs))
.map(|(sd_5, (zkproof, spend_auth_sig))| {
// the following `unwrap` is safe because we know n_spends > 0.
sd_5.into_spend_description(spend_anchor.unwrap(), zkproof, spend_auth_sig)
Expand All @@ -450,13 +446,13 @@ impl Transaction {

let shielded_converts = cd_v5s
.into_iter()
.zip(v_convert_proofs.into_iter())
.zip(v_convert_proofs)
.map(|(cd_5, zkproof)| cd_5.into_convert_description(convert_anchor.unwrap(), zkproof))
.collect();

let shielded_outputs = od_v5s
.into_iter()
.zip(v_output_proofs.into_iter())
.zip(v_output_proofs)
.map(|(od_5, zkproof)| od_5.into_output_description(zkproof))
.collect();

Expand Down
2 changes: 1 addition & 1 deletion masp_primitives/src/transaction/components/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ pub mod testing {

prop_compose! {
pub fn arb_i128_sum()(asset_type in arb_asset_type(), amt in i128::MIN..i128::MAX) -> I128Sum {
ValueSum::from_pair(asset_type, amt as i128).unwrap()
ValueSum::from_pair(asset_type, amt).unwrap()
}
}

Expand Down
6 changes: 3 additions & 3 deletions masp_primitives/src/transaction/components/sapling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,12 +498,12 @@ pub struct ConvertDescriptionV5 {
}

impl ConvertDescriptionV5 {
pub fn read<R: Read>(mut reader: &mut R) -> io::Result<Self> {
pub fn read<R: Read>(reader: &mut R) -> io::Result<Self> {
// Consensus rules (§4.4) & (§4.5):
// - Canonical encoding is enforced here.
// - "Not small order" is enforced in SaplingVerificationContext::(check_spend()/check_output())
// (located in zcash_proofs::sapling::verifier).
let cv = read_point(&mut reader, "cv")?;
let cv = read_point(reader, "cv")?;

Ok(ConvertDescriptionV5 { cv })
}
Expand Down Expand Up @@ -644,7 +644,7 @@ pub mod testing {
}

prop_compose! {
/// produce a spend description with invalid data (useful only for serialization
/// produce a convert description with invalid data (useful only for serialization
/// roundtrip testing).
pub fn arb_convert_description()(
cv in arb_extended_point(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ pub mod testing {
fn arb_bundle()(n_notes in 1..30usize)(
extsk in arb_extended_spending_key(),
spendable_notes in vec(
arb_positive_note_value(MAX_MONEY as u64 / 10000).prop_flat_map(arb_note),
arb_positive_note_value(MAX_MONEY / 10000).prop_flat_map(arb_note),
n_notes
),
commitment_trees in vec(
Expand Down
2 changes: 1 addition & 1 deletion masp_primitives/src/zip32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ mod tests {
let too_big = DiversifierIndex([
0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
]);
assert!(matches!(u32::try_from(too_big), Err(_)));
assert!(u32::try_from(too_big).is_err());
}
}

Expand Down
8 changes: 2 additions & 6 deletions masp_primitives/src/zip32/sapling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,7 @@ impl BorshSerialize for ExtendedFullViewingKey {

impl PartialOrd for ExtendedFullViewingKey {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
let a = borsh::to_vec(self).expect("unable to canonicalize ExtendedFullViewingKey");
let b = borsh::to_vec(other).expect("unable to canonicalize ExtendedFullViewingKey");
a.partial_cmp(&b)
Some(self.cmp(other))
}
}

Expand Down Expand Up @@ -870,9 +868,7 @@ impl FromStr for ExtendedSpendingKey {

impl PartialOrd for ExtendedSpendingKey {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
let a = borsh::to_vec(self).expect("unable to canonicalize ExtendedSpendingKey");
let b = borsh::to_vec(other).expect("unable to canonicalize ExtendedSpendingKey");
a.partial_cmp(&b)
Some(self.cmp(other))
}
}

Expand Down
2 changes: 1 addition & 1 deletion masp_proofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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]
Expand Down
4 changes: 2 additions & 2 deletions masp_proofs/src/circuit/sapling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ fn test_input_circuit_with_bls12_381_external_test_vectors() {

let tree_depth = 32;

let expected_commitment_us = vec![
let expected_commitment_us = [
"15274760159508878651789682992925045402656388195689586056903525226511870631006",
"17926082480702379779301751040578316677060182517930108360303758506447415843229",
"47560733217722603616763811825500591868568811326811130069535870262273364981945",
Expand All @@ -791,7 +791,7 @@ fn test_input_circuit_with_bls12_381_external_test_vectors() {
"27618789340710350120647137095252986938132361388195675764406370494688910938013",
];

let expected_commitment_vs = vec![
let expected_commitment_vs = [
"34821791232396287888199995100305255761362584209078006239735148846881442279277",
"25119990066174545608121950753413857831099772082356729649061420500567639159355",
"37379068700729686079521798425830021519833420633231595656391703260880647751299",
Expand Down
4 changes: 2 additions & 2 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.67.0"
components = [ "clippy", "rustfmt" ]
channel = "1.70.0"
components = [ "clippy", "rustfmt" ]

0 comments on commit 4eebd81

Please sign in to comment.