Skip to content

Scalar tweaks for DKLs23 key shares - #9

Draft
Jossec101 wants to merge 6 commits into
0xCarbon:mainfrom
Lunar-Rails:upstream/scalar-tweaks
Draft

Jossec101 wants to merge 6 commits into
0xCarbon:mainfrom
Lunar-Rails:upstream/scalar-tweaks

Conversation

@Jossec101

Copy link
Copy Markdown
Contributor

Why

Lightning derives a fresh key for every channel state by adding a number to its base key, or by multiplying it (see 0xCarbon/DKLs23#97). If a Lightning node is backed by a threshold key, every party has to apply the same tweak to its own share. Apps reach DKLs23 through libtss, so libtss needs to expose it.

What

  • tweak_add and tweak_mul for DKLs23 shares, in Rust, the C API (tss_tweak_add, tss_tweak_mul) and every binding.
  • libtss calls the new DKLs23 API and adds only the handle, the input checks and the bindings. The math stays in DKLs23, so there is one copy to review.
  • Scalars are 32 bytes, big-endian. A wrong length is InvalidConfig. A zero factor or an identity result is TweakError. Any other suite is ProtocolMismatch.
  • End-to-end tests: DKG, then tweak, then sign, then verify under the tweaked key.

Depends on

CI runs clippy on the latest stable with -D warnings, and that version
rejects uninlined format args, so every pull request fails before its own
changes are even checked.

Inlines the four format! calls it flags, in the tokio example, the FFI
memory hardening test and the protocol tests.
A wallet service hands out a new address for every customer or payment,
and today each one needs every party to run derive_child. The group key
plus the chain code make a BIP-32 xpub, so a server can derive addresses
on its own, and they match the ones the parties later sign for.

Adds chain_code() to the key share handle, in Rust, the C API
(tss_handle_chain_code) and every binding. DKLs23 returns the chain code
made at DKG; FROST Taproot returns the value derive.rs already uses,
through one shared helper. Other suites return ProtocolMismatch. Tests
check child keys against a separate BIP-32 implementation, and the FFI
tests get a shared DKG and signing driver.
Parties lose shares: a disk dies, a server is replaced, a backup is bad.
Today the only fix is a new DKG, which means a new key, new addresses and
moving every coin on chain. Repair brings the lost party back under the
same key.

Each helper sends the lost party one masked term; the masks cancel, so
the party learns its own share and nothing about the helpers'. It checks
the sum against its verifying share and stops on a mismatch. The rebuilt
share has no OT state, so signing refuses it until a complete refresh
across all parties gives every share new randomness and new OT state.
secp256k1 only for now, with C API and Go bindings, and tests in Rust,
the FFI and Go.
Repair and the complete refresh add new functions and a new kind of key
share, a rebuilt one that can't sign yet, so readers of the spec need to
know how they fit with the rest of the API.

Updates the API design, FFI and key management pages: the repair flow,
the hollow share and when it can sign again, the complete refresh, and the
three new C functions.
Lightning derives a fresh key for every channel state by adding a number
to its base key, or multiplying it. If the node is backed by a threshold
key, every party has to apply the same tweak to its own share, and apps
reach DKLs23 through libtss.

Adds tweak_add and tweak_mul for DKLs23 shares in Rust, the C API
(tss_tweak_add, tss_tweak_mul) and every binding. The math is DKLs23's
Party and PublicKeyPackage tweak API; libtss parses the 32-byte scalar,
picks the address function and wraps the result in a new handle. Tests
cover DKG, tweak, sign and verify under the tweaked key at the Rust, FFI,
Go, Node and Python layers.
The tweak commit calls Party::tweak_add and friends, which only exist on
the DKLs23 pull request that adds them, so this branch can't build
against DKLs23 main yet.

Points the two dkls23 crates at that pull request's branch on our fork,
and moves sha3 to rc.9, which the keccak version DKLs23 now pulls in
needs. Revert this commit once the DKLs23 change is on main.
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.

1 participant