Skip to content

Conversation

Empact
Copy link
Contributor

@Empact Empact commented Jan 30, 2019

To directly return a CRIPEMD160 hash from data.

Simplifies the call sites.

Copy link
Contributor

@jimpo jimpo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

src/hash.h Outdated
}

/** Compute the 160-bit RIPEMD-160 hash of a vector. */
inline uint160 RipeMd160(const std::vector<unsigned char>& vch)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could make this a template function over things with .data() and .size() so that it works for Spans too. In which case you could also remove the other signature for RipeMd160(ptr, size) and just call RipeMd160(Span<unsigned char>(ptr, size)).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a follow-up here: https://github.com/Empact/bitcoin/tree/base-blob-data that makes RipeMd160 just a template and makes base_blob and descendants compatible by adding base_blob::data(). I figure it's best to put that up separately as it's mostly to do with base_blob.

@Sjors
Copy link
Member

Sjors commented Feb 1, 2019

Concept ACK. I noticed you're not touching the CRIPEMD160 code in script/interpreter.cpp. I assume that's intentional?

This should have wallet tag I think, since it touches IsMine and signing code.

Why hash.h rather than ripemd160.h? I'm a bit confused by the division of labor between hash.h and the various specific hash function files anyway.

@Empact Empact changed the title [moveonly] Extract RipeMd160 [moveonly] wallet: Extract RipeMd160 Feb 1, 2019
@Empact Empact force-pushed the ripe-md branch 3 times, most recently from 3a380b4 to d9871b1 Compare February 1, 2019 21:25
@@ -8,6 +8,8 @@
#include <stdint.h>
#include <stdlib.h>

#include <uint256.h> // For uint160
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: crypto/ is pretty conservative wrt inclusion, but seems this is okay because crypto/siphash.h includes uint256.h.

@Empact
Copy link
Contributor Author

Empact commented Feb 4, 2019

@Sjors addressed your comments - now in ripemd160.h. Didn't touch script/interpreter.cpp both because the call pattern didn't fit, and to avoid touching consensus code.

@DrahtBot
Copy link
Contributor

DrahtBot commented Feb 4, 2019

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK achow101, theStack, MarcoFalke
Concept ACK jimpo
Stale ACK Sjors, kiminuo, kristapsk, jonatack, stratospher

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #26840 (refactor: importpubkey, importprivkey, importaddress, importmulti, and importdescriptors rpc by KolbyML)
  • #25429 (refactor: Avoid UniValue copies by MarcoFalke)
  • #21590 (Safegcd-based modular inverses in MuHash3072 by sipa)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@Empact
Copy link
Contributor Author

Empact commented Apr 14, 2019

Rebased for #15638

@Empact
Copy link
Contributor Author

Empact commented Jun 22, 2019

Rebased

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK b29e95c

Copy link
Contributor

@kristapsk kristapsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK b29e95c

Copy link
Member

@Sjors Sjors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK b29e95c

@achow101
Copy link
Member

Are you still working on this?

@Empact
Copy link
Contributor Author

Empact commented Dec 16, 2022

@achow101 Rebased to address conflict with #26158

@achow101
Copy link
Member

Two more places in src/wallet/rpc/coins.cpp could be updated:

diff --git a/src/wallet/rpc/coins.cpp b/src/wallet/rpc/coins.cpp
index 82642194c20..250b580c37c 100644
--- a/src/wallet/rpc/coins.cpp
+++ b/src/wallet/rpc/coins.cpp
@@ -679,8 +679,7 @@ RPCHelpMan listunspent()
                             CHECK_NONFATAL(extracted);
                             // Also return the witness script
                             const WitnessV0ScriptHash& whash = std::get<WitnessV0ScriptHash>(witness_destination);
