Skip to content

Instantly share code, notes, and snippets.

@storopoli
Last active May 9, 2024 13:13
Show Gist options
  • Save storopoli/0371af8d27a327f4be17060127fac07b to your computer and use it in GitHub Desktop.
Save storopoli/0371af8d27a327f4be17060127fac07b to your computer and use it in GitHub Desktop.
BDK PR Review Club - 2024-05-09

BDK PR Review Club - 2024-05-09

PR discussed: bitcoindevkit/bdk#1395

  1. Why does BDK needs pseudorandom number generators (PRNG)? Particularly in signing and in building a transaction.

    • Why when signing a tx?

      A: Because of nonces, even if you don't use a PRNG, you get deterministic nonce generated which depends on the private key and the message. Example code in libsecp256k1, and check section 3 of RFC-6979: Deterministic Usage of the Digital Signature Algorithm (DSA) and Elliptic Curve Digital Signature Algorithm (ECDSA).

    • Why when building a tx?

      A: BDK shuffle the inputs and outputs of a transaction, by default. Branch and bound is the default coin selection option.

    • What are the privacy implications of how transaction input/outputs are ordered?

      A: It can hide inferred details of the wallet in the inputs, given that the coin selection algorithm output ordering is randomized now; and also help to make change addresses higher to detect, given that the change addresses in the outputs order is randomized. BDK also uses the single random draw as a fallback to branch and bound during coin selection.

    • What is the impact on users when changing how coin selection behaves?

      A: Susceptible for fingerprinting, given a coin selection default behavior, for example.

    • What are some different coin selection strategies that could replace single random draw? A: full rabbit hole on itself. Check Coin selection on Bitcoin Optech.

  2. How would you bring your own PRNG?

    A: You can do this with rust by using a rand::thread_rng or anything that implements the rand::Rng trait

  3. How would you bring your own PRNG in WASM?

    A: The getrandom crate that provides an interface to the operating system’s random number generator can be used. More specifically the js feature assumes that you are building for an environment containing JavaScript, and will call the appropriate methods. It supports both a web browser and Node.js.

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