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

fix: N-09, Unexplained and unused constants #3909

Merged
merged 3 commits into from
May 18, 2022
Merged

Conversation

mrice32
Copy link
Member

@mrice32 mrice32 commented May 17, 2022

Motivation

Throughout the OptimisticGovernor contract, to check if a proposal has been approved
by the Optimistic Oracle the literal value int256 1e18 is used, where 1e18 signifies that a
proposal was not rejected by the Optimistic Oracle.

Similarly, in the update to the OptimisticOracle contract the function proposedPrice
uses a magic value type(int256).min to indicate that an event-based proposal cannot be
resolved, because the event has not yet taken place.

Lastly, in the OptimisticOracle contract the MAX_ADDED_ANCILLARY_DATA constant is
declared on line 129. On the next line the constant should be used, but instead the value of the
constant is used directly to derive another constant.

To improve the overall readability of the codebase and to facilitate refactoring, consider
defining a constant for every literal or magic value used, giving it a clear and self-explanatory
name, and then using it in place of literal values. Also consider adding an inline comment
explaining how literal values were calculated or why they were chosen.

Summary

Fixed these issues.

Testing

Check a box to describe how you tested these changes and list the steps for reviewers to test.

  • Ran end-to-end test, running the code as in production
  • New unit tests created
  • Existing tests adequate, no new tests required
  • All existing tests pass
  • Untested

Issue(s)

N/A

@mrice32 mrice32 marked this pull request as ready for review May 17, 2022 16:45
@mrice32 mrice32 requested a review from pemulis May 17, 2022 16:45
@@ -127,7 +127,8 @@ contract OptimisticOracle is OptimisticOracleInterface, Testable, Lockable {

// This is effectively the extra ancillary data to add ",ooRequester:0000000000000000000000000000000000000000".
uint256 private constant MAX_ADDED_ANCILLARY_DATA = 53;
uint256 public constant OO_ANCILLARY_DATA_LIMIT = ancillaryBytesLimit - 53;
uint256 public constant OO_ANCILLARY_DATA_LIMIT = ancillaryBytesLimit - MAX_ADDED_ANCILLARY_DATA;
int256 public constant TOO_EARLY_RESPONSE = type(int256).min;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be cool to refactor this in a way that we can re-use this magic number throughout some of the other contracts in this package such as here

function ignoreEarlyExpirationPrice() public pure returns (int256) {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree! But let's do this in a follow-up just to keep these fixes focused and simple.

Copy link
Member

@chrismaree chrismaree left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mrice32 mrice32 merged commit dae2e7f into master May 18, 2022
@mrice32 mrice32 deleted the mrice32-patch-10 branch May 18, 2022 19:28
@mrice32 mrice32 changed the title fix: [N09] Unexplained and unused constants fix: N-09, Unexplained and unused constants May 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants