-
Notifications
You must be signed in to change notification settings - Fork 22
Add HTLC support to BOLT 3 commitment transaction #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NishantBansal2003
wants to merge
14
commits into
lnfuzz:master
Choose a base branch
from
NishantBansal2003:htlc-commitment
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2707816
smite: extract verify helper for commitment signatures
NishantBansal2003 7e45671
smite: add htlc basepoints to commitment transaction
NishantBansal2003 c1c1c1e
smite: add htlc output witness scripts to commitment transaction
NishantBansal2003 1346c8b
smite: account for htlc in commitment transaction fees
NishantBansal2003 6a4f5d6
smite: add revocable script builder and privkey derivation
NishantBansal2003 c3c38a7
smite: track in-flight htlcs in commitment state
NishantBansal2003 b0b8de6
smite: account for non-dust htlcs in commitment cost
NishantBansal2003 f6311e0
smite: extract build_commitment_tx from sighash computation
NishantBansal2003 bb46421
smite: extract per-commitment keys into TxCreationKeys
NishantBansal2003 a9ab899
smite: sign and verify second-stage HTLC transactions
NishantBansal2003 807fde8
smite: add BOLT 3 Appendix C HTLC commitment test vectors
NishantBansal2003 4afecae
smite: add BOLT 3 Appendix F HTLC commitment test vectors
NishantBansal2003 fe1ff43
smite: add legacy commitment HTLC tests
NishantBansal2003 06279db
smite: add anchor commitment HTLC tests
NishantBansal2003 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -858,7 +858,7 @@ fn build_open_channel(variables: &[Option<Variable>], inputs: &[usize]) -> OpenC | |||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /// Builds a `funding_created` message from 3 input variables. | ||||||||||
| /// Builds a `funding_created` message from 4 input variables. | ||||||||||
| /// | ||||||||||
| /// Channel parameters are read from the negotiated `open_channel` and | ||||||||||
| /// `accept_channel` messages recorded in `negotiations`, ensuring the | ||||||||||
|
|
@@ -876,7 +876,8 @@ fn build_funding_created( | |||||||||
| ) -> Result<FundingCreated, ExecuteError> { | ||||||||||
| let funding_tx = resolve_funding_transaction(variables, inputs[0]); | ||||||||||
| let opener_funding_privkey_bytes = resolve_private_key(variables, inputs[1]); | ||||||||||
| let temporary_channel_id = resolve_channel_id(variables, inputs[2]); | ||||||||||
| let opener_htlc_basepoint_privkey_bytes = resolve_private_key(variables, inputs[2]); | ||||||||||
| let temporary_channel_id = resolve_channel_id(variables, inputs[3]); | ||||||||||
|
|
||||||||||
| let funding_outpoint = OutPoint { | ||||||||||
| txid: funding_tx.tx.compute_txid(), | ||||||||||
|
|
@@ -913,11 +914,16 @@ fn build_funding_created( | |||||||||
| let secp = Secp256k1::new(); | ||||||||||
| let opener_funding_pubkey = PublicKey::from_secret_key(&secp, &opener_funding_privkey); | ||||||||||
|
|
||||||||||
| let opener_htlc_basepoint_privkey = | ||||||||||
| SecretKey::from_slice(&opener_htlc_basepoint_privkey_bytes).expect("valid private key"); | ||||||||||
| let opener_htlc_basepoint = PublicKey::from_secret_key(&secp, &opener_htlc_basepoint_privkey); | ||||||||||
|
|
||||||||||
| let opener = ChannelPartyConfig { | ||||||||||
| funding_pubkey: opener_funding_pubkey, | ||||||||||
| payment_basepoint: open_channel.payment_basepoint, | ||||||||||
| revocation_basepoint: open_channel.revocation_basepoint, | ||||||||||
| delayed_payment_basepoint: open_channel.delayed_payment_basepoint, | ||||||||||
| htlc_basepoint: opener_htlc_basepoint, | ||||||||||
| dust_limit_satoshis: open_channel.dust_limit_satoshis, | ||||||||||
| to_self_delay: open_channel.to_self_delay, | ||||||||||
| }; | ||||||||||
|
|
@@ -926,6 +932,7 @@ fn build_funding_created( | |||||||||
| payment_basepoint: accept_channel.payment_basepoint, | ||||||||||
| revocation_basepoint: accept_channel.revocation_basepoint, | ||||||||||
| delayed_payment_basepoint: accept_channel.delayed_payment_basepoint, | ||||||||||
| htlc_basepoint: accept_channel.htlc_basepoint, | ||||||||||
| dust_limit_satoshis: accept_channel.dust_limit_satoshis, | ||||||||||
| to_self_delay: accept_channel.to_self_delay, | ||||||||||
| }; | ||||||||||
|
|
@@ -947,8 +954,10 @@ fn build_funding_created( | |||||||||
| let holder = HolderIdentity { | ||||||||||
| side: Side::Opener, | ||||||||||
| funding_privkey: opener_funding_privkey, | ||||||||||
| htlc_basepoint_privkey: opener_htlc_basepoint_privkey, | ||||||||||
| }; | ||||||||||
| let signature = config.sign_counterparty_commitment(&state, &holder); | ||||||||||
| let (signature, htlc_signature) = config.sign_counterparty_commitment(&state, &holder); | ||||||||||
| assert!(htlc_signature.is_empty()); // There are no HTLCs in the initial commitment transaction. | ||||||||||
|
Comment on lines
+959
to
+960
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
|
||||||||||
|
|
||||||||||
| let channel_id = ChannelId::v1_from_funding_outpoint(config.funding_outpoint); | ||||||||||
|
|
||||||||||
|
|
@@ -1334,7 +1343,7 @@ fn verify_funding_signed( | |||||||||
|
|
||||||||||
| state | ||||||||||
| .config | ||||||||||
| .verify_counterparty_signature(&state.commitment, &state.holder, &fs.signature) | ||||||||||
| .verify_counterparty_signature(&state.commitment, &state.holder, &fs.signature, &[]) | ||||||||||
| .then_some(()) | ||||||||||
| .ok_or(Violation::InvalidCounterpartySignature(fs.channel_id)) | ||||||||||
| } | ||||||||||
|
|
@@ -3336,19 +3345,28 @@ mod tests { | |||||||||
| } | ||||||||||
|
|
||||||||||
| fn send_funding_created_and_recv_funding_signed_instructions() -> Vec<Instruction> { | ||||||||||
| let opener_htlc_basepoint_privkey = | ||||||||||
| SecretKey::from_str("1111111111111111111111111111111111111111111111111111111111111111") | ||||||||||
| .unwrap() | ||||||||||
| .secret_bytes(); | ||||||||||
|
|
||||||||||
| let mut instrs = create_and_broadcast_tx_instructions(); | ||||||||||
| instrs.extend(vec![ | ||||||||||
| Instruction { | ||||||||||
| operation: Operation::LoadPrivateKey(opener_htlc_basepoint_privkey), | ||||||||||
| inputs: vec![], | ||||||||||
| }, | ||||||||||
| Instruction { | ||||||||||
| operation: Operation::LoadChannelId([0xbb; 32]), | ||||||||||
| inputs: vec![], | ||||||||||
| }, | ||||||||||
| Instruction { | ||||||||||
| operation: Operation::SendFundingCreated, | ||||||||||
| inputs: vec![6, 0, 8], | ||||||||||
| inputs: vec![6, 0, 8, 9], | ||||||||||
| }, | ||||||||||
| Instruction { | ||||||||||
| operation: Operation::RecvFundingSigned, | ||||||||||
| inputs: vec![9], | ||||||||||
| inputs: vec![10], | ||||||||||
| }, | ||||||||||
| ]); | ||||||||||
| instrs | ||||||||||
|
|
@@ -3414,12 +3432,17 @@ mod tests { | |||||||||
| "1552dfba4f6cf29a62a0af13c8d6981d36d0ef8d61ba10fb0fe90da7634d7e13", | ||||||||||
| ) | ||||||||||
| .unwrap(), | ||||||||||
| htlc_basepoint_privkey: SecretKey::from_str( | ||||||||||
| "4444444444444444444444444444444444444444444444444444444444444444", | ||||||||||
| ) | ||||||||||
| .unwrap(), | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| assert!(state.config.verify_counterparty_signature( | ||||||||||
| &state.commitment, | ||||||||||
| &holder, | ||||||||||
| &fc.signature | ||||||||||
| &fc.signature, | ||||||||||
| &[] | ||||||||||
| )); | ||||||||||
|
|
||||||||||
| let pending = executor | ||||||||||
|
|
@@ -3668,13 +3691,13 @@ mod tests { | |||||||||
| operation: Operation::SendChannelReady { | ||||||||||
| include_alias: false, | ||||||||||
| }, | ||||||||||
| inputs: vec![10, 1, 11], | ||||||||||
| inputs: vec![11, 1, 12], | ||||||||||
| }, | ||||||||||
| Instruction { | ||||||||||
| operation: Operation::SendChannelReady { | ||||||||||
| include_alias: true, | ||||||||||
| }, | ||||||||||
| inputs: vec![10, 3, 11], | ||||||||||
| inputs: vec![11, 3, 12], | ||||||||||
| }, | ||||||||||
| ]); | ||||||||||
|
|
||||||||||
|
|
@@ -4004,7 +4027,7 @@ mod tests { | |||||||||
| }, | ||||||||||
| Instruction { | ||||||||||
| operation: Operation::SendFundingCreated, | ||||||||||
| inputs: vec![6, 0, 9], | ||||||||||
| inputs: vec![6, 0, 2, 9], | ||||||||||
| }, | ||||||||||
| Instruction { | ||||||||||
| operation: Operation::RecvFundingSigned, | ||||||||||
|
|
||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we use the same
htlc_basepointthat we sent to the target in theopen_channelmessage?