-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(world-modules): add
validateCallWithSignature
to `Unstable_Cal…
…lWithSignatureModule` (#2614)
- Loading branch information
Showing
7 changed files
with
54 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@latticexyz/world-modules": patch | ||
--- | ||
|
||
Added `validateCallWithSignature` function to `Unstable_CallWithSignatureModule` to validate a signature without executing the call. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
packages/world-modules/src/modules/delegation/IUnstable_CallWithSignatureErrors.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.24; | ||
|
||
interface IUnstable_CallWithSignatureErrors { | ||
/** | ||
* @dev Mismatched signature. | ||
*/ | ||
error InvalidSignature(address signer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/world-modules/src/modules/delegation/validateCallWithSignature.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.24; | ||
import { ResourceId } from "@latticexyz/world/src/WorldResourceId.sol"; | ||
import { WorldContextConsumerLib } from "@latticexyz/world/src/WorldContext.sol"; | ||
import { CallWithSignatureNonces } from "./tables/CallWithSignatureNonces.sol"; | ||
import { getSignedMessageHash } from "./getSignedMessageHash.sol"; | ||
import { ECDSA } from "./ECDSA.sol"; | ||
import { IUnstable_CallWithSignatureErrors } from "./IUnstable_CallWithSignatureErrors.sol"; | ||
|
||
/** | ||
* @notice Verifies the given system call corresponds to the given signature. | ||
* @param signer The address on whose behalf the system is called. | ||
* @param systemId The ID of the system to be called. | ||
* @param callData The ABI data for the system call. | ||
* @param signature The EIP712 signature. | ||
* @dev Reverts with InvalidSignature(recoveredSigner) if the signature is invalid. | ||
*/ | ||
function validateCallWithSignature( | ||
address signer, | ||
ResourceId systemId, | ||
bytes memory callData, | ||
bytes memory signature | ||
) view { | ||
uint256 nonce = CallWithSignatureNonces._get(signer); | ||
bytes32 hash = getSignedMessageHash(signer, systemId, callData, nonce, WorldContextConsumerLib._world()); | ||
|
||
// If the message was not signed by the delegator or is invalid, revert | ||
address recoveredSigner = ECDSA.recover(hash, signature); | ||
if (recoveredSigner != signer) { | ||
revert IUnstable_CallWithSignatureErrors.InvalidSignature(recoveredSigner); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters