Open code423n4 opened 2 years ago
Variable declarations like "previous" in this QA report help code readability. 4th point is invalid as well because in cases where neither the from
or to
addresses are the zero address, then we would be declaring the variables and reading from storage for nothing. 5th point is valid though!
point 5 addressed here: https://github.com/aave/lens-protocol/pull/67
AAVEGasFindings
1-- -using storage instead memory to declare
snapshot
struct https://github.com/code-423n4/2022-02-aave-lens/blob/main/contracts/core/FollowNFT.sol#L135 https://github.com/code-423n4/2022-02-aave-lens/blob/main/contracts/core/FollowNFT.sol#L177 instead of cachingsnapshot
per loop just read it directly from storage. Its just called at most three times (or may be once) per loop and read it from storage cost less gas:2-- -unnecesary
previous
var declaration https://github.com/code-423n4/2022-02-aave-lens/blob/main/contracts/core/FollowNFT.sol#L257previous
just used once. just pass_snapshots[to][toSnapshotCount - 1].value;
directly below it and remove line 2573-- -using
require()
for gas optimisation https://github.com/code-423n4/2022-02-aave-lens/blob/main/contracts/core/FollowNFT.sol#L261-L264 instead of usingelse
andif
to check the condition, usingrequire()
to replaceif
and removingelse
can save gas4-- -declare
delSupplySnapshotCount
&previousDelSupply
once instead of twice https://github.com/code-423n4/2022-02-aave-lens/blob/main/contracts/core/FollowNFT.sol#L231-L274 by declaringdelSupplySnapshotCount
&previousDelSupply
once at line 243 and removing all of them inside if & else can save gas(better declare it once instead twice since they have the same value)5-- -unused interface https://github.com/code-423n4/2022-02-aave-lens/blob/main/contracts/core/FollowNFT.sol#L12
IERC721Metadata.sol
is never used inFollowNFT
contract