Skip to content

Commit

Permalink
Optimized mask creation in draw calc
Browse files Browse the repository at this point in the history
  • Loading branch information
asselstine committed Oct 13, 2021
1 parent 293e224 commit ce300fa
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions contracts/DrawCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,12 @@ contract DrawCalculator is IDrawCalculator, Ownable {
uint256[] memory masks = new uint256[](_prizeDistribution.matchCardinality);
uint256 _bitRangeMaskValue = (2**_prizeDistribution.bitRangeSize) - 1; // get a decimal representation of bitRangeSize

for (uint8 maskIndex = 0; maskIndex < _prizeDistribution.matchCardinality; maskIndex++) {
// create mask of width bitRangeSize bits at index
uint256 _matchIndexOffset = uint256(maskIndex) * uint256(_prizeDistribution.bitRangeSize);
if(_prizeDistribution.matchCardinality == 0) return masks;

masks[0] = _bitRangeMaskValue;
for (uint8 maskIndex = 1; maskIndex < _prizeDistribution.matchCardinality; maskIndex++) {
// shift mask bits to correct position and insert in result mask array
masks[maskIndex] = _bitRangeMaskValue << _matchIndexOffset;
masks[maskIndex] = masks[maskIndex - 1] << _prizeDistribution.bitRangeSize;
}

return masks;
Expand Down

0 comments on commit ce300fa

Please sign in to comment.