-                            CScriptID id;
-                            CRIPEMD160().Write(whash.begin(), whash.size()).Finalize(id.begin());
+                            CScriptID id{RIPEMD160(whash)};
                             CScript witnessScript;
                             if (provider->GetCScript(id, witnessScript)) {
                                 entry.pushKV("witnessScript", HexStr(witnessScript));
@@ -689,8 +688,7 @@ RPCHelpMan listunspent()
                     }
                 } else if (scriptPubKey.IsPayToWitnessScriptHash()) {
                     const WitnessV0ScriptHash& whash = std::get<WitnessV0ScriptHash>(address);
-                    CScriptID id;
-                    CRIPEMD160().Write(whash.begin(), whash.size()).Finalize(id.begin());
+                    CScriptID id{RIPEMD160(whash)};
                     CScript witnessScript;
                     if (provider->GetCScript(id, witnessScript)) {
                         entry.pushKV("witnessScript", HexStr(witnessScript));

To directly return a CRIPEMD160 hash from data.

Incidentally, decoding this acronym:
* RIPEMD -> RIPE Message Digest
* RIPE -> RACE Integrity Primitives Evaluation
* RACE -> Research and Development in Advanced Communications Technologies in Europe
@achow101
Copy link
Member

ACK 6879be6

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-ACK 6879be6

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review ACK 6879be6 🏔

Show signature

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

review ACK 6879be691bf636a53208ef058f2ebe18bfa8017c  🏔
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUiT1wv+JeOoQOIiy2NUd4vV1htnx+kXGz/gFFoDnqCY0M9sj6LdXfmwLf3EYpQA
fKhnS86I49ms/985+Z9jviAiwZ6iA9ViVZjmoLhcfPqUi8l/cDInfml8UVwLI2dj
0aXCAqXRex56hieA3q8zHCQ3L12UPyD/pJvdVGIDim18llMB5lxld7gT7eC3fhyO
i+jo6x86YDdxo7+OgwMXjSb/59IPK4bR/B10lBS64AGLKD1tSCpU2X/hQkUnNsut
Q/RCJipWDBL5cepJwCR/h1XO4C2KFzYEw998cYm0ZnLLivKTKimrHeDgQfJ3akfZ
m3YRylDN8OeJ/Fnwr7JuPisTBvisVm7wfFIF30RW8AgPF/5WFR2iddF7Awlf83Qr
AMnEcCnM6mMCO1xxrxR92NjnEqXsqlTqf6f0ygNuCiFIA5xyADUvT3B+dMiT0eg5
0M6xp/ppnrP5AA8Nc9m+FZ9tEDOwiCh/9cYeZAZyyruEhw1JgjZyUAgU7qMD2cr4
Ev+BKUFf
=XLKt
-----END PGP SIGNATURE-----

@maflcko maflcko merged commit 1c8b80f into bitcoin:master Jan 30, 2023
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jan 30, 2023
@Empact Empact deleted the ripe-md branch January 31, 2023 04:12
maflcko pushed a commit that referenced this pull request Feb 1, 2023
…ions

87f11ef refactor: use `Hash` helper for double-SHA256 calculations (Sebastian Falbesoner)

Pull request description:

  We have two helper templates `Hash(const T& in1)` and `Hash(const T& in1, const T& in2)` available for calculating the double-SHA256 hash of one object or two concatenated objects, respectively:

  https://github.com/bitcoin/bitcoin/blob/b5868f4b1f884e8d6612f34ca4005fe3a992053d/src/hash.h#L74-L89

  This PR uses them in order to increase readability and simplify the code. As in #15294 (which inspired this PR, doing the same for RIPEMD160), the helper is not utilized in validation.cpp and  script/interpreter.cpp to avoid touching consensus-relevant code.

ACKs for top commit:
  john-moffett:
    ACK 87f11ef
  stickies-v:
    ACK 87f11ef
  MarcoFalke:
    review ACK 87f11ef  😬

Tree-SHA512: 11d7e3d00c89685107784010fbffb33ccafb4d1b6a76c4dceb937b29bb234ef4d54581b16bd0737c8d2994a90cf4fe10a9738c7cc5b6d085c6a819f06176dab9
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Feb 1, 2023
…alculations

87f11ef refactor: use `Hash` helper for double-SHA256 calculations (Sebastian Falbesoner)

Pull request description:

  We have two helper templates `Hash(const T& in1)` and `Hash(const T& in1, const T& in2)` available for calculating the double-SHA256 hash of one object or two concatenated objects, respectively:

  https://github.com/bitcoin/bitcoin/blob/b5868f4b1f884e8d6612f34ca4005fe3a992053d/src/hash.h#L74-L89

  This PR uses them in order to increase readability and simplify the code. As in bitcoin#15294 (which inspired this PR, doing the same for RIPEMD160), the helper is not utilized in validation.cpp and  script/interpreter.cpp to avoid touching consensus-relevant code.

ACKs for top commit:
  john-moffett:
    ACK 87f11ef
  stickies-v:
    ACK 87f11ef
  MarcoFalke:
    review ACK 87f11ef  😬

Tree-SHA512: 11d7e3d00c89685107784010fbffb33ccafb4d1b6a76c4dceb937b29bb234ef4d54581b16bd0737c8d2994a90cf4fe10a9738c7cc5b6d085c6a819f06176dab9
@bitcoin bitcoin locked and limited conversation to collaborators Jan 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.