code-423n4 / 2022-07-swivel-findings

0 stars 1 forks source link

Gas Optimizations #2

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago
  1. !=0 is cheaper than > 0 In below code references, comparison is done using > 0. Instead consider using != for integer comparison. It's much cheaper.

Code: https://github.com/code-423n4/2022-07-swivel/blob/main/Creator/VaultTracker.sol#L54 https://github.com/code-423n4/2022-07-swivel/blob/main/Creator/VaultTracker.sol#L59 https://github.com/code-423n4/2022-07-swivel/blob/main/Creator/VaultTracker.sol#L93 https://github.com/code-423n4/2022-07-swivel/blob/main/Creator/VaultTracker.sol#L123 https://github.com/code-423n4/2022-07-swivel/blob/main/Creator/VaultTracker.sol#L165 https://github.com/code-423n4/2022-07-swivel/blob/main/Creator/VaultTracker.sol#L181 https://github.com/code-423n4/2022-07-swivel/blob/main/Creator/VaultTracker.sol#L184 https://github.com/code-423n4/2022-07-swivel/blob/main/Creator/VaultTracker.sol#L222 https://github.com/code-423n4/2022-07-swivel/blob/main/VaultTracker/VaultTracker.sol#L54 https://github.com/code-423n4/2022-07-swivel/blob/main/VaultTracker/VaultTracker.sol#L59 https://github.com/code-423n4/2022-07-swivel/blob/main/VaultTracker/VaultTracker.sol#L93 https://github.com/code-423n4/2022-07-swivel/blob/main/VaultTracker/VaultTracker.sol#L123 https://github.com/code-423n4/2022-07-swivel/blob/main/VaultTracker/VaultTracker.sol#L165 https://github.com/code-423n4/2022-07-swivel/blob/main/VaultTracker/VaultTracker.sol#L181 https://github.com/code-423n4/2022-07-swivel/blob/main/VaultTracker/VaultTracker.sol#L184 https://github.com/code-423n4/2022-07-swivel/blob/main/VaultTracker/VaultTracker.sol#L222

  1. Use of custom error Starting from Solidity v0.8.4, there is a convenient and gas-efficient way to explain to users why an operation failed through the use of custom errors. Until now, you could already use strings to give more information about failures (e.g., revert("Insufficient funds.");), but they are rather expensive, especially when it comes to deploy cost, and it is difficult to use dynamic information in them.

Code references: https://github.com/code-423n4/2022-07-swivel/blob/main/Creator/LibCompound.sol#L28 https://github.com/code-423n4/2022-07-swivel/blob/main/Creator/LibFuse.sol#L36

Mitigation: replace require with if (a != b) revert ERROR()