Browse Source

Avoid assembly in signature V and S decomposition (#3060)

* Avoid assembly in signature V and S decomposition

* Update ECDSA.sol
Anton Bukov 3 years ago
parent
commit
da3a9ae18b
1 changed files with 2 additions and 6 deletions
  1. 2 6
      contracts/utils/cryptography/ECDSA.sol

+ 2 - 6
contracts/utils/cryptography/ECDSA.sol

@@ -117,12 +117,8 @@ library ECDSA {
         bytes32 r,
         bytes32 vs
     ) internal pure returns (address, RecoverError) {
-        bytes32 s;
-        uint8 v;
-        assembly {
-            s := and(vs, 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
-            v := add(shr(255, vs), 27)
-        }
+        bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
+        uint8 v = uint8((uint256(vs) >> 255) + 27);
         return tryRecover(hash, v, r, s);
     }