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

1 stars 0 forks source link

Could early return in function `borrowForMember` if `_collateral` is 0. #318

Closed code423n4 closed 3 years ago

code423n4 commented 3 years ago

Handle

shw

Vulnerability details

Impact

In Router.sol, the function borrowForMember calls an internal function, _handleTransferIn, which may return 0. In such a case, borrowForMember can directly return to save gas since the zero value of _collateral does not affect any following logic.

Proof of Concept

Referenced code: Router.sol#L316 Router.sol#L386-L393

Tools Used

None

Recommended Mitigation Steps

Add if (_collateral == 0) return; to save gas if _collateral is equal to 0.

dmvt commented 3 years ago

This adds a gas cost for all instances in exchange for saving gas for someone who intentionally passed in a zero value or had no collateral. This would almost certainly have a net increase in overall gas spent by all users.