In the rankCandidatesBySig function logic is to call the _rankCandidates internal function by the address of the signer instead of msg.sender, this implementation allows the user(voters) to cast their vote more securely. The contract uses using EIP712 protocol for interacting with signatures. EIP721 has a function name _hashTypedDataV4 which gets the data of the target function (here the rankCandidates) and the data of its arguments (here address[] memory orderedCandidates) and keccak it in a specific way and then the function uses ECDSA protocol to recover the signer address. The functionality of working with these protocols is causing issues because at the end the signer and msg.sender address are not the same.
The address of the singer which ECDSA protocol recovers is not the same as msg.sender (the voter who calls rankCandidatesBySig function)
- To access the signer in the rankCandidatesBySig function, I implement a child contract, whose functionality is the same as RankedChoice contract.
Put this in test/RankedChoiceTest.t.sol.
By running this test, we can figure out that the address of signer and msg.sender are not the same.
Put this outside the test contract.
Malicious Manipulation
As the function does not have a condition to check if the signer is actually the msg.sender, an attacker could attempt to generate a valid signature for a different address. If the logic does not correctly verify the signer against expected conditions, it could lead to unauthorized actions.
User Confusion
If users expect a certain behavior based on the signature but see unexpected results due to mismatched signers, it could lead to a lack of trust in the application.
Make sure the process of extracting the signature is correct.
Possible issue: There might be a problem with the TYPEHASH constant, which should be assigned like this:
Make sureEIP712::_hashTypedDataV4 entries are correct.
Possible issue: It is possible that different parameters should be passed to the _hashTypedDataV4 function, instead of passing orderedCandidates itself maybe we should pass the keccak256 of it.
Make sure that the rankCandidatesBySig has an if statement to check whether the signer and msg.sender are the same before calling the _rankCandidates function.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.