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 Optimizations #86

Open
code423n4 opened this issue Jul 1, 2022 · 1 comment
Open

Gas Optimizations #86

code423n4 opened this issue Jul 1, 2022 · 1 comment
Labels
bug Something isn't working G (Gas Optimization)

Comments

@code423n4
Copy link
Contributor

[Gas - 01] - Useless variable

https://github.com/Plex-Engineer/lending-market-v2/blob/ea5840de72eab58bec837bb51986ac73712fcfde/contracts/ERC20.sol#L13

_initialSupply is not used anywhere so could be removed.

[Gas - 02] Use Custom Errors

Instead of using error strings, to reduce deployment and runtime cost, you should use Custom Errors: see https://blog.soliditylang.org/2021/04/21/custom-errors/. This would save both deployment and runtime cost.

Examples:
https://github.com/Plex-Engineer/lending-market-v2/blob/ea5840de72eab58bec837bb51986ac73712fcfde/contracts/Stableswap/BaseV1-periphery.sol#L104
https://github.com/Plex-Engineer/lending-market-v2/blob/ea5840de72eab58bec837bb51986ac73712fcfde/contracts/Stableswap/BaseV1-periphery.sol#L106

[Gas - 03] Using address to test equality would be more efficient

Instead of doing https://github.com/Plex-Engineer/lending-market-v2/blob/ea5840de72eab58bec837bb51986ac73712fcfde/contracts/Stableswap/BaseV1-periphery.sol#L495 or https://github.com/Plex-Engineer/lending-market-v2/blob/ea5840de72eab58bec837bb51986ac73712fcfde/contracts/Stableswap/BaseV1-periphery.sol#L500, it’d be more efficient to have setters and test that addresses are the same as it would avoid an external call.

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Jul 1, 2022
code423n4 added a commit that referenced this issue Jul 1, 2022
@GalloDaSballo
Copy link
Collaborator

GalloDaSballo commented Aug 14, 2022

[Gas - 03] Using address to test equality would be more efficient

100 gas from the CALL also another 2.1k here, another 200 for the second CALL + SLOAD.
Rest is negligible

I recommend focusing on immutables to keep it short and get additional savings

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)
Projects
None yet
Development

No branches or pull requests

2 participants