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-modules): callWithSignature chain id is salt #2648

Merged
merged 8 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions .changeset/itchy-baboons-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/world-modules": patch
---

Moved the chain ID in `CallWithSignature` from the `chainId` to the `salt` field, preventing wallets from attempting to switch networks based on the messages chain.
yonadaa marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { deployContracts, startViteServer, startBrowserAndPage, openClientWithRo
import { rpcHttpUrl } from "./setup/constants";
import { waitForInitialSync } from "./data/waitForInitialSync";
import { createBurnerAccount, resourceToHex, transportObserver } from "@latticexyz/common";
import { http, createWalletClient, ClientConfig, encodeFunctionData } from "viem";
import { http, createWalletClient, ClientConfig, encodeFunctionData, toHex } from "viem";
import { mudFoundry } from "@latticexyz/common/chains";
import { encodeEntity } from "@latticexyz/store-sync/recs";
import { callPageFunction } from "./data/callPageFunction";
Expand Down Expand Up @@ -79,8 +79,8 @@ describe("callWithSignature", async () => {
// Sign registration call message
const signature = await delegatorWalletClient.signTypedData({
domain: {
chainId: delegatorWalletClient.chain.id,
verifyingContract: worldContract.address,
salt: toHex(delegatorWalletClient.chain.id, { size: 32 }),
},
types: callWithSignatureTypes,
primaryType: "Call",
Expand Down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a comment in Discord but this directory name doesn't make much sense anymore and also kinda confusing alongside modules/std-delegations

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function getSignedMessageHash(
address worldAddress
) view returns (bytes32) {
bytes32 domainSeperator = keccak256(
abi.encode(keccak256("EIP712Domain(uint256 chainId,address verifyingContract)"), block.chainid, worldAddress)
abi.encode(keccak256("EIP712Domain(address verifyingContract,bytes32 salt)"), worldAddress, bytes32(block.chainid))
holic marked this conversation as resolved.
Show resolved Hide resolved
);

return
Expand Down
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,
0x824E5E0aF3eA693b906527Dc41E4a29F037d515b
0x5266996Bb73ce3ac0E75D79Db87f4a96063cEe1F
)
);
Unstable_CallWithSignatureSystem(address(world)).callWithSignature(
Expand Down
Loading