Skip to content

Commit dc59336

Browse files
committed
Fixup! remove closingNonce(), document signing nonce and verification nonce generation
1 parent aa5020a commit dc59336

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

eclair-core/src/main/scala/fr/acinq/eclair/channel/fsm/Channel.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ class Channel(val nodeParams: NodeParams, val wallet: OnChainChannelFunder with
667667
val finalScriptPubKey = getOrGenerateFinalScriptPubKey(d)
668668
val tlvStream: TlvStream[ShutdownTlv] = if (d.commitments.params.commitmentFormat.useTaproot) {
669669
log.info("generating closing nonce {} with fundingKeyPath = {} fundingTxIndex = {}", closingNonce, d.commitments.latest.localParams.fundingKeyPath, d.commitments.latest.fundingTxIndex)
670-
closingNonce = Some(keyManager.closingNonce(d.commitments.latest.localParams.fundingKeyPath, d.commitments.latest.fundingTxIndex))
670+
closingNonce = Some(keyManager.signingNonce(d.commitments.latest.localParams.fundingKeyPath, d.commitments.latest.fundingTxIndex))
671671
TlvStream(ShutdownTlv.ShutdownNonce(closingNonce.get._2))
672672
} else {
673673
TlvStream.empty
@@ -700,7 +700,7 @@ class Channel(val nodeParams: NodeParams, val wallet: OnChainChannelFunder with
700700
case Right(localShutdownScript) =>
701701
val tlvStream: TlvStream[ShutdownTlv] = if (d.commitments.params.commitmentFormat.useTaproot) {
702702
log.info("generating closing nonce {} with fundingKeyPath = {} fundingTxIndex = {}", closingNonce, d.commitments.latest.localParams.fundingKeyPath, d.commitments.latest.fundingTxIndex)
703-
closingNonce = Some(keyManager.closingNonce(d.commitments.latest.localParams.fundingKeyPath, d.commitments.latest.fundingTxIndex))
703+
closingNonce = Some(keyManager.signingNonce(d.commitments.latest.localParams.fundingKeyPath, d.commitments.latest.fundingTxIndex))
704704
TlvStream(ShutdownTlv.ShutdownNonce(closingNonce.get._2))
705705
} else {
706706
TlvStream.empty
@@ -759,7 +759,7 @@ class Channel(val nodeParams: NodeParams, val wallet: OnChainChannelFunder with
759759
case None =>
760760
val tlvStream: TlvStream[ShutdownTlv] = if (d.commitments.params.commitmentFormat.useTaproot) {
761761
log.info("generating closing nonce {} with fundingKeyPath = {} fundingTxIndex = {}", closingNonce, d.commitments.latest.localParams.fundingKeyPath, d.commitments.latest.fundingTxIndex)
762-
closingNonce = Some(keyManager.closingNonce(d.commitments.latest.localParams.fundingKeyPath, d.commitments.latest.fundingTxIndex))
762+
closingNonce = Some(keyManager.signingNonce(d.commitments.latest.localParams.fundingKeyPath, d.commitments.latest.fundingTxIndex))
763763
TlvStream(ShutdownTlv.ShutdownNonce(closingNonce.get._2))
764764
} else {
765765
TlvStream.empty

eclair-core/src/main/scala/fr/acinq/eclair/crypto/keymanager/ChannelKeyManager.scala

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,27 @@ trait ChannelKeyManager {
4343

4444
def commitmentPoint(channelKeyPath: DeterministicWallet.KeyPath, index: Long): Crypto.PublicKey
4545

46+
/**
47+
* Create a deterministic verification nonce for a specific funding private key and commit tx index. The public nonce will be sent to our peer to create a partial signature
48+
* of our commit tx, the private nonce is never shared (and never serialized or stored) and is used to create our local partial signature to be combined with our peer's.
49+
* @param fundingKeyPath funding key path
50+
* @param fundingTxIndex funding tx index
51+
* @param channelKeyPath channel key path
52+
* @param index commit tx index
53+
* @return a verification nonce that is used to create a partial musig2 signature for our commit tx.
54+
*/
4655
def verificationNonce(fundingKeyPath: DeterministicWallet.KeyPath, fundingTxIndex: Long, channelKeyPath: DeterministicWallet.KeyPath, index: Long): (SecretNonce, IndividualNonce)
4756

57+
/**
58+
* Create a new, randomized singing nonce for a specific funding private key. These nonces are used to create a partial musig2 signature for our peer's commit tx and are sent
59+
* alongside the partial signature. They are created on the fly, and never stored.
60+
* @param fundingKeyPath funding key path
61+
* @param fundingTxIndex funding tx index
62+
* @return a signing nonce that can be used to create a musig2 signature with the funding private key that matches the provided key path and key index.
63+
* Each call to this methode will return a different, randomized signing nonce.
64+
*/
4865
def signingNonce(fundingKeyPath: DeterministicWallet.KeyPath, fundingTxIndex: Long): (SecretNonce, IndividualNonce)
4966

50-
def closingNonce(fundingKeyPath: DeterministicWallet.KeyPath, fundingTxIndex: Long): (SecretNonce, IndividualNonce)
51-
5267
def keyPath(localParams: LocalParams, channelConfig: ChannelConfig): DeterministicWallet.KeyPath = {
5368
if (channelConfig.hasOption(ChannelConfig.FundingPubKeyBasedChannelKeyPath)) {
5469
// deterministic mode: use the funding pubkey to compute the channel key path

eclair-core/src/main/scala/fr/acinq/eclair/crypto/keymanager/LocalChannelKeyManager.scala

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,6 @@ class LocalChannelKeyManager(seed: ByteVector, chainHash: BlockHash) extends Cha
117117
Musig2.generateNonce(sessionId, fundingPrivateKey.privateKey, Seq(fundingPrivateKey.publicKey))
118118
}
119119

120-
override def closingNonce(fundingKeyPath: KeyPath, fundingTxIndex: Long): (SecretNonce, IndividualNonce) = {
121-
val fundingPrivateKey = privateKeys.get(internalKeyPath(fundingKeyPath, hardened(fundingTxIndex)))
122-
val sessionId = randomBytes32()
123-
Musig2.generateNonce(sessionId, fundingPrivateKey.privateKey, Seq(fundingPrivateKey.publicKey))
124-
}
125-
126120
/**
127121
* @param tx input transaction
128122
* @param publicKey extended public key

0 commit comments

Comments
 (0)