Skip to content

Commit

Permalink
feat(world,store): add ERC165 checks for all registration methods (#1458
Browse files Browse the repository at this point in the history
)
  • Loading branch information
alvrs committed Sep 12, 2023
1 parent 51914d6 commit b9e562d
Show file tree
Hide file tree
Showing 121 changed files with 5,067 additions and 121 deletions.
41 changes: 41 additions & 0 deletions .changeset/fast-zebras-drum.md
@@ -0,0 +1,41 @@
---
"@latticexyz/store": major
"@latticexyz/world": major
---

The `World` now performs `ERC165` interface checks to ensure that the `StoreHook`, `SystemHook`, `System`, `DelegationControl` and `Module` contracts to actually implement their respective interfaces before registering them in the World.

The required `supportsInterface` methods are implemented on the respective base contracts.
When creating one of these contracts, the recommended approach is to extend the base contract rather than the interface.

```diff
- import { IStoreHook } from "@latticexyz/store/src/IStore.sol";
+ import { StoreHook } from "@latticexyz/store/src/StoreHook.sol";

- contract MyStoreHook is IStoreHook {}
+ contract MyStoreHook is StoreHook {}
```

```diff
- import { ISystemHook } from "@latticexyz/world/src/interfaces/ISystemHook.sol";
+ import { SystemHook } from "@latticexyz/world/src/SystemHook.sol";

- contract MySystemHook is ISystemHook {}
+ contract MySystemHook is SystemHook {}
```

```diff
- import { IDelegationControl } from "@latticexyz/world/src/interfaces/IDelegationControl.sol";
+ import { DelegationControl } from "@latticexyz/world/src/DelegationControl.sol";

- contract MyDelegationControl is IDelegationControl {}
+ contract MyDelegationControl is DelegationControl {}
```

```diff
- import { IModule } from "@latticexyz/world/src/interfaces/IModule.sol";
+ import { Module } from "@latticexyz/world/src/Module.sol";

- contract MyModule is IModule {}
+ contract MyModule is Module {}
```
9 changes: 8 additions & 1 deletion packages/cli/src/utils/deploy.ts
Expand Up @@ -48,6 +48,8 @@ export async function deploy(
deployConfig;
const forgeOutDirectory = await getOutDirectory(profile);

const baseSystemFunctionNames = (await loadFunctionSignatures("System")).map((item) => item.functionName);

// Set up signer for deployment
const provider = new ethers.providers.StaticJsonRpcProvider(rpc);
provider.pollingInterval = pollInterval;
Expand Down Expand Up @@ -443,7 +445,7 @@ export async function deploy(
async function loadFunctionSignatures(contractName: string): Promise<FunctionSignature[]> {
const { abi } = await getContractData(contractName);

return abi
const functionSelectors = abi
.filter((item) => ["fallback", "function"].includes(item.type))
.map((item) => {
if (item.type === "fallback") return { functionName: "", functionArgs: "" };
Expand All @@ -453,6 +455,11 @@ export async function deploy(
functionArgs: parseComponents(item.inputs),
};
});

return contractName === "System"
? functionSelectors
: // Filter out functions that are defined in the base System contract for all non-base systems
functionSelectors.filter((item) => !baseSystemFunctionNames.includes(item.functionName));
}

/**
Expand Down
19 changes: 19 additions & 0 deletions packages/store/abi/EchoSubscriber.sol/EchoSubscriber.abi.json
Expand Up @@ -179,5 +179,24 @@
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes4",
"name": "interfaceId",
"type": "bytes4"
}
],
"name": "supportsInterface",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "pure",
"type": "function"
}
]
19 changes: 19 additions & 0 deletions packages/store/abi/EchoSubscriber.sol/EchoSubscriber.abi.json.d.ts
Expand Up @@ -179,6 +179,25 @@ declare const abi: [
outputs: [];
stateMutability: "nonpayable";
type: "function";
},
{
inputs: [
{
internalType: "bytes4";
name: "interfaceId";
type: "bytes4";
}
];
name: "supportsInterface";
outputs: [
{
internalType: "bool";
name: "";
type: "bool";
}
];
stateMutability: "pure";
type: "function";
}
];
export default abi;
21 changes: 21 additions & 0 deletions packages/store/abi/IERC165.sol/IERC165.abi.json
@@ -0,0 +1,21 @@
[
{
"inputs": [
{
"internalType": "bytes4",
"name": "interfaceID",
"type": "bytes4"
}
],
"name": "supportsInterface",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
}
]
22 changes: 22 additions & 0 deletions packages/store/abi/IERC165.sol/IERC165.abi.json.d.ts
@@ -0,0 +1,22 @@
declare const abi: [
{
inputs: [
{
internalType: "bytes4";
name: "interfaceID";
type: "bytes4";
}
];
name: "supportsInterface";
outputs: [
{
internalType: "bool";
name: "";
type: "bool";
}
];
stateMutability: "view";
type: "function";
}
];
export default abi;
Expand Up @@ -166,5 +166,24 @@
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes4",
"name": "interfaceID",
"type": "bytes4"
}
],
"name": "supportsInterface",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
}
]
Expand Up @@ -166,6 +166,25 @@ declare const abi: [
outputs: [];
stateMutability: "nonpayable";
type: "function";
},
{
inputs: [
{
internalType: "bytes4";
name: "interfaceID";
type: "bytes4";
}
];
name: "supportsInterface";
outputs: [
{
internalType: "bool";
name: "";
type: "bool";
}
];
stateMutability: "view";
type: "function";
}
];
export default abi;
19 changes: 19 additions & 0 deletions packages/store/abi/MirrorSubscriber.sol/MirrorSubscriber.abi.json
Expand Up @@ -261,5 +261,24 @@
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes4",
"name": "interfaceId",
"type": "bytes4"
}
],
"name": "supportsInterface",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "pure",
"type": "function"
}
]
Expand Up @@ -261,6 +261,25 @@ declare const abi: [
outputs: [];
stateMutability: "nonpayable";
type: "function";
},
{
inputs: [
{
internalType: "bytes4";
name: "interfaceId";
type: "bytes4";
}
];
name: "supportsInterface";
outputs: [
{
internalType: "bool";
name: "";
type: "bool";
}
];
stateMutability: "pure";
type: "function";
}
];
export default abi;
19 changes: 19 additions & 0 deletions packages/store/abi/RevertSubscriber.sol/RevertSubscriber.abi.json
Expand Up @@ -166,5 +166,24 @@
"outputs": [],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes4",
"name": "interfaceId",
"type": "bytes4"
}
],
"name": "supportsInterface",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "pure",
"type": "function"
}
]
Expand Up @@ -166,6 +166,25 @@ declare const abi: [
outputs: [];
stateMutability: "pure";
type: "function";
},
{
inputs: [
{
internalType: "bytes4";
name: "interfaceId";
type: "bytes4";
}
];
name: "supportsInterface";
outputs: [
{
internalType: "bool";
name: "";
type: "bool";
}
];
stateMutability: "pure";
type: "function";
}
];
export default abi;

0 comments on commit b9e562d

Please sign in to comment.