Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For uint replace > 0 with != 0 #8

Open
code423n4 opened this issue Nov 12, 2021 · 2 comments
Open

For uint replace > 0 with != 0 #8

code423n4 opened this issue Nov 12, 2021 · 2 comments
Assignees
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")

Comments

@code423n4
Copy link
Contributor

Handle

0x0x0x

Vulnerability details

Proof of Concept

For unsigned integers, it is cheaper to check != 0 than > 0. Both provide the same logic.

Occurences

contracts/FeeSplitter.sol:105:        require(_accounts.length > 0 && _accounts.length == _weights.length, "FeeSplitter: ARRAY_LENGTHS_ERR");
contracts/FeeSplitter.sol:172:        require(_totalWeights > 0, "FeeSplitter: TOTAL_WEIGHTS_ZERO");
contracts/FeeSplitter.sol:263:        require(_weight > 0, "FeeSplitter: ZERO_WEIGHT");
contracts/NestedBuybacker.sol:97:        if (feeSplitter.getAmountDue(address(this), _sellToken) > 0) {
contracts/NestedFactory.sol:69:        require(i > 0, "NestedFactory::removeOperator: Cant remove non-existent operator");
contracts/NestedFactory.sol:94:        require(_orders.length > 0, "NestedFactory::create: Missing orders");
contracts/NestedFactory.sol:110:        require(_orders.length > 0, "NestedFactory::addTokens: Missing orders");
contracts/NestedFactory.sol:124:        require(_orders.length > 0, "NestedFactory::swapTokenForTokens: Missing orders");
contracts/NestedFactory.sol:143:        require(_orders.length > 0, "NestedFactory::sellTokensToNft: Missing orders");
contracts/NestedFactory.sol:163:        require(_orders.length > 0, "NestedFactory::sellTokensToWallet: Missing orders");
contracts/NestedFactory.sol:194:        require(_orders.length > 0, "NestedFactory::destroy: Missing orders");
contracts/NestedFactory.sol:333:            if (_inputTokenAmounts[i] - amountSpent > 0) {
contracts/NestedFactory.sol:467:        if (_amountToSpent - _amountSpent > 0) {
contracts/NestedRecords.sol:171:        require(_maxHoldingsCount > 0, "NestedRecords: INVALID_MAX_HOLDINGS");
contracts/operators/Flat/FlatOperator.sol:18:        require(amount > 0, "FlatOperator::commitAndRevert: Amount must be greater than zero");
contracts/operators/ZeroEx/ZeroExOperator.sol:42:        assert(amountBought > 0);
contracts/operators/ZeroEx/ZeroExOperator.sol:43:        assert(amountSold > 0);
@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Nov 12, 2021
code423n4 added a commit that referenced this issue Nov 12, 2021
@maximebrugel
Copy link
Collaborator

Example :

Before:
image

After:
image

@maximebrugel maximebrugel added the sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") label Nov 17, 2021
@maximebrugel
Copy link
Collaborator

Only for require. Can be confusing when reading the code for ifstatements.
For example : if (_amountToSpent - _amountSpent > 0) is better than if (_amountToSpent - _amountSpent != 0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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")
Projects
None yet
Development

No branches or pull requests

2 participants