Friday, September 20, 2024
HomeBitcoinblockchain - Implementing Conditional Fund Locking in Bitcoin Just like Ethereum's Sensible...

blockchain – Implementing Conditional Fund Locking in Bitcoin Just like Ethereum’s Sensible Contracts


There’s rather a lot distinction between ethereum and bitcoin relating to locking and unlocking fund, however let me roughly examine.

  1. Locking Funds

In contrast to ethereum, most transaction of bitcoin itself is an motion of locking fund, utilizing sensible contract referred to as “Script”. You possibly can construct ScriptPubKey with “Script”, and transaction is an motion of sending bitcoin to ScriptPubKey. You may assume most transaction of bitcoin is a bit much like deploying ethereum sensible contract which locks ethereum.

  1. Unlocking Situations

To unlock bitcoin transaction, it’s important to present ScriptSig(or Witness for segwit), which has to cross the situation of ScriptPubKey to spend. ScriptSig consists of information to cross the situation of ScriptPubKey. For instance, if ScriptPubKey requires signature verifiable with particular public key, signature could be positioned into ScriptSig. Unlocking situation will be any of mixture applied with ”Script”, and time-based situations or fulfilling sure cryptographic proofs will be. Hash Time Lock Contract will be applied as effectively.

  1. Instruments and Practices

There is a description about ”Script”, or Miniscript can also be extensively used. Or simply search bitcoin library in GitHub along with your most well-liked language.

  1. Any insights or steering on method conditional fund locking in Bitcoin much like Ethereum’s sensible contracts

Commonest sensible contracts of bitcoin are p2pkh, p2wpkh and p2tr(key-path), which is analogous to Ethereum Switch Transaction with out calling sensible contract(i.e. simply switch eth by signing tx). It requires the fund proprietor to signal transaction(and supply public key if not p2tr). Nevertheless, as talked about above, most transaction of bitcoin is an motion of locking fund, so it means p2pkh, p2wpkh, and p2tr(key-path) are additionally means of locking fund utilizing sensible contract, of which unlocking situation is to supply signature(and public key if not p2tr).

Different sensible contracts of bitcoin will be applied with p2sh, p2wsh and p2tr(tapscript). p2sh and p2wsh is technique to ship bitcoin to hash of sensible contract(ScriptPubKey), which is the hash of redeem script(or witness script if segwit). To spend this, you must present each locking script and unlocking script in ScriptSig(or Witness for segwit. For extra element, verify BIP16).
p2tr(tapscript) is utilizing MAST to lock and unlock bitcoin(For extra element verify BIP341).

You possibly can simply ship to reveal ScriptPubKey as an alternative of above requirements, but it surely’s positively not beneficial.

Under is an instance of HTLC in bitcoin.

OP_IF
    blockheight_or_utc 
    OP_CHECKLOCKTIMEVERIFY
    OP_DROP
    
OP_ELSE
    OP_SHA256
    preimage_hash
    OP_EQUALVERIFY
    
OP_ENDIF
OP_CHECKSIG

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments