Skip to content

Update bitcoin_hashes to 1.0#282

Open
apoelstra wants to merge 4 commits into
ElementsProject:masterfrom
apoelstra:2026-06/hashes-1.0
Open

Update bitcoin_hashes to 1.0#282
apoelstra wants to merge 4 commits into
ElementsProject:masterfrom
apoelstra:2026-06/hashes-1.0

Conversation

@apoelstra

Copy link
Copy Markdown
Member

As part of our project to modernize this library and its dependencies, upgrade to bitcoin_hashes 1.0. This has a number of API improvements:

  • replacing all the Hash trait methods with inherent methods so you don't need to import a trait anymore
  • replacing the fallible from_slice methods with infallible from_byte_array methods
  • removing the hash method and other "compute a hash from arbitrary data" methods on wrapper types like Txid; these should only be constructed in specific prescribed ways

Also includes a followup commit to #279 to improve error typing.

@delta1

delta1 commented Jun 17, 2026

Copy link
Copy Markdown
Member

CI picked up a missing change in elementsd-tests

diff --git a/elementsd-tests/src/pset.rs b/elementsd-tests/src/pset.rs
index 7ce1d95..7b90727 100644
--- a/elementsd-tests/src/pset.rs
+++ b/elementsd-tests/src/pset.rs
@@ -8,7 +8,6 @@ use crate::{setup, Call};

 use bitcoin::{self, Address, Amount};
 use elements::encode::serialize;
-use elements::hashes::Hash;
 use elements::hex::DisplayHex as _;
 use elements::pset::PartiallySignedTransaction;
 use elements::{AssetId, ContractHash};
diff --git a/elementsd-tests/src/taproot.rs b/elementsd-tests/src/taproot.rs
index 8dcc6b1..6b3c4c0 100644
--- a/elementsd-tests/src/taproot.rs
+++ b/elementsd-tests/src/taproot.rs
@@ -10,7 +10,6 @@ use bitcoin::Amount;
 use elements::hex;
 use elements::confidential::{AssetBlindingFactor, ValueBlindingFactor};
 use elements::encode::{deserialize, serialize_hex};
-use elements::hashes::Hash;
 use elements::script::Builder;
 use elements::secp256k1_zkp;
 use elements::sighash::{self, SighashCache};
@@ -215,7 +214,7 @@ fn taproot_spend_test(
         );
         let tweak = secp256k1_zkp::Scalar::from_be_bytes(tweak.to_byte_array()).expect("hash value greater than curve order");
         let sig = secp.sign_schnorr(
-            &secp256k1_zkp::Message::from_digest_slice(&sighash_msg[..]).unwrap(),
+            &secp256k1_zkp::Message::from_digest_slice(sighash_msg.as_byte_array()).unwrap(),
             &output_keypair.add_xonly_tweak(secp, &tweak).unwrap(),
         );

@@ -239,7 +238,7 @@ fn taproot_spend_test(
             .unwrap();

         let sig = secp.sign_schnorr(
-            &secp256k1_zkp::Message::from_digest_slice(&sighash_msg[..]).unwrap(),
+            &secp256k1_zkp::Message::from_digest_slice(sighash_msg.as_byte_array()).unwrap(),
             &test_data.leaf1_keypair,
         );
         ```

@apoelstra apoelstra force-pushed the 2026-06/hashes-1.0 branch from 6ec9fb2 to c2bbe9a Compare June 18, 2026 14:49
@apoelstra

Copy link
Copy Markdown
Member Author

Nice :) two unwraps eliminated there.

@delta1 we want to use the infallible from_digest rather than fallible from_digest_slice in those two places. In general we don't want to use functions with the name _slice in the name unless our data really is variable-length. This way we don't need to unwrap.

And even then we may want to use the internals::SliceExt function to chop them up into compile-time known-length arrays.

@apoelstra apoelstra force-pushed the 2026-06/hashes-1.0 branch 2 times, most recently from e53ca8a to f5876db Compare June 18, 2026 14:53
@apoelstra

Copy link
Copy Markdown
Member Author

ACK f5876db; successfully ran local tests

@apoelstra apoelstra force-pushed the 2026-06/hashes-1.0 branch 2 times, most recently from 40739c1 to 4e00837 Compare June 18, 2026 15:25
@apoelstra

Copy link
Copy Markdown
Member Author

On 4e00837 successfully ran local tests

In ElementsProject#279 we fixed some slicing bugs in a fairly ugly way so that we could
easily backport the bugfixes without API breakage. However, the better
solution is to close the RangeProofMessage type, add a dedicated error
for parsing from an array, and update all callers.

This changes the CT validation logic to allow rangeproofs to contain
embedded asset IDs alongside explicit assets. This differs from Elements
which only allows unblinding an output if both its value and asset
commitment are confidential. However, if the confidential asset is
explicit, it seems like the "right thing to do" to embed the asset ID
and a zero blinding factor. This matches what we do in this library in
TxIn::blind_issuances_with_bfs for example.
@apoelstra apoelstra force-pushed the 2026-06/hashes-1.0 branch from 4e00837 to d2b0605 Compare June 19, 2026 03:47
Oops :) apparently I did not review this code as well as I should have.
This is a fairly big commit but it's mostly mechanical and it didn't seem
super helpful to pull it out into multiple commits. The bulk of the
prepatory work was done in ElementsProject#278.
@apoelstra apoelstra force-pushed the 2026-06/hashes-1.0 branch from d2b0605 to 6b97df8 Compare June 19, 2026 12:00
@apoelstra

Copy link
Copy Markdown
Member Author

Did some nontrivial changes for the new genesis-block stuff from #276. Likely needs re-review.

@apoelstra

Copy link
Copy Markdown
Member Author

On 6b97df8 successfully ran local tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants