Skip to content

Conversation

@shinghim
Copy link
Contributor

@shinghim shinghim commented Jul 15, 2025

Estimation can only occur if the P2TR input is a key spend, since we can't reliably predict the size of potential unlocking scripts

Closes #788

Estimation can only occur if the P2TR input is a key spend, since
we can't reliably predict the size of potential unlocking scripts
Copy link
Collaborator

@arminsabouri arminsabouri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for grabbing this ticket! I realize this is in draft but I wanted to leave my initial thoughts on the approach taken.

},
P2tr => Ok(InputWeightPrediction::P2TR_KEY_DEFAULT_SIGHASH),
P2tr => {
// Script spends can't be predicted, so we don't support those
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to use the same strategy as #862 at least for the sender where final_script_witness should be provided for all inputs.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One strategy is to first look at whats on the witness stack. We have two cases:

  1. You have one element per bip341 we assume its a key spend. If a non-default sighash is used then we need to account for an extra witness byte.
  2. greater than one witness elements. In which case you can do what we did in Derive weight from witness for p2wsh inputs #862.

If witness is not provided then we can't know how much the input will weight. We need to rely on the application to provide this information (#772).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to use the same strategy as #862 at least for the sender where final_script_witness should be provided for all inputs.

IIUC, this would be for a finalized psbt, and the checks i currently have here would be for unfinalized psbts. Would we want to support both finalized and unfinalized psbts? If so, I should keep the existing checks and add the checks for final_script_witness, right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we want to support both finalized and unfinalized psbts? If so, I should keep the existing checks and add the checks for final_script_witness, right?

yes, exactly. We want to support finalized and unfinalized txs. For the final_script_witness & input.segwit checks we can probably extract what exists for p2wsh and create a common method.

}

#[cfg(test)]
mod tests {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other input pair test live in /src/core/psbt.rs. Any reason these new tests aren't added there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, i didn't see. I just had them here since that's where the method that's being tested is located, but i can move it

@arminsabouri
Copy link
Collaborator

Paging @shinghim are you still planning on working on this?

@shinghim
Copy link
Contributor Author

@arminsabouri sorry, got carried away with some other stuff, feel free to work on this

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.

Incorrectly estimating taproot satisfiability weights

2 participants