Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constants are not explicitly declared #115

Open
code423n4 opened this issue Jan 6, 2022 · 2 comments
Open

Constants are not explicitly declared #115

code423n4 opened this issue Jan 6, 2022 · 2 comments
Labels
0 (Non-critical) Code style, clarity, syntax, versioning, off-chain monitoring (events etc), exclude gas optimisation bug Something isn't working resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")

Comments

@code423n4
Copy link
Contributor

Handle

WatchPug

Vulnerability details

It's a best practice to use constant variables rather than literal values to make the code easier to understand and maintain.

Consider defining a constant variable for the literal value used and giving it a clear and self-explanatory name.

Instances include:

https://github.com/XDeFi-tech/xdefi-distribution/blob/3856a42df295183b40c6eee89307308f196612fe/contracts/XDEFIDistribution.sol#L82-L82

require(duration <= uint256(18250 days), "INVALID_DURATION");

Consider changing uint256(18250 days) to MAX_DURATION constant.

@code423n4 code423n4 added 0 (Non-critical) Code style, clarity, syntax, versioning, off-chain monitoring (events etc), exclude gas optimisation bug Something isn't working labels Jan 6, 2022
code423n4 added a commit that referenced this issue Jan 6, 2022
@deluca-mike
Copy link
Collaborator

I agree. We will define MAX_DURATION and MAX_BONUS_MULTIPLIER and used them accordingly in the contact.

I actually like this a lot, so I am going to define a ZERO_ADDRESS, ZERO, ONE, and TWO as well, since it will make things a bit clearer, and because so many people kept erroneously claiming that uint256(0) (and the sort) were wasting gas casting, when it is in fact an in-line literal of explicit type.

@deluca-mike deluca-mike added the sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") label Jan 8, 2022
@deluca-mike
Copy link
Collaborator

In release candidate contracts, constants defined here and they are used throughout.

@deluca-mike deluca-mike added the resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) label Jan 14, 2022
@Ivshti Ivshti closed this as completed Jan 16, 2022
@CloudEllie CloudEllie reopened this Jan 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0 (Non-critical) Code style, clarity, syntax, versioning, off-chain monitoring (events etc), exclude gas optimisation bug Something isn't working resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Projects
None yet
Development

No branches or pull requests

4 participants