Repository: summa-tx/bitcoin-spv (language: rust)

Issue:
Unnecessary intermediate cast in CheckBitcoinSigs
#### Description

`CheckBitcoinSigs.accountFromPubkey()` casts the `bytes32` keccack256 hash of the `pubkey` to `uint256`, then `uint160` and then finally to `address` while the intermediate cast is not required.

#### Examples

https://github.com/summa-tx/bitcoin-spv/blob/f5e4da091a1c97e6432c2d70eba434edb189f919/solidity/contracts/CheckBitcoinSigs.sol#L15-L25

#### Recommendation

The intermediate cast from `uint256` to `uint160` can be omitted. Refactor to `return address(uint256(_digest))` instead.



Discussion / hints:

Fix patch:
diff --git a/solidity/contracts/CheckBitcoinSigs.sol b/solidity/contracts/CheckBitcoinSigs.sol
index d622e269..1724837d 100644
--- a/solidity/contracts/CheckBitcoinSigs.sol
+++ b/solidity/contracts/CheckBitcoinSigs.sol
@@ -21,7 +21,7 @@ library CheckBitcoinSigs {
 
         // keccak hash of uncompressed unprefixed pubkey
         bytes32 _digest = keccak256(_pubkey);
-        return address(uint160(uint256(_digest)));
+        return address(uint256(_digest));
     }
 
     /// @notice          Calculates the p2wpkh output script of a pubkey


Test patch: