From 2c9b16c77aca12e4c23e96de83e5820c09cb3b9d Mon Sep 17 00:00:00 2001 From: yonada Date: Tue, 23 Apr 2024 14:12:34 +0100 Subject: [PATCH] feat(world-modules): string systemId in `callWithSignature` typehash (#2700) --- .changeset/tender-cherries-hammer.md | 6 ++++++ .../registerDelegationWithSignature.test.ts | 3 ++- packages/world-modules/gas-report.json | 2 +- .../callwithsignature/getSignedMessageHash.sol | 18 ++++++++++++++++-- .../test/CallWithSignatureModule.t.sol | 2 +- packages/world/ts/callWithSignatureTypes.ts | 3 ++- 6 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 .changeset/tender-cherries-hammer.md diff --git a/.changeset/tender-cherries-hammer.md b/.changeset/tender-cherries-hammer.md new file mode 100644 index 0000000000..0cf0459c20 --- /dev/null +++ b/.changeset/tender-cherries-hammer.md @@ -0,0 +1,6 @@ +--- +"@latticexyz/world-modules": patch +"@latticexyz/world": patch +--- + +Replaced the `systemId` field in the `Unstable_CallWithSignatureSystem` typehash with individual `systemNamespace` and `systemName` string fields. diff --git a/e2e/packages/sync-test/registerDelegationWithSignature.test.ts b/e2e/packages/sync-test/registerDelegationWithSignature.test.ts index b12a46791b..810949d8f9 100644 --- a/e2e/packages/sync-test/registerDelegationWithSignature.test.ts +++ b/e2e/packages/sync-test/registerDelegationWithSignature.test.ts @@ -86,7 +86,8 @@ describe("callWithSignature", async () => { primaryType: "Call", message: { signer: delegator.address, - systemId, + systemNamespace: "", + systemName: "Registration", callData, nonce, }, diff --git a/packages/world-modules/gas-report.json b/packages/world-modules/gas-report.json index 2b9a55876e..853c07d2d5 100644 --- a/packages/world-modules/gas-report.json +++ b/packages/world-modules/gas-report.json @@ -9,7 +9,7 @@ "file": "test/CallWithSignatureModule.t.sol", "test": "testRegisterDelegationWithSignature", "name": "register an unlimited delegation with signature", - "gasUsed": 133659 + "gasUsed": 135913 }, { "file": "test/ERC20.t.sol", diff --git a/packages/world-modules/src/modules/callwithsignature/getSignedMessageHash.sol b/packages/world-modules/src/modules/callwithsignature/getSignedMessageHash.sol index 46a42fe5f9..02a44fe2bf 100644 --- a/packages/world-modules/src/modules/callwithsignature/getSignedMessageHash.sol +++ b/packages/world-modules/src/modules/callwithsignature/getSignedMessageHash.sol @@ -2,12 +2,17 @@ pragma solidity >=0.8.24; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; +import { WorldResourceIdLib, WorldResourceIdInstance } from "@latticexyz/world/src/WorldResourceId.sol"; + +using WorldResourceIdInstance for ResourceId; // Note the intended value of the `salt` field is the chain ID. // It is not included in `chainId`, to allow cross-chain signing without requiring wallets to switch networks. // The value of this field should be the chain on which the world lives, rather than the chain the wallet is connected to. bytes32 constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(address verifyingContract,bytes32 salt)"); -bytes32 constant CALL_TYPEHASH = keccak256("Call(address signer,bytes32 systemId,bytes callData,uint256 nonce)"); +bytes32 constant CALL_TYPEHASH = keccak256( + "Call(address signer,string systemNamespace,string systemName,bytes callData,uint256 nonce)" +); /** * @notice Generate the message hash for a given delegation signature. @@ -34,7 +39,16 @@ function getSignedMessageHash( abi.encodePacked( "\x19\x01", domainSeperator, - keccak256(abi.encode(CALL_TYPEHASH, signer, systemId, keccak256(callData), nonce)) + keccak256( + abi.encode( + CALL_TYPEHASH, + signer, + keccak256(abi.encodePacked(WorldResourceIdLib.toTrimmedString(systemId.getNamespace()))), + keccak256(abi.encodePacked(WorldResourceIdLib.toTrimmedString(systemId.getName()))), + keccak256(callData), + nonce + ) + ) ) ); } diff --git a/packages/world-modules/test/CallWithSignatureModule.t.sol b/packages/world-modules/test/CallWithSignatureModule.t.sol index 1d2b74a36f..42d4a68a24 100644 --- a/packages/world-modules/test/CallWithSignatureModule.t.sol +++ b/packages/world-modules/test/CallWithSignatureModule.t.sol @@ -104,7 +104,7 @@ contract Unstable_CallWithSignatureModuleTest is Test, GasReporter { vm.expectRevert( abi.encodeWithSelector( IUnstable_CallWithSignatureErrors.InvalidSignature.selector, - 0x5266996Bb73ce3ac0E75D79Db87f4a96063cEe1F + 0x65F0D93280688178Ec3F55bBd6f6088290639Bfb ) ); Unstable_CallWithSignatureSystem(address(world)).callWithSignature( diff --git a/packages/world/ts/callWithSignatureTypes.ts b/packages/world/ts/callWithSignatureTypes.ts index 6c16828081..c9a22550fc 100644 --- a/packages/world/ts/callWithSignatureTypes.ts +++ b/packages/world/ts/callWithSignatureTypes.ts @@ -3,7 +3,8 @@ export const callWithSignatureTypes = { Call: [ { name: "signer", type: "address" }, - { name: "systemId", type: "bytes32" }, + { name: "systemNamespace", type: "string" }, + { name: "systemName", type: "string" }, { name: "callData", type: "bytes" }, { name: "nonce", type: "uint256" }, ],