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

1 stars 0 forks source link

Remove duplicate function call #115

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

sirhashalot

Vulnerability details

Impact

The Exchange.sol removeLiquidity() function calls this.totalSupply() twice. To save gas, call it once and set the value to a variable, because using a variable is cheaper than a second function call.

Proof of Concept

There are two calls to this.totalSupply() in removeLiquidity()

Recommended Mitigation Steps

Move line 187, shown below, to a line before the require statement. Modify the require statement to reference the variable. The end result will look like:

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

dupe of #178