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: enable/disable earning in HubPortal #20

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

0xIryna
Copy link
Collaborator

@0xIryna 0xIryna commented Nov 19, 2024

Proposed changes:

  • remove isApproveEarner check from enableEarning() and disableEarning() functions, since the same check already exists in MToken startEarning() and stopEarning(address) functions.
  • implement "virtual index" for HubPortal calculated proportionally to the current M Token index.

Benefits of "virtual index":

  • allows re-enabling earning after it was disabled.
  • fixes Kirill M-01 finding since Spoke Token index won't "jump" from EXP_SCALE_ONE to the latest current index on the Hub but will be increased gradually.

Drawbacks of "virtual index":

  • M Token index on Spoke chains will be different from M Token index on the Hub chain, which might confuse users and integrators.

Copy link

github-actions bot commented Nov 19, 2024

LCOV of commit 6683a6e during Forge Coverage #110

Summary coverage rate:
  lines......: 96.7% (203 of 210 lines)
  functions..: 90.5% (67 of 74 functions)
  branches...: 78.7% (37 of 47 branches)

Files changed coverage rate:
                                 |Lines       |Functions  |Branches    
  Filename                       |Rate     Num|Rate    Num|Rate     Num
  =====================================================================
  src/HubPortal.sol              | 100%     37| 100%    11|75.0%      4

Copy link

github-actions bot commented Nov 19, 2024

Changes to gas cost

Generated at commit: 49a0bbc1a2bdbe1f532cc3506d37e683941a6cd1, compared to commit: b8b570fc01e64445006eccc1b67867f7d1864917

🧾 Summary (20% most significant diffs)

Contract Method Avg (+/-) %
SpokePortal attestationReceived -3,319 ✅ -3.00%

Full diff report 👇
Contract Deployment Cost (+/-) Method Min (+/-) % Avg (+/-) % Median (+/-) % Max (+/-) % # Calls (+/-)
SpokePortal 5,327,645 (0) attestationReceived 54,466 (-5,318) -8.90% 107,260 (-3,319) -3.00% 135,383 (-4,479) -3.20% 135,383 (-4,479) -3.20% 7 (0)

src/HubPortal.sol Outdated Show resolved Hide resolved
src/HubPortal.sol Outdated Show resolved Hide resolved
src/HubPortal.sol Show resolved Hide resolved
src/HubPortal.sol Outdated Show resolved Hide resolved
src/HubPortal.sol Outdated Show resolved Hide resolved
src/HubPortal.sol Outdated Show resolved Hide resolved
@toninorair toninorair self-requested a review November 20, 2024 02:54
super._initialize();

// set _disablePortalIndex to the default value on first deployment
if (_disablePortalIndex == 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why this check is required? isn't it 0 by default on initialize?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I want to set _disablePortalIndex to EXP_SCALED_ONE only during first initialization, and do not override it after

/// @dev Array of indices at which earning was enabled or disabled.
uint128[] internal _enableDisableEarningIndices;
/// @dev The M token's index when earning was most recently enabled
uint128 private _enableMTokenIndex;
Copy link
Collaborator

@toninorair toninorair Nov 20, 2024

Choose a reason for hiding this comment

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

why names_disablePortalIndex and _enableMTokenIndex are not symmetrical? why private and not internal?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

_disablePortalIndex is the last index of the Portal when earning was disabled, it's "virtual" index.
_enableMTokenIndex is the index of M Token when earning was enabled, the "actual" index.
Private because we're not planning to inherit from HubPortal

@toninorair toninorair self-requested a review November 20, 2024 02:59
src/HubPortal.sol Outdated Show resolved Hide resolved
src/HubPortal.sol Outdated Show resolved Hide resolved
@toninorair toninorair self-requested a review November 20, 2024 03:38
@0xIryna 0xIryna force-pushed the fix/enable-disable-earnings branch from e3c810f to 6683a6e Compare November 20, 2024 04:50
@0xIryna 0xIryna marked this pull request as draft November 20, 2024 16:21
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.

3 participants