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: ToB-04 (summit tip upper bound) #1432

Merged
merged 6 commits into from
Oct 17, 2023

Conversation

ChiTimesChi
Copy link
Collaborator

@ChiTimesChi ChiTimesChi commented Oct 6, 2023

Description

  • Fixed ToB-04 issue by implementing a hard cap for the the summit tip of 0.01 ether.
  • Exposed summit tip value in GasOracle

Summary by CodeRabbit

Release Notes for Pull Request

  • New Feature: Introduced a maximum limit for the summit tip in the GasOracle contract. This limit is set to 0.01 ether and any attempt to set a higher value will result in a transaction revert.
  • Refactor: The _summitTipWei variable in the GasOracle contract has been made public and renamed to summitTipWei.
  • Test: Added new test cases in the GasOracle.GasData.t.sol suite to verify the behavior of the setSummitTip function when the provided value is above the maximum limit, at the limit, or when the caller is not the owner of the contract.

@ChiTimesChi ChiTimesChi requested a review from trajan0x as a code owner October 6, 2023 14:12
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 6, 2023

Walkthrough

The changes primarily focus on the implementation of a maximum limit for summitTipWei in the GasOracle contract. This includes the addition of error handling, constant declaration, and test cases to ensure the functionality works as expected.

Changes

File Path Summary
packages/contracts-core/contracts/GasOracle.sol Updated import statements, changed _summitTipWei to public, added check in setSummitTip function, replaced _summitTipWei with summitTipWei in calculateTotalCost.
packages/contracts-core/contracts/libs/Constants.sol Added MAX_SUMMIT_TIP constant.
packages/contracts-core/contracts/libs/Errors.sol Added SummitTipTooHigh() error type.
packages/contracts-core/test/suite/GasOracle.GasData.t.sol Imported SummitTipTooHigh error, added new test functions for setSummitTip function.
packages/deployment-utils/lib/forge-std Single commit hash provided, no specific code changes detailed.

🐇💻

"In the land of code, where logic is king,
A rabbit hops forth, changes to bring.
With a tip too high, an error we fling,
Ensuring our contract does just the right thing!" 🎉


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • Mention @coderabbitai in any review comment for bot assistance.
  • Note: Review comments are made on code diffs or files, not on the PR overview.

Pause Incremental Reviews

  • Insert @coderabbitai: ignore in the PR description to halt the bot's ongoing reviews. Remove the line to resume.
  • Additionally, enter @coderabbitai pause to halt the bot's ongoing reviews as any issue or review comment. To
    resume reviews, enter @coderabbitai resume as any issue or review comment.

@github-actions github-actions bot added M-contracts Module: Contracts 2-reviewers C-Protocol-Critical PRs that modify protocol-critical code. size/xs labels Oct 6, 2023
@ChiTimesChi ChiTimesChi force-pushed the fix/tob/04-summit-tip-upper-bound branch from bfa2b10 to 4b65beb Compare October 6, 2023 14:13
@codecov
Copy link

codecov bot commented Oct 6, 2023

Codecov Report

Attention: 10 lines in your changes are missing coverage. Please review.

Comparison is base (9947d7d) 50.51623% compared to head (d18ec89) 50.81805%.
Report is 15 commits behind head on master.

Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #1432         +/-   ##
===================================================
+ Coverage   50.51623%   50.81805%   +0.30181%     
===================================================
  Files            343         356         +13     
  Lines          24117       24204         +87     
  Branches         277         268          -9     
