Skip to content

Instantly share code, notes, and snippets.

@Crypt-iQ
Last active March 1, 2023 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Crypt-iQ/b0b2294467d61c2ba03508e97f829de5 to your computer and use it in GitHub Desktop.
Save Crypt-iQ/b0b2294467d61c2ba03508e97f829de5 to your computer and use it in GitHub Desktop.
taproot-2nd-level-htlc-timeout-weights

HTLC Timeout Transaction Weight

  • htlc_timeout_script: 70 bytes

    • OP_DATA: 1 byte (local_htlcpubkey length)
    • local_htlcpubkey: 33 bytes
    • OP_CHECKSIGVERIFY: 1 byte
    • OP_DATA: 1 byte (remote_htlcpubkey length)
    • remote_htlcpubkey: 33 bytes
    • OP_CHECKSIG: 1 byte
  • htlc_timeout_control_block: 65 bytes

    • c[0] & 0xfe: leaf version
    • c[1:33]: p
    • c[33:65]: hash of htlc_success
  • htlc_timeout_input_witness: 269 bytes

    • number_of_witness_elements: 1 byte
    • local_schnorr_sig_length: 1 byte
    • local_schnorr_sig: 64 bytes
    • remote_schnorr_sig_length: 1 byte
    • remote_schnorr_sig: 65 bytes
    • htlc_timeout_script_length: 1 byte
    • htlc_timeout_script: 70 bytes
    • htlc_timeout_control_block_length: 1 byte
    • htlc_timeout_control_block: 65 bytes
  • htlc_timeout_txin_0: 41 bytes (excl. witness)

    • previous_out_point: 36 bytes
      • hash: 32 bytes
      • index: 4 bytes
    • var_int: 1 byte (script_sig length)
    • script_sig: 0 bytes
    • witness: <---- part of the witness data
    • sequence: 4 bytes
  • htlc_timeout_second_level_output: 43 bytes

    • value: 8 bytes
    • var_int: 1 byte (pk_script length)
    • pk_script (p2tr): 34 bytes
  • htlc timeout transaction: 94 bytes (excl. witness)

    • version: 4 bytes
    • witness_header: <---- part of the witness data
    • count_tx_in: 1 byte
    • tx_in: 41 bytes
      • htlc_timeout_txin_0: 41 bytes
    • count_tx_out: 1 byte
    • tx_out: 43 bytes
      • htlc_timeout_second_level_output: 43 bytes
    • lock_time: 4 bytes
  • Multiplying non-witness data by 4 gives a weight of:

    • htlc_timeout_transaction_weight = 94vbytes * 4 = 376WU
  • Adding the witness data:

    • htlc_timeout_transaction_weight += (htlc_timeout_input_witness + witness_header)
    • htlc_timeout_transaction_weight = 647WU
  • Minimum relay feerate is 250 satoshis per kWU

  • 250sats/1000WU * 647WU = 161.75sats

  • If 161.75sats is rounded down, then this is 161 satoshis and is below the minimum relay fee of 162 satoshis. Bitcoin Core will use a ceiling instead of the rounding down that the BOLTs currently use. See https://github.com/bitcoin/bitcoin/blob/74981aa02d2b14ad1c0b82d1eb09cf3169eaa8ae/src/policy/feerate.cpp#L29

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