Forgeries contest - Madalad's results

A protocol for on-chain games with NFT prizes on Ethereum.

General Information

Platform: Code4rena

Start Date: 13/12/2022

Pot Size: $36,500 USDC

Total HM: 5

Participants: 77

Period: 3 days

Judge: gzeon

Total Solo HM: 1

Id: 191

League: ETH

Forgeries

Findings Distribution

Researcher Performance

Rank: 17/77

Findings: 2

Award: $155.98

QA:
grade-b

🌟 Selected for report: 0

🚀 Solo Findings: 0

Findings Information

Labels

bug
2 (Med Risk)
satisfactory
duplicate-273

Awards

110.2711 USDC - $110.27

External Links

Lines of code

https://github.com/code-423n4/2022-12-forgeries/blob/main/src/VRFNFTRandomDraw.sol#L33

Vulnerability details

Impact

In VRFNFTRandomDraw, we have that

uint256 immutable MONTH_IN_SECONDS = (3600 * 24 * 7) * 30;

however that calculation is actually 30 weeks, not 30 days. The correct calculation is:

uint256 immutable MONTH_IN_SECONDS = (3600 * 24) * 30;

This means that certain waiting periods may actually be 7 times as long as advertised. For example, users may have to wait as long as 7 months in between draws as opposed to 1 month, and an admin may have to wait 7 years as opposed to 1 year to retreive their target NFT from the contract.

Use solidity constants hours, days for time calculations to avoid such calculation mistakes, and to improve code readability.

uint256 immutable MONTH_IN_SECONDS = 30 days;

#0 - c4-judge

2022-12-17T12:53:17Z

gzeon-c4 marked the issue as duplicate of #273

#1 - c4-judge

2022-12-17T12:53:54Z

gzeon-c4 marked the issue as satisfactory

Awards

45.7078 USDC - $45.71

Labels

bug
grade-b
QA (Quality Assurance)
Q-21

External Links

QA Report

Misleading comments

There are two instances of comments which contradict the code. Either the comment or the code ought to be updated:

<br>

Non-ERC721 contracts (e.g. CryptoPunks) incompatible with draw contract

NFTs that do not adhere to the ERC721 standard will not be usable in VRFNFTRandomDraw, as the IERC721EnumerableUpgradeable interface is used when interacting with the NFT contract. While non-ERC721 NFTs are rare, it is worth noting since CryptoPunks were mentioned as an example drawing NFT in the contest overview/README.

<br>

Use solidity built in time constants

Instead of manually calculating seconds, use the build in keywords minutes, hours and days. This reduces margin for error and improves readability (the calculation for MONTH_IN_SECONDS is actually incorrect by a factor of 7).

<br>

No enforcement for strictly increasing versions

Version is intended to keep track of implementation versions. However it is possible to upgrade to a new implementation with a version that is less than or equal to the old version. Strictly increasing versions should be enforced for each proxy.

<br>

Use fixed compiler version rather than floating one

A floating pragma risks a different compiler version being used in production vs testing, which poses security risks.

<br>

Use constant instead of immutable

For immutable variables whose value is set outside of the constructor, the constant keyword ought to be used instead to save gas and improve readability.

<br>

Use safeTransferFrom instead of transferFrom

Concerning ERC721 tokens, transferFrom can result in tokens being lost if they are sent to a contract that does not implement IERC721Receiver.onERC721Received. OpenZeppelin encourages the use of safeTransferFrom over transferFrom for this reason.

<br>

Mark state variables as either public or private

#0 - c4-judge

2022-12-17T17:07:14Z

gzeon-c4 marked the issue as grade-b

#1 - gzeoneth

2022-12-17T17:07:39Z

Possible dupe of #108

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