Skip to content

Commit

Permalink
Merge branch 'murisi+grarco/multi-tx-masp-vp-rebased2' (#3264)
Browse files Browse the repository at this point in the history
* origin/murisi+grarco/multi-tx-masp-vp-rebased2:
  Enable governance to change MASP token map.
  Moved SignedAmount into core and removed use of unchecked arithmetic.
  Use try_fold to build the ChangedBalances object.
  Created a structure for representing conversion leafs.
  Factored the accumulation code out of verify_sapling_balancing_value.
  Updated the WASM binaries.
  Extend SignedAmount to hold MASP value balance.
  Use a MASP crate that guarantees ValueSums.
  Make MASP VP accept IBC transactions.
  Ensure that all implied transfers have been authorized by the relevant party.
  Split validate_transparent_bundle into 3 functions.
  Now check that the diff between pre and post is the value balance.
  Now decode AssetTypes separately.
  Unifies `DeltaBalance` and `SignedAmount`
  Fix transparent bundle validation bug
  Fixes balances check in masp vp to allow non-masp transfers
  Fixes balance owner when token is minted
  Changelog #2690
  Refactors transparent bundle validation into a separate function. Removes unchecked operation.
  `valid_spend_descriptions_anchor` does not expect the presence of the sapling bundle anymore
  Refactors balances split
  Fixes unrecognized assets
  Refactors transparent bundle check to just compare maps
  Reworks masp vp to accept multiple transfers in a single tx
  • Loading branch information
brentstone committed May 21, 2024
2 parents f6ca04e + 96218d8 commit 93f626f
Show file tree
Hide file tree
Showing 38 changed files with 1,162 additions and 800 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/2690-multi-tx-masp-vp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Updated the masp vp to accept multiple transfers in a single transaction.
([\#3264](https://github.com/anoma/namada/pull/3264))
17 changes: 13 additions & 4 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ ledger-transport-hid = "0.10.0"
libc = "0.2.97"
libloading = "0.7.2"
linkme = "0.3.24"
# branch = "main"
masp_primitives = { git = "https://github.com/anoma/masp", rev = "b5e87a01c5928ce341f2d2a63a6fa6c4033be395" }
masp_proofs = { git = "https://github.com/anoma/masp", rev = "b5e87a01c5928ce341f2d2a63a6fa6c4033be395", default-features = false, features = ["local-prover"] }
# branch = "murisi/alternative-num-traits"
masp_primitives = { git = "https://github.com/anoma/masp", rev = "6fc4692841a2241633792c429cc66b42023e5bf3" }
masp_proofs = { git = "https://github.com/anoma/masp", rev = "6fc4692841a2241633792c429cc66b42023e5bf3", default-features = false, features = ["local-prover"] }
num256 = "0.3.5"
num_cpus = "1.13.0"
num-derive = "0.3.3"
Expand Down
26 changes: 6 additions & 20 deletions crates/core/src/arith.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
//! Arithmetics helpers

pub use masp_primitives::num_traits::ops::checked::{
CheckedAdd, CheckedDiv, CheckedMul, CheckedNeg, CheckedRem, CheckedSub,
};
pub use masp_primitives::num_traits::ops::overflowing::{
OverflowingAdd, OverflowingSub,
};
pub use smooth_operator::{checked, Error};

/// Performs addition that returns `None` instead of wrapping around on
/// overflow.
pub trait CheckedAdd: Sized + Copy {
/// Adds two numbers, checking for overflow. If overflow happens, `None` is
/// returned.
fn checked_add(&self, rhs: Self) -> Option<Self>;
}

/// Helpers for testing.
#[cfg(feature = "testing")]
pub mod testing {
use super::*;

impl CheckedAdd for u64 {
fn checked_add(&self, rhs: Self) -> Option<Self> {
u64::checked_add(*self, rhs)
}
}
}
36 changes: 33 additions & 3 deletions crates/core/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize};
use thiserror::Error;

use crate::address::Address;
use crate::arith::{self, checked, CheckedAdd};
use crate::arith::{self, checked, CheckedAdd, CheckedSub};
use crate::dec::{Dec, POS_DECIMAL_PRECISION};
use crate::hash::Hash;
use crate::ibc::apps::transfer::types::Amount as IbcAmount;
Expand Down Expand Up @@ -336,8 +336,38 @@ impl Amount {
}

impl CheckedAdd for Amount {
fn checked_add(&self, rhs: Self) -> Option<Self> {
self.checked_add(rhs)
type Output = Amount;

fn checked_add(self, rhs: Self) -> Option<Self::Output> {
Amount::checked_add(&self, rhs)
}
}

impl CheckedAdd for &Amount {
type Output = Amount;

fn checked_add(self, rhs: Self) -> Option<Self::Output> {
self.checked_add(*rhs)
}
}

impl CheckedSub for Amount {
type Output = Amount;

fn checked_sub(self, amount: Self) -> Option<Self::Output> {
self.raw
.checked_sub(amount.raw)
.map(|result| Self { raw: result })
}
}

impl CheckedSub for &Amount {
type Output = Amount;

fn checked_sub(self, amount: Self) -> Option<Self::Output> {
self.raw
.checked_sub(amount.raw)
.map(|result| Amount { raw: result })
}
}

Expand Down
Loading

0 comments on commit 93f626f

Please sign in to comment.