Numoen contest - btk's results

Automated exchange for power perpetuals.

General Information

Platform: Code4rena

Start Date: 26/01/2023

Pot Size: $60,500 USDC

Total HM: 7

Participants: 31

Period: 6 days

Judge: berndartmueller

Total Solo HM: 3

Id: 207

League: ETH

Numoen

Findings Distribution

Researcher Performance

Rank: 11/31

Findings: 1

Award: $997.11

QA:
grade-a

🌟 Selected for report: 0

🚀 Solo Findings: 0

Findings Information

🌟 Selected for report: CodingNameKiki

Also found by: 0xAgro, 0xSmartContract, IllIllI, Rolezn, SleepingBugs, btk, chrisdior4, matrix_0wl

Labels

bug
grade-a
QA (Quality Assurance)
edited-by-warden
Q-07

Awards

997.1116 USDC - $997.11

External Links

Total Low issues
RiskIssues DetailsNumber
[L-01]Solmate's SafeTransferLib.sol doesn't check whether the ERC20 contract exists4
[L-02]Loss of precision due to rounding6
[L-03]Missing Event for initialize5
Total Non-Critical issues
RiskIssues DetailsNumber
[NC-01]Lock pragmas to specific compiler versionAll Contracts
[NC-02]Use a more recent version of solidityAll Contracts
[NC-03]Constants in comparisons should appear on the left side27
[NC-04]Use bytes.concat() and string.concat()3
[NC-05]Include @return parameters in NatSpec comments29
[NC-06]Function writing does not comply with the Solidity Style Guide3 Contracts
[NC-07]NatSpec comments should be increased in contractsAll Contracts
[NC-08]Contracts should have full test coverageAll Contracts
[NC-09]Add NatSpec comment to mapping4
[NC-10]Remove Unused Codes1
[NC-11]For functions, follow Solidity standard naming conventionsAll Contracts
[NC-12]Not using the named return variables anywhere in the function is confusing3
[NC-13]Constants should be defined rather than using magic numbers4
[NC-14]Need Fuzzing testAll Contracts

[L-01] Solmate's SafeTransferLib.sol doesn't check whether the ERC20 contract exists

Description

Solmate's SafeTransferLib.sol, which is often used to interact with non-compliant/unsafe ERC20 tokens, does not check whether the ERC20 contract exists. The following code will not revert in case the token doesn't exist.

Refrence

/// @dev Note that none of the functions in this library check that a token has code at all! That responsibility is delegated to the caller.
Lines of code

Add a contract exist check to your SafeTransferLib.sol library.

[L-02] Loss of precision due to rounding

Description

Loss of precision due to the nature of arithmetics and rounding errors.

    return FullMath.mulDiv(liquidity, 2 * upperBound, 1e18) / token1Scale;
Lines of code

[L-03] Missing Event for initialize

Description

Events help non-contract tools to track changes, and events prevent users from being surprised by changes Issuing event-emit during initialization is a detail that many projects skip.

Lines of code

Add Event-Emit.

[NC-01] Lock pragmas to specific compiler version

Description

Pragma statements can be allowed to float when a contract is intended for consumption by other developers, as in the case with contracts in a library or EthPM package. Otherwise, the developer would need to manually update the pragma in order to compile locally.

Ref: https://swcregistry.io/docs/SWC-103

Lines of code

Ethereum Smart Contract Best Practices: Lock pragmas to specific compiler version.

[NC-02] Use a more recent version of solidity

Description

For security, it is best practice to use the latest Solidity version.

pragma solidity ^0.8.4;
Lines of code

Old version of Solidity is used (^0.8.4), newer version can be used (0.8.17).

[NC-03] Constants in comparisons should appear on the left side

Description

Constants in comparisons should appear on the left side, doing so will prevent typo bug.

    if (totalLiquidity == 0) return 0;
Lines of code
    if (0 == totalLiquidity) return 0;

[NC-04] Use bytes.concat() and string.concat()

Description
  • bytes.concat() vs abi.encodePacked(<bytes>,<bytes>)
  • string.concat() vs abi.encodePacked(<string>,<string>)

