8000 Refactoring CHashWriter & Get{Prevouts,Sequence,Outputs}Hash to SHA256 (Alternative to #18071) by JeremyRubin · Pull Request #19601 · bitcoin/bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Refactoring CHashWriter & Get{Prevouts,Sequence,Outputs}Hash to SHA256 (Alternative to #18071) #19601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 25, 2020

Conversation

JeremyRubin
Copy link
Contributor
@JeremyRubin JeremyRubin commented Jul 27, 2020

Opened as an alternative to #18071 to be more similar to #17977.

I'm fine with either, deferring to others.

cc jnewbery Sjors

@DrahtBot
Copy link
Contributor
DrahtBot commented Jul 27, 2020

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

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.

@instagibbs
Copy link
Member

I have mild preference for other PR but

utACK 2f45092

hashPrevouts = GetPrevoutHash(txTo);
hashSequence = GetSequenceHash(txTo);
hashOutputs = GetOutputsHash(txTo);
hashPrevouts = GetPrevoutsSHA256(txTo);
Copy link
Member

Choose a reason for hiding this comment

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

Why this weird double assignment? = SHA256Uint256(GetPrevoutsSHA256(txTo)) is shorter and more clear IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR was made before #17977 (comment) was added (or before I saw it at least).

I specifically made it so it would be easy on rebase to switch the first assignment and argument to SHA256Uint256 to m_hash_prevouts for taproot, but now since that logic is all different it's not clear that this is an easier rebase. In any case, this part of the patch was designed so that master is correct, but was intended to be blown out by #17977.

Copy link
Member

Choose a reason for hiding this comment

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

Don't worry about such trivial rebasing impact on #17977.

@sipa
Copy link
Member
sipa commented Aug 4, 2020

I prefer this PR over #18071 (but see nit above).

src/hash.h Outdated
@@ -200,6 +213,9 @@ uint256 SerializeHash(const T& obj, int nType=SER_GETHASH, int nVersion=PROTOCOL
return ss.GetHash();
}

/** Single-SHA256 a 32-byte input (represented as uint256). */
uint256 SHA256Uint256(const uint256& input);
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps add NODISCARD here to guard against the issue you pointed out in the other PR.

@practicalswift
Copy link
Contributor
practicalswift commented Aug 5, 2020

Concept ACK

I prefer this PR over the alternative (#1807)1: this one is simpler and thus more likely to be used correctly by callers.

Adding NODISCARD to SHA256Uint256 would be nice as observed by sipa.

@JeremyRubin JeremyRubin force-pushed the refactoring-hashers-2 branch from 2f45092 to a8b95a3 Compare August 6, 2020 23:28
@JeremyRubin JeremyRubin force-pushed the refactoring-hashers-2 branch from a8b95a3 to 8986838 Compare August 6, 2020 23:53
@JeremyRubin
Copy link
Contributor Author

rebased and added NODISCARD.

Copy link
Contributor
@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

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

utACK 8986838.

One request for additional comments inline.

…Outputs}SHA256.

Several proposals (Taproot, MuHash, CTV) require access to the single
hash.
@JeremyRubin JeremyRubin force-pushed the refactoring-hashers-2 branch from 8986838 to 9ab4caf Compare August 7, 2020 18:09
@jnewbery
Copy link
Contributor
jnewbery commented Aug 7, 2020

Code review ACK 9ab4caf

@practicalswift
Copy link
Contributor

Nit: Could add unit tests for the newly introduced functions?

Copy link
Contributor
@fjahr fjahr left a comment

Choose a reason for hiding this comment

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

tested ACK 9ab4caf

On tests: I think it's ok as is in this case because CSHA256 is tested extensively and the GetHash() function is used in several test cases as a utility. If the GetSHA256() would be used inside GetHash() it would be covered through those as well.

@practicalswift
Copy link
Contributor

On tests: I think it's ok as is in this case because CSHA256 is tested extensively and the GetHash() function is used in several test cases as a utility. If the GetSHA256() would be used inside GetHash() it would be covered through those as well.

AFAICT SHA256Uint256 is used in src/script/interpreter.cpp but not tested directly, or indirectly via a call from another tested function.

I don't think we should settle with "OK testing" for consensus critical code -- we want excellent testing :)

@JeremyRubin
Copy link
Contributor Author

We should be hitting the PrecomputedTransactionData init all across the tests, and then validation would fail in numerous places if those have an error.

@JeremyRubin
Copy link
Contributor Author

In fact I'd go as far as to say if this code isn't already widely tested, we have bigger problems (because it would mean we have no tests covering our PrecomputedTransactionData).

@sipa
Copy link
Member
sipa commented Aug 9, 2020

It's also an absolutely trivial function. Testing is important, but there is no point in wasting effort on more than a covering test for a single-line wrapper around otherwise very well-tested code.

6D40

Copy link
Member
@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

Tested ACK 9ab4caf

@jnewbery
Copy link
Contributor

@sipa @instagibbs mind re-reviewing this? It's a fairly basic change and it'd be nice to get it merged to simplify #19055 and #17977

@instagibbs
Copy link
Member

reACK 9ab4caf

@fanquake fanquake merged commit f8462a6 into bitcoin:master Aug 25, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 25, 2020
…Outputs}Hash to SHA256 (Alternative to bitcoin#18071)

9ab4caf Refactor Get{Prevout,Sequence,Outputs}Hash to Get{Prevouts,Sequences,Outputs}SHA256. (Jeremy Rubin)
6510d0f Add SHA256Uint256 helper functions (Jeremy Rubin)
b475d7d Add single sha256 call to CHashWriter (Jeremy Rubin)

Pull request description:

  Opened as an alternative to bitcoin#18071 to be more similar to bitcoin#17977.

  I'm fine with either, deferring to others.

  cc jnewbery Sjors

ACKs for top commit:
  jnewbery:
    Code review ACK 9ab4caf
  jonatack:
    Tested ACK 9ab4caf
  fjahr:
    tested ACK 9ab4caf
  instagibbs:
    reACK bitcoin@9ab4caf

Tree-SHA512: 93a7a47697f1657f027b18407bdcce16963f6b23d12372e7ac8fd4ee96769b3e2639369f9956fee669cc881b6338641cddfeeef1516c7104cb50ef4b880bb0a7
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
470F
Development

Successfully merging this pull request may close these issues.

9 participants
0