Skip to content

Conversation

benma
Copy link
Collaborator

@benma benma commented Aug 7, 2025

End-goal: reduce the number of secure chip ops when signing a BTC transaction, to reduce the chance of going over the Optiga chip's "rate limit", which induces throttling.

With antiklepto, we derived the private key twice for each input that is signed: once to commit to the nonce, and after that to sign.

This commit decouples the nonce commit and sign functions from the underlying keystore, and allows reusing a private key instead of re-deriving it, which requires secure chip operations.

This halves the number of secure chip ops needed per input when signing a BTC transaction.

We do not reuse the privkey for the other instances of antiklepto (signing a msg, signing an ETH tx), as there it's one commit/sign pair only and unlikely to cause secure chip throttling.

@benma benma requested a review from Beerosagos August 7, 2025 12:35
End-goal: reduce the number of secure chip ops when signing a BTC
transaction, to reduce the chance of going over the Optiga chip's
"rate limit", which induces throttling.

With antiklepto, we derived the private key twice for each input that
is signed: once to commit to the nonce, and after that to sign.

This commit decouples the nonce commit and sign functions from the
underlying keystore, and allows reusing a private key instead of
re-deriving it, which requires secure chip operations.

This halves the number of secure chip ops needed per input when
signing a BTC transaction.

We do not reuse the privkey for the other instances of
antiklepto (signing a msg, signing an ETH tx), as there it's one
commit/sign pair only and unlikely to cause secure chip throttling.
@@ -98,7 +98,10 @@ pub async fn process(
// Engage in the anti-klepto protocol if the host sends a host nonce commitment.
Some(pb::AntiKleptoHostNonceCommitment { ref commitment }) => {
let signer_commitment = keystore::secp256k1_nonce_commit(
keypath,
crate::keystore::secp256k1_get_private_key(keypath)?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it make sense to zeroize the privkey here and in the other places?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The return type of secp256k1_get_private_key is zeroize::Zeroizing<Vec<u8>>, so it should zeroize automatically at the end of the statement.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Aha! I missed that, sorry :)

Copy link
Collaborator

@Beerosagos Beerosagos left a comment

Choose a reason for hiding this comment

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

utACK!

@benma benma merged commit ae18fce into BitBoxSwiss:master Aug 19, 2025
32 checks passed
@benma benma deleted the reduce-sc-ops branch August 19, 2025 14:04
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.

2 participants