Sturdy contest - 0xNazgul's results

The first protocol for interest-free borrowing and high yield lending.

General Information

Platform: Code4rena

Start Date: 13/05/2022

Pot Size: $30,000 USDC

Total HM: 8

Participants: 65

Period: 3 days

Judge: hickuphh3

Total Solo HM: 1

Id: 125

League: ETH

Sturdy

Findings Distribution

Researcher Performance

Rank: 24/65

Findings: 2

Award: $93.84

🌟 Selected for report: 0

🚀 Solo Findings: 0

Missing Equivalence Checks in Setters

Severity: Low Context: GeneralVault.sol#L165-L172, YieldManager.sol#L64-L67, YieldManager.sol#L73-L76, YieldManager.sol#L92-L99

Description: Setter functions are missing checks to validate if the new value being set is the same as the current value already set in the contract. Such checks will showcase mismatches between on-chain and off-chain states.

Recommendation: Add in the additional checks to validate if the new value being set is the same as the current value already set in the contract.

Missing Time locks

Severity: Low Context: YieldManager.sol#L64-L67, YieldManager.sol#L73-L76, YieldManager.sol#L92-L99

Description: Some onlyOwner functions that change critical protocol addresses/parameters appear to have a time lock for a time-delayed change to alert: (1) users and give them a chance to engage/exit protocol if they are not agreeable to the changes (2) team in case of compromised owner(s) and given them a chance to perform incident response.

Recommendation: Add a time lock to these functions for a time-delayed change to alert users and protect against possible malicious changes by compromised owners(s).

Missing Zero-address Validation

Severity: Low Context: GeneralVault.sol#L61-L63, ConvexCurveLPVault.sol#L37-L49, CollateralAdapter.sol#L43-L50, YieldManager.sol#L73-L76, YieldManager.sol#L92-L99 (For L93 & L94)

Description: Lack of zero-address validation on address parameters may lead to reverts and force contract redeployments.

Recommendation: Add explicit zero-address validation on input parameters of address type.

Lack of Event Emission For Critical Functions

Severity: Low Context: ConvexCurveLPVault.sol#L37-L49, CollateralAdapter.sol#L43-L50, YieldManager.sol#L64-L67, YieldManager.sol#L73-L76, YieldManager.sol#L92-L99, YieldManager.sol#L118-L137,

Description: Several functions update critical parameters that are missing event emission. These should be performed to ensure tracking of changes of such critical parameters.

Recommendation: Add events to functions that change critical parameters.

Missing or Incomplete NatSpec

Severity: Informational Context: All Contracts

Description: Some functions are missing @notice/@dev NatSpec comments for the function, @param for all/some of their parameters and @return for return values. Given that NatSpec is an important part of code documentation, this affects code comprehension, auditability and usability.

Recommendation: Add in full NatSpec comments for all functions to have complete code documentation for future use.

Older Version Pragma

Severity: Informational Context: All Contracts

Description: Using very old versions of Solidity prevents benefits of bug fixes and newer security checks. Using the latest versions might make contracts susceptible to undiscovered compiler bugs.

Recommendation: Consider using a more recent version such as 0.8.4.

#0 - HickupHH3

2022-06-06T03:06:35Z

Low issues: timelocks NC issues: equivalence checks, zero address validation, event emissions, natspec compatibility, older version pragma Invalid:

Awards

24.3601 USDC - $24.36

Labels

bug
G (Gas Optimization)

External Links

Use ++index instead of index++ to increment a loop counter

Context: GeneralVault.sol#L204-L233, ConvexCurveLPVault.sol#L87-L111, YieldManager.sol#L118-L137 (For both), YieldManager.sol#L142-L171

Description: Due to reduced stack operations, using ++index saves 5 gas per iteration.

Recommendation: Use ++index to increment a loop counter.

Catching The Array Length Prior To Loop

Context: YieldManager.sol#L118-L137 (For L130)

Description: One can save gas by caching the array length (in stack) and using that set variable in the loop. Replace state variable reads and writes within loops with local variable reads and writes. This is done by assigning state variable values to new local variables, reading and/or writing the local variables in a loop, then after the loop assigning any changed local variables to their equivalent state variables.

Recommendation: Simply do something like so before the for loop: uint length = variable.length. Then add length in place of variable.length in the for loop.

In require(), Use != 0 Instead of > 0 With Uint Values

Context: GeneralVault.sol#L177-L183, LidoVault.sol#L79-L104 (For L88)

Description: In a require, when checking a uint, using != 0 instead of > 0 saves 6 gas. This will jump over or avoid an extra ISZERO opcode.

Recommendation: Use != 0 instead of > 0 with uint values but only in require() statements.

State Variables That Can Be Set To Immutable

Context: ConvexCurveLPVault.sol#L27

Description: Solidity 0.6.5 introduced immutable as a major feature. It allows setting contract-level variables at construction time which gets stored in code rather than storage. Each call to it reads from storage, using a sload costing 2100 gas cold or 100 gas warm. Setting it to immutable will have each storage read of the state variable to be replaced by the instruction push32 value, where value is set during contract construction time and this costs only 3 gas.

Recommendation: Set the state variable to immutable

Function Ordering via Method ID

Context: All Contracts

Description: Contracts most called functions could simply save gas by function ordering via Method ID. Calling a function at runtime will be cheaper if the function is positioned earlier in the order (has a relatively lower Method ID) because 22 gas are added to the cost of a function for every position that came before it. The caller can save on gas if you prioritize most called functions. One could use This tool to help find alternative function names with lower Method IDs while keeping the original name intact.

Recommendation: Find a lower method ID name for the most called functions for example mostCalled() vs. mostCalled_41q() is cheaper by 44 gas.

Upgrade To At Least 0.8.4

Context: All Contracts

Description: Using newer compiler versions and the optimizer gives gas optimizations and additional safety checks for free!

The advantages of versions =0.8.*= over =<0.8.0= are:

  • Safemath by default from =0.8.0= (can be more gas efficient than /some/ library based safemath).
  • Low level inliner from =0.8.2=, leads to cheaper runtime gas. Especially relevant when the contract has small functions. For example, OpenZeppelin libraries typically have a lot of small helper functions and if they are not inlined, they cost an additional 20 to 40 gas because of 2 extra =jump= instructions and additional stack operations needed for function calls.
  • Optimizer improvements in packed structs: Before =0.8.3=, storing packed structs, in some cases used an additional storage read operation. After EIP-2929, if the slot was already cold, this means unnecessary stack operations and extra deploy time costs. However, if the slot was already warm, this means additional cost of =100= gas alongside the same unnecessary stack operations and extra deploy time costs.
  • Custom errors from =0.8.4=, leads to cheaper deploy time cost and run time cost. Note: the run time cost is only relevant when the revert condition is met. In short, replace revert strings by custom errors.

Recommendation: Upgrade to at least 0.8.4 for the additional benefits.

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter