Page MenuHomePhabricator

Add a CHashWriter::GetSHA256() method to compute a single sha256
ClosedPublic

Authored by PiRK on Mar 9 2022, 14:55.

Details

Summary

This is a partial backport of core#19601

The unbackported part of the PR is currently only used by Bitcoin Core for Taproot related code, so I don't excpect we will need it. The backported method is needed in the MuHash3072 implementation.

The test vectors are from https://www.di-mgt.com.au/sha_testvectors.html

Test Plan

ninja all check-all

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

PiRK requested review of this revision.Mar 9 2022, 14:55

Tail of the build log:

Build 'Bitcoin ABC Diffs / Diff Testing' #43675, branch 'refs/tags/phabricator/diff/32639'
Triggered 2022-03-09 14:55:24 by 'Phabricator Staging (phabricator-staging)'
Started 2022-03-09 14:55:26 on agent 'buildagent1'
Finished 2022-03-09 14:55:31 with status FAILURE 'Snapshot dependency failed to start: Automated Deployments / Bitcoin ABC Infra / Bitcoin-ABC Infra Checkout'
VCS revisions: 'PhabBitcoinAbcStagingRo' (Git, instance id 18): 'N/A' (checkout rules: '+:. => ./bitcoin-abc')
TeamCity URL https://build.bitcoinabc.org/viewLog.html?buildId=364253&buildTypeId=BitcoinABC_BitcoinAbcStaging 
TeamCity server version is 2019.2.4 (build 72059), server timezone: GMT (UTC)

[14:55:24]E: bt15 (running for 6s)
[14:55:24]i: TeamCity server version is 2019.2.4 (build 72059)
[14:55:24] : Collecting changes in 2 VCS roots
[14:55:24] :	 [Collecting changes in 2 VCS roots] VCS Root details
[14:55:24] :		 [VCS Root details] "phab-bitcoin-abc-staging-ro" {instance id=18, parent internal id=14, parent id=PhabBitcoinAbcStagingRo, description: "https://reviews.bitcoinabc.org/source/bitcoin-abc-staging.git#refs/heads/master"}
[14:55:24] :		 [VCS Root details] "abc-infrastructure" {instance id=7, parent internal id=7, parent id=AutomatedDeployments_BitcoinAbcDeveloperTools_AbcInfrastructure, description: "ssh://vcs@reviews.bitcoinabc.org:2221/source/infrastructure.git#refs/heads/master"}
[14:55:26] : The build is removed from the queue to be prepared for the start
[14:55:31]W: This build has not been started because some of the builds it depends on failed to start
[14:55:31]E: Snapshot dependency "Automated Deployments / Bitcoin ABC Infra / Bitcoin-ABC Infra Checkout" failed
[14:55:31] : Build finished

Tail of the build log:

Build 'Bitcoin ABC Diffs / Diff Testing' #43677, branch 'refs/tags/phabricator/diff/32639'
Triggered 2022-03-09 14:55:24 by 'Phabricator Staging (phabricator-staging)'
Started 2022-03-09 14:55:42 on agent 'buildagent1'
Finished 2022-03-09 14:55:48 with status FAILURE 'Snapshot dependency failed to start: Automated Deployments / Bitcoin ABC Infra / Bitcoin-ABC Infra Checkout'
VCS revisions: 'PhabBitcoinAbcStagingRo' (Git, instance id 18): 'N/A' (checkout rules: '+:. => ./bitcoin-abc')
TeamCity URL https://build.bitcoinabc.org/viewLog.html?buildId=364255&buildTypeId=BitcoinABC_BitcoinAbcStaging 
TeamCity server version is 2019.2.4 (build 72059), server timezone: GMT (UTC)

[14:55:24]E: bt15 (running for 24s)
[14:55:24]i: TeamCity server version is 2019.2.4 (build 72059)
[14:55:24] : Collecting changes in 2 VCS roots (15s)
[14:55:24] :	 [Collecting changes in 2 VCS roots] VCS Root details
[14:55:24] :		 [VCS Root details] "phab-bitcoin-abc-staging-ro" {instance id=18, parent internal id=14, parent id=PhabBitcoinAbcStagingRo, description: "https://reviews.bitcoinabc.org/source/bitcoin-abc-staging.git#refs/heads/master"}
[14:55:24] :		 [VCS Root details] "abc-infrastructure" {instance id=7, parent internal id=7, parent id=AutomatedDeployments_BitcoinAbcDeveloperTools_AbcInfrastructure, description: "ssh://vcs@reviews.bitcoinabc.org:2221/source/infrastructure.git#refs/heads/master"}
[14:55:42] : The build is removed from the queue to be prepared for the start
[14:55:48]W: This build has not been started because some of the builds it depends on failed to start
[14:55:48]E: Snapshot dependency "Automated Deployments / Bitcoin ABC Infra / Bitcoin-ABC Infra Checkout" failed
[14:55:48] : Build finished

Tail of the build log:

Build 'Bitcoin ABC Diffs / Diff Testing' #43676, branch 'refs/tags/phabricator/diff/32639'
Triggered 2022-03-09 14:55:24 by 'Phabricator Staging (phabricator-staging)'
Started 2022-03-09 14:55:41 on agent 'buildagent2'
Finished 2022-03-09 14:55:49 with status FAILURE 'Snapshot dependency failed to start: Automated Deployments / Bitcoin ABC Infra / Bitcoin-ABC Infra Checkout'
VCS revisions: 'PhabBitcoinAbcStagingRo' (Git, instance id 18): 'N/A' (checkout rules: '+:. => ./bitcoin-abc')
TeamCity URL https://build.bitcoinabc.org/viewLog.html?buildId=364257&buildTypeId=BitcoinABC_BitcoinAbcStaging 
TeamCity server version is 2019.2.4 (build 72059), server timezone: GMT (UTC)

[14:55:24]E: bt15 (running for 25s)
[14:55:24]i: TeamCity server version is 2019.2.4 (build 72059)
[14:55:24] : Collecting changes in 2 VCS roots (15s)
[14:55:24] :	 [Collecting changes in 2 VCS roots] VCS Root details
[14:55:24] :		 [VCS Root details] "phab-bitcoin-abc-staging-ro" {instance id=18, parent internal id=14, parent id=PhabBitcoinAbcStagingRo, description: "https://reviews.bitcoinabc.org/source/bitcoin-abc-staging.git#refs/heads/master"}
[14:55:24] :		 [VCS Root details] "abc-infrastructure" {instance id=7, parent internal id=7, parent id=AutomatedDeployments_BitcoinAbcDeveloperTools_AbcInfrastructure, description: "ssh://vcs@reviews.bitcoinabc.org:2221/source/infrastructure.git#refs/heads/master"}
[14:55:24]i:	 [Collecting changes in 2 VCS roots] Loading current repository state for VCS root 'abc-infrastructure' (15s)
[14:55:41] : The build is removed from the queue to be prepared for the start
[14:55:49]W: This build has not been started because some of the builds it depends on failed to start
[14:55:49]E: Snapshot dependency "Automated Deployments / Bitcoin ABC Infra / Bitcoin-ABC Infra Checkout" failed
[14:55:49] : Build finished

Tail of the build log:

Build 'Bitcoin ABC Diffs / Diff Testing' #43678, branch 'refs/tags/phabricator/diff/32639'
Triggered 2022-03-09 14:55:24 by 'Phabricator Staging (phabricator-staging)'
Started 2022-03-09 14:55:58 on agent 'buildagent1'
Finished 2022-03-09 14:56:03 with status FAILURE 'Snapshot dependency failed to start: Automated Deployments / Bitcoin ABC Infra / Bitcoin-ABC Infra Checkout'
VCS revisions: 'PhabBitcoinAbcStagingRo' (Git, instance id 18): 'N/A' (checkout rules: '+:. => ./bitcoin-abc')
TeamCity URL https://build.bitcoinabc.org/viewLog.html?buildId=364263&buildTypeId=BitcoinABC_BitcoinAbcStaging 
TeamCity server version is 2019.2.4 (build 72059), server timezone: GMT (UTC)

[14:55:24]E: bt15 (running for 38s)
[14:55:24]i: TeamCity server version is 2019.2.4 (build 72059)
[14:55:24] : Collecting changes in 2 VCS roots (31s)
[14:55:24] :	 [Collecting changes in 2 VCS roots] VCS Root details
[14:55:24] :		 [VCS Root details] "phab-bitcoin-abc-staging-ro" {instance id=18, parent internal id=14, parent id=PhabBitcoinAbcStagingRo, description: "https://reviews.bitcoinabc.org/source/bitcoin-abc-staging.git#refs/heads/master"}
[14:55:24] :		 [VCS Root details] "abc-infrastructure" {instance id=7, parent internal id=7, parent id=AutomatedDeployments_BitcoinAbcDeveloperTools_AbcInfrastructure, description: "ssh://vcs@reviews.bitcoinabc.org:2221/source/infrastructure.git#refs/heads/master"}
[14:55:25]i:	 [Collecting changes in 2 VCS roots] Loading current repository state for VCS root 'phab-bitcoin-abc-staging-ro' (31s)
[14:55:58] : The build is removed from the queue to be prepared for the start
[14:56:03]W: This build has not been started because some of the builds it depends on failed to start
[14:56:03]E: Snapshot dependency "Automated Deployments / Bitcoin ABC Infra / Bitcoin-ABC Infra Checkout" failed
[14:56:03] : Build finished

Tail of the build log:

Build 'Bitcoin ABC Diffs / Diff Testing' #43679, branch 'refs/tags/phabricator/diff/32639'
Triggered 2022-03-09 14:55:24 by 'Phabricator Staging (phabricator-staging)'
Started 2022-03-09 14:56:02 on agent 'buildagent2'
Finished 2022-03-09 14:56:11 with status FAILURE 'Snapshot dependency failed to start: Automated Deployments / Bitcoin ABC Infra / Bitcoin-ABC Infra Checkout'
VCS revisions: 'PhabBitcoinAbcStagingRo' (Git, instance id 18): 'N/A' (checkout rules: '+:. => ./bitcoin-abc')
TeamCity URL https://build.bitcoinabc.org/viewLog.html?buildId=364259&buildTypeId=BitcoinABC_BitcoinAbcStaging 
TeamCity server version is 2019.2.4 (build 72059), server timezone: GMT (UTC)

[14:55:24]E: bt15 (running for 46s)
[14:55:24]i: TeamCity server version is 2019.2.4 (build 72059)
[14:55:24] : Collecting changes in 2 VCS roots (35s)
[14:55:24] :	 [Collecting changes in 2 VCS roots] VCS Root details
[14:55:24] :		 [VCS Root details] "phab-bitcoin-abc-staging-ro" {instance id=18, parent internal id=14, parent id=PhabBitcoinAbcStagingRo, description: "https://reviews.bitcoinabc.org/source/bitcoin-abc-staging.git#refs/heads/master"}
[14:55:24] :		 [VCS Root details] "abc-infrastructure" {instance id=7, parent internal id=7, parent id=AutomatedDeployments_BitcoinAbcDeveloperTools_AbcInfrastructure, description: "ssh://vcs@reviews.bitcoinabc.org:2221/source/infrastructure.git#refs/heads/master"}
[14:55:24]i:	 [Collecting changes in 2 VCS roots] Loading current repository state for VCS root 'phab-bitcoin-abc-staging-ro' (31s)
[14:55:24]i:	 [Collecting changes in 2 VCS roots] Loading current repository state for VCS root 'abc-infrastructure' (35s)
[14:56:02] : The build is removed from the queue to be prepared for the start
[14:56:11]W: This build has not been started because some of the builds it depends on failed to start
[14:56:11]E: Snapshot dependency "Automated Deployments / Bitcoin ABC Infra / Bitcoin-ABC Infra Checkout" failed
[14:56:11] : Build finished
Fabien added inline comments.
src/hash.cpp
87 ↗(On Diff #32639)

CSHA256::OUTPUT_SIZE

src/script/interpreter.cpp
1532 ↗(On Diff #32639)

I don't understand this change, this is strictly worst than the previous version. Is that required for a follow up or something ?

src/script/interpreter.cpp
1532 ↗(On Diff #32639)

The single sha256 is going to be used in D11150 for MuHash3072.

I suspect Core is going to move away from double sha256 in new features (taproot... etc). I saw Pieter Wuille mention double hashing does not provide any benefit : https://bitcoin.stackexchange.com/questions/110065/checksum-sha256sha256prefixdata-why-double-hashing/110142#110142

PiRK planned changes to this revision.Mar 10 2022, 11:13
PiRK retitled this revision from Refactoring CHashWriter & Get{Prevouts,Sequence,Outputs}Hash to SHA256 to Add a CHashWriter::GetSHA256() method to compute a single sha256.
PiRK edited the summary of this revision. (Show Details)

Remove changes and new wrapper function (SHA256Uint256) that I do not expect we will need because they are only used in taproot related code by Bitcoin Core.
Add a unit test for the new GetSHA256 method.

Tail of the build log:

Build 'Bitcoin ABC Diffs / Diff Testing' #43709, branch 'refs/tags/phabricator/diff/32650'
Triggered 2022-03-10 15:41:19 by 'Phabricator Staging (phabricator-staging)'
Started 2022-03-10 15:41:22 on agent 'buildagent1'
Finished 2022-03-10 15:41:28 with status FAILURE 'Snapshot dependency failed to start: Automated Deployments / Bitcoin ABC Infra / Bitcoin-ABC Infra Checkout'
VCS revisions: 'PhabBitcoinAbcStagingRo' (Git, instance id 18): 'N/A' (checkout rules: '+:. => ./bitcoin-abc')
TeamCity URL https://build.bitcoinabc.org/viewLog.html?buildId=364338&buildTypeId=BitcoinABC_BitcoinAbcStaging 
TeamCity server version is 2019.2.4 (build 72059), server timezone: GMT (UTC)

[15:41:19]E: bt15 (running for 8s)
[15:41:19]i: TeamCity server version is 2019.2.4 (build 72059)
[15:41:19] : Collecting changes in 2 VCS roots
[15:41:19] :	 [Collecting changes in 2 VCS roots] VCS Root details
[15:41:19] :		 [VCS Root details] "phab-bitcoin-abc-staging-ro" {instance id=18, parent internal id=14, parent id=PhabBitcoinAbcStagingRo, description: "https://reviews.bitcoinabc.org/source/bitcoin-abc-staging.git#refs/heads/master"}
[15:41:19] :		 [VCS Root details] "abc-infrastructure" {instance id=7, parent internal id=7, parent id=AutomatedDeployments_BitcoinAbcDeveloperTools_AbcInfrastructure, description: "ssh://vcs@reviews.bitcoinabc.org:2221/source/infrastructure.git#refs/heads/master"}
[15:41:22] : The build is removed from the queue to be prepared for the start
[15:41:28]W: This build has not been started because some of the builds it depends on failed to start
[15:41:28]E: Snapshot dependency "Automated Deployments / Bitcoin ABC Infra / Bitcoin-ABC Infra Checkout" failed
[15:41:28] : Build finished

Tail of the build log:

Build 'Bitcoin ABC Diffs / Diff Testing' #43710, branch 'refs/tags/phabricator/diff/32650'
Triggered 2022-03-10 15:41:19 by 'Phabricator Staging (phabricator-staging)'
Started 2022-03-10 15:41:37 on agent 'buildagent1'
Finished 2022-03-10 15:41:43 with status FAILURE 'Snapshot dependency failed to start: Automated Deployments / Bitcoin ABC Infra / Bitcoin-ABC Infra Checkout'
VCS revisions: 'PhabBitcoinAbcStagingRo' (Git, instance id 18): 'N/A' (checkout rules: '+:. => ./bitcoin-abc')
TeamCity URL https://build.bitcoinabc.org/viewLog.html?buildId=364340&buildTypeId=BitcoinABC_BitcoinAbcStaging 
TeamCity server version is 2019.2.4 (build 72059), server timezone: GMT (UTC)

[15:41:19]E: bt15 (running for 23s)
[15:41:19]i: TeamCity server version is 2019.2.4 (build 72059)
[15:41:19] : Collecting changes in 2 VCS roots (15s)
[15:41:19] :	 [Collecting changes in 2 VCS roots] VCS Root details
[15:41:19] :		 [VCS Root details] "phab-bitcoin-abc-staging-ro" {instance id=18, parent internal id=14, parent id=PhabBitcoinAbcStagingRo, description: "https://reviews.bitcoinabc.org/source/bitcoin-abc-staging.git#refs/heads/master"}
[15:41:19] :		 [VCS Root details] "abc-infrastructure" {instance id=7, parent internal id=7, parent id=AutomatedDeployments_BitcoinAbcDeveloperTools_AbcInfrastructure, description: "ssh://vcs@reviews.bitcoinabc.org:2221/source/infrastructure.git#refs/heads/master"}
[15:41:19]i:	 [Collecting changes in 2 VCS roots] Loading current repository state for VCS root 'abc-infrastructure' (15s)
[15:41:37] : The build is removed from the queue to be prepared for the start
[15:41:43]W: This build has not been started because some of the builds it depends on failed to start
[15:41:43]E: Snapshot dependency "Automated Deployments / Bitcoin ABC Infra / Bitcoin-ABC Infra Checkout" failed
[15:41:43] : Build finished

Tail of the build log:

Build 'Bitcoin ABC Diffs / Diff Testing' #43711, branch 'refs/tags/phabricator/diff/32650'
Triggered 2022-03-10 15:41:19 by 'Phabricator Staging (phabricator-staging)'
Started 2022-03-10 15:41:37 on agent 'buildagent2'
Finished 2022-03-10 15:41:44 with status FAILURE 'Snapshot dependency failed to start: Automated Deployments / Bitcoin ABC Infra / Bitcoin-ABC Infra Checkout'
VCS revisions: 'PhabBitcoinAbcStagingRo' (Git, instance id 18): 'N/A' (checkout rules: '+:. => ./bitcoin-abc')
TeamCity URL https://build.bitcoinabc.org/viewLog.html?buildId=364342&buildTypeId=BitcoinABC_BitcoinAbcStaging 
TeamCity server version is 2019.2.4 (build 72059), server timezone: GMT (UTC)

[15:41:19]E: bt15 (running for 24s)
[15:41:19]i: TeamCity server version is 2019.2.4 (build 72059)
[15:41:19] : Collecting changes in 2 VCS roots (15s)
[15:41:19] :	 [Collecting changes in 2 VCS roots] VCS Root details
[15:41:19] :		 [VCS Root details] "phab-bitcoin-abc-staging-ro" {instance id=18, parent internal id=14, parent id=PhabBitcoinAbcStagingRo, description: "https://reviews.bitcoinabc.org/source/bitcoin-abc-staging.git#refs/heads/master"}
[15:41:19] :		 [VCS Root details] "abc-infrastructure" {instance id=7, parent internal id=7, parent id=AutomatedDeployments_BitcoinAbcDeveloperTools_AbcInfrastructure, description: "ssh://vcs@reviews.bitcoinabc.org:2221/source/infrastructure.git#refs/heads/master"}
[15:41:19]i:	 [Collecting changes in 2 VCS roots] Loading current repository state for VCS root 'phab-bitcoin-abc-staging-ro' (15s)
[15:41:37] : The build is removed from the queue to be prepared for the start
[15:41:44]W: This build has not been started because some of the builds it depends on failed to start
[15:41:44]E: Snapshot dependency "Automated Deployments / Bitcoin ABC Infra / Bitcoin-ABC Infra Checkout" failed
[15:41:44] : Build finished

Tail of the build log:

Build 'Bitcoin ABC Diffs / Diff Testing' #43712, branch 'refs/tags/phabricator/diff/32650'
Triggered 2022-03-10 15:41:20 by 'Phabricator Staging (phabricator-staging)'
Started 2022-03-10 15:41:54 on agent 'buildagent1'
Finished 2022-03-10 15:41:58 with status FAILURE 'Snapshot dependency failed to start: Automated Deployments / Bitcoin ABC Infra / Bitcoin-ABC Infra Checkout'
VCS revisions: 'PhabBitcoinAbcStagingRo' (Git, instance id 18): 'N/A' (checkout rules: '+:. => ./bitcoin-abc')
TeamCity URL https://build.bitcoinabc.org/viewLog.html?buildId=364348&buildTypeId=BitcoinABC_BitcoinAbcStaging 
TeamCity server version is 2019.2.4 (build 72059), server timezone: GMT (UTC)

[15:41:20]E: bt15 (running for 38s)
[15:41:20]i: TeamCity server version is 2019.2.4 (build 72059)
[15:41:20] : Collecting changes in 2 VCS roots (31s)
[15:41:20] :	 [Collecting changes in 2 VCS roots] VCS Root details
[15:41:20] :		 [VCS Root details] "phab-bitcoin-abc-staging-ro" {instance id=18, parent internal id=14, parent id=PhabBitcoinAbcStagingRo, description: "https://reviews.bitcoinabc.org/source/bitcoin-abc-staging.git#refs/heads/master"}
[15:41:20] :		 [VCS Root details] "abc-infrastructure" {instance id=7, parent internal id=7, parent id=AutomatedDeployments_BitcoinAbcDeveloperTools_AbcInfrastructure, description: "ssh://vcs@reviews.bitcoinabc.org:2221/source/infrastructure.git#refs/heads/master"}
[15:41:20]i:	 [Collecting changes in 2 VCS roots] Loading current repository state for VCS root 'phab-bitcoin-abc-staging-ro' (31s)
[15:41:54] : The build is removed from the queue to be prepared for the start
[15:41:58]W: This build has not been started because some of the builds it depends on failed to start
[15:41:58]E: Snapshot dependency "Automated Deployments / Bitcoin ABC Infra / Bitcoin-ABC Infra Checkout" failed
[15:41:58] : Build finished

Tail of the build log:

Build 'Bitcoin ABC Diffs / Diff Testing' #43713, branch 'refs/tags/phabricator/diff/32650'
Triggered 2022-03-10 15:41:19 by 'Phabricator Staging (phabricator-staging)'
Started 2022-03-10 15:41:57 on agent 'buildagent2'
Finished 2022-03-10 15:42:02 with status FAILURE 'Snapshot dependency failed to start: Automated Deployments / Bitcoin ABC Infra / Bitcoin-ABC Infra Checkout'
VCS revisions: 'PhabBitcoinAbcStagingRo' (Git, instance id 18): 'N/A' (checkout rules: '+:. => ./bitcoin-abc')
TeamCity URL https://build.bitcoinabc.org/viewLog.html?buildId=364344&buildTypeId=BitcoinABC_BitcoinAbcStaging 
TeamCity server version is 2019.2.4 (build 72059), server timezone: GMT (UTC)

[15:41:19]E: bt15 (running for 42s)
[15:41:19]i: TeamCity server version is 2019.2.4 (build 72059)
[15:41:19] : Collecting changes in 2 VCS roots (35s)
[15:41:19] :	 [Collecting changes in 2 VCS roots] VCS Root details
[15:41:19] :		 [VCS Root details] "phab-bitcoin-abc-staging-ro" {instance id=18, parent internal id=14, parent id=PhabBitcoinAbcStagingRo, description: "https://reviews.bitcoinabc.org/source/bitcoin-abc-staging.git#refs/heads/master"}
[15:41:19] :		 [VCS Root details] "abc-infrastructure" {instance id=7, parent internal id=7, parent id=AutomatedDeployments_BitcoinAbcDeveloperTools_AbcInfrastructure, description: "ssh://vcs@reviews.bitcoinabc.org:2221/source/infrastructure.git#refs/heads/master"}
[15:41:19]i:	 [Collecting changes in 2 VCS roots] Loading current repository state for VCS root 'phab-bitcoin-abc-staging-ro' (31s)
[15:41:19]i:	 [Collecting changes in 2 VCS roots] Loading current repository state for VCS root 'abc-infrastructure' (35s)
[15:41:57] : The build is removed from the queue to be prepared for the start
[15:42:02]W: This build has not been started because some of the builds it depends on failed to start
[15:42:02]E: Snapshot dependency "Automated Deployments / Bitcoin ABC Infra / Bitcoin-ABC Infra Checkout" failed
[15:42:02] : Build finished
This revision is now accepted and ready to land.Mar 11 2022, 09:07