From 7a103a9b022a4d07f37aae9b8e9b849cfd19aab0 Mon Sep 17 00:00:00 2001 From: Pascal Marco Caversaccio Date: Sun, 31 Jul 2022 18:53:36 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20=20comments=20on=20type=20?= =?UTF-8?q?byte=20size?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pascal Marco Caversaccio --- src/utils/ECDSA.vy | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/utils/ECDSA.vy b/src/utils/ECDSA.vy index d93257b1..a6dca6ad 100644 --- a/src/utils/ECDSA.vy +++ b/src/utils/ECDSA.vy @@ -18,14 +18,16 @@ def _recover_sig(hash: bytes32, signature: Bytes[65]) -> address: """ @dev Recover the signer address from a message digest `hash` and the signature `signature`. - @param hash The message digest that was signed. - @param signature The secp256k1 signature of `hash`. + @param hash The 32-bytes message digest that was signed. + @param signature The secp256k1 64/65-bytes signature of `hash`. """ + # 65-bytes case: r,s,v standard signature if (len(signature) == 65): r: uint256 = extract32(signature, 0, output_type=uint256) s: uint256 = extract32(signature, 32, output_type=uint256) v: uint256 = convert(slice(signature, 64, 1), uint256) return self._try_recover_vrs(hash, v, r, s) + # 64-bytes case: r,vs signature; see: https://eips.ethereum.org/EIPS/eip-2098 elif (len(signature) == 64): r: uint256 = extract32(signature, 0, output_type=uint256) vs: uint256 = extract32(signature, 32, output_type=uint256) @@ -40,10 +42,10 @@ def _recover_vrs(hash: bytes32, v: uint256, r: uint256, s: uint256) -> address: """ @dev Recover the signer address from a message digest `hash` and the secp256k1 signature parameters `v`, `r`, and `s`. - @param hash The message digest that was signed. - @param v secp256k1 signature parameter `v`. - @param r secp256k1 signature parameter `r`. - @param s secp256k1 signature parameter `s`. + @param hash The 32-bytes message digest that was signed. + @param v The secp256k1 1-byte signature parameter `v`. + @param r The secp256k1 32-bytes signature parameter `r`. + @param s The secp256k1 32-bytes signature parameter `s`. """ return self._try_recover_vrs(hash, v, r, s) @@ -56,9 +58,9 @@ def _try_recover_r_vs(hash: bytes32, r: uint256, vs: uint256) -> address: and the secp256k1 short signature fields `r` and `vs`. @notice See https://eips.ethereum.org/EIPS/eip-2098 for the compact signature representation. - @param hash The message digest that was signed. - @param r The secp256k1 signature parameter `r`. - @param vs The secp256k1 short signature field of `v` and `s`. + @param hash The 32-bytes message digest that was signed. + @param r The secp256k1 32-bytes signature parameter `r`. + @param vs The secp256k1 32-bytes short signature field of `v` and `s`. """ s: uint256 = vs & convert(SIGNATURE_INCREMENT, uint256) v: uint256 = shift(vs, -255) + 27 @@ -76,10 +78,10 @@ def _try_recover_vrs(hash: bytes32, v: uint256, r: uint256, s: uint256) -> addre the different client implementations can be found here: https://github.com/ethereum/yellowpaper/pull/860. Thus, the signature check on the value of `v` is neglected. - @param hash The message digest that was signed. - @param v The secp256k1 signature parameter `v`. - @param r The secp256k1 signature parameter `r`. - @param s The secp256k1 signature parameter `s`. + @param hash The 32-bytes message digest that was signed. + @param v The secp256k1 1-byte signature parameter `v`. + @param r The secp256k1 32-bytes signature parameter `r`. + @param s The secp256k1 32-bytes signature parameter `s`. """ if (s > convert(MALLEABILITY_THRESHOLD, uint256)): raise "ECDSA: invalid signature \'s\' value"