diff --git a/Cargo.lock b/Cargo.lock index 84cbd6f48ef..1c0d1cb6d86 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3748,7 +3748,7 @@ dependencies = [ [[package]] name = "masp_note_encryption" version = "0.2.0" -source = "git+https://github.com/anoma/masp?rev=50acc5028fbcd52a05970fe7991c7850ab04358e#50acc5028fbcd52a05970fe7991c7850ab04358e" +source = "git+https://github.com/anoma/masp?rev=1345b463e8fa3b3a6fa13e4a43fb1c410690ad62#1345b463e8fa3b3a6fa13e4a43fb1c410690ad62" dependencies = [ "borsh 0.9.4", "chacha20 0.9.1", @@ -3761,7 +3761,7 @@ dependencies = [ [[package]] name = "masp_primitives" version = "0.9.0" -source = "git+https://github.com/anoma/masp?rev=50acc5028fbcd52a05970fe7991c7850ab04358e#50acc5028fbcd52a05970fe7991c7850ab04358e" +source = "git+https://github.com/anoma/masp?rev=1345b463e8fa3b3a6fa13e4a43fb1c410690ad62#1345b463e8fa3b3a6fa13e4a43fb1c410690ad62" dependencies = [ "aes 0.7.5", "bip0039", @@ -3792,7 +3792,7 @@ dependencies = [ [[package]] name = "masp_proofs" version = "0.9.0" -source = "git+https://github.com/anoma/masp?rev=50acc5028fbcd52a05970fe7991c7850ab04358e#50acc5028fbcd52a05970fe7991c7850ab04358e" +source = "git+https://github.com/anoma/masp?rev=1345b463e8fa3b3a6fa13e4a43fb1c410690ad62#1345b463e8fa3b3a6fa13e4a43fb1c410690ad62" dependencies = [ "bellman", "blake2b_simd", diff --git a/Cargo.toml b/Cargo.toml index 9c731f0fdf1..db71e929894 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -90,8 +90,8 @@ libc = "0.2.97" libloading = "0.7.2" libsecp256k1 = {git = "https://github.com/heliaxdev/libsecp256k1", rev = "bbb3bd44a49db361f21d9db80f9a087c194c0ae9", default-features = false, features = ["std", "static-context"]} # branch = "murisi/namada-integration" -masp_primitives = { git = "https://github.com/anoma/masp", rev = "50acc5028fbcd52a05970fe7991c7850ab04358e" } -masp_proofs = { git = "https://github.com/anoma/masp", rev = "50acc5028fbcd52a05970fe7991c7850ab04358e", default-features = false, features = ["local-prover"] } +masp_primitives = { git = "https://github.com/anoma/masp", rev = "1345b463e8fa3b3a6fa13e4a43fb1c410690ad62" } +masp_proofs = { git = "https://github.com/anoma/masp", rev = "1345b463e8fa3b3a6fa13e4a43fb1c410690ad62", default-features = false, features = ["local-prover"] } num256 = "0.3.5" num_cpus = "1.13.0" num-derive = "0.3.3" diff --git a/apps/src/lib/client/rpc.rs b/apps/src/lib/client/rpc.rs index d750ccc7590..1645009011d 100644 --- a/apps/src/lib/client/rpc.rs +++ b/apps/src/lib/client/rpc.rs @@ -2126,7 +2126,7 @@ pub async fn query_conversions< // Track whether any non-sentinel conversions are found let mut conversions_found = false; for ((addr, _), epoch, conv, _) in conv_state.assets.values() { - let amt: masp_primitives::transaction::components::I32Sum = + let amt: masp_primitives::transaction::components::I128Sum = conv.clone().into(); // If the user has specified any targets, then meet them // If we have a sentinel conversion, then skip printing @@ -2181,7 +2181,7 @@ pub async fn query_conversion( Address, MaspDenom, Epoch, - masp_primitives::transaction::components::I32Sum, + masp_primitives::transaction::components::I128Sum, MerklePath, )> { namada::sdk::rpc::query_conversion(client, asset_type).await diff --git a/apps/src/lib/config/genesis.rs b/apps/src/lib/config/genesis.rs index eac5f5bdca0..3331a30c036 100644 --- a/apps/src/lib/config/genesis.rs +++ b/apps/src/lib/config/genesis.rs @@ -1012,8 +1012,8 @@ pub fn genesis(num_validators: u64) -> Genesis { implicit_vp_code_path: vp_implicit_path.into(), implicit_vp_sha256: Default::default(), max_signatures_per_transaction: 15, - epochs_per_year: 525_600, /* seconds in yr (60*60*24*365) div seconds - * per epoch (60 = min_duration) */ + epochs_per_year: 365, /* seconds in yr (60*60*24*365) div seconds + * per epoch (60 = min_duration) */ pos_gain_p: Dec::new(1, 1).expect("This can't fail"), pos_gain_d: Dec::new(1, 1).expect("This can't fail"), staked_ratio: Dec::zero(), diff --git a/core/src/ledger/storage/masp_conversions.rs b/core/src/ledger/storage/masp_conversions.rs index 5b195dd29dc..9e52d4e7872 100644 --- a/core/src/ledger/storage/masp_conversions.rs +++ b/core/src/ledger/storage/masp_conversions.rs @@ -10,6 +10,7 @@ use masp_primitives::sapling::Node; use crate::ledger::inflation::{RewardsController, ValsToUpdate}; use crate::ledger::parameters; +use crate::ledger::storage_api::token::read_denom; use crate::ledger::storage_api::{StorageRead, StorageWrite}; use crate::types::address::Address; use crate::types::dec::Dec; @@ -17,18 +18,11 @@ use crate::types::storage::Epoch; use crate::types::token::MaspDenom; use crate::types::{address, token}; -/// Inflation is implicitly denominated by this value. The lower this figure, -/// the less precise inflation computations are. The higher this figure, the -/// larger the fixed-width types that are required to carry out inflation -/// computations. This value should be fixed constant for each asset type - here -/// we have simplified it and made it constant across asset types. -const PRECISION: u64 = 100; - /// A representation of the conversion state #[derive(Debug, Default, BorshSerialize, BorshDeserialize)] pub struct ConversionState { /// The last amount of the native token distributed - pub normed_inflation: Option, + pub normed_inflation: Option, /// The tree currently containing all the conversions pub tree: FrozenCommitmentTree, /// Map assets to their latest conversion and position in Merkle tree @@ -44,11 +38,20 @@ pub struct ConversionState { pub fn calculate_masp_rewards( wl_storage: &mut super::WlStorage, addr: &Address, -) -> crate::ledger::storage_api::Result<(u32, u32)> +) -> crate::ledger::storage_api::Result<(u128, u128)> where D: 'static + super::DB + for<'iter> super::DBIter<'iter>, H: 'static + super::StorageHasher, { + let denomination = read_denom(wl_storage, addr).unwrap().unwrap(); + // Inflation is implicitly denominated by this value. The lower this + // figure, the less precise inflation computations are. This is especially + // problematic when inflation is coming from a token with much higher + // denomination than the native token. The higher this figure, the higher + // the threshold of holdings required in order to receive non-zero rewards. + // This value should be fixed constant for each asset type. + let precision = 10u128.pow(std::cmp::max(u32::from(denomination.0), 3) - 3); + let masp_addr = address::masp(); // Query the storage for information @@ -126,10 +129,11 @@ where // Since we must put the notes in a compatible format with the // note format, we must make the inflation amount discrete. let noterized_inflation = if total_token_in_masp.is_zero() { - 0u32 + 0u128 } else { crate::types::uint::Uint::try_into( - (inflation.raw_amount() * PRECISION) + (inflation.raw_amount() + * crate::types::uint::Uint::from(precision)) / total_token_in_masp.raw_amount(), ) .unwrap() @@ -164,7 +168,12 @@ where wl_storage .write( &token::masp_last_inflation(addr), - (total_token_in_masp / PRECISION) * u64::from(noterized_inflation), + token::Amount::from_uint( + (total_token_in_masp.raw_amount() / precision) + * crate::types::uint::Uint::from(noterized_inflation), + 0, + ) + .unwrap(), ) .expect("unable to encode new inflation rate (Decimal)"); @@ -172,15 +181,7 @@ where .write(&token::masp_last_locked_ratio(addr), locked_ratio) .expect("unable to encode new locked ratio (Decimal)"); - // to make it conform with the expected output, we need to - // move it to a ratio of x/100 to match the masp_rewards - // function This may be unneeded, as we could describe it as a - // ratio of x/1 - - Ok(( - noterized_inflation, - PRECISION.try_into().expect("inflation precision too large"), - )) + Ok((noterized_inflation, precision)) } // This is only enabled when "wasm-runtime" is on, because we're using rayon @@ -196,7 +197,7 @@ where use std::cmp::Ordering; use masp_primitives::ff::PrimeField; - use masp_primitives::transaction::components::I32Sum as MaspAmount; + use masp_primitives::transaction::components::I128Sum as MaspAmount; use rayon::iter::{ IndexedParallelIterator, IntoParallelIterator, ParallelIterator, }; @@ -288,12 +289,12 @@ where (addr.clone(), denom), (MaspAmount::from_pair( old_asset, - -(*normed_inflation as i32), + -(*normed_inflation as i128), ) .unwrap() + MaspAmount::from_pair( new_asset, - new_normed_inflation as i32, + new_normed_inflation as i128, ) .unwrap()) .into(), @@ -320,13 +321,13 @@ where // intermediate tokens cancel/ telescope out current_convs.insert( (addr.clone(), denom), - (MaspAmount::from_pair(old_asset, -(reward.1 as i32)) + (MaspAmount::from_pair(old_asset, -(reward.1 as i128)) .unwrap() - + MaspAmount::from_pair(new_asset, reward.1 as i32) + + MaspAmount::from_pair(new_asset, reward.1 as i128) .unwrap() + MaspAmount::from_pair( reward_assets[denom as usize], - real_reward as i32, + real_reward as i128, ) .unwrap()) .into(), diff --git a/core/src/types/address.rs b/core/src/types/address.rs index 416b3f059ea..b0b709d69fc 100644 --- a/core/src/types/address.rs +++ b/core/src/types/address.rs @@ -681,23 +681,6 @@ pub fn tokens() -> HashMap { .collect() } -/// Temporary helper for testing, a hash map of tokens addresses with their -/// MASP XAN incentive schedules. If the reward is (a, b) then a rewarded tokens -/// are dispensed for every b possessed tokens. -pub fn masp_rewards() -> HashMap { - vec![ - (nam(), (0, 100)), - (btc(), (1, 100)), - (eth(), (2, 100)), - (dot(), (3, 100)), - (schnitzel(), (4, 100)), - (apfel(), (5, 100)), - (kartoffel(), (6, 100)), - ] - .into_iter() - .collect() -} - #[cfg(test)] pub mod tests { use proptest::prelude::*; diff --git a/core/src/types/token.rs b/core/src/types/token.rs index c6fefea9c6a..1c6a75335d0 100644 --- a/core/src/types/token.rs +++ b/core/src/types/token.rs @@ -596,6 +596,20 @@ impl Mul for Amount { } } +/// A combination of Euclidean division and fractions: +/// x*(a,b) = (a*(x//b), x%b). +impl Mul<(u128, u128)> for Amount { + type Output = (Amount, Amount); + + fn mul(mut self, rhs: (u128, u128)) -> Self::Output { + let amt = Amount { + raw: (self.raw / rhs.1) * Uint::from(rhs.0), + }; + self.raw %= rhs.1; + (amt, self) + } +} + /// A combination of Euclidean division and fractions: /// x*(a,b) = (a*(x//b), x%b). impl Mul<(u64, u64)> for Amount { @@ -1336,10 +1350,10 @@ pub mod testing { H: 'static + ledger_storage::StorageHasher, { use crate::ledger::parameters::storage::get_epochs_per_year_key; - use crate::types::address::masp_rewards; + use crate::types::address::tokens; - let masp_rewards = masp_rewards(); - let masp_reward_keys: Vec<_> = masp_rewards.keys().collect(); + let tokens = tokens(); + let masp_reward_keys: Vec<_> = tokens.keys().collect(); wl_storage .write(&get_epochs_per_year_key(), epochs_per_year) diff --git a/shared/src/ledger/queries/shell.rs b/shared/src/ledger/queries/shell.rs index a766846916a..520c702608c 100644 --- a/shared/src/ledger/queries/shell.rs +++ b/shared/src/ledger/queries/shell.rs @@ -30,7 +30,7 @@ type Conversion = ( Address, MaspDenom, Epoch, - masp_primitives::transaction::components::I32Sum, + masp_primitives::transaction::components::I128Sum, MerklePath, ); @@ -254,7 +254,7 @@ where addr.clone(), *denom, *epoch, - Into::::into( + Into::::into( conv.clone(), ), ctx.wl_storage.storage.conversion_state.tree.path(*pos), diff --git a/shared/src/sdk/masp.rs b/shared/src/sdk/masp.rs index 739f941b9a6..f9459f6cab0 100644 --- a/shared/src/sdk/masp.rs +++ b/shared/src/sdk/masp.rs @@ -34,8 +34,8 @@ use masp_primitives::transaction::builder::{self, *}; use masp_primitives::transaction::components::sapling::builder::SaplingMetadata; use masp_primitives::transaction::components::transparent::builder::TransparentBuilder; use masp_primitives::transaction::components::{ - ConvertDescription, I128Sum, I32Sum, OutputDescription, SpendDescription, - TxOut, U64Sum, + ConvertDescription, I128Sum, OutputDescription, SpendDescription, TxOut, + U64Sum, }; use masp_primitives::transaction::fees::fixed::FeeRule; use masp_primitives::transaction::sighash::{signature_hash, SignableInput}; @@ -989,7 +989,7 @@ impl ShieldedContext { Address, MaspDenom, _, - I32Sum, + I128Sum, MerklePath, ) = rpc::query_conversion(client, asset_type).await?; self.asset_types diff --git a/shared/src/sdk/rpc.rs b/shared/src/sdk/rpc.rs index 58609bed427..cb881e88a26 100644 --- a/shared/src/sdk/rpc.rs +++ b/shared/src/sdk/rpc.rs @@ -228,7 +228,7 @@ pub async fn query_conversion( Address, MaspDenom, Epoch, - masp_primitives::transaction::components::I32Sum, + masp_primitives::transaction::components::I128Sum, MerklePath, )> { Some(unwrap_client_response::( diff --git a/shared/src/sdk/tx.rs b/shared/src/sdk/tx.rs index 9d7fe0cfe48..0381e6f6aa0 100644 --- a/shared/src/sdk/tx.rs +++ b/shared/src/sdk/tx.rs @@ -15,7 +15,7 @@ use masp_primitives::transaction::components::sapling::fees::{ use masp_primitives::transaction::components::transparent::fees::{ InputView as TransparentInputView, OutputView as TransparentOutputView, }; -use masp_primitives::transaction::components::I32Sum; +use masp_primitives::transaction::components::I128Sum; use namada_core::ledger::governance::cli::onchain::{ DefaultProposal, OnChainProposal, PgfFundingProposal, PgfStewardProposal, ProposalVote, @@ -1643,7 +1643,7 @@ async fn used_asset_types< // Collect all the asset types used in the Sapling converts for output in builder.sapling_converts() { for (asset_type, _) in - I32Sum::from(output.conversion().clone()).components() + I128Sum::from(output.conversion().clone()).components() { add_asset_type(&mut asset_types, shielded, client, *asset_type) .await; diff --git a/test_fixtures/masp_proofs/1362F1CF9B836CF8B05D8189EA9CB1712CCA85B0E96A3330A63BE7CD9E5ECD22.bin b/test_fixtures/masp_proofs/1362F1CF9B836CF8B05D8189EA9CB1712CCA85B0E96A3330A63BE7CD9E5ECD22.bin index 20634c1de5e..741f4d5106a 100644 Binary files a/test_fixtures/masp_proofs/1362F1CF9B836CF8B05D8189EA9CB1712CCA85B0E96A3330A63BE7CD9E5ECD22.bin and b/test_fixtures/masp_proofs/1362F1CF9B836CF8B05D8189EA9CB1712CCA85B0E96A3330A63BE7CD9E5ECD22.bin differ diff --git a/test_fixtures/masp_proofs/29AC8DE3B07495BEABEAF50FE8FF8BF07596031CD460FEBFAEA4F75AF65D5402.bin b/test_fixtures/masp_proofs/29AC8DE3B07495BEABEAF50FE8FF8BF07596031CD460FEBFAEA4F75AF65D5402.bin new file mode 100644 index 00000000000..b748454de8f Binary files /dev/null and b/test_fixtures/masp_proofs/29AC8DE3B07495BEABEAF50FE8FF8BF07596031CD460FEBFAEA4F75AF65D5402.bin differ diff --git a/test_fixtures/masp_proofs/37332141CB34FC30FF51F4BEE8D76149D3088F539CF8372D404609B89B095EF7.bin b/test_fixtures/masp_proofs/37332141CB34FC30FF51F4BEE8D76149D3088F539CF8372D404609B89B095EF7.bin index 1fbae646028..18f83d05436 100644 Binary files a/test_fixtures/masp_proofs/37332141CB34FC30FF51F4BEE8D76149D3088F539CF8372D404609B89B095EF7.bin and b/test_fixtures/masp_proofs/37332141CB34FC30FF51F4BEE8D76149D3088F539CF8372D404609B89B095EF7.bin differ diff --git a/test_fixtures/masp_proofs/52984E26D4A044A259B441C1DAEB66F886B3A3B6C71D33F456B859D01DA47ADD.bin b/test_fixtures/masp_proofs/52984E26D4A044A259B441C1DAEB66F886B3A3B6C71D33F456B859D01DA47ADD.bin new file mode 100644 index 00000000000..c51b5ed0d97 Binary files /dev/null and b/test_fixtures/masp_proofs/52984E26D4A044A259B441C1DAEB66F886B3A3B6C71D33F456B859D01DA47ADD.bin differ diff --git a/test_fixtures/masp_proofs/8B29BC2E1A96DF331C7C3A2B227C98D1E5AAAA9988F26B1A47090ACCE693572F.bin b/test_fixtures/masp_proofs/8B29BC2E1A96DF331C7C3A2B227C98D1E5AAAA9988F26B1A47090ACCE693572F.bin index fc528241a15..afcad7c6544 100644 Binary files a/test_fixtures/masp_proofs/8B29BC2E1A96DF331C7C3A2B227C98D1E5AAAA9988F26B1A47090ACCE693572F.bin and b/test_fixtures/masp_proofs/8B29BC2E1A96DF331C7C3A2B227C98D1E5AAAA9988F26B1A47090ACCE693572F.bin differ diff --git a/test_fixtures/masp_proofs/917B7AD5FD4F2F0CB33924511A59181FA326C06FCA9A49B5A5C394C75942820E.bin b/test_fixtures/masp_proofs/917B7AD5FD4F2F0CB33924511A59181FA326C06FCA9A49B5A5C394C75942820E.bin deleted file mode 100644 index 4dde0ccf5f1..00000000000 Binary files a/test_fixtures/masp_proofs/917B7AD5FD4F2F0CB33924511A59181FA326C06FCA9A49B5A5C394C75942820E.bin and /dev/null differ diff --git a/test_fixtures/masp_proofs/9883C2EF7971504BB1CF651BAFFC3DA2C57E4FD8FF0811D9CB129887F0F9F706.bin b/test_fixtures/masp_proofs/9883C2EF7971504BB1CF651BAFFC3DA2C57E4FD8FF0811D9CB129887F0F9F706.bin new file mode 100644 index 00000000000..094103100a7 Binary files /dev/null and b/test_fixtures/masp_proofs/9883C2EF7971504BB1CF651BAFFC3DA2C57E4FD8FF0811D9CB129887F0F9F706.bin differ diff --git a/test_fixtures/masp_proofs/99393E3AC8046F86ABA05519568B6780B6F18A312AE3909BEA19D16FCFE837DC.bin b/test_fixtures/masp_proofs/99393E3AC8046F86ABA05519568B6780B6F18A312AE3909BEA19D16FCFE837DC.bin new file mode 100644 index 00000000000..f456d94d7d5 Binary files /dev/null and b/test_fixtures/masp_proofs/99393E3AC8046F86ABA05519568B6780B6F18A312AE3909BEA19D16FCFE837DC.bin differ diff --git a/test_fixtures/masp_proofs/A08264B610C5903A47D48E90ABA700BB49387329F8FD049D5F66C95B11B55ADE.bin b/test_fixtures/masp_proofs/A08264B610C5903A47D48E90ABA700BB49387329F8FD049D5F66C95B11B55ADE.bin deleted file mode 100644 index 4d88ddcc5d4..00000000000 Binary files a/test_fixtures/masp_proofs/A08264B610C5903A47D48E90ABA700BB49387329F8FD049D5F66C95B11B55ADE.bin and /dev/null differ diff --git a/test_fixtures/masp_proofs/A9D6D90370C747C254D4DD4A2D4B1C762CEA0436B0ECA42C52A830A0FD66BC00.bin b/test_fixtures/masp_proofs/A9D6D90370C747C254D4DD4A2D4B1C762CEA0436B0ECA42C52A830A0FD66BC00.bin deleted file mode 100644 index d67642b43e9..00000000000 Binary files a/test_fixtures/masp_proofs/A9D6D90370C747C254D4DD4A2D4B1C762CEA0436B0ECA42C52A830A0FD66BC00.bin and /dev/null differ diff --git a/test_fixtures/masp_proofs/BA4FED83467B6FEE522748C6F7E72A01F0B169F946835583DC2C71B550315603.bin b/test_fixtures/masp_proofs/BA4FED83467B6FEE522748C6F7E72A01F0B169F946835583DC2C71B550315603.bin new file mode 100644 index 00000000000..565d189c0ce Binary files /dev/null and b/test_fixtures/masp_proofs/BA4FED83467B6FEE522748C6F7E72A01F0B169F946835583DC2C71B550315603.bin differ diff --git a/test_fixtures/masp_proofs/C7ECE8C02C2E764EFD5B6A0756CFE8EEC08E2D8512695A667D294AE1A4A8D4E6.bin b/test_fixtures/masp_proofs/C7ECE8C02C2E764EFD5B6A0756CFE8EEC08E2D8512695A667D294AE1A4A8D4E6.bin new file mode 100644 index 00000000000..d7fe00a74fe Binary files /dev/null and b/test_fixtures/masp_proofs/C7ECE8C02C2E764EFD5B6A0756CFE8EEC08E2D8512695A667D294AE1A4A8D4E6.bin differ diff --git a/test_fixtures/masp_proofs/EE7C912B7E21F07494D58AA6668DC6BBB31619C7E93A1A5A2E64B694DBE1BD6E.bin b/test_fixtures/masp_proofs/EE7C912B7E21F07494D58AA6668DC6BBB31619C7E93A1A5A2E64B694DBE1BD6E.bin new file mode 100644 index 00000000000..fee4361a2b5 Binary files /dev/null and b/test_fixtures/masp_proofs/EE7C912B7E21F07494D58AA6668DC6BBB31619C7E93A1A5A2E64B694DBE1BD6E.bin differ diff --git a/test_fixtures/masp_proofs/EEB91EB873807EC77BBCA95D4CFA3F379DB351AB4AE081207ABFDFC429C9FA48.bin b/test_fixtures/masp_proofs/EEB91EB873807EC77BBCA95D4CFA3F379DB351AB4AE081207ABFDFC429C9FA48.bin new file mode 100644 index 00000000000..5064fd5593a Binary files /dev/null and b/test_fixtures/masp_proofs/EEB91EB873807EC77BBCA95D4CFA3F379DB351AB4AE081207ABFDFC429C9FA48.bin differ diff --git a/test_fixtures/masp_proofs/F068FDF05B8F25DD923E667215344FFFAA6CA273027CD480AEA68DDED57D88CA.bin b/test_fixtures/masp_proofs/F068FDF05B8F25DD923E667215344FFFAA6CA273027CD480AEA68DDED57D88CA.bin index 9d76ce43f2f..3b05c546b0a 100644 Binary files a/test_fixtures/masp_proofs/F068FDF05B8F25DD923E667215344FFFAA6CA273027CD480AEA68DDED57D88CA.bin and b/test_fixtures/masp_proofs/F068FDF05B8F25DD923E667215344FFFAA6CA273027CD480AEA68DDED57D88CA.bin differ diff --git a/test_fixtures/masp_proofs/F36A8353F15FD6D8158DBC67DDB827EEEDA858AB983D16024AAA415579A68953.bin b/test_fixtures/masp_proofs/F36A8353F15FD6D8158DBC67DDB827EEEDA858AB983D16024AAA415579A68953.bin new file mode 100644 index 00000000000..755c32011e4 Binary files /dev/null and b/test_fixtures/masp_proofs/F36A8353F15FD6D8158DBC67DDB827EEEDA858AB983D16024AAA415579A68953.bin differ diff --git a/test_fixtures/masp_proofs/F3FE67606FCCCE54C3BCF643F0C7F5019CA3DF4CB89D10CB4E38DA9CDE3A9A0A.bin b/test_fixtures/masp_proofs/F3FE67606FCCCE54C3BCF643F0C7F5019CA3DF4CB89D10CB4E38DA9CDE3A9A0A.bin deleted file mode 100644 index b10162bc6b0..00000000000 Binary files a/test_fixtures/masp_proofs/F3FE67606FCCCE54C3BCF643F0C7F5019CA3DF4CB89D10CB4E38DA9CDE3A9A0A.bin and /dev/null differ diff --git a/tests/src/integration/masp.rs b/tests/src/integration/masp.rs index ecd1b34465d..592130e574e 100644 --- a/tests/src/integration/masp.rs +++ b/tests/src/integration/masp.rs @@ -6,9 +6,6 @@ use namada::types::io::DefaultIo; use namada_apps::client::tx::CLIShieldedUtils; use namada_apps::node::ledger::shell::testing::client::run; use namada_apps::node::ledger::shell::testing::utils::{Bin, CapturedOutput}; -use namada_core::types::address::{btc, eth, masp_rewards}; -use namada_core::types::token; -use namada_core::types::token::{DenominatedAmount, NATIVE_MAX_DECIMAL_PLACES}; use test_log::test; use super::setup; @@ -22,10 +19,6 @@ use crate::e2e::setup::constants::{ /// for leaving their assets in the pool for varying periods of time. #[test] fn masp_incentives() -> Result<()> { - // The number of decimal places used by BTC amounts. - const BTC_DENOMINATION: u8 = 8; - // The number of decimal places used by ETH amounts. - const ETH_DENOMINATION: u8 = 18; // This address doesn't matter for tests. But an argument is required. let validator_one_rpc = "127.0.0.1:26567"; // Download the shielded pool parameters before starting node @@ -35,7 +28,7 @@ fn masp_incentives() -> Result<()> { // not invalidated. let mut node = setup::setup()?; // Wait till epoch boundary - let ep0 = node.next_epoch(); + node.next_epoch(); // Send 20 BTC from Albert to PA run( &node, @@ -94,10 +87,8 @@ fn masp_incentives() -> Result<()> { assert!(captured.result.is_ok()); assert!(captured.contains("No shielded nam balance found")); - let masp_rewards = masp_rewards(); - // Wait till epoch boundary - let ep1 = node.next_epoch(); + node.next_epoch(); // Assert BTC balance at VK(A) is 20 let captured = CapturedOutput::of(|| { @@ -118,9 +109,6 @@ fn masp_incentives() -> Result<()> { assert!(captured.result.is_ok()); assert!(captured.contains("btc: 20")); - let amt20 = token::Amount::from_uint(20, BTC_DENOMINATION).unwrap(); - let amt10 = token::Amount::from_uint(10, ETH_DENOMINATION).unwrap(); - // Assert NAM balance at VK(A) is 20*BTC_reward*(epoch_1-epoch_0) let captured = CapturedOutput::of(|| { run( @@ -138,13 +126,8 @@ fn masp_incentives() -> Result<()> { ) }); - let amt = (amt20 * masp_rewards[&btc()]).0 * (ep1.0 - ep0.0); - let denominated = DenominatedAmount { - amount: amt, - denom: NATIVE_MAX_DECIMAL_PLACES.into(), - }; assert!(captured.result.is_ok()); - assert!(captured.contains(&format!("nam: {}", denominated))); + assert!(captured.contains("nam: 22.74")); // Assert NAM balance at MASP pool is 20*BTC_reward*(epoch_1-epoch_0) let captured = CapturedOutput::of(|| { @@ -162,16 +145,11 @@ fn masp_incentives() -> Result<()> { ], ) }); - let amt = (amt20 * masp_rewards[&btc()]).0 * (ep1.0 - ep0.0); - let denominated = DenominatedAmount { - amount: amt, - denom: NATIVE_MAX_DECIMAL_PLACES.into(), - }; assert!(captured.result.is_ok()); - assert!(captured.contains(&format!("nam: {}", denominated))); + assert!(captured.contains("nam: 22.74")); // Wait till epoch boundary - let ep2 = node.next_epoch(); + node.next_epoch(); // Assert BTC balance at VK(A) is 20 let captured = CapturedOutput::of(|| { @@ -208,13 +186,8 @@ fn masp_incentives() -> Result<()> { ], ) }); - let amt = (amt20 * masp_rewards[&btc()]).0 * (ep2.0 - ep0.0); - let denominated = DenominatedAmount { - amount: amt, - denom: NATIVE_MAX_DECIMAL_PLACES.into(), - }; assert!(captured.result.is_ok()); - assert!(captured.contains(&format!("nam: {}", denominated))); + assert!(captured.contains("nam: 90.96")); // Assert NAM balance at MASP pool is 20*BTC_reward*(epoch_2-epoch_0) let captured = CapturedOutput::of(|| { @@ -232,16 +205,11 @@ fn masp_incentives() -> Result<()> { ], ) }); - let amt = (amt20 * masp_rewards[&btc()]).0 * (ep2.0 - ep0.0); - let denominated = DenominatedAmount { - amount: amt, - denom: NATIVE_MAX_DECIMAL_PLACES.into(), - }; assert!(captured.result.is_ok()); - assert!(captured.contains(&format!("nam: {}", denominated))); + assert!(captured.contains("nam: 90.96")); // Wait till epoch boundary - let ep3 = node.next_epoch(); + node.next_epoch(); // Send 10 ETH from Albert to PA(B) run( @@ -302,7 +270,7 @@ fn masp_incentives() -> Result<()> { assert!(captured.contains("No shielded nam balance found")); // Wait till epoch boundary - let ep4 = node.next_epoch(); + node.next_epoch(); // Assert ETH balance at VK(B) is 10 let captured = CapturedOutput::of(|| { @@ -339,13 +307,8 @@ fn masp_incentives() -> Result<()> { ], ) }); - let amt = (amt10 * masp_rewards[ð()]).0 * (ep4.0 - ep3.0); - let denominated = DenominatedAmount { - amount: amt, - denom: NATIVE_MAX_DECIMAL_PLACES.into(), - }; assert!(captured.result.is_ok()); - assert!(captured.contains(&format!("nam: {}", denominated))); + assert!(captured.contains("nam: 22.71432")); // Assert NAM balance at MASP pool is // 20*BTC_reward*(epoch_4-epoch_0)+10*ETH_reward*(epoch_4-epoch_3) @@ -364,17 +327,11 @@ fn masp_incentives() -> Result<()> { ], ) }); - let amt = ((amt20 * masp_rewards[&btc()]).0 * (ep4.0 - ep0.0)) - + ((amt10 * masp_rewards[ð()]).0 * (ep4.0 - ep3.0)); - let denominated = DenominatedAmount { - amount: amt, - denom: NATIVE_MAX_DECIMAL_PLACES.into(), - }; assert!(captured.result.is_ok()); - assert!(captured.contains(&format!("nam: {}", denominated))); + assert!(captured.contains("nam: 386.46336")); // Wait till epoch boundary - let ep5 = node.next_epoch(); + node.next_epoch(); // Send 10 ETH from SK(B) to Christel run( @@ -417,7 +374,7 @@ fn masp_incentives() -> Result<()> { assert!(captured.result.is_ok()); assert!(captured.contains("No shielded eth balance found")); - let _ep = node.next_epoch(); + node.next_epoch(); // Assert NAM balance at VK(B) is 10*ETH_reward*(ep-epoch_3) let captured = CapturedOutput::of(|| { @@ -435,15 +392,10 @@ fn masp_incentives() -> Result<()> { ], ) }); - let amt = (amt10 * masp_rewards[ð()]).0 * (ep5.0 - ep3.0); - let denominated = DenominatedAmount { - amount: amt, - denom: NATIVE_MAX_DECIMAL_PLACES.into(), - }; assert!(captured.result.is_ok()); - assert!(captured.contains(&format!("nam: {}", denominated))); + assert!(captured.contains("nam: 86.60024")); - let ep = node.next_epoch(); + node.next_epoch(); // Assert NAM balance at MASP pool is // 20*BTC_reward*(epoch_5-epoch_0)+10*ETH_reward*(epoch_5-epoch_3) let captured = CapturedOutput::of(|| { @@ -461,17 +413,11 @@ fn masp_incentives() -> Result<()> { ], ) }); - let amt = ((amt20 * masp_rewards[&btc()]).0 * (ep.0 - ep0.0)) - + ((amt10 * masp_rewards[ð()]).0 * (ep5.0 - ep3.0)); - let denominated = DenominatedAmount { - amount: amt, - denom: NATIVE_MAX_DECIMAL_PLACES.into(), - }; assert!(captured.result.is_ok()); - assert!(captured.contains(&format!("nam: {}", denominated))); + assert!(captured.contains("nam: 1180.41525")); // Wait till epoch boundary - let ep6 = node.next_epoch(); + node.next_epoch(); // Send 20 BTC from SK(A) to Christel run( @@ -530,13 +476,8 @@ fn masp_incentives() -> Result<()> { ], ) }); - let amt = (amt20 * masp_rewards[&btc()]).0 * (ep6.0 - ep0.0); - let denominated = DenominatedAmount { - amount: amt, - denom: NATIVE_MAX_DECIMAL_PLACES.into(), - }; assert!(captured.result.is_ok()); - assert!(captured.contains(&format!("nam: {}", denominated,))); + assert!(captured.contains("nam: 1407.16324")); // Assert NAM balance at MASP pool is // 20*BTC_reward*(epoch_6-epoch_0)+20*ETH_reward*(epoch_5-epoch_3) @@ -555,17 +496,11 @@ fn masp_incentives() -> Result<()> { ], ) }); - let amt = ((amt20 * masp_rewards[&btc()]).0 * (ep6.0 - ep0.0)) - + ((amt10 * masp_rewards[ð()]).0 * (ep5.0 - ep3.0)); - let denominated = DenominatedAmount { - amount: amt, - denom: NATIVE_MAX_DECIMAL_PLACES.into(), - }; assert!(captured.result.is_ok()); - assert!(captured.contains(&format!("nam: {}", denominated,))); + assert!(captured.contains("nam: 1520.37191")); // Wait till epoch boundary - let _ep7 = node.next_epoch(); + node.next_epoch(); // Assert NAM balance at VK(A) is 20*BTC_reward*(epoch_6-epoch_0) let captured = CapturedOutput::of(|| { @@ -583,13 +518,8 @@ fn masp_incentives() -> Result<()> { ], ) }); - let amt = (amt20 * masp_rewards[&btc()]).0 * (ep6.0 - ep0.0); - let denominated = DenominatedAmount { - amount: amt, - denom: NATIVE_MAX_DECIMAL_PLACES.into(), - }; assert!(captured.result.is_ok()); - assert!(captured.contains(&format!("nam: {}", denominated))); + assert!(captured.contains("nam: 1573.18")); // Assert NAM balance at VK(B) is 10*ETH_reward*(epoch_5-epoch_3) let captured = CapturedOutput::of(|| { @@ -607,13 +537,8 @@ fn masp_incentives() -> Result<()> { ], ) }); - let amt = (amt10 * masp_rewards[ð()]).0 * (ep5.0 - ep3.0); - let denominated = DenominatedAmount { - amount: amt, - denom: NATIVE_MAX_DECIMAL_PLACES.into(), - }; assert!(captured.result.is_ok()); - assert!(captured.contains(&format!("nam: {}", denominated,))); + assert!(captured.contains("nam: 126.565")); // Assert NAM balance at MASP pool is // 20*BTC_reward*(epoch_6-epoch_0)+10*ETH_reward*(epoch_5-epoch_3) @@ -632,18 +557,12 @@ fn masp_incentives() -> Result<()> { ], ) }); - let amt = ((amt20 * masp_rewards[&btc()]).0 * (ep6.0 - ep0.0)) - + ((amt10 * masp_rewards[ð()]).0 * (ep5.0 - ep3.0)); - let denominated = DenominatedAmount { - amount: amt, - denom: NATIVE_MAX_DECIMAL_PLACES.into(), - }; assert!(captured.result.is_ok()); - assert!(captured.contains(&format!("nam: {}", denominated,))); + assert!(captured.contains("nam: 1699.745")); // Wait till epoch boundary to prevent conversion expiry during transaction // construction - let _ep8 = node.next_epoch(); + node.next_epoch(); // Send 10*ETH_reward*(epoch_5-epoch_3) NAM from SK(B) to Christel run( @@ -658,8 +577,7 @@ fn masp_incentives() -> Result<()> { "--token", NAM, "--amount", - &((amt10 * masp_rewards[ð()]).0 * (ep5.0 - ep3.0)) - .to_string_native(), + "141.49967", "--signing-keys", BERTHA, "--node", @@ -669,7 +587,7 @@ fn masp_incentives() -> Result<()> { node.assert_success(); // Wait till epoch boundary - let _ep9 = node.next_epoch(); + node.next_epoch(); // Send 20*BTC_reward*(epoch_6-epoch_0) NAM from SK(A) to Bertha run( @@ -684,8 +602,7 @@ fn masp_incentives() -> Result<()> { "--token", NAM, "--amount", - &((amt20 * masp_rewards[&btc()]).0 * (ep6.0 - ep0.0)) - .to_string_native(), + "1980.356", "--signing-keys", ALBERT, "--node", diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index 5dbe91c1e42..439d62e184a 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -3101,7 +3101,7 @@ dependencies = [ [[package]] name = "masp_note_encryption" version = "0.2.0" -source = "git+https://github.com/anoma/masp?rev=50acc5028fbcd52a05970fe7991c7850ab04358e#50acc5028fbcd52a05970fe7991c7850ab04358e" +source = "git+https://github.com/anoma/masp?rev=1345b463e8fa3b3a6fa13e4a43fb1c410690ad62#1345b463e8fa3b3a6fa13e4a43fb1c410690ad62" dependencies = [ "borsh 0.9.4", "chacha20 0.9.1", @@ -3114,7 +3114,7 @@ dependencies = [ [[package]] name = "masp_primitives" version = "0.9.0" -source = "git+https://github.com/anoma/masp?rev=50acc5028fbcd52a05970fe7991c7850ab04358e#50acc5028fbcd52a05970fe7991c7850ab04358e" +source = "git+https://github.com/anoma/masp?rev=1345b463e8fa3b3a6fa13e4a43fb1c410690ad62#1345b463e8fa3b3a6fa13e4a43fb1c410690ad62" dependencies = [ "aes 0.7.5", "bip0039", @@ -3145,7 +3145,7 @@ dependencies = [ [[package]] name = "masp_proofs" version = "0.9.0" -source = "git+https://github.com/anoma/masp?rev=50acc5028fbcd52a05970fe7991c7850ab04358e#50acc5028fbcd52a05970fe7991c7850ab04358e" +source = "git+https://github.com/anoma/masp?rev=1345b463e8fa3b3a6fa13e4a43fb1c410690ad62#1345b463e8fa3b3a6fa13e4a43fb1c410690ad62" dependencies = [ "bellman", "blake2b_simd", diff --git a/wasm/wasm_source/Cargo.toml b/wasm/wasm_source/Cargo.toml index 81f07ba0497..2022e64ca07 100644 --- a/wasm/wasm_source/Cargo.toml +++ b/wasm/wasm_source/Cargo.toml @@ -43,7 +43,7 @@ once_cell = {version = "1.8.0", optional = true} wee_alloc = "0.4.5" getrandom = { version = "0.2", features = ["custom"] } # branch = "murisi/namada-integration" -masp_primitives = { git = "https://github.com/anoma/masp", rev = "50acc5028fbcd52a05970fe7991c7850ab04358e", optional = true } +masp_primitives = { git = "https://github.com/anoma/masp", rev = "1345b463e8fa3b3a6fa13e4a43fb1c410690ad62", optional = true } ripemd = "0.1" [dev-dependencies] diff --git a/wasm_for_tests/wasm_source/Cargo.lock b/wasm_for_tests/wasm_source/Cargo.lock index 8e3bc2bb202..c8cafdda1c6 100644 --- a/wasm_for_tests/wasm_source/Cargo.lock +++ b/wasm_for_tests/wasm_source/Cargo.lock @@ -3101,7 +3101,7 @@ dependencies = [ [[package]] name = "masp_note_encryption" version = "0.2.0" -source = "git+https://github.com/anoma/masp?rev=50acc5028fbcd52a05970fe7991c7850ab04358e#50acc5028fbcd52a05970fe7991c7850ab04358e" +source = "git+https://github.com/anoma/masp?rev=1345b463e8fa3b3a6fa13e4a43fb1c410690ad62#1345b463e8fa3b3a6fa13e4a43fb1c410690ad62" dependencies = [ "borsh 0.9.4", "chacha20 0.9.1", @@ -3114,7 +3114,7 @@ dependencies = [ [[package]] name = "masp_primitives" version = "0.9.0" -source = "git+https://github.com/anoma/masp?rev=50acc5028fbcd52a05970fe7991c7850ab04358e#50acc5028fbcd52a05970fe7991c7850ab04358e" +source = "git+https://github.com/anoma/masp?rev=1345b463e8fa3b3a6fa13e4a43fb1c410690ad62#1345b463e8fa3b3a6fa13e4a43fb1c410690ad62" dependencies = [ "aes 0.7.5", "bip0039", @@ -3145,7 +3145,7 @@ dependencies = [ [[package]] name = "masp_proofs" version = "0.9.0" -source = "git+https://github.com/anoma/masp?rev=50acc5028fbcd52a05970fe7991c7850ab04358e#50acc5028fbcd52a05970fe7991c7850ab04358e" +source = "git+https://github.com/anoma/masp?rev=1345b463e8fa3b3a6fa13e4a43fb1c410690ad62#1345b463e8fa3b3a6fa13e4a43fb1c410690ad62" dependencies = [ "bellman", "blake2b_simd",