Skip to content

Commit

Permalink
fix(world): identify modules by addresses instead of names [L-08] (#2168
Browse files Browse the repository at this point in the history
)
  • Loading branch information
yonadaa authored Jan 22, 2024
1 parent 2bfee92 commit 52c37b5
Show file tree
Hide file tree
Showing 23 changed files with 132 additions and 200 deletions.
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": 114354
"gasUsed": 114348
},
{
"file": "test/ERC20.t.sol",
"test": "testBurn",
"name": "burn",
"gasUsed": 75916
"gasUsed": 75910
},
{
"file": "test/ERC20.t.sol",
"test": "testMint",
"name": "mint",
"gasUsed": 161755
"gasUsed": 161749
},
{
"file": "test/ERC20.t.sol",
"test": "testTransfer",
"name": "transfer",
"gasUsed": 93001
"gasUsed": 92995
},
{
"file": "test/ERC20.t.sol",
"test": "testTransferFrom",
"name": "transferFrom",
"gasUsed": 130337
"gasUsed": 130331
},
{
"file": "test/ERC721.t.sol",
"test": "testApproveAllGas",
"name": "setApprovalForAll",
"gasUsed": 113978
"gasUsed": 113972
},
{
"file": "test/ERC721.t.sol",
"test": "testApproveGas",
"name": "approve",
"gasUsed": 87987
"gasUsed": 87981
},
{
"file": "test/ERC721.t.sol",
"test": "testBurnGas",
"name": "burn",
"gasUsed": 101916
"gasUsed": 101910
},
{
"file": "test/ERC721.t.sol",
"test": "testMintGas",
"name": "mint",
"gasUsed": 169486
"gasUsed": 169480
},
{
"file": "test/ERC721.t.sol",
"test": "testSafeMintToEOAGas",
"name": "safeMint",
"gasUsed": 169757
"gasUsed": 169751
},
{
"file": "test/ERC721.t.sol",
"test": "testSafeTransferFromToEOAGas",
"name": "safeTransferFrom",
"gasUsed": 143750
"gasUsed": 143744
},
{
"file": "test/ERC721.t.sol",
"test": "testTransferFromGas",
"name": "transferFrom",
"gasUsed": 136907
"gasUsed": 136901
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallComposite",
"name": "install keys in table module",
"gasUsed": 1439094
"gasUsed": 1438512
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallGas",
"name": "install keys in table module",
"gasUsed": 1439094
"gasUsed": 1438512
},
{
"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": 1439094
"gasUsed": 1438512
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookCompositeGas",
"name": "install keys in table module",
"gasUsed": 1439094
"gasUsed": 1438512
},
{
"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": 1439094
"gasUsed": 1438512
},
{
"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": 684471
"gasUsed": 683899
},
{
"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": 684471
"gasUsed": 683899
},
{
"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": 684471
"gasUsed": 683899
},
{
"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": 684471
"gasUsed": 683899
},
{
"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": 118201
"gasUsed": 118198
},
{
"file": "test/StandardDelegationsModule.t.sol",
"test": "testCallFromCallboundDelegation",
"name": "call a system via a callbound delegation",
"gasUsed": 36685
"gasUsed": 36679
},
{
"file": "test/StandardDelegationsModule.t.sol",
"test": "testCallFromSystemDelegation",
"name": "register a systembound delegation",
"gasUsed": 115754
"gasUsed": 115751
},
{
"file": "test/StandardDelegationsModule.t.sol",
"test": "testCallFromSystemDelegation",
"name": "call a system via a systembound delegation",
"gasUsed": 33857
"gasUsed": 33851
},
{
"file": "test/StandardDelegationsModule.t.sol",
"test": "testCallFromTimeboundDelegation",
"name": "register a timebound delegation",
"gasUsed": 112677
"gasUsed": 112674
},
{
"file": "test/StandardDelegationsModule.t.sol",
"test": "testCallFromTimeboundDelegation",
"name": "call a system via a timebound delegation",
"gasUsed": 26803
"gasUsed": 26797
},
{
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstall",
"name": "install unique entity module",
"gasUsed": 704234
"gasUsed": 703658
},
{
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstall",
"name": "get a unique entity nonce (non-root module)",
"gasUsed": 50368
"gasUsed": 50365
},
{
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstallRoot",
"name": "installRoot unique entity module",
"gasUsed": 673154
"gasUsed": 672525
},
{
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstallRoot",
"name": "get a unique entity nonce (root module)",
"gasUsed": 50371
"gasUsed": 50368
}
]
19 changes: 2 additions & 17 deletions packages/world-modules/src/modules/erc20-puppet/ERC20Module.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import { revertWithBytes } from "@latticexyz/world/src/revertWithBytes.sol";

