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

feat(world,store): add ERC165 checks for all registration methods #1458

Merged
merged 9 commits into from
Sep 12, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .changeset/fast-zebras-drum.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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"
}
]
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
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"
}
]
Original file line number Diff line number Diff line change
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;
Original file line number Diff line number Diff line change
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"
}
]
Original file line number Diff line number Diff line change
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;
Original file line number Diff line number Diff line change
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"
}
]
Original file line number Diff line number Diff line change
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;
Loading