-
Notifications
You must be signed in to change notification settings - Fork 611
refactor: TokenWithRefunds optimizations
#7628
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
Merged
benesjan
merged 1 commit into
master
from
07-26-refactor_tokenwithrefunds_optimizations
Jul 31, 2024
+19
−44
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know why these two scalars are not constructed the same way as the amoutn scalar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If they all were constructed the same way, then we could have a fn that takes some values and does msm over them generically, instead of having to inline it manually in every place and deal with the unsafe values
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say this is because the npk_m_hash and randomness can span the whole Field so it does not fit only into the lower limb of a scalar. I think Mitch originally wrote this.
@just-mitch do you know if we are really guaranteed that the amount is smaller then lower limb of a grumpkin scalar? Is it the case that it would simply be too huge of an amount of token that you considered it unrealistic to occur?
If this would occur it would brick the contract for the user as MSM would try to constrain the limb and as a result it would fail to generate the proof. Given that we can use from_field_unsafe (which doesn't add constraints) here it's probably better to just call it for amount as well (what if we had token with too a lot of decimals?).
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be fine to constrain token balances to be uint128s - we'd just need to do that consistently. Many DeFi systems use even smaller amounts (e.g. Balancer uses 112 bits).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At any rate this function would likely be incorporated into eg #7585