Skip to content

Fix spurious panic on bogus funding txn that confirm and are spent #1585

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

Merged

Conversation

TheBlueMatt
Copy link
Collaborator

In c02b6a3 we moved the
payment_preimage copy from inside the macro which only runs if we
are spending an output we know is an HTLC output to doing it for
any script that matches our expected length. This can panic if an
inbound channel is created with a bogus funding transaction that
has a witness program of the HTLC-Success/-Offered length but which
does not have a second-to-last witness element which is 32 bytes.

Luckily this panic is relatively simple for downstream users to
work around - if an invalid-length-copy panic occurs, simply remove
the ChannelMonitor from the bogus channel on startup and run
without it. Because the channel must be funded by a bogus script in
order to reach this panic, the channel will already have closed by
the time the funding transaction is spent, and there can be no
local funds in such a channel, so removing the ChannelMonitor
wholesale is completely safe.

In order to test this we have to disable an in-line assertion that
checks that our transactions match expected scripts which we do by
checking for the specific bogus script that we now use in
test_invalid_funding_tx.

Thanks to Eugene Siegel for reporting this issue.

@TheBlueMatt TheBlueMatt added this to the 0.0.109 milestone Jul 1, 2022
ariard
ariard previously approved these changes Jul 1, 2022
Copy link

@ariard ariard left a comment

Choose a reason for hiding this comment

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

Code Review ACK 9d91dac, in conformity to what have been reviewed elsewhere.

@TheBlueMatt TheBlueMatt mentioned this pull request Jul 1, 2022
@TheBlueMatt TheBlueMatt force-pushed the 2022-06-copy_from_slice-sucks branch 2 times, most recently from 1f80fad to dfc6a32 Compare July 1, 2022 14:30
@TheBlueMatt
Copy link
Collaborator Author

Oops, had some rebase errors in use statements, had to resolve that.

Copy link

@ariard ariard left a comment

Choose a reason for hiding this comment

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

Code Review ACK dfc6a32

Changes since last push :

  • removing the use for Transaction, TxOut, TxIn, OutPoint as BitcoinOutPoint in functional tests
  • removing the use for Witness in functional tests

In c02b6a3 we moved the
`payment_preimage` copy from inside the macro which only runs if we
are spending an output we know is an HTLC output to doing it for
any script that matches our expected length. This can panic if an
inbound channel is created with a bogus funding transaction that
has a witness program of the HTLC-Success/-Offered length but which
does not have a second-to-last witness element which is 32 bytes.

Luckily this panic is relatively simple for downstream users to
work around - if an invalid-length-copy panic occurs, simply remove
the ChannelMonitor from the bogus channel on startup and run
without it. Because the channel must be funded by a bogus script in
order to reach this panic, the channel will already have closed by
the time the funding transaction is spent, and there can be no
local funds in such a channel, so removing the `ChannelMonitor`
wholesale is completely safe.

In order to test this we have to disable an in-line assertion that
checks that our transactions match expected scripts which we do by
checking for the specific bogus script that we now use in
`test_invalid_funding_tx`.

Thanks to Eugene Siegel for reporting this issue.
@TheBlueMatt TheBlueMatt force-pushed the 2022-06-copy_from_slice-sucks branch from dfc6a32 to 6c480ae Compare July 1, 2022 14:47
@TheBlueMatt
Copy link
Collaborator Author

Oops, sorry, one more, looks like Vec::from(array) needed const generics which we don't support.

Copy link

@ariard ariard left a comment

Choose a reason for hiding this comment

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

One More Time Code Review ACK 6c480ae 🎵

Oops, sorry, one more, looks like Vec::from(array) needed const generics which we don't support.

Hmmm, the previous branch built well on my local host. Some issue with bindings or other platforms than x86_64 ?

@TheBlueMatt
Copy link
Collaborator Author

Hmmm, the previous branch built well on my local host. Some issue with bindings or other platforms than x86_64 ?

It was an MSRV issue.

Copy link
Contributor

@dunxen dunxen left a comment

Choose a reason for hiding this comment

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

ACK 6c480ae

// in-line tests later.

#[cfg(test)]
pub fn deliberately_bogus_accepted_htlc_witness_program() -> Vec<u8> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks all bogus to me, but perhaps the beginning of a new age techno rap.

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.

4 participants