Wenwin contest - lukris02's results

The next generation of chance-based gaming.

General Information

Platform: Code4rena

Start Date: 06/03/2023

Pot Size: $36,500 USDC

Total HM: 8

Participants: 93

Period: 3 days

Judge: cccz

Total Solo HM: 3

Id: 218

League: ETH

Wenwin

Findings Distribution

Researcher Performance

Rank: 27/93

Findings: 1

Award: $169.80

QA:
grade-a

🌟 Selected for report: 0

πŸš€ Solo Findings: 0

Awards

169.7989 USDC - $169.80

Labels

bug
grade-a
QA (Quality Assurance)
sponsor confirmed
Q-08

External Links

QA Report for Wenwin contest

Overview

During the audit, 9 low and 5 non-critical issues were found.

β„–TitleRisk RatingInstance Count
L-1Change ticket type from uint256 to uint120Low2
L-2If refferer == address (0), make refferer = msg.senderLow1
L-3Misleading commentLow1
L-4Validate nonJackpotFixedRewardsLow1
L-5Use SafeCast LibraryLow8
L-6Validate minimum valuesLow2
L-7Change constant namesLow2
L-8Make contracts more universalLow3
L-9Consider returning zero value instead of revertingLow1
NC-1Order of FunctionsNon-Critical5
NC-2Order of LayoutNon-Critical2
NC-3Prevent zero transfersNon-Critical5
NC-4Unused named return variablesNon-Critical8
NC-5Missing leading underscoresNon-Critical15

Low Risk Findings(9)

L-1. Change ticket type from uint256 to uint120

Description

In the modifier requireValidTicket(uint256 ticket) and in the function isValidTicket(), ticket has uint256 type, though in the registerTicket() function, ticket has uint128 type. And even here and here it is written that "Ticket is represented as uint120 packed ticket".

Instances
Recommendation

In the modifier requireValidTicket(uint256 ticket) and in the function isValidTicket() change ticket type to uint120.

L-2. If refferer`` == address (0), make refferer`` = msg.sender

Description

The protocol wants to maximize efficiency for participants, so maybe if the referrer is set to address(0) in the buyTickets() function, then make msg.sender the referrer. The user could buy a lot of tickets (and pass refferal requirements) but find out the opportunity to set themself a refferer lately - it will be sad to know about missed β€œbonus” ).

Instances
Recommendation
if (refferer == address (0)) { refferer = msg.sender; }

L-3. Misleading comment

Description

The comment is "0 - staking reward, 1 - frontend reward", but it should be "0 - frontend reward, 1 - staking reward".

Instances
Recommendation

Change the comment.

L-4. Validate nonJackpotFixedRewards

Description

It can be validated that rewards are in ascending order, for example: reward for (3/7) < reward for (4/7) < reward for (5/7) and so on.

Instances

L-5. Use SafeCast Library

Description

Downcasting from uint256/int256 in Solidity does not revert on overflow. This can easily result in undesired exploitation or bugs, since developers usually assume that overflows raise errors. SafeCast restores this intuition by reverting the transaction when such an operation overflows.

Instances

Although it is impossible that somebody will buy so many tickets ( >= uint128.max + 1), it is still better to do not use unsafe type casting to avoid even theoretical truncation and prevent loss of user funds:

Other instances:

Recommendation

It is better to use safe casting library.

L-6. Validate minimum values

Description

It can be validated that MAX_MAX_FAILED_ATTEMPTS and MAX_REQUEST_DELAY are not set to too small values.

Instances
Recommendation

Change to:

if (_maxFailedAttempts > MAX_MAX_FAILED_ATTEMPTS || _maxFailedAttempts < MIN_MAX_FAILED_ATTEMPTS) { revert MaxFailedAttemptsTooBigOrTooSmall(); } if (_maxRequestDelay > MAX_REQUEST_DELAY || _maxRequestDelay < MIN_REQUEST_DELAY) { revert MaxRequestDelayTooBigOrTooSmall();

L-7. Change constant names

Description

Here one constant has double "MAX" but other - single:

uint256 private constant MAX_MAX_FAILED_ATTEMPTS = 10; uint256 private constant MAX_REQUEST_DELAY = 5 hours;
Instances
Recommendation

Change to:

uint256 private constant MAX_FAILED_ATTEMPTS = 10; uint256 private constant MAX_REQUEST_DELAY = 5 hours;

or

uint256 private constant MAX_MAX_FAILED_ATTEMPTS = 10; uint256 private constant MAX_MAX_REQUEST_DELAY = 5 hours;

L-8. Make contracts more universal

Description

Protocol team wants to make different lotteries with different parameters without changing contracts, so it is better to change some constants to immutables and add parameters.

Instances

L-9. Consider returning zero value instead of reverting

Description

Consider returning zero value instead of reverting in the function claimWinningTicket. So, the user can pass as parameter (in the function claimWinningTickets) all their ticketIds β€” user just will receive rewards without checking which tickets are winning and which are not.

Instances
Recommendation

Change:

revert NothingToClaim(ticketId);

to:

return 0;

Non-Critical Risk Findings(5)

NC-1. Order of Functions

Description

According to Style Guide, ordering helps readers identify which functions they can call and to find the constructor and fallback definitions easier.
Functions should be grouped according to their visibility and ordered:

  1. constructor
  2. receive function (if exists)
  3. fallback function (if exists)
  4. external
  5. public
  6. internal
  7. private
Instances
Recommendation

Reorder functions where possible.

NC-2. Order of Layout

Description

According to Order of Layout, inside each contract, library or interface, use the following order:

  1. Type declarations
  2. State variables
  3. Events
  4. Modifiers
  5. Functions
Instances

Modifiers should be placed before constructor:

Events should be placed before functions:

Recommendation

Place events and modifiers before functions.

NC-3. Prevent zero transfers

Description

It can be checked that amount/claimedAmount/tickets.length > 0 to avoid zero transfers and do not spend gas.

Instances
Recommendation

Before the transfer check that transferredAmount > 0.

NC-4. Unused named return variables

Description

Both named return variable(s) and return statement are used.

Instances
Recommendation

To improve clarity use only named return variables.
For example, change:

function functionName() returns (uint id) { return x;

to

function functionName() returns (uint id) { id = x;

NC-5. Missing leading underscores

Description

Internal and private constants, immutables, state variables and functions should have a leading underscore.

Instances

Constants:

Immutables:

State variables:

Functions:

Recommendation

Add leading underscores where needed.

#0 - thereksfour

2023-03-12T07:57:22Z

4 L 4 INFO 6 NC DOWN 1 L

#1 - c4-judge

2023-03-12T07:57:26Z

thereksfour marked the issue as grade-b

#2 - c4-judge

2023-03-12T10:54:08Z

thereksfour marked the issue as grade-a

#3 - c4-sponsor

2023-03-14T09:57:43Z

0xluckydev marked the issue as sponsor confirmed

#4 - thereksfour

2023-03-18T04:16:02Z

5 L 4 INFO 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