Fix ECDSA signature malleability (#3610)

(cherry picked from commit d693d89d99)
This commit is contained in:
Francisco
2022-08-10 15:40:03 -03:00
committed by Francisco Giordano
parent 64e48203ce
commit e1878ace8c
3 changed files with 16 additions and 30 deletions

View File

@ -55,9 +55,6 @@ library ECDSA {
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
// Check the signature length
// - case 65: r,s,v signature (standard)
// - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._
if (signature.length == 65) {
bytes32 r;
bytes32 s;
@ -71,17 +68,6 @@ library ECDSA {
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else if (signature.length == 64) {
bytes32 r;
bytes32 vs;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
/// @solidity memory-safe-assembly
assembly {
r := mload(add(signature, 0x20))
vs := mload(add(signature, 0x40))
}
return tryRecover(hash, r, vs);
} else {
return (address(0), RecoverError.InvalidSignatureLength);
}