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): prevent initialising the world multiple times [L-05] #2170

Merged
merged 7 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/neat-tools-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/world": patch
---

Added a table to track the `CoreModule` address the world was initialised with.
62 changes: 31 additions & 31 deletions packages/world-modules/gas-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,85 +3,85 @@
"file": "test/ERC20.t.sol",
"test": "testApprove",
"name": "approve",
"gasUsed": 114348
"gasUsed": 114354
},
{
"file": "test/ERC20.t.sol",
"test": "testBurn",
"name": "burn",
"gasUsed": 75910
"gasUsed": 75916
},
{
"file": "test/ERC20.t.sol",
"test": "testMint",
"name": "mint",
"gasUsed": 161749
"gasUsed": 161755
},
{
"file": "test/ERC20.t.sol",
"test": "testTransfer",
"name": "transfer",
"gasUsed": 92995
"gasUsed": 93001
},
{
"file": "test/ERC20.t.sol",
"test": "testTransferFrom",
"name": "transferFrom",
"gasUsed": 130331
"gasUsed": 130337
},
{
"file": "test/ERC721.t.sol",
"test": "testApproveAllGas",
"name": "setApprovalForAll",
"gasUsed": 113972
"gasUsed": 113978
},
{
"file": "test/ERC721.t.sol",
"test": "testApproveGas",
"name": "approve",
"gasUsed": 87981
"gasUsed": 87987
},
{
"file": "test/ERC721.t.sol",
"test": "testBurnGas",
"name": "burn",
"gasUsed": 101910
"gasUsed": 101916
},
{
"file": "test/ERC721.t.sol",
"test": "testMintGas",
"name": "mint",
"gasUsed": 169480
"gasUsed": 169486
},
{
"file": "test/ERC721.t.sol",
"test": "testSafeMintToEOAGas",
"name": "safeMint",
"gasUsed": 169751
"gasUsed": 169757
},
{
"file": "test/ERC721.t.sol",
"test": "testSafeTransferFromToEOAGas",
"name": "safeTransferFrom",
"gasUsed": 143744
"gasUsed": 143750
},
{
"file": "test/ERC721.t.sol",
"test": "testTransferFromGas",
"name": "transferFrom",
"gasUsed": 136901
"gasUsed": 136907
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallComposite",
"name": "install keys in table module",
"gasUsed": 1439079
"gasUsed": 1439094
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallGas",
"name": "install keys in table module",
"gasUsed": 1439079
"gasUsed": 1439094
},
{
"file": "test/KeysInTableModule.t.sol",
Expand All @@ -93,13 +93,13 @@
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallSingleton",
"name": "install keys in table module",
"gasUsed": 1439079
"gasUsed": 1439094
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookCompositeGas",
"name": "install keys in table module",
"gasUsed": 1439079
"gasUsed": 1439094
},
{
"file": "test/KeysInTableModule.t.sol",
Expand All @@ -117,7 +117,7 @@
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookGas",
"name": "install keys in table module",
"gasUsed": 1439079
"gasUsed": 1439094
},
{
"file": "test/KeysInTableModule.t.sol",
Expand All @@ -135,7 +135,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testGetKeysWithValueGas",
"name": "install keys with value module",
"gasUsed": 684459
"gasUsed": 684471
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand All @@ -153,7 +153,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testInstall",
"name": "install keys with value module",
"gasUsed": 684459
"gasUsed": 684471
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand All @@ -165,7 +165,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testSetAndDeleteRecordHook",
"name": "install keys with value module",
"gasUsed": 684459
"gasUsed": 684471
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand All @@ -183,7 +183,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testSetField",
"name": "install keys with value module",
"gasUsed": 684459
"gasUsed": 684471
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand Down Expand Up @@ -267,60 +267,60 @@
"file": "test/StandardDelegationsModule.t.sol",
"test": "testCallFromCallboundDelegation",
"name": "register a callbound delegation",
"gasUsed": 118198
"gasUsed": 118201
},
{
"file": "test/StandardDelegationsModule.t.sol",
"test": "testCallFromCallboundDelegation",
"name": "call a system via a callbound delegation",
"gasUsed": 36679
"gasUsed": 36685
},
{
"file": "test/StandardDelegationsModule.t.sol",
"test": "testCallFromSystemDelegation",
"name": "register a systembound delegation",
"gasUsed": 115751
"gasUsed": 115754
},
{
"file": "test/StandardDelegationsModule.t.sol",
"test": "testCallFromSystemDelegation",
"name": "call a system via a systembound delegation",
"gasUsed": 33851
"gasUsed": 33857
},
{
"file": "test/StandardDelegationsModule.t.sol",
"test": "testCallFromTimeboundDelegation",
"name": "register a timebound delegation",
"gasUsed": 112674
"gasUsed": 112677
},
{
"file": "test/StandardDelegationsModule.t.sol",
"test": "testCallFromTimeboundDelegation",
"name": "call a system via a timebound delegation",
"gasUsed": 26797
"gasUsed": 26803
},
{
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstall",
"name": "install unique entity module",
"gasUsed": 704219
"gasUsed": 704234
},
{
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstall",
"name": "get a unique entity nonce (non-root module)",
"gasUsed": 50365
"gasUsed": 50368
},
{
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstallRoot",
"name": "installRoot unique entity module",
"gasUsed": 673145
"gasUsed": 673154
},
{
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstallRoot",
"name": "get a unique entity nonce (root module)",
"gasUsed": 50368
"gasUsed": 50371
}
]
32 changes: 16 additions & 16 deletions packages/world/gas-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,49 +45,49 @@
"file": "test/BatchCall.t.sol",
"test": "testBatchCallFromReturnData",
"name": "call systems with batchCallFrom",
"gasUsed": 52611
"gasUsed": 52620
},
{
"file": "test/BatchCall.t.sol",
"test": "testBatchCallReturnData",
"name": "call systems with batchCall",
"gasUsed": 51457
"gasUsed": 51466
},
{
"file": "test/Factories.t.sol",
"test": "testCreate2Factory",
"name": "deploy contract via Create2",
"gasUsed": 4659744
"gasUsed": 4759984
},
{
"file": "test/Factories.t.sol",
"test": "testWorldFactory",
"name": "deploy world via WorldFactory",
"gasUsed": 12642949
"gasUsed": 13039359
},
{
"file": "test/World.t.sol",
"test": "testCall",
"name": "call a system via the World",
"gasUsed": 12361
"gasUsed": 12364
},
{
"file": "test/World.t.sol",
"test": "testCallFromNamespaceDelegation",
"name": "call a system via a namespace fallback delegation",
"gasUsed": 26131
"gasUsed": 26137
},
{
"file": "test/World.t.sol",
"test": "testCallFromUnlimitedDelegation",
"name": "register an unlimited delegation",
"gasUsed": 47607
"gasUsed": 47610
},
{
"file": "test/World.t.sol",
"test": "testCallFromUnlimitedDelegation",
"name": "call a system via an unlimited delegation",
"gasUsed": 12797
"gasUsed": 12800
},
{
"file": "test/World.t.sol",
Expand All @@ -105,37 +105,37 @@
"file": "test/World.t.sol",
"test": "testRegisterFunctionSelector",
"name": "Register a function selector",
"gasUsed": 84542
"gasUsed": 84545
},
{
"file": "test/World.t.sol",
"test": "testRegisterNamespace",
"name": "Register a new namespace",
"gasUsed": 120969
"gasUsed": 120972
},
{
"file": "test/World.t.sol",
"test": "testRegisterRootFunctionSelector",
"name": "Register a root function selector",
"gasUsed": 80445
"gasUsed": 80448
},
{
"file": "test/World.t.sol",
"test": "testRegisterSystem",
"name": "register a system",
"gasUsed": 164363
"gasUsed": 164366
},
{
"file": "test/World.t.sol",
"test": "testRegisterTable",
"name": "Register a new table in the namespace",
"gasUsed": 536881
"gasUsed": 536884
},
{
"file": "test/World.t.sol",
"test": "testRenounceNamespace",
"name": "Renounce namespace ownership",
"gasUsed": 36773
"gasUsed": 36776
},
{
"file": "test/World.t.sol",
Expand All @@ -153,13 +153,13 @@
"file": "test/World.t.sol",
"test": "testUnregisterNamespaceDelegation",
"name": "unregister a namespace delegation",
"gasUsed": 28360
"gasUsed": 28363
},
{
"file": "test/World.t.sol",
"test": "testUnregisterUnlimitedDelegation",
"name": "unregister an unlimited delegation",
"gasUsed": 26255
"gasUsed": 26258
},
{
"file": "test/WorldDynamicUpdate.t.sol",
Expand Down
4 changes: 4 additions & 0 deletions packages/world/mud.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ export default mudConfig({
},
offchainOnly: true,
},
CoreModuleAddress: {
keySchema: {},
valueSchema: "address",
},
},
excludeSystems: [
// Worldgen currently does not support systems inheriting logic
Expand Down
5 changes: 4 additions & 1 deletion packages/world/src/World.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { requireInterface } from "./requireInterface.sol";
import { InstalledModules } from "./codegen/tables/InstalledModules.sol";
import { UserDelegationControl } from "./codegen/tables/UserDelegationControl.sol";
import { NamespaceDelegationControl } from "./codegen/tables/NamespaceDelegationControl.sol";
import { CoreModuleAddress } from "./codegen/tables/CoreModuleAddress.sol";

import { IModule, IModule } from "./IModule.sol";
import { IWorldKernel } from "./IWorldKernel.sol";
Expand Down Expand Up @@ -71,10 +72,12 @@ contract World is StoreData, IWorldKernel {
}

// The World can only be initialized once
if (InstalledModules._get(CORE_MODULE_NAME, keccak256("")) != address(0)) {
if (CoreModuleAddress.get() != address(0)) {
revert World_AlreadyInitialized();
}

CoreModuleAddress.set(address(coreModule));

// Initialize the World by installing the core module
_installRootModule(coreModule, new bytes(0));
}
Expand Down
1 change: 1 addition & 0 deletions packages/world/src/codegen/index.sol

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.