code-423n4 / 2022-01-elasticswap-findings

1 stars 0 forks source link

Repeated calls #178

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

pauliax

Vulnerability details

Impact

Result of this.totalSupply() could be cached to avoid duplicate calls:

  require(this.totalSupply() > 0, "Exchange: INSUFFICIENT_LIQUIDITY");
  ...
  uint256 totalSupplyOfLiquidityTokens = this.totalSupply();
GalloDaSballo commented 2 years ago

Caching totalSupply to memory will yield gas savings. Reading from Storage costs 100 (after first hot read (2.1k)) Reading from memory costs only 3

Agree with finding