Closed code423n4 closed 2 years ago
address(this).balance - _fromBalance is found to be operated twice while it could be operated once and save the result to a local variable for later use.
address(this).balance - _fromBalance
For greater gas-optimization, the code can be rewrite as following:
/* from */ require(address(this).balance - _fromBalance >= _anyswapData.amount, "ERR_INVALID_AMOUNT"); uint256 _postSwapBalance = address(this).balance - _fromBalance; require(_postSwapBalance > 0, "ERR_INVALID_AMOUNT"); /* to */ uint256 _postSwapBalance = address(this).balance - _fromBalance; require(_postSwapBalance >= _anyswapData.amount && _postSwapBalance > 0, "ERR_INVALID_AMOUNT");
Warden submitted multiple QA report #149
Redundant Operation
Description
address(this).balance - _fromBalance
is found to be operated twice while it could be operated once and save the result to a local variable for later use.Permalinks
Mitigation
For greater gas-optimization, the code can be rewrite as following: