Merge remote-tracking branch 'agent/benma-agent/silent-payment-constant-time-ecdh'
What changed, and why it matters
This commit changes how the BitBox02 hardware wallet computes a secret value used in Bitcoin silent payments. Previously, the device used a function that could leak timing information about the secret key through how long the calculation took. The new code uses a constant-time elliptic-curve Diffie-Hellman operation and passes the intermediate public point into the proof creation so the secret is no longer multiplied in a variable-time way. This is a defensive side-channel fix, not an active exploit.
Treat as a security hardening fix. Review whether any other secret-key multiplications in the silent-payments path use variable-time operations, and ensure the ECDH shared-secret output is handled safely (e.g., clearing the uncompressed buffer). No urgent user action is indicated absent evidence of an exploited vulnerability.
Security signals we found
Constant-time cryptographic operation added
Variable-time secret-key multiplication removed
Side-channel hardening for silent payments
libsecp256k1 ECDH module enabled
Evidence from the diff
The patch enables libsecp256k1’s ECDH module and replaces a variable-time PublicKey::mul_tweak of the scan pubkey by the secret a_sum with secp256k1::ecdh::shared_secret_point, which is constant-time. The resulting point c_pubkey is then passed into create_dleq_proof instead of being recomputed inside it with mul_tweak. A later mul_tweak by inputs_hash on the public c_pubkey remains, but the comment notes that inputs_hash and c_pubkey are both known to the host, so that operation does not protect a secret. The change hardens the silent-payment output derivation against timing side-channels.
Changed components
src/rust/streaming-silent-payments/src/lib.rssrc/rust/bitbox-secp256k1/build.rsBitBox02 silent payment output creationInspect captured patch +21 / −12
### src/rust/bitbox-secp256k1/build.rs
@@ -29,6 +29,7 @@ fn main() {
.define("COMB_TEETH", Some("5"))
.define("USE_EXTERNAL_DEFAULT_CALLBACKS", Some("1"))
.define("ENABLE_MODULE_RECOVERY", Some("1")) // needed only in Rust unit tests.
+ .define("ENABLE_MODULE_ECDH", Some("1"))
.define("ENABLE_MODULE_EXTRAKEYS", Some("1"))
.define("ENABLE_MODULE_SCHNORRSIG", Some("1"))
.define("ENABLE_MODULE_ECDSA_ADAPTOR", Some("1"))
### src/rust/streaming-silent-payments/src/lib.rs
@@ -106,7 +106,7 @@ impl InputType {
// a_sum_pubkey is the corresponding pubkey.
// scan_pubkey is the output's silent payment scan pubkey (extracted from the silent payment address).
//
-// We create c_pubkey = a_sum*scan_pubkey and a DLEQ (discrete log equivalence) proof that
+// Given c_pubkey = a_sum*scan_pubkey, create a DLEQ (discrete log equivalence) proof that
// a_sum_pubkey has the same discrete log with respect to the secp256k1 base G as c_pubkey to the
// base scan_pubkey. The result returned to the host is
// `<33 byte compressed c_pubkey><64 byte dleq proof>`.
@@ -118,27 +118,24 @@ impl InputType {
// - verifying using the dleq proof that the discrete log of a_sum_pubkey to G is the same as the
// discrete log of c_pubkey to the base scan_pubkey.
// - re-computing the output (https://github.com/bitcoin/bips/blob/ad1d3bc2a7b0d84247c29f847e85c35283094e2f/bip-0352.mediawiki#creating-outputs)
-// using ecdsa_shared_secret = input_hash·a_sum·scan_pubkey = input_hash·c_pubkey
+// using ecdh_shared_secret = input_hash·a_sum·scan_pubkey = input_hash·c_pubkey
// - verifying that the created output matches the re-computed output.
fn create_dleq_proof(
secp: &Secp256k1<secp256k1::All>,
a_sum: &SecretKey,
a_sum_pubkey: &PublicKey,
scan_pubkey: &PublicKey,
+ c_pubkey: &PublicKey,
) -> Result<[u8; DLEQ_PROOF_SIZE], ()> {
- let c_pubkey = scan_pubkey
- .mul_tweak(secp, &Scalar::from(*a_sum))
- .map_err(|_| ())?;
-
let proof =
- bitbox_secp256k1::dleq_prove(secp, a_sum.as_ref(), scan_pubkey, a_sum_pubkey, &c_pubkey)?;
+ bitbox_secp256k1::dleq_prove(secp, a_sum.as_ref(), scan_pubkey, a_sum_pubkey, c_pubkey)?;
// Sanity check.
bitbox_secp256k1::dleq_verify(
secp,
proof.as_slice().try_into().unwrap(),
scan_pubkey,
a_sum_pubkey,
- &c_pubkey,
+ c_pubkey,
)?;
let mut result = c_pubkey.serialize().to_vec();
@@ -221,10 +218,15 @@ impl<'a> SilentPayment<'a> {
let inputs_hash =
hash::calculate_input_hash(self.smallest_outpoint.as_ref().ok_or(())?, a_sum_pubkey);
- let partial_secret = a_sum.mul_tweak(&inputs_hash).map_err(|_| ())?;
+ let xy = secp256k1::ecdh::shared_secret_point(&scan_pubkey, a_sum);
+ let mut uncompressed = [0u8; secp256k1::constants::UNCOMPRESSED_PUBLIC_KEY_SIZE];
+ uncompressed[0] = 0x04;
+ uncompressed[1..].copy_from_slice(&xy);
+ let c_pubkey = PublicKey::from_slice(&uncompressed).map_err(|_| ())?;
- let ecdh_shared_secret: PublicKey = scan_pubkey
- .mul_tweak(self.secp, &partial_secret.into())
+ // mul_tweak is variable-time. The host knows inputs_hash and receives c_pubkey in the proof.
+ let ecdh_shared_secret = c_pubkey
+ .mul_tweak(self.secp, &inputs_hash)
.map_err(|_| ())?;
// If we want to support more than one silent payment output, we need to get this value from
@@ -242,7 +244,13 @@ impl<'a> SilentPayment<'a> {
Ok(TransactionOutput {
pubkey: reskey_xonly,
- dleq_proof: create_dleq_proof(self.secp, a_sum, &a_sum_pubkey, &scan_pubkey)?,
+ dleq_proof: create_dleq_proof(
+ self.secp,
+ a_sum,
+ &a_sum_pubkey,
+ &scan_pubkey,
+ &c_pubkey,
+ )?,
})
}
}Why this scored 47/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.