Transaction weight calculation

I’ve been exposed to the details of creating a transaction (thanks, @igno.peverell). It contains this equation for transaction weight:

MAX(-1 * num_inputs + 4 * num_change_outputs + 1, 1)

A couple questions:

  • Is MAX really needed – would it be a problem if a negative weight just had a zero fee, as a reward for shrinking the UTXO set?
  • Why are num_change_outputs multiplied by 4, but the recipient’s output is not?
  • Is the maximum block size based on the average weights of previous blocks? Where can I find the details on that, or is it still undecided?

A few answers:

  • Yes. Generally zero cost for operations that still incur one (like the cost of nodes validating and propagating this transaction) is an invitation for attacks.
  • The variable name may not have been very clear in those docs, and it’s missing parentheses, but it is 4 times the total number of outputs.
  • Still undecided, but we do have a proposal for quadratic fee burn.