Wrong DOMAIN_TYPEHASH definition
The contract's DOMAIN_TYPEHASH constant omits the version field, while the delegateBySig function builds the domain separator including version, causing signature verification to fail. An attacker could not exploit this for gain, but legitimate signatures from compliant wallets would be rejected.
Originally disclosed on Code4rena
Submitted by rotcivegaf
Broke the EIP 712, and the delegateBySig function.
Proof of Concept
In the build of the DOMAIN TYPEHASH the string version is forgotten, but the delegateBySig function, build the domainSeparator with the string version.
Some contract or dapp/backend could building the DOMAIN_TYPEHASH with “rigth” struct(include the version) and try to use the delegateBySig function but this function will revert in the L1378 with the message "VotingEscrow::delegateBySig: invalid signature" because the expect DOMAIN_TYPEHASH in the VotingEscrow.sol contract was built with the “wrong” struct.
Recommended Mitigation Steps
Acording the EIP 712, in the Definition of domainSeparator:
- ”
string versionthe current major version of the signing domain. Signatures from different versions are not compatible”
Add string version, to the EIP712Domain string, L1106:
bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
Other Recommendation
Build the domainSeparator L1362 in the constructor to save gas and clarify/clean code
- Remove the
bytes32 public constant DOMAIN_TYPEHASHL1106 - Add
bytes32 private immutable DOMAIN_SEPARATORas a contract VAR - Assign the
DOMAIN_SEPARATORin the constructor - Use the
DOMAIN_SEPARATORindelegateBySigfunction when buil thebytes32 digest
contract VotingEscrow is IERC721, IERC721Metadata, IVotes {
...
/* DELETE THIS LINE
bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");
*/
bytes32 private immutable DOMAIN_SEPARATOR;
...
constructor(address token_addr) {
bytes32 domainTypeHash = keccak256(
"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
);
DOMAIN_SEPARATOR = keccak256(
abi.encode(
domainTypeHash,
keccak256(bytes(name)),
keccak256(bytes(version)),
block.chainid,
address(this)
)
);
...
function delegateBySig(
address delegatee,
uint nonce,
uint expiry,
uint8 v,
bytes32 r,
bytes32 s
) public {
bytes32 structHash = keccak256(
abi.encode(DELEGATION_TYPEHASH, delegatee, nonce, expiry)
);
bytes32 digest = keccak256(
abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR, structHash)
);
...
pooltypes (Velodrome) disputed
Alex the Entreprenerd (judge) commented:
The warden has shown how the code has broken EIP-712. I do not expect any security risk, and I assume wallets will still pick up the code; however, because the code breaks the standard, in line with another finding I’ve judged in this contest, I think Medium severity to be appropriate.
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 DOMAIN_TYPEHASH constant was defined without the version field, while the domain separator used in delegateBySig included version, creating a mismatch.
Impact
The delegateBySig function would revert for signatures built according to EIP-712, breaking the standard and the delegation feature, though the judge did not expect a security risk.
What the attacker needed
None
The fix
The DOMAIN_TYPEHASH should include the version field, and the domain separator should be built in the constructor as an immutable value.
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.
This is about a smart contract that lets people vote by signing a message off-chain. The contract checks the signature using a standard format, but it made a mistake in one part of that format, so signatures created correctly by wallets would be rejected. No one can steal funds, but the feature simply does not work as intended.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.