Skip to content

Commit

Permalink
feat(world-modules): string systemId in callWithSignature typehash (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
yonadaaa authored Apr 23, 2024
1 parent 6bd4fad commit 2c9b16c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changeset/tender-cherries-hammer.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ describe("callWithSignature", async () => {
primaryType: "Call",
message: {
signer: delegator.address,
systemId,
systemNamespace: "",
systemName: "Registration",
callData,
nonce,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/world-modules/gas-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
)
)
)
);
}
2 changes: 1 addition & 1 deletion packages/world-modules/test/CallWithSignatureModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion packages/world/ts/callWithSignatureTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
],
Expand Down

0 comments on commit 2c9b16c

Please sign in to comment.