code-423n4 / 2022-06-infinity-findings

4 stars 0 forks source link

QA Report #351

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

1. Incorrect check >= instead of >

Risk

Low

Impact

Function InfinityStaker.getRageQuitAmounts uses require statement to check if uint256 variable totalStaked is bigger or equal to 0.

193:    require(totalStaked >= 0, 'nothing staked to rage quit');

The check should be verifying if totalStaked is bigger than 0 - >.

Proof of Concept

staking/InfinityStaker.so:193     require(totalStaked >= 0, 'nothing staked to rage quit');

Tools Used

Manual Review / VSCode

Recommended Mitigation Steps

It is recommended to change the require check to:

193:    require(totalStaked > 0, 'nothing staked to rage quit');

2. Missing zero address checks

Risk

Low

Impact

Multiple contracts do not check for zero addresses which might lead to loss of funds, failed transactions and can break the protocol functionality.

Proof of Concept

InfinityStaker.sol:

InfinityExchange.sol:

InfinityToken.sol:

Tools Used

Manual Review / VSCode

Recommended Mitigation Steps

It is recommended to add zero address checks for listed parameters.

3. Missing events

Risk

Low

Impact

Multiple contracts are not implementing events for critical functions. Lack of events makes it difficult for off-chain applications to monitor the protocol.

Proof of Concept

InfinityExchange.sol:

InfinityStaker.sol:

Tools Used

Manual Review / VSCode

Recommended Mitigation Steps

It is recommended to add missing events to listed functions.

4. Critical address change

Risk

Low

Impact

Changing critical addresses such as ownership should be a two-step process where the first transaction (from the old/current address) registers the new address (i.e. grants ownership) and the second transaction (from the new address) replaces the old address with the new one. This gives an opportunity to recover from incorrect addresses mistakenly used in the first step. If not, contract functionality might become inaccessible.

Proof of Concept

InfinityStaker.sol

InfinityExchange.sol

InfinityOrderBookComplication.sol:

Tools Used

Manual Review / VSCode

Recommended Mitigation Steps

It is recommended to implement two-step process for changing critical addresses.

5. Use scientific notation

Risk

Non-Critical

Impact

Defining big numbers that consists of many digits or performing additional math calculations might lead to accidential errors and mistakes.

Proof of Concept

core/InfinityExchange.sol:1161:    uint256 PRECISION = 10**4; // precision for division; similar to bps
core/InfinityOrderBookComplication.sol:338:    uint256 PRECISION = 10**4; // precision for division; similar to bp
staking/InfinityStaker.sol:237:        (userstakedAmounts[user][Duration.TWELVE_MONTHS].amount * 4)) / (10**18);

Tools Used

Manual Review / VSCode

Recommended Mitigation Steps

It is recommended to use scientific notation.

6. Missing indexing for events

Risk

Non-Critical

Impact

Events should index addresses which helps off-chain applications in monitoring the protocol.

Proof of Concept

core/InfinityExchange.sol:80:  event CancelAllOrders(address user, uint256 newMinNonce);
core/InfinityExchange.sol:81:  event CancelMultipleOrders(address user, uint256[] orderNonces);
core/InfinityExchange.sol:82:  event NewWethTransferGasUnits(uint32 wethTransferGasUnits);
core/InfinityExchange.sol:83:  event NewProtocolFee(uint16 protocolFee);
---
core/InfinityExchange.sol:85:  event MatchOrderFulfilled(
                     bytes32 sellOrderHash,
                     bytes32 buyOrderHash,
                     address seller,
                     address buyer,
                     address complication, // address of the complication that defines the execution
                     address currency, // token address of the transacting currency
                     uint256 amount // amount spent on the order
                   );
---
core/InfinityExchange.sol:95:  event TakeOrderFulfilled(
                     bytes32 orderHash,
                     address seller,
                     address buyer,
                     address complication, // address of the complication that defines the execution
                     address currency, // token address of the transacting currency
                     uint256 amount // amount spent on the order
                   );
---
staking/InfinityStaker.sol:44:  event Staked(address indexed user, uint256 amount, Duration duration);
staking/InfinityStaker.sol:45:  event DurationChanged(address indexed user, uint256 amount, Duration oldDuration, Duration newDuration);
staking/InfinityStaker.sol:46:  event UnStaked(address indexed user, uint256 amount);
staking/InfinityStaker.sol:47:  event RageQuit(address indexed user, uint256 totalToUser, uint256 penalty);
token/TimelockConfig.sol:34:  event ChangeRequested(bytes32 configId, uint256 value);
token/TimelockConfig.sol:35:  event ChangeConfirmed(bytes32 configId, uint256 value);
token/TimelockConfig.sol:36:  event ChangeCanceled(bytes32 configId, uint256 value);
token/InfinityToken.sol:35:  event EpochAdvanced(uint256 currentEpoch, uint256 supplyMinted);

Tools Used

Manual Review / VSCode

Recommended Mitigation Steps

It is recommended to add indexing to address type parameters.

7. Missing/incomplete natspec comments

Risk

Non-Critical

Impact

Contracts are missing natspec comments which makes code more difficult to read and prone to errors.

Proof of Concept

InfinityExchange.sol:

InfinityOrderBookComplication.sol:

InfinityStaker.sol:

InfinityToken.sol:

TimelockConfig.sol:

Tools Used

Manual Review / VSCode

Recommended Mitigation Steps

It is recommended to add missing natspec comments.

8. Typos

Risk

Non-Critical

Impact

Code and comments contain typos which makes code more difficult to read and prone to errors.

Proof of Concept

InfinityStaker.sol:

Tools Used

Manual Review / VSCode

Recommended Mitigation Steps

It is recommended to correct listed typos.

8. Check return values

Risk

Non-Critical

Impact

Multiple contracts do not check for return values of executed functions. This might lead to accidents and errors since the created transaction is valid but the underlying code did not execute properly.

Proof of Concept

InfinityExchange.sol:

InfinityToken.sol:

Tools Used

Manual Review / VSCode

Recommended Mitigation Steps

It is recommended to check the return values of executed functions.

nneverlander commented 2 years ago

Thank you

HardlyDifficult commented 2 years ago

Merging with https://github.com/code-423n4/2022-06-infinity-findings/issues/44

HardlyDifficult commented 2 years ago

Merging with https://github.com/code-423n4/2022-06-infinity-findings/issues/42

HardlyDifficult commented 2 years ago

Merging with https://github.com/code-423n4/2022-06-infinity-findings/issues/328