Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made Amount more generic. #52

Merged
9 commits merged into from
Aug 11, 2023
Merged

Made Amount more generic. #52

9 commits merged into from
Aug 11, 2023

Conversation

murisi
Copy link
Contributor

@murisi murisi commented Jun 29, 2023

I've been thinking about other approaches to allowing u64::MAX notes and eliminating risk of overflow problems. Here's one that came to mind. Specifically, the following changes are made:

  • Made Amount generic over the integer type (so it can now be i64, 128, or perhaps i256 or u256)
  • Added support for overflow/underflow checks using the Checked* traits from the num-traits library (which is also used in the namada repo)
  • Everything else is similar to Promote value arithmetic to i128 #46 and Zcash, specifically the use of i128 to accumulate value_balances

The benefits of this approach are that:

MAX_MONEY values that are smaller than the range of the underlying integer type are not currently supported here, but it should be doable if it is desired. This is just another approach, maybe some of the ideas here could be used to extend #46 ?

@murisi murisi requested review from a user, batconjurer, juped and cwgoes June 29, 2023 18:16
Ok(Self::zero())
} else if 0 <= amount && amount <= MAX_MONEY {
} else if Magnitude::default() <= amount {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it would be worth having a trait for these magnitudes? Then we could add associated MIN_MONEY and MAX_MONEY constants.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe as a separate PR. For this PR I think it's probably be simpler to not restrict the range of Amounts allowed by the MASP crate (beyond what is already imposed by the cryptography).

@murisi murisi force-pushed the murisi/generic-amount branch 5 times, most recently from 63d83f4 to d3a4384 Compare July 31, 2023 06:32
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might need additional tests/cleanup later

@ghost ghost merged commit e83521d into main Aug 11, 2023
23 checks passed
@ghost ghost deleted the murisi/generic-amount branch August 11, 2023 01:04
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants