code-423n4 / 2021-04-marginswap-findings

1 stars 0 forks source link

[Gas] Extract storage variable to a memory variable #59

Open code423n4 opened 3 years ago

code423n4 commented 3 years ago

Email address

pauliax6@gmail.com

Handle

paulius.eth

Eth address

0x523B5b2Cc58A818667C22c862930B141f85d49DD

Vulnerability details

Gas optimization suggestion:

Storage access is expensive. holdingTokens length can be extracted into a variable and used where necessary to reduce the number of storage read. change this: holdingTokens = account.holdingTokens; holdingAmounts = new uint256; for (uint256 idx = 0; holdingTokens.length > idx; idx++) to this: holdingTokens = account.holdingTokens; uint holdingTokensLength = holdingTokens.length; holdingAmounts = new uint256; for (uint256 idx = 0; holdingTokensLength > idx; idx++)