code-423n4 / 2021-12-yetifinance-findings

0 stars 0 forks source link

!= 0 costs less gass compared to > 0 for unsigned integer inside pure or view functions #173

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

Dravee

Vulnerability details

Impact

In view and pure functions, != 0 costs less gass compared to > 0 for unsigned integer

Proof of Concept

0 checks inside view or pure functions:


BorrowerOperations.sol:
913:         require(_YUSDChange > 0, "BorrowerOps: Debt increase requires non-zero debtChange");

HintHelpers.sol: 100: while (currentTroveuser != address(0) && remainingYUSD > 0 && _maxIterations-- > 0) {

StabilityPool.sol: 1090: require(_initialDeposit > 0, "StabilityPool: User must have a non-zero deposit"); 1099: require(_amount > 0, "StabilityPool: Amount must be non-zero");

TroveManager.sol: 502: assert(totalStakesSnapshot[token] > 0);

TroveManagerLiquidations.sol: 657: if (_YUSDInStabPool > 0) {

TroveManagerRedemptions.sol: 497: require(_amount > 0, "TroveManager: Amount must be greater than zero"); 520: require(total > 0, "must be non zero redemption amount");

AssetWrappers\WJLP\SafeMath.sol: 196: require(b > 0, errorMessage); 222: require(b > 0, errorMessage);

Dependencies\CheckContract.sol: 17: require(size > 0, "Account code size cannot be zero");

Dependencies\LiquityBase.sol: 159: if (coll.amounts[i] > 0) {

Dependencies\LiquityMath.sol: 83: if (_debt > 0) {

Dependencies\SafeMath.sol: 122: require(b > 0, errorMessage);

Dependencies\TellorCaller.sol: 50: if (_value > 0) return (true, _value, _time);

Dependencies\YetiCustomBase.sol: 38: if (_coll1.amounts[i] > 0) { 46: if (_coll2.amounts[i] > 0) { 60: if (coll3.amounts[i] > 0) { 145: if (_coll1.amounts[i] > 0) { 166: if (coll3.amounts[i] > 0) {

LPRewards\Dependencies\Address.sol: 34: return size > 0; 152: if (returndata.length > 0) {

PriceCurves\ThreePieceWiseLinearPriceCurve.sol: 144: if (decay > 0 && decay < decayTime) {

YETI\sYETIToken.sol: 271: require(b > 0, "BoringMath: Div By 0");



## Tools Used
VS Code

## Recommended Mitigation Steps
Change > 0 with != 0.
kingyetifinance commented 2 years ago

@LilYeti: Duplicate #125

alcueca commented 2 years ago

Taking as main