code-423n4 / 2022-05-backd-findings

0 stars 0 forks source link

Gas Optimizations #138

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Caching

https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/access/RoleManager.sol#L82 cache the value of roles.length before starting the loop to save gas

https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/BkdLocker.sol#L144 Use variable length instead of stashedWithdraws.length to save 1 SLOAD

!=0 is cheaper than >0 inside require staements

https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/BkdLocker.sol#L91 https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/BkdLocker.sol#L92 https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/BkdLocker.sol#L137

GalloDaSballo commented 2 years ago

cache the value of roles.length before starting the loop to save gas

Saves 3 gas

Use variable length instead of stashedWithdraws.length to save 1 SLOAD

Saves 94 gas (100 - 6)

!=0 is cheaper than >0 inside require staements

3 * 3 = 9

Total Gas Saved 106