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(world): identify modules by addresses instead of names [L-08] #2168

Merged
merged 7 commits into from
Jan 22, 2024

Conversation

yonadaaa
Copy link
Contributor

@yonadaaa yonadaaa commented Jan 19, 2024

Modules are now identified by address instead of a single, global name.

  • Modules have a __self variable that stores their address, allowing them to check if they have been installed.
  • The ERC20 and ERC721 modules store the address of their puppet module in an immutable variable. This is passed into the registration helpers so will require a change for consumers (see the Sky Strife PostDeploy script)

Copy link

changeset-bot bot commented Jan 19, 2024

⚠️ No Changeset found

Latest commit: 8ce1239

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

@yonadaaa
Copy link
Contributor Author

yonadaaa commented Jan 19, 2024

The big change here is that we can't read data on modules unless we know the address of a specific instantiation.

For example, ERC20Module needs to know whether PuppetModule is installed, so expects it to be installed under "puppet":

// Require PuppetModule to be installed
if (!isInstalled(PUPPET_MODULE_NAME, new bytes(0))) {
  revert Module_MissingDependency(string(bytes.concat(PUPPET_MODULE_NAME)));
}

However, this is not foolproof because anything could be installed under that name. As of this PR modules are referenced by address.

So, we will have to pass in the address of the puppet module when installing the ERC20 module.

@yonadaaa
Copy link
Contributor Author

TODO:

  • Add a isInitialized table the World to prevent initialising the world multiple times.
  • Declare the address of a puppet module as an immutable variable in the constructor of the ERC20/ERC721 module

@yonadaaa yonadaaa force-pushed the yonadaaa/module-access-control branch from 056dce2 to 6a517cd Compare January 22, 2024 13:48
@yonadaaa yonadaaa changed the title wip(world): identify modules by addresses instead of names [L-08] wip(world): identify modules by addresses instead of names [L-05] [L-08] Jan 22, 2024
@yonadaaa yonadaaa marked this pull request as ready for review January 22, 2024 13:50
@yonadaaa yonadaaa marked this pull request as draft January 22, 2024 13:55
@yonadaaa yonadaaa changed the title wip(world): identify modules by addresses instead of names [L-05] [L-08] refactor(world): identify modules by addresses instead of names [L-05] [L-08] Jan 22, 2024
@yonadaaa yonadaaa changed the title refactor(world): identify modules by addresses instead of names [L-05] [L-08] fix(world): identify modules by addresses instead of names [L-05] [L-08] Jan 22, 2024
@yonadaaa yonadaaa changed the title fix(world): identify modules by addresses instead of names [L-05] [L-08] fix(world): identify modules by addresses instead of names [L-08] Jan 22, 2024
@yonadaaa yonadaaa marked this pull request as ready for review January 22, 2024 14:13
@@ -18,13 +18,14 @@ import { ERC20Registry } from "./tables/ERC20Registry.sol";
*/
function registerERC20(
IBaseWorld world,
address puppetModule,
Copy link
Member

Choose a reason for hiding this comment

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

i feel like this additional params is making it pretty impractical to use since it's currently not easy to find the address of the puppet module. Why don't we add an overload for this function that doesn't require the puppetModule address and instead calls this overload with the CREATE2 default address of the puppet module? That way it's not a breaking change for consumers (on CREATE2 compatible chains) but still allows customisation if necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The puppet module is part of the deployment pipeline right now, so doesn't use Create2. For example Sky Strife manually deploys the puppet: https://github.com/latticexyz/skystrife-public/blob/main/packages/contracts/script/PostDeploy.s.sol#L111-L119

Comment on lines 106 to 111
WorldInitialized: {
keySchema: {},
valueSchema: {
isInitialized: "bool",
},
},
Copy link
Member

Choose a reason for hiding this comment

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

this one got pulled out to the other PR right?

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 we can merge the other one first and then rebase this one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes exactly, this PR should really not have those changes but it only occurred to me later to break it out

@alvrs alvrs changed the base branch from main to yonadaaa/world-initialized January 22, 2024 18:06
@alvrs alvrs changed the base branch from yonadaaa/world-initialized to main January 22, 2024 18:06
alvrs
alvrs previously approved these changes Jan 22, 2024
@yonadaaa yonadaaa merged commit 52c37b5 into main Jan 22, 2024
11 checks passed
@yonadaaa yonadaaa deleted the yonadaaa/module-access-control branch January 22, 2024 19:42
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