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 #16

Open
code423n4 opened this issue Mar 30, 2022 · 1 comment
Open

Gas Optimizations #16

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

Comments

@code423n4
Copy link
Contributor

Catching The Array Length Prior To Loop

Context: LenderPool.sol#L661-L692

Description:
One can save gas by caching the array length (in stack) and using that set variable in the loop.

Recommendation:
Simply do something like so before the for loop: uint length = variable.length. Then add length in place of variable.length in the for loop.

Function Ordering via Method ID

Context: All Contracts

Description:
Contracts most called functions could simply save gas by function ordering via Method ID. Calling a function at runtime will be cheaper if the function is positioned earlier in the order (has a relatively lower Method ID) because 22 gas are added to the cost of a function for every position that came before it. The caller can save on gas if you prioritize most called functions. One could use This tool to help find alternative function names with lower Method IDs while keeping the original name intact.

Recommendation:
Find a lower method ID name for the most called functions for example mostCalled() vs. mostCalled_41q() is cheaper by 44 gas.

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

ritik99 commented Apr 12, 2022

Both suggestions are acknowledged/valid. The second suggestion is unique

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