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

Open
code423n4 opened this issue Jun 26, 2022 · 0 comments
Open

Gas Optimizations #375

code423n4 opened this issue Jun 26, 2022 · 0 comments
Labels
bug Something isn't working G (Gas Optimization)

Comments

@code423n4
Copy link
Contributor

-> X = X + Y IS CHEAPER THAN X += Y (Same for X = X - Y is cheaper than X -= Y)

https://github.com/code-423n4/2022-06-illuminate/blob/main/lender/Lender.sol#:~:text=Track%20accumulated%20fees-,totalFee%20%2B%3D%20fee%3B,-//%20Amount%20lent%20for

https://github.com/code-423n4/2022-06-illuminate/blob/main/lender/Lender.sol#:~:text=mint)%20minus%20fees-,lent%20%2B%3D%20amountLent%3B,-//%20Sum%20the%20total

https://github.com/code-423n4/2022-06-illuminate/blob/main/lender/Lender.sol#:~:text=returned%20%2B%3D%20amountLent%20*%20order.premium%20/%20order.principal%3B294

https://github.com/code-423n4/2022-06-illuminate/blob/main/lender/Lender.sol#:~:text=fees%5Bu%5D%20%2B%3D%20calculateFee(a)%3B

https://github.com/code-423n4/2022-06-illuminate/blob/main/lender/Lender.sol#:~:text=calculateFee(a)%3B-,fees%5Bu%5D%20%2B%3D%20fee%3B,-address%5B%5D%20memory

https://github.com/code-423n4/2022-06-illuminate/blob/main/lender/Lender.sol#:~:text=%3D%20calculateFee(a)%3B-,fees%5Bu%5D%20%2B%3D%20fee%3B,-//%20Swap%20on%20the%20Tempus

https://github.com/code-423n4/2022-06-illuminate/blob/main/lender/Lender.sol#:~:text=to%20the%20total-,fees%5Bu%5D%20%2B%3D%20fee%3B,-//%20Determine%20lent%20amount

https://github.com/code-423n4/2022-06-illuminate/blob/main/lender/Lender.sol#:~:text=to%20the%20total-,fees%5Bu%5D%20%2B%3D%20fee%3B,-//%20Determine%20the%20amount

https://github.com/code-423n4/2022-06-illuminate/blob/main/lender/Lender.sol#:~:text=%3D%20calculateFee(a)%3B-,fees%5Bu%5D%20%2B%3D%20fee%3B,-//%20Swap%20on%20the%20Notional

->STATE VARIABLES ONLY SET IN THE CONSTRUCTOR SHOULD BE DECLARED IMMUTABLE
Avoids a Gsset (20000 gas) in the constructor, and replaces each Gwarmacces (100 gas) with a PUSH32 (3 gas)

https://github.com/code-423n4/2022-06-illuminate/blob/main/lender/Lender.sol#:~:text=address%20public%20immutable%20pendleAddr%3B

https://github.com/code-423n4/2022-06-illuminate/blob/main/lender/Lender.sol#:~:text=address%20public%20immutable%20tempusAddr%3B

-> COMPARISON OPERATORS Problem

In the EVM, there is no opcode for >= or <=. When using greater than or equal, two operations are performed: > and =.
Using strict comparison operators hence saves gas

https://github.com/code-423n4/2022-06-illuminate/blob/main/lender/Lender.sol#:~:text=require%20(block.timestamp%20%3E%3D%20when%2C%20%27withdrawal%20still%20on%20hold%27)%3B

-> DEFAULT VALUE INITIALIZATION
If a variable is not set/initialized, it is assumed to have the default value (0, false, 0x0 etc depending on the data type). Explicitly initializing it with its default value is an anti-pattern and wastes gas.

https://github.com/code-423n4/2022-06-illuminate/blob/main/lender/Lender.sol#:~:text=for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20o.length%3B%20)

-> ++i costs less gas compared to i++ or i += 1 (Also --i costs less gas compared to i--- or i -= 1)

https://github.com/code-423n4/2022-06-illuminate/blob/main/lender/Lender.sol#:~:text=token)%2C%20r%2C%20max)%3B-,%7D,%7D,-return%20true%3B

https://github.com/code-423n4/2022-06-illuminate/blob/main/lender/Lender.sol#:~:text=a%5Bi%5D%2C%20max)%3B-,%7D,%7D,-return%20true%3B

https://github.com/code-423n4/2022-06-illuminate/blob/main/lender/Lender.sol#:~:text=/%20order.principal%3B-,%7D,%7D,-//%20Track%20accumulated%20fee

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Jun 26, 2022
code423n4 added a commit that referenced this issue Jun 26, 2022
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

1 participant