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

refactor(world): encapsulate functionality [N-01] #2157

Merged
merged 15 commits into from
Jan 19, 2024

Conversation

yonadaa
Copy link
Contributor

@yonadaa yonadaa commented Jan 18, 2024

A few suggestions were fixed in previous PR's.

#2007 fixed registerTable:

The registerTable function might register a namespace as well.

#2007 fixed registerSystem:

The registerSystem function might register a namespace

#2096 added unregisterDelegation:

Individual delegations must be removed by overwriting them using the regular registration function, which still leaves a stray record in the UserDelegationControl table.

@yonadaa yonadaa requested review from alvrs and holic as code owners January 18, 2024 14:10
Copy link

changeset-bot bot commented Jan 18, 2024

⚠️ No Changeset found

Latest commit: b673d76

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@yonadaa yonadaa marked this pull request as draft January 18, 2024 14:10
@yonadaa yonadaa force-pushed the yonadaaa/encapsulate-functionality branch from 5881958 to 06f2ca2 Compare January 18, 2024 14:53
@yonadaa yonadaa marked this pull request as ready for review January 18, 2024 14:56
* @dev Unregisters the system at the given ID
* @param systemId The unique identifier for the system
*/
function unregisterSystem(ResourceId systemId) public virtual {
Copy link
Member

Choose a reason for hiding this comment

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

I think we intentionally don't allow for unregistering systems? cc @alvrs

Copy link
Member

Choose a reason for hiding this comment

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

from @alvrs via discord

yeah it's this weird situation where other contracts that interact with yours might break if you unregister function selectors or unregister systems, so I think we should only encourage upgrading systems in a non-breaking way
if someone really wants to remove a system or function selector they can do it by editing the tables, but i don't think it should be something we encourage

@yonadaa yonadaa marked this pull request as ready for review January 19, 2024 13:45
@@ -250,7 +251,9 @@ contract WorldTest is Test, GasReporter {
coreRegistrationSystem.registerFunctionSelector.selector,
coreRegistrationSystem.registerRootFunctionSelector.selector,
coreRegistrationSystem.registerDelegation.selector,
coreRegistrationSystem.registerNamespaceDelegation.selector
coreRegistrationSystem.unregisterDelegation.selector,
Copy link
Member

Choose a reason for hiding this comment

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

oof, we didn't have this before, eh?

Copy link
Member

Choose a reason for hiding this comment

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

another reason for #2155

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, this was forgotten. Although this is a test file so whatever automation we add needs to apply here too.

Comment on lines 80 to 92
function renounceOwnership(ResourceId namespaceId) public virtual onlyDelegatecall {
// Require the namespace ID to be a valid namespace
requireNamespace(namespaceId);

// Require the caller to own the namespace
AccessControl.requireOwner(namespaceId, _msgSender());

// Delete namespace owner
NamespaceOwner._deleteRecord(namespaceId);

// Revoke access from old owner
ResourceAccess._deleteRecord(namespaceId, _msgSender());
}
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Could transfer to address 0 and then delete the resource access record. No strong opinion though.

Copy link
Member

Choose a reason for hiding this comment

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

that would basically be the same logic but a few extra writes, wouldn't it?

Copy link
Contributor Author

@yonadaa yonadaa Jan 19, 2024

Choose a reason for hiding this comment

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

This is an interesting pattern, but it ~doubles the gas from 35488 to 74700. Plus, setting then deleting the ResourceAccess record seems potentially more confusing then not? Unless folks feel strongly i think the inlined code is fine

Copy link
Member

Choose a reason for hiding this comment

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

I think this is fine how it is, but I did make a code suggestion below for completeness with other audit fixes (adding namespace existence check for better reverts)

Comment on lines 344 to 348
// Require namespace ID to be a valid namespace
requireNamespace(namespaceId);

// Require the caller to own the namespace
AccessControl.requireOwner(namespaceId, _msgSender());
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
// Require namespace ID to be a valid namespace
requireNamespace(namespaceId);
// Require the caller to own the namespace
AccessControl.requireOwner(namespaceId, _msgSender());
// Require namespace ID to be a valid namespace
requireNamespace(namespaceId);
// Require the namespace to exist
AccessControl.requireExistence(namespaceId);
// Require the caller to own the namespace
AccessControl.requireOwner(namespaceId, _msgSender());

@yonadaa yonadaa merged commit 61985bb into main Jan 19, 2024
11 checks passed
@yonadaa yonadaa deleted the yonadaaa/encapsulate-functionality branch January 19, 2024 15:08
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.

3 participants