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

PrizeSplit.sol#_totalPrizeSplitPercentageAmount() Avoid unnecessary copy from storage to memory can save gas #40

Open
code423n4 opened this issue Oct 13, 2021 · 2 comments
Assignees
Labels
bug Warden finding G (Gas Optimization) resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")

Comments

@code423n4
Copy link
Contributor

Handle

WatchPug

Vulnerability details

https://github.com/pooltogether/v4-core/blob/055335bf9b09e3f4bbe11a788710dd04d827bf37/contracts/prize-strategy/PrizeSplit.sol#L135-L136

PrizeSplitConfig memory split = _prizeSplits[index];
_tempTotalPercentage = _tempTotalPercentage + split.percentage;

Only percentage of the PrizeSplitConfig struct is accessed, however, the current implementation created a memory variable that will load _prizeSplits[index] and copy to memory, this is unnecessary and gas inefficient.

Recommendation

Change to:

_tempTotalPercentage = _tempTotalPercentage + split.percentage;
code423n4 added a commit that referenced this issue Oct 13, 2021
@asselstine asselstine self-assigned this Oct 14, 2021
@asselstine asselstine added the resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) label Oct 14, 2021
@asselstine
Copy link
Collaborator

asselstine commented Oct 14, 2021

pooltogether/v4-core#234

@PierrickGT PierrickGT added the sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") label Oct 14, 2021
@GalloDaSballo
Copy link
Collaborator

Sponsor has applied optimization in a subsequent PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Warden finding G (Gas Optimization) resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Projects
None yet
Development

No branches or pull requests

4 participants