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

gas optimization of clearRaffle #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/MultiRaffle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,23 @@ contract MultiRaffle is Ownable, ERC721, VRFConsumerBase {
require(clearingEntropySet, "No entropy to clear raffle");

// Run Fisher-Yates shuffle for AVAILABLE_SUPPLY
for (uint256 i = shuffledCount; i < shuffledCount + numShuffles; i++) {
address randomTmp;
uint256 i = shuffledCount;
uint256 limit = shuffledCount + numShuffles;
uint256 randomIndex;
while(i < limit){
// Generate a random index to select from
uint256 randomIndex = i + entropy % (raffleEntries.length - i);
randomIndex = i + entropy % (raffleEntries.length - i);
// Collect the value at that random index
address randomTmp = raffleEntries[randomIndex];
randomTmp = raffleEntries[randomIndex];
// Update the value at the random index to the current value
raffleEntries[randomIndex] = raffleEntries[i];
// Update the current value to the value at the random index
raffleEntries[i] = randomTmp;

unchecked {
i = i +1;
}
}

// Update number of shuffled entries
Expand Down Expand Up @@ -369,4 +377,4 @@ contract MultiRaffle is Ownable, ERC721, VRFConsumerBase {
}
return string(buffer);
}
}
}