HardhatFoundry
30,000 USDC
View results
Submission Details
Severity: medium
Valid

Typehash for ModuleEnableMode struct is incorrect

Summary

There are two different errors in the typehash for the ModuleEnableMode structure, resulting in incompatibility with the EIP-712 standard.

Vulnerability Details

The typehash for the ModuleEnableMode structure is defined in the MODULE_ENABLE_MODE_TYPE_HASH constant as the following:

41: bytes32 constant MODULE_ENABLE_MODE_TYPE_HASH = keccak256("ModuleEnableMode(address module, bytes32 initDataHash)");

The first error is the blank space after the first comma between the members. According to the EIP-712 standard, members are joined by a "," without any blank space.

The type of a struct is encoded as name ‖ "(" ‖ member₁ ‖ "," ‖ member₂ ‖ "," ‖ … ‖ memberₙ ")" where each member is written as type ‖ " " ‖ name. For example, the above Mail struct is encoded as Mail(address from,address to,string contents).

The added space completely changes the result of the typehash:

keccak256("ModuleEnableMode(address module, bytes32 initDataHash)") => 0x9f34cc46003dee27a148c367555bac140aa3fbfc713cf44b3842f343fc2a4e7b
keccak256("ModuleEnableMode(address module,bytes32 initDataHash)") => 0xe81b75314ee7a02a1f49592b5a66846e18745ee8948ef8f98f4649864a3f701e

There is another error in the data types, the typehash is used in the _getEnableModeDataHash() function:

388: function _getEnableModeDataHash(address module, bytes calldata initData) internal view returns (bytes32 digest) {
389: digest = _hashTypedData(
390: keccak256(
391: abi.encode(
392: MODULE_ENABLE_MODE_TYPE_HASH,
393: module,
394: keccak256(initData)
395: )
396: )
397: );
398: }

As we can see in the code snippet, the second argument, initDataHash, is of type bytes while the typehash defined it as bytes32.

Impact

Both errors will lead to an incompatibility with the EIP-712 standard. Existing tools and signing devices that implement EIP-712 will produce signatures that will be rejected due to these small errors even if the signer is valid.

Tools Used

None.

Recommendations

Change the typehash to:

bytes32 constant MODULE_ENABLE_MODE_TYPE_HASH = keccak256("ModuleEnableMode(address module,bytes initData)");
Updates

Lead Judging Commences

0xnevi Lead Judge 10 months ago
Submission Judgement Published
Validated
Assigned finding tags:

finding-wrong-EIP712-typehash-ModuleEnableMode

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.