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

reset rewardsLocked to 0 when no longer used #13

Open
code423n4 opened this issue Oct 19, 2021 · 1 comment
Open

reset rewardsLocked to 0 when no longer used #13

code423n4 opened this issue Oct 19, 2021 · 1 comment
Labels
bug Something isn't working 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

gpersoon

Vulnerability details

Impact

The function _stake() initializes endEpoch using the value of rewardsLocked.
Afterwards rewardsLocked is no longer used (because now endEpoch !=0)

So you can set rewardsLocked to 0 save a bit of gas.

Proof of Concept

https://github.com/code-423n4/2021-10-covalent/blob/ded3aeb2476da553e8bb1fe43358b73334434737/contracts/DelegatedStaking.sol#L171-L176

Tools Used

Recommended Mitigation Steps

Update to code of _stake() to:
if (endEpoch == 0) {
endEpoch = uint128(block.number) + rewardsLocked / allocatedTokensPerEpoch;
rewardsLocked = 0; // no longer used and saves a bit of gas
}

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Oct 19, 2021
code423n4 added a commit that referenced this issue Oct 19, 2021
@kitti-katy kitti-katy added the sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") label Oct 21, 2021
@kitti-katy kitti-katy reopened this Oct 21, 2021
@kitti-katy kitti-katy added the resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) label Oct 22, 2021
@GalloDaSballo
Copy link
Collaborator

I believe gas refunds have bee removed when EIP-1559 made it to mainnet, that said, the sponsor has applied the improvement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 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

3 participants