From 1a82c278dd8037155b6449e383b3a00d6453ea3e Mon Sep 17 00:00:00 2001 From: yonada Date: Thu, 7 Mar 2024 16:49:08 +0000 Subject: [PATCH] feat(world): add system signatures to FunctionSignatures (#2392) Co-authored-by: Kevin Ingersoll --- .changeset/poor-fishes-pretend.md | 5 +++++ packages/world-modules/gas-report.json | 4 ++-- packages/world/gas-report.json | 2 +- .../init/implementations/WorldRegistrationSystem.sol | 9 +++++---- 4 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 .changeset/poor-fishes-pretend.md diff --git a/.changeset/poor-fishes-pretend.md b/.changeset/poor-fishes-pretend.md new file mode 100644 index 0000000000..5bee4bc37b --- /dev/null +++ b/.changeset/poor-fishes-pretend.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/world": patch +--- + +Added system signatures to the `FunctionSignatures` table, so they can be used to generate system ABIs and decode system calls made via the world. diff --git a/packages/world-modules/gas-report.json b/packages/world-modules/gas-report.json index 5c555d87b2..8bfcd3de5e 100644 --- a/packages/world-modules/gas-report.json +++ b/packages/world-modules/gas-report.json @@ -303,7 +303,7 @@ "file": "test/UniqueEntityModule.t.sol", "test": "testInstall", "name": "install unique entity module", - "gasUsed": 710507 + "gasUsed": 715495 }, { "file": "test/UniqueEntityModule.t.sol", @@ -315,7 +315,7 @@ "file": "test/UniqueEntityModule.t.sol", "test": "testInstallRoot", "name": "installRoot unique entity module", - "gasUsed": 680976 + "gasUsed": 685964 }, { "file": "test/UniqueEntityModule.t.sol", diff --git a/packages/world/gas-report.json b/packages/world/gas-report.json index 1eb0de70d3..04c9ccb0b4 100644 --- a/packages/world/gas-report.json +++ b/packages/world/gas-report.json @@ -105,7 +105,7 @@ "file": "test/World.t.sol", "test": "testRegisterFunctionSelector", "name": "Register a function selector", - "gasUsed": 111621 + "gasUsed": 116605 }, { "file": "test/World.t.sol", diff --git a/packages/world/src/modules/init/implementations/WorldRegistrationSystem.sol b/packages/world/src/modules/init/implementations/WorldRegistrationSystem.sol index e5fd723544..691697b0e4 100644 --- a/packages/world/src/modules/init/implementations/WorldRegistrationSystem.sol +++ b/packages/world/src/modules/init/implementations/WorldRegistrationSystem.sol @@ -202,8 +202,8 @@ contract WorldRegistrationSystem is System, IWorldErrors, LimitedCallContext { // Compute global function selector string memory namespaceString = WorldResourceIdLib.toTrimmedString(systemId.getNamespace()); - bytes memory worldFunctionSignature = abi.encodePacked(namespaceString, "__", systemFunctionSignature); - worldFunctionSelector = bytes4(keccak256(worldFunctionSignature)); + string memory worldFunctionSignature = string.concat(namespaceString, "__", systemFunctionSignature); + worldFunctionSelector = bytes4(keccak256(bytes(worldFunctionSignature))); // Require the function selector to be globally unique ResourceId existingSystemId = FunctionSelectors._getSystemId(worldFunctionSelector); @@ -214,8 +214,9 @@ contract WorldRegistrationSystem is System, IWorldErrors, LimitedCallContext { bytes4 systemFunctionSelector = bytes4(keccak256(bytes(systemFunctionSignature))); FunctionSelectors._set(worldFunctionSelector, systemId, systemFunctionSelector); - // Register the function signature for offchain use - FunctionSignatures._set(worldFunctionSelector, string(worldFunctionSignature)); + // Register the function signatures for offchain use + FunctionSignatures._set(systemFunctionSelector, systemFunctionSignature); + FunctionSignatures._set(worldFunctionSelector, worldFunctionSignature); } /**