Protocol is not EIP712 compliant: incorrect typehash for Validation and Transaction structures
The contract's EIP-712 typehashes for the Transaction and Validation structs were computed from outdated, removed struct definitions, so the signed data did not match the declared structs. This made the protocol non-compliant with EIP-712, which could cause issues with integrators relying on the standard.
Submitted by ABA, also found by 0xmystery
When implementing EIP712, among other things, for data structures that will be a part of signing message, a typehash must be defined.
The structure typehash is defined as: typeHash = keccak256(encodeType(typeOf(s)))
Where encodeType is the type of a struct that is encoded as: name ‖ "(" ‖ member₁ ‖ "," ‖ member₂ ‖ "," ‖ … ‖ memberₙ ")"
And each member is written as: type ‖ " " ‖ name.
The project uses 2 structures on the signed data Transaction and Validation declared in TypeHashHelper:
/**
* @notice Structural representation of transaction details
* @param operation type of operation
* @param to address to send tx to
* @param account address of safe
* @param executor address of executor if executed via executor plugin, address(0) if executed via execTransaction
* @param value txn value
* @param nonce txn nonce
* @param data txn callData
*/
struct Transaction {
uint8 operation;
address to;
address account;
address executor;
uint256 value;
uint256 nonce;
bytes data;
}
/**
* @notice Type of validation struct to hash
* @param expiryEpoch max time till validity of the signature
* @param transactionStructHash txn digest generated using TypeHashHelper._buildTransactionStructHash()
* @param policyHash policy commit hash of the safe account
*/
struct Validation {
uint32 expiryEpoch;
bytes32 transactionStructHash;
bytes32 policyHash;
}
However, the precalculated typehash for each of the structure are of different structures:
- For
Transactionthe hash is actually calculated on a now removedExecutionParamsstructure:
/**
* @notice EIP712 typehash for transaction data
* @dev keccak256("ExecutionParams(address to,uint256 value,bytes data,uint8 operation,address account,address executor,uint256 nonce)");
*/
bytes32 public constant TRANSACTION_PARAMS_TYPEHASH =
0xfd4628b53a91b366f1977138e2eda53b93c8f5cc74bda8440f108d7da1e99290;
- For
Validationthe hash is calculated on another old, removed structureValidationParams:
/**
* @notice EIP712 typehash for validation data
* @dev keccak256("ValidationParams(ExecutionParams executionParams,bytes32 policyHash,uint32 expiryEpoch)ExecutionParams(address to,uint256 value,bytes data,uint8 operation,address account,address executor,uint256 nonce)")
*/
bytes32 public constant VALIDATION_PARAMS_TYPEHASH =
0x0c7f653e0f641e41fbb4ed1440c7d0b08b8d2a19e1c35cfc98de2d47519e15b1;
POC
The issue went undetected in the initial development phase, and can be verified, because the tests still use the old hashes:
function testValidateConstants() public {
assertEq(
TypeHashHelper.TRANSACTION_PARAMS_TYPEHASH,
keccak256(
"ExecutionParams(address to,uint256 value,bytes data,uint8 operation,address account,address executor,uint256 nonce)"
)
);
assertEq(
TypeHashHelper.VALIDATION_PARAMS_TYPEHASH,
keccak256(
"ValidationParams(ExecutionParams executionParams,bytes32 policyHash,uint32 expiryEpoch)ExecutionParams(address to,uint256 value,bytes data,uint8 operation,address account,address executor,uint256 nonce)"
)
);
}
The specific test can be verified by running:
forge test --fork-url "https://eth-mainnet.g.alchemy.com/v2/<ALCHEMY_API_KEY>" -vvv --ffi --match-test testValidateConstants
Impact
Protocol is not EIP712 compliant, which will result in issues with integrators.
Tools Used
An online keccak256 checker for validating that the those hashes are not actually for the correct structures.
Recommendations
Modify the structure typehash (and tests) to point to the correct structures.
0xad1onchain (Brahma) confirmed
The Warden has demonstrated that the contract is non-compliant with EIP-712 as the type-hashes defined within it are outdated and incorrect.
The Warden has articulated what the potential impact is and, while slightly brief, the recommendation the Warden provided is correct.
As a result, I fully accept this submission as satisfactory as well as the best of its kind. Issue #182 will be awarded partial credit, given that it managed to pinpoint a single flaw in a single type-hash rather than identify that multiple type hashes were incorrect.
0xad1onchain (Brahma) commented:
Fixed, amended EIP 712 struct.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The typehash constants were not updated when the structs were renamed and their fields reordered, so they still hash the old ExecutionParams and ValidationParams definitions.
What the attacker needed
None
The fix
The typehash constants and their tests were updated to match the correct Transaction and Validation struct definitions.
How it was found
- Compare the declared Transaction and Validation structs with the typehash constants in TypeHashHelper.
- Notice that the typehash comments and values refer to the removed ExecutionParams and ValidationParams structs.
- Run the existing test testValidateConstants, which still asserts the old hashes, to confirm the mismatch.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
EIP-712 is a standard for signing structured data in Ethereum, so wallets and other tools can show exactly what is being signed. Each struct has a typehash, a fingerprint of its field names and types, and here those fingerprints were left over from older struct definitions. As a result, the signatures did not follow the standard, which can confuse or break integrations.
What is Crypto?
Encryption, signatures, randomness or certificate checks that do not protect what they claim to.