Skip to content

Derive BOLT 3 keys from the tweak LND sends - #5

Open
Jossec101 wants to merge 1 commit into
lunar-rails/mainfrom
feat/bolt3-derive-from-tweak
Open

Jossec101 wants to merge 1 commit into
lunar-rails/mainfrom
feat/bolt3-derive-from-tweak

Conversation

@Jossec101

@Jossec101 Jossec101 commented Dec 1, 2026 •

Copy link
Copy Markdown

Why

LND's remote signer receives the BOLT 3 tweak SHA256(per_commitment_point || basepoint) and never the per-commitment point: it is signrpc's single_tweak, and PSBT field 0x51 in LND's remote-signing client. bolt3_derive needs the point, so it cannot serve that signer.

What

  • bolt3::bolt3_derive_from_tweak and bolt3_derive_from_tweak_public_keys give the bolt3_derive result from the tweak. They are secp256k1 only, like the other BOLT 3 calls. A zero, out-of-range or wrong-length tweak is refused.
  • The tweak is only ever added (x + t), never multiplied. A signature under X + t·G is a signature under X on the hash m + r·t, and the session binding fixes t before r exists.
  • DKLs23 0.6.2 has no such call, so libtss applies the shift through Party's public fields, as DKLs23's ShareMap does with a factor of one.
  • C API tss_bolt3_derive_from_tweak and tss_bolt3_derive_from_tweak_pubkey_package, with the header regenerated. Go, WASM, Node, React Native, Python and .NET wrappers. Spec 03, 06 and 07.
  • Tests: the BOLT 3 Appendix E tweak gives the Appendix E local key, and the same shares and package as bolt3_derive. The derived shares sign. Invalid inputs are refused.

Tests

  • cargo test --locked --workspace --release, clippy with -D warnings, cargo fmt --check.
  • Go (-tags libtss_local,libtss_testhooks), Python, .NET and Node against the release build. WASM with wasm-pack test --node --features testing.
  • React Native: the mocked test is included but was not run, because the package has no lockfile.

LND's remote signer is given the BOLT 3 tweak
SHA256(per_commitment_point || basepoint), never the per-commitment
point, so bolt3_derive cannot serve it. LND signs the HTLC and delayed
outputs of a commitment with keys derived this way.

Add bolt3_derive_from_tweak and its public key variant to the core, the
C API and every binding, with tests and spec. DKLs23 0.6.2 has no such
call, so the core applies the shift through Party's public fields, as
ShareMap does with a factor of one. The tweak is only ever added, never
multiplied.
@Jossec101
Jossec101 force-pushed the feat/bolt3-derive-from-tweak branch from 967c482 to 15362c4 Compare December 1, 2026 16:26
@Jossec101
Jossec101 marked this pull request as ready for review December 1, 2026 16:54
@Jossec101
Jossec101 requested a review from itek09 as a code owner December 1, 2026 16:54

@markettes markettes left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

Comment thread libtss/src/bolt3.rs
let tweak = Option::<Scalar>::from(Scalar::from_repr(repr.into()))
.ok_or_else(|| TssError::InvalidConfig("invalid tweak".into()))?;
if bool::from(tweak.is_zero()) {
return Err(bolt3_error(Bolt3Error::HashOutOfRange));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

NIT: why HashOutOfRange?

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