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

Removal of last token in the array can be optimized #46

Open
code423n4 opened this issue Sep 15, 2021 · 1 comment
Open

Removal of last token in the array can be optimized #46

code423n4 opened this issue Sep 15, 2021 · 1 comment
Labels
bug Warden finding G (Gas Optimization) sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons

Comments

@code423n4
Copy link
Contributor

Handle

0xRajeev

Vulnerability details

Impact

The removal of the last token in the array can be optimized by checking if index == k-1, i.e. last element match, when there is no need to copy and simply popping will do. This will avoid the copy which involves several SLOADs/SSTOREs.

Proof of Concept

https://github.com/code-423n4/2021-09-yaxis/blob/cf7d9448e70b5c1163a1773adb4709d9d6ad6c99/contracts/v3/Manager.sol#L485

https://github.com/code-423n4/2021-09-yaxis/blob/cf7d9448e70b5c1163a1773adb4709d9d6ad6c99/contracts/v3/Harvester.sol#L141

Tools Used

Manual Analysis

Recommended Mitigation Steps

Example: Check if index != k-1 for tokens[_vault][index] = tokens[_vault][k-1];

code423n4 added a commit that referenced this issue Sep 15, 2021
@Haz077 Haz077 added the sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons label Sep 21, 2021
@GalloDaSballo
Copy link
Collaborator

Agree with sponsor and severity, wouldn't mind not mitigating as it's very minor

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) sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons
Projects
None yet
Development

No branches or pull requests

3 participants