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

Make the splits weights uint256 #345

Merged
merged 2 commits into from
Mar 26, 2024
Merged

Make the splits weights uint256 #345

merged 2 commits into from
Mar 26, 2024

Conversation

CodeSandwich
Copy link
Collaborator

This makes the API simpler and more sane, it requires less effort and gas to parse and validate the calldata.

Copy link
Collaborator

@xmxanuel xmxanuel left a comment

Choose a reason for hiding this comment

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

looks good.

require(weight != 0, "Splits receiver weight is zero");
if (weight > _TOTAL_SPLITS_WEIGHT) weight = _TOTAL_SPLITS_WEIGHT + 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay, just to verify if I understood this correctly.

weight = _TOTAL_SPLITS_WEIGHT + 1;

This is a gas optimization. You want to operate with unchecked and still have a the potential overflow protection. Therefore you check if the weight is greater than the _TOTAL_SPLITS_WEIGHT.

You add +1 to ensure it will revert later with totalWeight <= _TOTAL_SPLITS_WEIGHT an additional require would be more expensive.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, exactly 👍

Base automatically changed from igor/gas to main March 26, 2024 13:28
@CodeSandwich CodeSandwich merged commit 30be8e4 into main Mar 26, 2024
1 check passed
@CodeSandwich CodeSandwich deleted the igor/splits_api branch March 26, 2024 13:29
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