https://docs.soliditylang.org/en/v0.8.17/types.html?highlight=bytes.concat#the-functions-bytes-concat-and-string-concat

Lines of code

Use bytes.concat() and string.concat() instead.

[NC-05] Include @return parameters in NatSpec comments

Description

If Return parameters are declared, you must prefix them with @return. Some code analysis programs do analysis by reading NatSpec details, if they can't see the @return tag, they do incomplete analysis.

Lines of code

Include the @return argument in the NatSpec comments.

[NC-06] Function writing does not comply with the Solidity Style Guide

Description

Ordering helps readers identify which functions they can call and to find the constructor and fallback definitions easier. But there are contracts in the project that do not comply with this.

Functions should be grouped according to their visibility and ordered:

  • constructor()
  • receive()
  • fallback()
  • external / public / internal / private
  • view / pure
Lines of code

Follow Solidity Style Guide.

[NC-07] NatSpec comments should be increased in contracts

Description

It is recommended that Solidity contracts are fully annotated using NatSpec, it is clearly stated in the Solidity official documentation.

  • In complex projects such as Defi, the interpretation of all functions and their arguments and returns is important for code readability and auditability.

  • Some code analysis programs do analysis by reading NatSpec details, if they can't see the tags (@param, @dev, @return), they do incomplete analysis.

Lines of code

Include NatSpec comments in the codebase.

[NC-08] Contracts should have full test coverage

Description

While 100% code coverage does not guarantee that there are no bugs, it often will catch easy-to-find bugs, and will ensure that there are fewer regressions when the code invariably has to be modified. Furthermore, in order to get full coverage, code authors will often have to re-organize their code so that it is more modular, so that each component can be tested separately, which reduces interdependencies between modules and layers, and makes for code that is easier to reason about and audit.

- What is the overall line coverage percentage provided by your tests?: 0 
Lines of code

Line coverage percentage should be 100%.

[NC-09] Add NatSpec comment to mapping

Description

Add NatSpec comments describing mapping keys and values.

Lines of code
/// @dev  uint(timestamp) => uint(token Id)
    mapping(uint => uint) public timestampForTokenId;

[NC-10] Remove Unused Codes

Description

The below error is unused code:

  error FailedApprove();
Lines of code

I recommend removing unused codes from the codebase.

[NC-11] For functions, follow Solidity standard naming conventions

Description

The protocol don't follow solidity standard naming convention.

Ref: https://docs.soliditylang.org/en/v0.8.17/style-guide.html#naming-conventions

Lines of code

Follow solidity standard naming convention.

[NC-12] Not using the named return variables anywhere in the function is confusing

Description

Not using the named return variables anywhere in the function is confusing.

  function utilizationRate(uint256 borrowedLiquidity, uint256 totalLiquidity) private pure returns (uint256 rate) {
    if (totalLiquidity == 0) return 0;
    return (borrowedLiquidity * 1e18) / totalLiquidity;
  }
Lines of code

Consider changing the variable to be an unnamed one.

  function utilizationRate(uint256 borrowedLiquidity, uint256 totalLiquidity) private pure returns (uint256) {
    if (totalLiquidity == 0) return 0;
    return (borrowedLiquidity * 1e18) / totalLiquidity;
  }

[NC-13] Constants should be defined rather than using magic numbers

Description
    uint256 amountInWithFee = amountIn * 997;
    uint256 denominator = (reserveIn * 1000) + amountInWithFee;
    uint256 numerator = reserveIn * amountOut * 1000;
    uint256 denominator = (reserveOut - amountOut) * 997;
Lines of code

[NC-14] Need Fuzzing test

Description

As Alberto Cuesta Canada said: Fuzzing is not easy, the tools are rough, and the math is hard, but it is worth it. Fuzzing gives me a level of confidence in my smart contracts that I didn’t have before. Relying just on unit testing anymore and poking around in a testnet seems reckless now.

Ref: https://medium.com/coinmonks/smart-contract-fuzzing-d9b88e0b0a05

Lines of code

Use fuzzing test like Echidna.

#0 - c4-judge

2023-02-16T11:47:16Z

berndartmueller marked the issue as grade-a

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