SwingTrader.costBasis function should have internal version that uses Malt balance from sellMalt #73
Labels
bug
Something isn't working
G (Gas Optimization)
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Handle
hyh
Vulnerability details
Impact
ERC20 balanceOf call is costly. Malt balance is read twice in sellMalt call, which isn't needed, so gas is overspent here.
Proof of Concept
Malt balanceOf(address(this)) is called twice:
https://github.com/code-423n4/2021-11-malt/blob/main/src/contracts/SwingTrader.sol#L86
https://github.com/code-423n4/2021-11-malt/blob/main/src/contracts/SwingTrader.sol#L150
Recommended Mitigation Steps
It's recommended to make internal version of costBasis that takes Malt balance as an argument.
Now:
To be:
The text was updated successfully, but these errors were encountered: