Open code423n4 opened 2 years ago
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
roles.length
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
length
stashedWithdraws.length
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
Saves 3 gas
Saves 94 gas (100 - 6)
3 * 3 = 9
Total Gas Saved 106
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 gashttps://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/BkdLocker.sol#L144 Use variable
length
instead ofstashedWithdraws.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