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

Rebase Circuit Breaker #294

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Rebase Circuit Breaker #294

wants to merge 3 commits into from

Conversation

aalavandhan
Copy link
Member

Owner can limit the total supply contraction over an x-epoch period

Copy link

openzeppelin-code bot commented Oct 29, 2024

Rebase Circuit Breaker

Generated at commit: 98ae0127da465d820af45fb8a7d3a1b114c8f61f

🚨 Report Summary

Severity Level Results
Contracts Critical
High
Medium
Low
Note
Total
1
1
0
5
23
30
Dependencies Critical
High
Medium
Low
Note
Total
0
0
0
0
0
0

For more details view the full report in OpenZeppelin Code Inspector

Copy link
Member

@brandoniles brandoniles left a comment

Choose a reason for hiding this comment

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

I was wondering if we should use a circular array, rather than a linearly increasing hashmap. The flexibility of the map the gas benefits, though, I agree. It could still be moved to in the future if it became a concern

contracts/UFragmentsPolicy.sol Show resolved Hide resolved
contracts/UFragmentsPolicy.sol Outdated Show resolved Hide resolved
contracts/UFragmentsPolicy.sol Outdated Show resolved Hide resolved
contracts/UFragmentsPolicy.sol Outdated Show resolved Hide resolved
Copy link
Member

@brandoniles brandoniles left a comment

Choose a reason for hiding this comment

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

I like the idea of having an owner-callable history cleanup function. I imagine it would take a start epoch, end epoch, and wouldn't zero-out anything within the existing lookback window.

* @notice Sets the parameters which control rebase circuit breaker.
* @param epochLookback_ The number of rebase epochs to look back.
* @param tolerableDeclinePercentage_ The supply decline percentage which is allowed
* within the defined look back period.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* within the defined look back period.
* from the beginning of the defined look back period.

uint8 epochLookback_,
int256 tolerableDeclinePercentage_
) external onlyOwner {
require(tolerableDeclinePercentage_ > 0 && tolerableDeclinePercentage_ <= ONE);
Copy link
Member

Choose a reason for hiding this comment

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

I guess 0 "should" be an allowable value... It's not a useful config per se, but there's no mechanical reason the implementation wouldn't allow it.

@@ -340,7 +371,27 @@ contract UFragmentsPolicy is Ownable {
rebaseFunctionUpperPercentage,
rebaseFunctionGrowth
);
return uFrags.totalSupply().toInt256Safe().mul(rebasePercentage).div(ONE);

int256 currentSupply = uFrags.totalSupply().toInt256Safe(); // (or) supplyHistory[epoch]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
int256 currentSupply = uFrags.totalSupply().toInt256Safe(); // (or) supplyHistory[epoch]
int256 currentSupply = uFrags.totalSupply().toInt256Safe();

I don't think the supplyHistory has been written to yet, in the core rebase flow.

return uFrags.totalSupply().toInt256Safe().mul(rebasePercentage).div(ONE);

int256 currentSupply = uFrags.totalSupply().toInt256Safe(); // (or) supplyHistory[epoch]
int256 newSupply = ONE.add(rebasePercentage).mul(currentSupply).div(ONE);
Copy link
Member

Choose a reason for hiding this comment

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

Looking for it, but I don't see this change... Where did rebasePercentage move from being 1-centered to 0-centered? (We add one here but not in the previous version's line)


// When supply is decreasing:
// We limit the supply delta, based on recent supply history.
if (rebasePercentage < 0 && epoch > epochLookback) {
Copy link
Member

Choose a reason for hiding this comment

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

In the case that the supply history hasn't been written to yet, and is 0, then the below code basically no-ops? That's what it seems like. Do we have an explicit test case for this?

i.e.

  1. Test for supply history lookup returns 0
  2. Test for when epochLookback equals 0 (should basically be same as above since history will return 0)

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.

2 participants