Skip to content

Commit

Permalink
MantaPay v1 (#286)
Browse files Browse the repository at this point in the history
* utxo protocol

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* utxo finished

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* sender and receiver

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* transfer mod finished

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* wallet done

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* mantapay config

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* mantapay config works

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* tests

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* signer base fixed

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* signer client

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* parameters + testing

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* parameters, test, simulation and binaries

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* benchmark

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* sdk

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* re-exports in manta-pay

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* feature issue solved

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* docs

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* changelog

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* sample impls revised

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* sample issue solved in tests

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* balance tests

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* DEFAULT_BRANCH changed

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* zero signature issue tested and fixed

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* Apply suggestions from code review

Co-authored-by: Brandon H. Gomes <bhgomes@pm.me>
Signed-off-by: Francisco Hernández Iglesias <38819712+SupremoUGH@users.noreply.github.com>

* some comments addressed

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* more comments addressed

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* sample issue solved

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* public fields made private again

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* compat deleted

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* FIXME

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* parameters branch changed to main + feature issue solved

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* feature issue solved

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>

* Apply suggestions from code review

Co-authored-by: Todd Norton <93260651+GhostOfGauss@users.noreply.github.com>
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>

* fix: use corrections from PR review

Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>

* chore: remove extra FIXME

Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>

* chore: fix test dependencies

Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>

Signed-off-by: Francisco Hernandez Iglesias <f.hernandeziglesias@outlook.com>
Signed-off-by: Francisco Hernández Iglesias <38819712+SupremoUGH@users.noreply.github.com>
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
Co-authored-by: Brandon H. Gomes <bhgomes@pm.me>
Co-authored-by: Todd Norton <93260651+GhostOfGauss@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 3, 2022
1 parent b45ecb5 commit 6572219
Show file tree
Hide file tree
Showing 99 changed files with 12,464 additions and 6,484 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]
### Added
- [\#286](https://github.com/Manta-Network/manta-rs/pull/286) MantaPay v1.0.0

### Changed
- [\#283](https://github.com/Manta-Network/manta-rs/pull/283) Upgrade asset system.
Expand Down
2 changes: 2 additions & 0 deletions manta-accounting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ std = ["manta-crypto/std", "manta-util/std"]
test = [
"futures",
"indexmap",
"manta-crypto/arkworks",
"manta-crypto/rand",
"manta-crypto/test",
"parking_lot",
"statrs"
]
Expand Down
6 changes: 2 additions & 4 deletions manta-accounting/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,9 +879,8 @@ impl<K, I, V> AssetMap<I, V> for BTreeAssetMap<K, I, V>
where
K: Clone + Ord,
I: Clone + Ord,
V: AddAssign + Clone + Default + Ord + Sub<Output = V>,
V: AddAssign + Clone + Default + Ord + Sub<Output = V> + for<'v> AddAssign<&'v V>,
for<'v> &'v V: Sub<Output = V>,
for<'v> &'v V: AddAssign<&'v V>,
{
impl_asset_map_for_maps_body! { K, I, V, BTreeMapEntry }
}
Expand All @@ -897,9 +896,8 @@ impl<K, I, V, S> AssetMap<I, V> for HashAssetMap<K, I, V, S>
where
K: Clone + Hash + Eq,
I: Clone + Ord,
V: AddAssign + Clone + Default + Ord + Sub<Output = V>,
V: AddAssign + Clone + Default + Ord + Sub<Output = V> + for<'v> AddAssign<&'v V>,
for<'v> &'v V: Sub<Output = V>,
for<'v> &'v V: AddAssign<&'v V>,
S: BuildHasher + Default,
{
impl_asset_map_for_maps_body! { K, I, V, HashMapEntry }
Expand Down
66 changes: 54 additions & 12 deletions manta-accounting/src/transfer/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,43 @@

// TODO: Move more of the batching algorithm here to improve library interfaces.

use crate::transfer::{Asset, Configuration, Parameters, PreSender, Receiver, SpendingKey, Utxo};
use crate::transfer::{
internal_pair, internal_zero_pair, Address, Asset, AuthorizationContext, Configuration,
Parameters, PreSender, Receiver, UtxoAccumulatorItem, UtxoAccumulatorModel,
};
use alloc::vec::Vec;
use core::{fmt::Debug, hash::Hash};
use manta_crypto::{
accumulator::Accumulator,
rand::{CryptoRng, Rand, RngCore},
rand::{CryptoRng, RngCore},
};
use manta_util::into_array_unchecked;

#[cfg(feature = "serde")]
use manta_util::serde::{Deserialize, Serialize};

/// Batch Join Structure
#[cfg_attr(
feature = "serde",
derive(Deserialize, Serialize),
serde(
bound(
deserialize = "PreSender<C>: Deserialize<'de>",
serialize = "PreSender<C>: Serialize",
),
crate = "manta_util::serde",
deny_unknown_fields
)
)]
#[derive(derivative::Derivative)]
#[derivative(
Clone(bound = "PreSender<C>: Clone"),
Debug(bound = "PreSender<C>: Debug"),
Default(bound = "PreSender<C>: Default"),
Eq(bound = "PreSender<C>: Eq"),
Hash(bound = "PreSender<C>: Hash"),
PartialEq(bound = "PreSender<C>: PartialEq")
)]
pub struct Join<C>
where
C: Configuration,
Expand All @@ -42,25 +70,39 @@ impl<C> Join<C>
where
C: Configuration,
{
/// Builds a new [`Join`] for `asset` using `spending_key` and `zero_key`.
/// Builds a new [`Join`] for `asset` using `address`.
#[inline]
pub fn new<R, const RECEIVERS: usize>(
parameters: &Parameters<C>,
authorization_context: &mut AuthorizationContext<C>,
address: Address<C>,
asset: Asset<C>,
spending_key: &SpendingKey<C>,
rng: &mut R,
) -> ([Receiver<C>; RECEIVERS], Self)
where
R: CryptoRng + RngCore + ?Sized,
{
let mut receivers = Vec::with_capacity(RECEIVERS);
let mut zeroes = Vec::with_capacity(RECEIVERS - 1);
let (receiver, pre_sender) =
spending_key.internal_pair(parameters, rng.gen(), asset.clone());
let asset_id = asset.id.clone();
let (receiver, pre_sender) = internal_pair::<C, _>(
parameters,
authorization_context,
address.clone(),
asset,
Default::default(),
rng,
);
receivers.push(receiver);
for _ in 1..RECEIVERS {
let (receiver, pre_sender) =
spending_key.internal_zero_pair(parameters, rng.gen(), asset.id.clone());
let (receiver, pre_sender) = internal_zero_pair::<C, _>(
parameters,
authorization_context,
address.clone(),
asset_id.clone(),
Default::default(),
rng,
);
receivers.push(receiver);
zeroes.push(pre_sender);
}
Expand All @@ -69,13 +111,13 @@ where

/// Inserts UTXOs for each sender in `self` into the `utxo_accumulator` for future proof selection.
#[inline]
pub fn insert_utxos<A>(&self, utxo_accumulator: &mut A)
pub fn insert_utxos<A>(&self, parameters: &Parameters<C>, utxo_accumulator: &mut A)
where
A: Accumulator<Item = Utxo<C>, Model = C::UtxoAccumulatorModel>,
A: Accumulator<Item = UtxoAccumulatorItem<C>, Model = UtxoAccumulatorModel<C>>,
{
self.pre_sender.insert_utxo(utxo_accumulator);
self.pre_sender.insert_utxo(parameters, utxo_accumulator);
for zero in &self.zeroes {
zero.insert_utxo(utxo_accumulator);
zero.insert_utxo(parameters, utxo_accumulator);
}
}
}
Loading

0 comments on commit 6572219

Please sign in to comment.