aave / aave-v3-core

This repository contains the core smart contracts of the Aave V3 protocol.
https://aave.com
Other
879 stars 573 forks source link

Update ReservesSetupHelper.sol: Optimized Gas #904

Open 0xScratch opened 1 year ago

0xScratch commented 1 year ago

Types of changes made:

1st - Struct Packing - Aligning booleans with the address in order to decrease the slots which kinds of save gas. Refer this -> https://dev.to/javier123454321/solidity-gas-optimizations-pt-3-packing-structs-23f4

2nd - uint256 i = 0; to uint256 i - This change too saves some gas cuz the default value of all unsigned integers is 0. Thus, I find no need to initialize it

3rd - using unchecked - After the Solidity 0.8 version, Solidity compilers started using overflow/underflow checks which is gas costly. But I find that there's no chance of any underflow/overflow in this loop, so unchecked can be used in this purpose. (Tho, I still suggest to take a brief look into this change)

4th - i++ to ++i - Saves gas, just make sure it doesn't messes up with the code's logic.

Refer this for 2nd, 3rd and 4th change -> https://gist.github.com/grGred/9bab8b9bad0cd42fc23d4e31e7347144#for-loops-improvement

height[bot] commented 1 year ago

Link Height tasks by mentioning a task ID in the pull request title or commit messages, or description and comments with the keyword link (e.g. "Link T-123").

💡Tip: You can also use "Close T-X" to automatically close a task when the pull request is merged.