===================================================
+ Hits           12183       12300        +117     
+ Misses         10724       10695         -29     
+ Partials        1210        1209          -1     
Flag Coverage Δ
packages 90.62003% <97.06745%> (+7.19462%) ⬆️
solidity 93.00813% <100.00000%> (-0.07569%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
packages/contracts-core/contracts/GasOracle.sol 100.00000% <100.00000%> (ø)
packages/sdk-router/src/constants/addresses.ts 100.00000% <100.00000%> (ø)
packages/sdk-router/src/constants/chainIds.ts 100.00000% <100.00000%> (ø)
packages/sdk-router/src/constants/index.ts 100.00000% <100.00000%> (ø)
packages/sdk-router/src/constants/testValues.ts 100.00000% <100.00000%> (ø)
packages/sdk-router/src/operations/bridge.ts 100.00000% <100.00000%> (ø)
packages/sdk-router/src/operations/index.ts 100.00000% <100.00000%> (ø)
packages/sdk-router/src/router/index.ts 100.00000% <100.00000%> (ø)
packages/sdk-router/src/router/query.ts 100.00000% <100.00000%> (ø)
...ackages/sdk-router/src/router/synapseCCTPRouter.ts 100.00000% <100.00000%> (ø)
... and 10 more

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Commits Files that changed from the base of the PR and between 9f50aa3 and 4b65beb.
Files selected for processing (4)
  • packages/contracts-core/contracts/GasOracle.sol (4 hunks)
  • packages/contracts-core/contracts/libs/Constants.sol (1 hunks)
  • packages/contracts-core/contracts/libs/Errors.sol (1 hunks)
  • packages/contracts-core/test/suite/GasOracle.GasData.t.sol (2 hunks)
Files skipped from review due to trivial changes (2)
  • packages/contracts-core/contracts/libs/Constants.sol
  • packages/contracts-core/contracts/libs/Errors.sol
Additional comments (Suppressed): 8
packages/contracts-core/test/suite/GasOracle.GasData.t.sol (4)
  • 2-8: The import statement for SummitTipTooHigh from the Errors.sol library is new. Ensure that this error type is correctly defined and used in the contract.

  • 21-26: This test checks if the setSummitTip function reverts when called by a non-owner. It's good to see tests for access control.

  • 28-30: This test verifies that the setSummitTip function allows setting the summit tip to the upper bound (0.01 ether). This is a good check for boundary conditions.

  • 33-36: This test checks if the setSummitTip function reverts when trying to set the summit tip higher than the upper bound. This is an important test to ensure the hard cap is enforced.

packages/contracts-core/contracts/GasOracle.sol (4)
  • 1-10: The import statements have been updated to include the MAX_SUMMIT_TIP constant from Constants.sol and the SummitTipTooHigh error from Errors.sol. Ensure that these new imports are used correctly in the code.

  • 48-54: The _summitTipWei variable has been made public and renamed to summitTipWei. This change increases transparency but also exposes this variable to external contracts. Make sure this is intended and does not introduce any security risks.

  • 87-93: The setSummitTip function now checks if the provided summitTipWei_ exceeds MAX_SUMMIT_TIP and reverts with a SummitTipTooHigh error if it does. This is a good practice for enforcing limits and preventing misuse.

-    function setSummitTip(uint256 summitTipWei) external onlyOwner {
-        _summitTipWei = summitTipWei;
-     }
+    function setSummitTip(uint256 summitTipWei_) external onlyOwner {
+        if (summitTipWei_ > MAX_SUMMIT_TIP) revert SummitTipTooHigh();
+        summitTipWei = summitTipWei_;
+    }
  • 144-150: The calculation of summitTip now uses the public summitTipWei instead of the previously internal _summitTipWei. Ensure that all references to _summitTipWei in the codebase have been updated to summitTipWei.
-        uint256 summitTip = (_summitTipWei << NumberLib.BWAD_SHIFT) / localEtherPrice;
+        uint256 summitTip = (summitTipWei << NumberLib.BWAD_SHIFT) / localEtherPrice;

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Commits Files that changed from the base of the PR and between 4b65beb and d18ec89.
Files selected for processing (1)
  • packages/contracts-core/contracts/GasOracle.sol (4 hunks)
Additional comments (Suppressed): 3
packages/contracts-core/contracts/GasOracle.sol (3)
  • 1-10: The import statements have been updated to include the MAX_SUMMIT_TIP constant from Constants.sol and the SummitTipTooHigh error from Errors.sol. Ensure that these new imports do not conflict with existing code.

  • 48-54: The _summitTipWei variable has been made public and renamed as summitTipWei. This change increases transparency but also exposes the variable to external contracts. Make sure this does not introduce any security risks.

  • 145-151: The calculateTotalCost function now uses summitTipWei instead of _summitTipWei. Ensure that all references to _summitTipWei in the codebase have been updated to summitTipWei.

Comment on lines 87 to 94
}

/// @notice MVP function to set the summit tip.
function setSummitTip(uint256 summitTipWei) external onlyOwner {
_summitTipWei = summitTipWei;
function setSummitTip(uint256 summitTipWei_) external onlyOwner {
if (summitTipWei_ > MAX_SUMMIT_TIP) revert SummitTipTooHigh();
summitTipWei = summitTipWei_;
// TODO: emit event
}
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 7, 2023

Choose a reason for hiding this comment

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

The setSummitTip function now checks if the provided summitTipWei_ exceeds the MAX_SUMMIT_TIP constant, and if so, reverts with a SummitTipTooHigh error. This is a good practice for enforcing upper limits. However, an event emission is missing after setting the summitTipWei, which could be useful for tracking changes.

    function setSummitTip(uint256 summitTipWei_) external onlyOwner {
        if (summitTipWei_ > MAX_SUMMIT_TIP) revert SummitTipTooHigh();
        summitTipWei = summitTipWei_;
+        emit SummitTipChanged(summitTipWei_);
    }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This event will be added in a separate PR

Copy link
Contributor

Choose a reason for hiding this comment

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

@ChiTimesChi: Understood. Please ensure to include the event emission in the upcoming PR as it is crucial for tracking changes to summitTipWei. This will enhance the transparency and traceability of the contract's operations.

function setSummitTip(uint256 summitTipWei_) external onlyOwner {
if (summitTipWei_ > MAX_SUMMIT_TIP) revert SummitTipTooHigh();
summitTipWei = summitTipWei_;
// TODO: emit event
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to add an event now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@aureliusbtc I'm going to add the missing events in the PR that fixes ToB-20 later on

@ChiTimesChi ChiTimesChi merged commit 2da67ba into master Oct 17, 2023
49 checks passed
@ChiTimesChi ChiTimesChi deleted the fix/tob/04-summit-tip-upper-bound branch October 17, 2023 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants