Incorrect `EIP-712` data hashing implementation
The IvSignerRecovery.sol contract aims to use EIP-712 for verifying signatures related to option parameters (iv, strategy, maturityDate, relativeStrike) needed in the OperationalTreasury.buy() function.
The IvSignerRecovery.sol contract aims to use EIP-712 for verifying signatures related to option parameters (iv, strategy, maturityDate, relativeStrike) needed in the OperationalTreasury.buy() function. However, the implementation of the structured data hashing within the _hash function deviates significantly from the EIP-712 standard.
The EIP-712 standard specifies that the hash of a structure (structHash) should be calculated as: hashStruct(s : 𝕊) = keccak256(typeHash ‖ encodeData(s)) Where:
typeHashis thekeccak256hash of the structure's type definition string.encodeData(s)ABI-encodes the struct members, crucially encoding dynamic types likestringandbytesas thekeccak256hash of their content.
The current _hash function calculates the hash as follows:
function _hash(uint256 iv, IStrategy strategy, uint256 maturityDate, uint256 relativeStrike)internalviewreturns (bytes32){(string memory uAsset, string memory oType) = _getAssetAndType(strategy);// Incorrect hashing: Missing typeHash and incorrect string encodingreturn keccak256(abi.encode(iv, uAsset, oType, maturityDate, relativeStrike));}
This implementation has two critical flaws regarding the EIP-712 standard:
- Missing
typeHash: It completely omits thetypeHashcomponent. ThetypeHashprevents signature collisions between different data structures. - Incorrect Encoding of Dynamic Types: It uses
abi.encodefor thestringvariablesuAssetandoType. EIP-712 requires dynamic types (string,bytes) withinencodeDatato be represented by thekeccak256hash of their byte content (i.e.,keccak256(bytes(uAsset))andkeccak256(bytes(oType))).
- High Risk of Signature Mismatch (DoS): If the off-chain signing service correctly implements the EIP-712 standard (calculating
typeHashand hashing strings properly), the signatures generated off-chain will never match the hash calculated by the non-standard_hashfunction on-chain. This will cause allbuy()transactions to fail signature verification, resulting in a Denial of Service for the core functionality of purchasing options.
Recommendations:
Refactor the _hash function to strictly adhere to the EIP-712 hashStruct specification.
-
Define the
TYPEHASH: Define the type string for the signed data structure and compute itskeccak256hash. This can be stored as a constant. -
Implement Correct
encodeData: Modify the hashing logic to prepend theSIGNED_DATA_TYPEHASHand correctly encode the members according to EIP-712 rules (hashing dynamic types likestring).
Report provenance
Published by Pashov Audit Group, with Carlos (Bloqarl) participating as a contractor. The source report states that its fixes review was not fully completed; no final remediation disposition is recorded for this finding. Read the full report.