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

getPausedRegions does not return the region with the highest pausable indext #949

Open
zajck opened this issue Jun 4, 2024 · 6 comments

Comments

@zajck
Copy link
Member

zajck commented Jun 4, 2024

function getPausedRegions() external view returns (BosonTypes.PausableRegion[] memory regions) {
// Cache protocol status for reference
ProtocolLib.ProtocolStatus storage status = protocolStatus();
uint256 totalRegions = uint256(type(BosonTypes.PausableRegion).max);
regions = new BosonTypes.PausableRegion[](totalRegions);
// Return all regions if all are paused.
if (status.pauseScenario == ALL_REGIONS_MASK) {
for (uint256 i = 0; i < totalRegions; ) {
regions[i] = BosonTypes.PausableRegion(i);
unchecked {
i++;
}
}
} else {
uint256 count = 0;
for (uint256 i = 0; i < totalRegions; ) {
// Check if the region is paused by bitwise AND operation with shifted 1
if (status.pauseScenario & (1 << i) != 0) {
regions[count] = BosonTypes.PausableRegion(i);
count++;
}
unchecked {
i++;
}
}
// setting the correct number of regions
assembly {
mstore(regions, count)
}
}
}

The following line is not the total number of regions, but the maximum pausable region index. The region count is 1 higher.

uint256 totalRegions = uint256(type(BosonTypes.PausableRegion).max);

The loops below do not reach the latest element and never report if the last region is paused.

This does not affect the pausing functionality otherwise.

@neverm25
Copy link

neverm25 commented Sep 2, 2024

@zajck, you are right.
Then, why don't you update like this?

uint256 totalRegions = uint256(type(BosonTypes.PausableRegion).max) + 1;

@zajck
Copy link
Member Author

zajck commented Sep 2, 2024

@neverm25 , yes that's the solution.
In fact, we use it in the other project that the team is currently focused on - Fermion protocol, which is built on top of Boson. Its GitHub repo is not public yet, but you can read about the project here: https://www.fermionprotocol.io/

We haven't fixed this in Boson Contracts yet, since it's such a low-priority issue, but we'll do it as soon as we develop some other new features and schedule the next upgrade.

@neverm25
Copy link

neverm25 commented Sep 2, 2024

Sounds interesting.
Could you share the information with me?
I would like to contribute to your project.

@neverm25
Copy link

neverm25 commented Sep 2, 2024

@zajck can I create a PR for your issues?

@zajck
Copy link
Member Author

zajck commented Sep 3, 2024

@neverm25 sure, go ahead.
Just make sure you've read the contributing section and as noted here, your PR must originate from your forked repo.

Also, when you start working on an open issue it helps us if you assign it to yourself and notify us by commenting on it.

Regarding Fermion, it will become public soon (probably in about a month), but we might give you early access since we always welcome new contributors. I'll let you know once we align on it internally.

@neverm25
Copy link

neverm25 commented Sep 3, 2024

@zajck thanks for your support.
I look forward to working with you and your team.

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

No branches or pull requests

2 participants