bdk icon indicating copy to clipboard operation
bdk copied to clipboard

timestamp timelocks are not satisfied

Open LLFourn opened this issue 3 years ago • 11 comments

It looks like the logic of finalize_psbt only checks if height based timelocks are satisfied:

                  match desc.satisfy(
                        &mut tmp_input,
                        (
                            PsbtInputSatisfier::new(psbt, n),
                            After::new(current_height, false),
                            Older::new(current_height, create_height, false),
                        ),
                    ) {

In addition, we should check satisfaction of timestamp based timelocks. I will fix this in bdk_core but I thought this was worth noting and fixing ahead of then.

LLFourn avatar Jun 28 '22 02:06 LLFourn

Maybe I could work on this.

wszdexdrf avatar Jul 06 '22 08:07 wszdexdrf

Sure. To do this strictly correctly you need to know the "median time past": https://github.com/bitcoin/bitcoin/blob/a4e066af8573dcefb11dff120e1c09e8cf7f40c2/src/chain.h#L290-L302

I think an implementation on latest block timestamp would be better than nothing though?

LLFourn avatar Jul 06 '22 08:07 LLFourn

Maybe relevant: https://github.com/rust-bitcoin/rust-miniscript/pull/408

LLFourn avatar Jul 12 '22 09:07 LLFourn

I have reached a small hiccup. I was going to get blocktimes (for median time past) from the blockchain object, but then realised there is no way of actually accessing the blockchain inside finalize_psbt (no reference passed as an argument). What should we do here?

wszdexdrf avatar Jul 12 '22 10:07 wszdexdrf

I have reached a small hiccup. I was going to get blocktimes (for median time past) from the blockchain object, but then realised there is no way of actually accessing the blockchain inside finalize_psbt (no reference passed as an argument). What should we do here?

I think just use the last sync height rather than the median time past thingo. Should give pretty good approximation and very rarely make something valid when it is not (and it would not be invalid for long).

(this implies we need to store the time as well as height in DB)

LLFourn avatar Jul 12 '22 13:07 LLFourn

Wait, I'm a bit lost on this: the PR says that this is actually not a problem because miniscript correctly checks for the timestamps as well, so I guess we could close this issue, right?

Or did anybody ever encounter some actual issue trying to finalize a tx with timestamps?

afilini avatar Sep 23 '22 10:09 afilini

Added to alpha release, need to confirm miniscript correctly checks for the timestamps and if so close. Otherwise need to see if/how to fix.

notmandatory avatar Mar 17 '24 23:03 notmandatory

Need a check to see if it remains in alpha @notmandatory

nondiremanuel avatar Mar 21 '24 23:03 nondiremanuel

@ValuedMammal per your note in discord. I found a "threshold" test that includes timelocks in the rust-miniscript plan module, but we're not yet using this. It's possible we don't have any tests right now that confirm timestamp timelocks are satisfied. But it should be possible to create a test similar to the one in the plan module: https://github.com/rust-bitcoin/rust-miniscript/blob/45904881e0d6f27f8b81ab310c4739cc14429a9b/src/plan.rs#L863

notmandatory avatar May 06 '24 00:05 notmandatory