When fetching data from a storage location, assigning the data to a memory
variable causes all fields of the struct/array to be read from storage, which incurs a Gcoldsload (2100 gas) for each field of the struct/array. If the fields are read from the new memory variable, they incur an additional MLOAD
rather than a cheap stack read. Instead of declearing the variable with the memory
keyword, declaring the variable with the storage
keyword and caching any fields that need to be re-read in stack variables, will be much cheaper, only incuring the Gcoldsload for the fields actually read. The only time it makes sense to read the whole struct/array into a memory
variable, is if the full struct/array is being returned by the function, is being passed to a function that requires memory
, or if the array/struct is being read from another memory
array/struct
There are 11
instances of this issue:
local memory variable Fees.sellProfits(address).params is initialized from storage: Fees.WETH should read data from storage
directly
local memory variable Lender.getLoanDebt(uint256).loan is initialized from storage: Lender.loans should read data from storage
directly
local memory variable Lender.borrow(Borrow[]).pool is initialized from storage: Lender.pools should read data from storage
directly
local memory variable Lender.repay(uint256[]).loan is initialized from storage: Lender.loans should read data from storage
directly
local memory variable Lender.giveLoan(uint256[],bytes32[]).loan is initialized from storage: Lender.loans should read data from storage
directly
local memory variable Lender.giveLoan(uint256[],bytes32[]).pool is initialized from storage: Lender.pools should read data from storage
directly
local memory variable Lender.startAuction(uint256[]).loan is initialized from storage: Lender.loans should read data from storage
directly
local memory variable Lender.buyLoan(uint256,bytes32).loan is initialized from storage: Lender.loans should read data from storage
directly
local memory variable Lender.seizeLoan(uint256[]).loan is initialized from storage: Lender.loans should read data from storage
directly
local memory variable Lender.refinance(Refinance[]).loan is initialized from storage: Lender.loans should read data from storage
directly
local memory variable Lender.refinance(Refinance[]).pool is initialized from storage: Lender.pools should read data from storage
directly
Fetching data from storage
directly, don't convert storage
to memory
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.