jcnelson / clarity-bitcoin

Clarity library for parsing Bitcoin transactions and verifying Merkle proofs
GNU Affero General Public License v3.0
35 stars 12 forks source link

How to verify flash block btc transactions ? #1

Open friedger opened 3 years ago

friedger commented 3 years ago

To verify bitcoin txs the burnchain header hash is verified using: (get-block-info? burnchain-header-hash block-height)

For btc transactions in flash blocks, i.e. btc blocks that don't have corresponding stx blocks there is no way to verify the btc tx in clarity. Correct?

BTC blocks : |1| -- |2| -- |3| -- |4|
STX blocks:  |1| --     -- |2| -- |3|

Txs in BTC block 2 can't be verified.

Would (get-block-info? burnchain-header-hash 2) return the header hash of btc block 3?

jcnelson commented 3 years ago

(get-block-info? burnchain-header-hash X) takes a Bitcoin block height for X, so it should work. The Stacks node processes all Bitcoin blocks and has all their header hashes, even if some of them don't have Stacks blocks attached to them.

friedger commented 3 years ago

(get-block-info? burnchain-header-hash X) takes a Bitcoin block height for X

@jcnelson Does it?

Calling get-block-info with e.g. stacks block 11319 on https://explorer.stacks.co/txid/ST2PABAF9FTAJYNFZH93XENAJ8FVY99RRM4DF2YCW.block-info?chain=testnet returns

(tuple 
  (burnchain-header-hash (some 0x0000000000000020d1f8c2ef300d9590069396ff40611f16fd660ae74f86fc44)) 
  (header-hash (some 0x13588072c8b4eca88a505db5c453123c5c91db98d90ac1cd124402dba596531e)) 
  (id-header-hash (some 0xbb527bf66002e33ed82916c89b989448684040e69b46c8d09eab35c0ec3c440c)) 
  (miner-address (some ST2X2FYCY01Y7YR2TGC2Y6661NFF3SMH0NGXPWTV5)) 
  (time (some u1620494526)) 
  (vrf-seed (some 0xbf945361dbdbcb0a43e8d6984ab8eee14982d0341eab198fc74d2d917c6d95dc)))

The burnchain header hash is the hash of bitcoin block 1974723 https://www.blockchain.com/btc-testnet/block/0000000000000020d1f8c2ef300d9590069396ff40611f16fd660ae74f86fc44

jcnelson commented 3 years ago

Yes, you're right. I checked the code. Relevant issue: https://github.com/blockstack/stacks-blockchain/issues/2663

cryptopanter commented 3 years ago

To verify bitcoin txs the burnchain header hash is verified using: (get-block-info? burnchain-header-hash block-height)

For btc transactions in flash blocks, i.e. btc blocks that don't have corresponding stx blocks there is no way to verify the btc tx in clarity. Correct?

BTC blocks : |1| -- |2| -- |3| -- |4|
STX blocks:  |1| --     -- |2| -- |3|

Txs in BTC block 2 can't be verified.

Would (get-block-info? burnchain-header-hash 2) return the header hash of btc block 3?

But anyway you can get the tx verification

To verify bitcoin txs the burnchain header hash is verified using: (get-block-info? burnchain-header-hash block-height)

For btc transactions in flash blocks, i.e. btc blocks that don't have corresponding stx blocks there is no way to verify the btc tx in clarity. Correct?

BTC blocks : |1| -- |2| -- |3| -- |4|
STX blocks:  |1| --     -- |2| -- |3|

Txs in BTC block 2 can't be verified.

Would (get-block-info? burnchain-header-hash 2) return the header hash of btc block 3?

But anyway, can you get the tx verification of that flash block in the next Btc transaction?... I mean it's about a delay or you can never verify Bitcoin tx in the missed 2nd block?!... I am asking this bcuz for some Dapp you need to verify if a Btc transaction is done successfully or not!

friedger commented 3 years ago

@cryptopanter No, currently, you can get the bitcoin txs of btc blocks that are not an achor block of the stacks chain.

cryptopanter commented 3 years ago

@cryptopanter No, currently, you can get the bitcoin txs of btc blocks that are not an achor block of the stacks chain.

We can or we can't?... 👉 Anchor block...