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

Inline assembly for number matching #25

Merged
merged 1 commit into from
Aug 30, 2021
Merged

Conversation

aodhgan
Copy link
Contributor

@aodhgan aodhgan commented Aug 23, 2021

optimizer on 2000 runs:
old method using high level solidity 1000 picks: 2.371M gas
this PR: 2.064M gas

@@ -147,8 +147,11 @@ contract TsunamiDrawCalculator is IDrawCalculator, OwnableUpgradeable {

uint256 numberOfMatches = 0;
for(uint256 matchIndex = 0; matchIndex < _masks.length; matchIndex++) {
if((uint256(_randomNumberThisPick) & _masks[matchIndex]) == (uint256(_winningRandomNumber) & _masks[matchIndex])) {
numberOfMatches++;
uint256 mask = _masks[matchIndex];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

could actually probably do this whole loop in assembly

@aodhgan aodhgan merged commit ea99646 into master Aug 30, 2021
@aodhgan aodhgan deleted the assembly-number-matching branch October 14, 2021 17:08
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.

None yet

1 participant