import { Puppet } from "../puppet/Puppet.sol";
import { createPuppet } from "../puppet/createPuppet.sol";
import { MODULE_NAME as PUPPET_MODULE_NAME } from "../puppet/constants.sol";
import { Balances } from "../tokens/tables/Balances.sol";

import { MODULE_NAME, MODULE_NAMESPACE, MODULE_NAMESPACE_ID, ERC20_REGISTRY_TABLE_ID } from "./constants.sol";
import { MODULE_NAMESPACE, MODULE_NAMESPACE_ID, ERC20_REGISTRY_TABLE_ID } from "./constants.sol";
import { _allowancesTableId, _balancesTableId, _metadataTableId, _erc20SystemId } from "./utils.sol";
import { ERC20System } from "./ERC20System.sol";

Expand All @@ -26,20 +25,9 @@ contract ERC20Module is Module {

address immutable registrationLibrary = address(new ERC20ModuleRegistrationLibrary());

function getName() public pure override returns (bytes16) {
return MODULE_NAME;
}

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

function install(bytes memory args) public {
// Require the module to not be installed with these args yet
requireNotInstalled(MODULE_NAME, args);
requireNotInstalled(__self, args);

// Extract args
(bytes14 namespace, ERC20MetadataData memory metadata) = abi.decode(args, (bytes14, ERC20MetadataData));
Expand All @@ -49,9 +37,6 @@ contract ERC20Module is Module {
revert ERC20Module_InvalidNamespace(namespace);
}

// Require dependencies
_requireDependencies();

// Register the ERC20 tables and system
IBaseWorld world = IBaseWorld(_world());
(bool success, bytes memory returnData) = registrationLibrary.delegatecall(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
import { RESOURCE_TABLE } from "@latticexyz/store/src/storeResourceTypes.sol";
import { RESOURCE_SYSTEM, RESOURCE_NAMESPACE } from "@latticexyz/world/src/worldResourceTypes.sol";

bytes16 constant MODULE_NAME = "erc20-puppet";
bytes14 constant MODULE_NAMESPACE = "erc20-puppet";
ResourceId constant MODULE_NAMESPACE_ID = ResourceId.wrap(
bytes32(abi.encodePacked(RESOURCE_NAMESPACE, MODULE_NAMESPACE))
Expand Down
19 changes: 2 additions & 17 deletions packages/world-modules/src/modules/erc721-puppet/ERC721Module.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import { revertWithBytes } from "@latticexyz/world/src/revertWithBytes.sol";

import { Puppet } from "../puppet/Puppet.sol";
import { createPuppet } from "../puppet/createPuppet.sol";
import { MODULE_NAME as PUPPET_MODULE_NAME } from "../puppet/constants.sol";
import { Balances } from "../tokens/tables/Balances.sol";

import { MODULE_NAME, MODULE_NAMESPACE, MODULE_NAMESPACE_ID, ERC721_REGISTRY_TABLE_ID } from "./constants.sol";
import { MODULE_NAMESPACE, MODULE_NAMESPACE_ID, ERC721_REGISTRY_TABLE_ID } from "./constants.sol";
import { _erc721SystemId, _balancesTableId, _metadataTableId, _tokenUriTableId, _operatorApprovalTableId, _ownersTableId, _tokenApprovalTableId } from "./utils.sol";
import { ERC721System } from "./ERC721System.sol";

Expand All @@ -30,20 +29,9 @@ contract ERC721Module is Module {

address immutable registrationLibrary = address(new ERC721ModuleRegistrationLibrary());

function getName() public pure override returns (bytes16) {
return MODULE_NAME;
}

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

function install(bytes memory args) public {
// Require the module to not be installed with these args yet
requireNotInstalled(MODULE_NAME, args);
requireNotInstalled(__self, args);

// Extract args
(bytes14 namespace, ERC721MetadataData memory metadata) = abi.decode(args, (bytes14, ERC721MetadataData));
Expand All @@ -53,9 +41,6 @@ contract ERC721Module is Module {
revert ERC721Module_InvalidNamespace(namespace);
}

// Require dependencies
_requireDependencies();

// Register the ERC721 tables and system
IBaseWorld world = IBaseWorld(_world());
(bool success, bytes memory returnData) = registrationLibrary.delegatecall(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
import { RESOURCE_TABLE } from "@latticexyz/store/src/storeResourceTypes.sol";
import { RESOURCE_SYSTEM, RESOURCE_NAMESPACE } from "@latticexyz/world/src/worldResourceTypes.sol";

bytes16 constant MODULE_NAME = "erc721-puppet";
bytes14 constant MODULE_NAMESPACE = "erc721-puppet";
ResourceId constant MODULE_NAMESPACE_ID = ResourceId.wrap(
bytes32(abi.encodePacked(RESOURCE_NAMESPACE, MODULE_NAMESPACE))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,10 @@ contract KeysInTableModule is Module {
// from the source table id (passed as argument to the hook methods)
KeysInTableHook private immutable hook = new KeysInTableHook();

function getName() public pure returns (bytes16) {
return bytes16("keysInTable");
}

function installRoot(bytes memory args) public override {
// Naive check to ensure this is only installed once
// TODO: only revert if there's nothing to do
requireNotInstalled(getName(), args);
requireNotInstalled(__self, args);

// Extract source table id from args
ResourceId sourceTableId = ResourceId.wrap(abi.decode(args, (bytes32)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,10 @@ contract KeysWithValueModule is Module {
// from the source table id (passed as argument to the hook methods)
KeysWithValueHook private immutable hook = new KeysWithValueHook();

function getName() public pure returns (bytes16) {
return bytes16("index");
}

function installRoot(bytes memory args) public {
// Naive check to ensure this is only installed once
// TODO: only revert if there's nothing to do
requireNotInstalled(getName(), args);
requireNotInstalled(__self, args);

// Extract source table id from args
ResourceId sourceTableId = ResourceId.wrap(abi.decode(args, (bytes32)));
Expand Down
6 changes: 1 addition & 5 deletions packages/world-modules/src/modules/puppet/PuppetModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";

import { PuppetFactorySystem } from "./PuppetFactorySystem.sol";
import { PuppetDelegationControl } from "./PuppetDelegationControl.sol";
import { MODULE_NAME, PUPPET_DELEGATION, PUPPET_FACTORY, PUPPET_TABLE_ID, NAMESPACE_ID } from "./constants.sol";
import { PUPPET_DELEGATION, PUPPET_FACTORY, PUPPET_TABLE_ID, NAMESPACE_ID } from "./constants.sol";

import { PuppetRegistry } from "./tables/PuppetRegistry.sol";

Expand All @@ -23,10 +23,6 @@ contract PuppetModule is Module {
PuppetDelegationControl private immutable puppetDelegationControl = new PuppetDelegationControl();
PuppetFactorySystem private immutable puppetFactorySystem = new PuppetFactorySystem();

function getName() public pure returns (bytes16) {
return MODULE_NAME;
}

function installRoot(bytes memory) public {
IBaseWorld world = IBaseWorld(_world());

Expand Down
1 change: 0 additions & 1 deletion packages/world-modules/src/modules/puppet/constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { RESOURCE_TABLE } from "@latticexyz/store/src/storeResourceTypes.sol";
import { RESOURCE_SYSTEM, RESOURCE_NAMESPACE } from "@latticexyz/world/src/worldResourceTypes.sol";
import { ROOT_NAMESPACE } from "@latticexyz/world/src/constants.sol";

bytes16 constant MODULE_NAME = bytes16("puppet");
bytes14 constant NAMESPACE = bytes14("puppet");

ResourceId constant NAMESPACE_ID = ResourceId.wrap(bytes32(abi.encodePacked(RESOURCE_NAMESPACE, NAMESPACE)));
Expand Down
Loading

0 comments on commit 52c37b5

Please sign in to comment.