President Elector

First Flight #24
Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: medium
Valid

Incorrect TYPEHASH

Summary

In the RankedChoice smart contract due to an incorrect TYPEHASH used in the rankCandidatesBySig function. The TYPEHASH is defined for uint256[] instead of the correct address[]. This discrepancy leads to a mismatch in the signature verification process, allowing an attacker to potentially bypass verification or causing legitimate voters to be rejected.

Vulnerability Details

The contract incorrectly defines the TYPEHASHas keccak256("rankCandidates(uint256[])"), even though the function rankCandidatesBySig expects an address[] for the orderedCandidates argument.

@> bytes32 public constant TYPEHASH = keccak256("rankCandidates(uint256[])");

The vulnerability arises during the signature recovery process in rankCandidatesBySig. Since the TYPEHASH is designed for address[] but the function passes [uint256], the generated struct hash will be incorrect. Consequently, the recovered signer address will not match the expected value.

function rankCandidatesBySig(address[] memory orderedCandidates, bytes memory signature) external {
@> bytes32 structHash = keccak256(abi.encode(TYPEHASH, orderedCandidates));
bytes32 hash = _hashTypedDataV4(structHash);
address signer = ECDSA.recover(hash, signature);
_rankCandidates(orderedCandidates, signer);
}

Impact

The incorrect TYPEHASH leads to the following potential issues:

  • Signature Verification Failure

  • Bypassing Voter Authentication

  • Denial of Service

Tools Used

Manual Review

Recommendations

Change the TYPEHASH to reflect the correct address[]

bytes32 public constant TYPEHASH = keccak256("rankCandidates(address[])");
Updates

Lead Judging Commences

inallhonesty Lead Judge 12 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Typehash hashes the wrong function input.

Support

FAQs

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