veToken Finance contest - 0xNazgul's results

Lock more veAsset permanently.

General Information

Platform: Code4rena

Start Date: 26/05/2022

Pot Size: $75,000 USDT

Total HM: 31

Participants: 71

Period: 7 days

Judge: GalloDaSballo

Total Solo HM: 18

Id: 126

League: ETH

veToken Finance

Findings Distribution

Researcher Performance

Rank: 32/71

Findings: 3

Award: $262.40

🌟 Selected for report: 0

🚀 Solo Findings: 0

Findings Information

🌟 Selected for report: xiaoming90

Also found by: 0xNazgul, FSchmoede, Funen, Kumpa, VAD37, berndartmueller, cccz, kirk-baird

Labels

bug
duplicate
2 (Med Risk)

Awards

99.6119 USDT - $99.61

External Links

Lines of code

https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/Booster.sol#L219-L241

Vulnerability details

Impact

Function setFees() only checks that the total fees are <= MaxFees. There is no individual value range validity of each fee being set.

Tools Used

Manual Review

Each fee input parameter updated in setFees() should have it's own value range checks to ensure their validity.

#0 - jetbrain10

2022-06-15T16:19:46Z

same as #215

#1 - GalloDaSballo

2022-07-24T22:05:37Z

Dup of #215

Missing Equivalence Checks in Setters

Severity: Low Context: VeAssetDepositor.sol#L53-L57, VeAssetDepositor.sol#L59-L66, Booster.sol#L123-L127, Booster.sol#L129-L133, Booster.sol#L135-L139, Booster.sol#L141-L160, Booster.sol#L162-L166, Booster.sol#L168-L172, Booster.sol#L174-L190, Booster.sol#L193-L217, Booster.sol#L219-L241, Booster.sol#L243-L247, VeTokenMinter.sol#L32-L46

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: Booster.sol#L193-L217, Booster.sol#L219-L241, VeTokenMinter.sol#L41-L46

Description: None of the onlyOwner functions that change critical protocol addresses/parameters appear to have a timelock 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 timelock to these functions for a time-delayed change to alert users and protect against possiable malicious changes by compromised owners(s).

Missing Zero-address Validation

Severity: Low Context: VeAssetDepositor.sol#L53-L57, Booster.sol#L123-L127, Booster.sol#L129-L133, Booster.sol#L135-L139, Booster.sol#L141-L160, Booster.sol#L162-L166, Booster.sol#L168-L172, VE3DRewardPool.sol#L114-L116, VE3DRewardPool.sol#L118-L120

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: VE3DRewardPool.sol#L114-L116, VE3DRewardPool.sol#L118-L120, VoterProxy.sol#L62-L89, VeTokenMinter.sol#L32-L46

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.

Spelling Errors

Severity: Informational Context: VeAssetDepositor.sol#L93 (ammount => amount), VeAssetDepositor.sol#L126 (isnt => isn't), Booster.sol#L31 (platoform => platform), Booster.sol#L363 (seperate => separate), Booster.sol#L414 (seperate => separate), VE3dRewardPool.sol#L204 (dont => don't)

Description: Spelling errors in comments can cause confusion to both users and developers.

Recommendation: Check all misspellings to ensure they are corrected.

Use Of SafeMath.sol With ^0.8.0

Severity: Informational Context: All Contracts

Description: There is no need of SafeMath.sol in ^0.8.0.

Recommendation: Remove the use of SafeMath.sol for it is unneeded with 0.8.0 and up

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.

#0 - GalloDaSballo

2022-07-06T23:27:32Z

Missing Equivalence Checks in Setters

NC

Missing Time locks

Disagree as you can't prove there's no timelock

Missing Zero-address Validation

Valid Low

Lack of Event Emission For Critical Functions

Valid NC

## Spelling Errors Valid Refactoring

Use Of SafeMath.sol With ^0.8.0

Valid Refactoring (version is correct, no risk)

Missing or Incomplete NatSpec

Valid NC

Neat report

1L, 2R, 3NC

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

Context: Booster.sol#L325-L342, BaseRewardPool.sol#L172-L187, BaseRewardPool.sol#L195-L212, BaseRewardPool.sol#L214-L233, BaseRewardPool.sol#L239-L261, BaseRewardPool.sol#L267-L287, VE3DRewardPool.sol#L146-L164, VE3DRewardPool.sol#L209-L226, VE3DRewardPool.sol#L233-L250, VE3DRewardPool.sol#L252-L269, VE3DRewardPool.sol#L275-L330 (For both), VoterProxy.sol#L207-L222

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: Booster.sol#L325-L342, BaseRewardPool.sol#L172-L187, BaseRewardPool.sol#L195-L212, BaseRewardPool.sol#L214-L233, BaseRewardPool.sol#L239-L261, BaseRewardPool.sol#L267-L287, VE3DRewardPool.sol#L146-L164, VE3DRewardPool.sol#L275-L330 (For L281), VoterProxy.sol#L207-L222

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.

The Increment In For Loop Post Condition Can Be Made Unchecked

Context: Booster.sol#L325-L342, BaseRewardPool.sol#L172-L187, BaseRewardPool.sol#L195-L212, BaseRewardPool.sol#L214-L233, BaseRewardPool.sol#L239-L261, BaseRewardPool.sol#L267-L287, VE3DRewardPool.sol#L146-L164, VE3DRewardPool.sol#L209-L226, VE3DRewardPool.sol#L233-L250, VE3DRewardPool.sol#L252-L269, VE3DRewardPool.sol#L275-L330 (For both), VoterProxy.sol#L207-L222

Description: (This is only relevant if you are using the default solidity checked arithmetic). i++ involves checked arithmetic, which is not required. This is because the value of i is always strictly less than length <= 2**256 - 1. Therefore, the theoretical maximum value of i to enter the for-loop body is 2**256 - 2. This means that the i++ in the for loop can never overflow. Regardless, the overflow checks are performed by the compiler.

Unfortunately, the Solidity optimizer is not smart enough to detect this and remove the checks. One can manually do this by:

for (uint i = 0; i < length; i = unchecked_inc(i)) {
    // do something that doesn't change the value of i
}

function unchecked_inc(uint i) returns (uint) {
    unchecked {
        return i + 1;
    }
}

Note that it’s important that the call to unchecked_inc is inlined. This is only possible for solidity versions starting from 0.8.2.

Recommendation: The increment in the for loop post condition can be made unchecked.

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

Context: VeAssetDepositor.sol#L127-L167, BaseRewardPool.sol#L172-L187, BaseRewardPool.sol#L195-L212, BaseRewardPool.sol#L214-L233, VE3DRewardPool.sol#L209-L226, VE3DRewardPool.sol#L233-L250, VE3DRewardPool.sol#L252-L269

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.

Setting The Constructor To Payable

Context: All Contracts

Description: You can cut out 10 opcodes in the creation-time EVM bytecode if you declare a constructor payable. Making the constructor payable eliminates the need for an initial check of msg.value == 0 and saves 21 gas on deployment with no security risks.

Recommendation: Set the constructor to payable.

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.

#0 - GalloDaSballo

2022-07-14T01:48:34Z

Saves 1k at most

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