Skip to main content

How Bitcoin transactions work

Skip to content

Sirus Shahini

How Bitcoin transactions work

July 16, 2017 Cyrus.ShCryptograhpy

Introduced in 2009, bitcoin appeared as the most remarkable digital cryptocurrecy. The theory behind bitcoin is to how to send some amount of money to someone directly without the need for any intermediary and in a secure manner which both guarantees the integrity of the payment data and its authorization. Unfortunately the official documents are difficult for many people and developers who are not familiar with the concept. In this post, with a simple literature I tried to clarify bitcoin transactions as simple as possible. It is expected the reader would assimilate the exact idea behind bitcoin transactions and authorization system after reading the post thoroughly . So please read till the end of if you are interested.

Bitcoin transactions use a peer-to-peer system to transfer digital coins. It may be interesting to know there is actually not any records of the coins stored anywhere. In fact there is no coin! These are the transactions that specify how much bitcoin each person has. Transactions are chained together in a manner that makes it nearly impossible for an attacker to manipulate any part of what we know as the block chain. A new block is added to the whole blockchain after mining new bitcoins, but in this article we only focus on how an individual sends some specified amount of bitcoin to another.

Let’s start simple. Consider a payment system named arbitrarily LockCoin. We use LockCoin as an analogy with the real bitcoin transactions.
We have Alice here who wants to send some money to Bob. This is the scenario to send this money in a way that only Bob and no one else would be able to get the money and use it:

Alice has a magic safe (we are talking here about physical money and safe not digital!) and the safe has been magically designed in a way that after someone puts some money inside it, it can only be opened by the key of the recipient of that money. Anybody else may have their own key but none of them can access the money inside the safe except the recipient.Bob receives the money and since the money is actually destined to him, he can open the safe by his private key and access the money.Now if Bob wants to send this money to someone else, the money goes through same stages; he puts the money inside the safe and closes it. The safe remains closed until the true recipient of the money inside arrives with his personal key!

Figure below depicts this scenario; only the specific key whose owner is the recipient can open the safe:

The idea behind a transaction in bitcoin system is more or less the same; only the valid user will be able to spend the amount of bitcoin another party previously has sent to him. To understand how this is possible, you should see the way a transaction is structured. That is understanding the format of a transaction and the steps involved for verifying it. First let’s look at a transaction different parts.

The two main elements of a transaction are input and output. We may have more than one output in each transaction; i.e. we can send bitcoins to multiple parties. For the sake of simplicity we only consider a transaction with one input and one output then you can do some inferring yourself to understand how other cases work. Outputs of a transaction are indexed starting from zero, thus for our example the output index is always 0 since we only have one output in the transaction.
A transaction is spending an old output, creating a new output.
This is the general structure of a single such transaction:

TXID: Every transaction has a unique ID to be identified among other transactions. Remember a transaction is shown as TX and we will use this abbreviation later.A TXID referring to a previous transaction whose output is gonna be spent. We call it oldTXVOUT: The output index of the output in oldTX which as stated before is 0.ScriptSig: Explained shortlyAmount of bitcoin to deliver to the party. This must be less than or equal to the output’s amount in oldTX. This is the amount of the new output. We suppose it to be equal to the amount of the output of oldTX. i.e we are going to spend all of the output of oldTX.ScriptPubKey: Conditions to authorize spending the new transaction in future. This is explained in more details shortly.VOUT: Again 0The receiver bitcoin address. (Explained shortly)

The most remarkable parts are bitcoin address, ScriptSig, scriptPubKey

Bitcoin Address:

Each party participating in the transaction procedure has a key pair used in public key cryptography which establishes the main security and integrity aspects of cryptocurrencies. Public key encryption as opposed to symmetric encryption uses two keys instead of one for encryption/decryption processes. A bitcoin address is the hashed version of one’s public key. Each person who’s going to request payment and provide others with a means to send him money, delivers his bitcoin address using which others can send him bitcoin.
Bitcoin uses Elliptic Curve Digital Signature Algorithm and as previously introduced, the system calculates the hash of the public key before publishing it. This has two main benefits:
1. The hash is transformed to another shorter string using base58 encoding algorithm. The final string has only those ASCII characters which are less prone to human errors while reading them. For example it may have “1” but not “l”.  The full characters allowed to be part of bitcoin address are as follows:

123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz

2. Using the calculations related to key generation in bitcoin protocol, if we have a private key we can deterministically derive the corresponding public key but the reverse is not possible so far. That is by having the public key, there is no solution yet to calculate the private key. But to make everything safer, bitcoin avoids disclosing the public key until the output is spent. This eliminates the chance of reconstructing the private key from public key in a possible future attack.

The sender of bitcoin needs to have receiver’s address to associate the output of transaction to the owner of the address.

An output with any specific address which is the hashed version of a public key can be spent by anyone who has the corresponding private key and no one else.

Here the public key is only a means for the receiver to prove he is the true and valid receiver. We will see how this is possible.

Now we need to remind you the definition of a transaction in bitcoin once again:

A transaction means spending a previously-made output of a previous transaction.

Each transaction has two fundamental parts: input and output

The input provides the proof to be the receiver of and spend an old output.
The output specifies the receiver of the transaction – or the receiver of the money which the transaction is made to deliver.

Look at the figure below. I tried to visualize what I mean by the few lines above. Suppose that Andy has already sent Alice some bitcoins. So transaction Andy->Alice is the old transaction here. Now Alice wants to spend the received bitcoins from the old transaction and send them to Bob.

As you can see we have TX1 (transaction number one which has been issued in a previous time by Andy) and TX2 (transaction number two which we want to create now to send same amount of bitcoins to Bob’s address specified in output2)
The input in TX2 is actually spending the money sent to Alice whose address is specified in output1. But in order to do this, Alice needs to prove she is the the one who Andy has actually sent the bitcoins to and consequently the owner of the bitcoins. Alice does this by using ScriptSig.

ScriptSig:

This is where the bitcoin system (the miners to be more specific) looks into to find the necessary items needed to prove the person who has the associated private key actually issued the new transaction. In fact Alice must have the corresponding private key to the public key of output1. And since she is really the person who Andy has sent the money to and she is the person that Andy used her public key to specify the sender, then she can compose a valid ScriptSig using her private key which satisfies the conditions available in scriptPubKey of TX1.

ScriptPubKey

Each output has a scriptPubKey part that specifies the receiver of the transaction. The receiver later needs to prove his authenticity using the ScriptSig of a future transaction he makes.

Now we need to see how scriptPubKey and ScriptSig are made and how they associate with each other.
Bitcoin system uses a scripting language to compose scriptPubKey and ScriptSig. This scripting language has its own syntax and opcodes and also uses a software simulated stack as its temporary memory. For a detailed explanation of this scripting language please refer to the related bitcoin wiki. We just explain how these two parts are made and used to verify a transaction which is enough to understand how transactions properly work.
scriptPubKey is defined as follows:

scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG

Focus on the transaction you already saw in the figure above. Having Andy sent bitcoins to Alice, the scriptPubKey of TX1 would be something like this:

scriptPubKey: OP_DUP OP_HASH160 <Public Key Hash of Alice> OP_EQUALVERIFY OP_CHECKSIG

ScriptSig is simply the combination of the signature and the associated public key with the private key using which the signature has been made.

scriptSig: <signature> <Public Key>

Referring back to our example we have ScriptSig of TX2 like this:

scriptSig: <signature of Alice> <Public Key of Alice>

Okay. Now the system uses the script written in scriptPubKey of TX1 and ScriptSig of TX2 to verify the authenticity of the transaction sent by Alice. To do this it first pushes on the stack the contents of the ScriptSig (stack contents in line2 of the table below) then executes scriptPubKey one command at a time.

 

nStackScriptDescription1Empty.<sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIGscriptSig and scriptPubKey are combined.2<sig> <pubKey>OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIGConstants are added to the stack.3<sig> <pubKey> <pubKey>OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIGTop stack item is duplicated.4<sig> <pubKey> <pubHashA><pubKeyHash> OP_EQUALVERIFY OP_CHECKSIGTop stack item is hashed.5<sig> <pubKey> <pubHashA> <pubKeyHash>OP_EQUALVERIFY OP_CHECKSIGConstant added.6<sig> <pubKey>OP_CHECKSIGEquality is checked between the top two stack items.7trueEmpty.Signature is checked for top two stack items.

This is the process of verifying the transaction step by step:

OP_DUP: This duplicates the top entry of the stack which is pubkey of ScriptSig. See the result in line 3OP_HASH160: Calculates the hash of the top entry of the stack and removes the entry before pushing the hash onto the stack. See the result in line 4.Then pubKeyHash which was present in scriptPubKey of TX1 is pushed onto the stack. See the result in line 4OP_EQUALVERIFY: Compares the calculated Hash and pubKeyHash at top of the stack then removes both from the stack. Up to this point if the two aforementioned values are equal it is shown that the sender of TX2 has actually the public key whose hashed value existed in TX1 scriptPubKey. (Remember only the hashed version of one’s public key is published using the bitcoin address not the plain version) This is the point where the public key is disclosed and this is one of the reasons it is better not to use a same bitcoin address to receive bitcoin for more than once. See the result in line 6.OP_CHECKSIG: This is the final phase which the system goes through to check whether the sender is the Alice herself. This can be done by checking the signature -that Alice has made using her private key and is provided in ScriptSig of TX2- against the public key in the same ScriptSig. In theory there’s no difference what to sign to verify the a signature (having a signature and the public key giving that we know what has been signed is enough to verify a signature) but in bitcoin, the entire transaction is signed (except script parts) to not only verify the owner but also to make the transaction resistant against any modification by attackers. If the signature matches the public key then the transaction is valid.

If a transaction is verified without an error the new output becomes “An Unspent Transaction Output”; abbreviated as UTXO. Also note an output need not be sent totally to a single person and you can break it into parts sending to different parties. But we did not cover that since it’s not relevant to our purpose of writing this article. But in practice you can even spend only a part of a UTXO; sending a fraction of it to another person and receiving back the remainder in a new bitcoin address belonged to yourself. (For example if I have 1 bitcoin and want to send Bob 0.2 of it, I cannot keep the 0.8 of old output, the output must be spent altogether but instead I send 0.2 of it to Bob and send 0.8 of it to another one of my own addresses. This makes a valid UTXO with 0.8 a bitcoin worth amount sent to my bitcoin address along with an output specifying Bob as the receiver of 0.2 a bitcoin so that in future I can spend the former and Bob can spend the later.)

After the transaction of our example passes the verification, Bob would be able to spend the output of TX2 since he is now the owner of the output as long as he possesses his private key. I think you can simply relate this to the example of our hypothetical LockCoin system we proposed at the beginning of the post.

Feel free to contact me or write comments if any of these I’ve written here still seems vague to you.

 

Please donate

Post navigation

How does the processor differentiate between signed and unsigned numbers?

One thought on “How Bitcoin transactions work”

Dop says:

July 20, 2017 at 11:08 am

Thank you!

Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Comment 

Name *

Email *

Website

CONTACT

Mail
sirus.shahini@gmail.com

Twitter
https://twitter.com/_BitWar

LinkedIn
https://www.linkedin.com/in/sirus-shahini-040a6162/
 

SEARCH

Search for:

How Bitcoin transactions work

How does the processor differentiate between signed and unsigned numbers?

A Simple Low Level Example of How Pointers Work in C

Tinkering with Linux Execution Environment(3)

Instagram Private Profiles Are Open to MITM Attacks

Home 

About Donation

Powered by WordPress | Theme: Astrid by aThemes.

Comments

Popular posts from this blog

50 HIGH PR FORUMS AND BOOKMARKING SITES FOR BACKLINKS

50 HIGH PR FORUMS AND BOOKMARKING SITES FOR BACKLINKS http://answers.microsoft.com/en-us http://archiveoflinks.com / http://community.sitepoint.com / http://de.lirio.us / http://del.icio.us / http://dondir.com / http://filesharingtalk.com / http://forum.deviantart.com / http://forum.joomla.org / http://forums.cnet.com / http://forums.hostgator.com / http://forums.mysql.com / http://forums.searchenginewatch.com / http://simplemachines.org/community/index.php http://www.247webdirectory.com / http://www.2daydir.com / http://www.9dir.com/Submit http://www.9sites.net / http://www.9w1.net / http://www.a1webdirectory.org / http://www.abacusseo.com / http://www.abc-directory.com / http://www.abigdir.com / http://www.acewebdirectory.com / http://www.add2us.com / http://www.addbusiness.net / http://www.addlink.us / http://www.addlinkzfree.com / http://www.addsite.info / http://www.afreeurl.info / http://www.agrieducation.org / http://www.alistdirectory.com / http...
200++ high pr eductinon&goverment site backline As We know how important backlinks are for rankings in Google for a blog/site and page rank which definitely is the trusted way to show how well your blog is which most advertiser look for.I have come up with top .gov & .edu website by registering where you can get backlinks easily.Sograb these backlinsk and see the magic how  your website ranks on Google with these high PR boosting .gov and .edu backlinks.A high quality backlinks worth thousands low quality backlinks, especially the one coming fromedu and .gov sites. Google loves backlinks from.edu & .gov sites and thus give your site good ranking in SERPs. An edu & .’gov backlinks is associated with an educational institute & government organization therefore considered asmost authentic and valued backlink in term of SEO because they are from non-profit source givequality information, not a spam one and since exists for long time in the field, have high ...

How to Hack Website

inurl:/editor/editor/filemanager Just open uploadtest.html Or test.html Then select PHP server Upload file Copy uploaded file url Paste it after the link Www.xyz.com //.... Enjoy Regards :- HACKER 22385

Abdul hacker deface page

Abdul hacker deface page     <EMBED src=" http://greencall.co.kr/.p/we_will_not_go_down.swf " type="application/x-shockwave-flash" wmode="transparent" width="1" height="1">     <html>         <body onload="scrlsts()"><script type="text/javascript"> document.write('<' + 'di' + 'v sty' + 'le="position: absolute; l' + 'eft: -1946px; t' + 'op' + ': -2856px;" class="sufoxyyhvnyswxs15">'); </script> <a href=" http://cergyd7.dev2.cmantika.com/includes/index.php ">installment loans california bad credit</a> <a href=" http://www.diamondwares.net/logs/index.php ">online cash loan direct lenders</a> <a href=" http://armastroy.com/templates/index.php ">easy loan kota kinabalu</a> <a href=" http://www.magazinecambodia.com/templates/index....

Blogs on Computer Security:

Blogs on Computer Security: https://antelox.blogspot.com / http://www.dumpanalysis.org/blog / http://www.abuse.ch / http://zairon.wordpress.com / http://androguard.blogspot.com / http://blog.w4kfu.com / http://akhenath0n.blogspot.com / http://diarrlf.wordpress.com / http://deobfuscated.blogspot.com / http://www.h-i-r.net / http://mysterie.fr/blog / http://www.skullsecurity.org/blog / http://www.wrgross.com/blogs/security / http://net-effects.blogspot.com / http://eiploader.wordpress.com / http://cyb3rsleuth.blogspot.com / http://0entropy.blogspot.com / http://siri-urz.blogspot.com / http://newsoft-tech.blogspot.com / http://www.ragestorm.net/blogs / http://codeexploration.blogspot.com / http://esploit.blogspot.com / http://thexploit.com / http://mysterie.fr/blog / http://bailey.st/blog / http://touchmymalware.blogspot.ru / http://blog.delroth.net / http://novahackers.blogspot.com / http://greatis.com/blog / http://mcdermottcybersecurity.com / http://grand...

Various Forums

JuanDeLemos: 1. Kali Linux http://distrowatch.com/kali   http://www.kali.org/  http://forums.kali.org/ Kali Linux (formerly known as BackTrack) is a Debian-based distribution with a collection of security and forensics tools. It features timely security updates, support for the ARM architecture, a choice of four popular desktop environments, and seamless upgrades to newer versions. 2. Tails  http://distrowatch.com/tails  https://tails.boum.org/  https://tails.boum.org/support/index.en.html https://mailman.boum.org/listinfo/ The Amnesic Incognito Live System (Tails) is a Debian-based live CD/USB with the goal of providing complete Internet anonymity for the user. The product ships with several Internet applications, including web browser, IRC client, mail client and instant messenger, all pre-configured with security in mind and with all traffic anonymised. To achieve this, Incognito uses the Tor network to make Internet traffic very hard to trace...

Darkweb and Deepweb llinks latest 2017 Huge collection!!!!

hi guys... as u know deep web and darkweb is most dangeorus part of the internet... but without site link....what where will u surf it ... so i did some reasearch and get the collection.... hope u like it.. Gonzalo Nuñez: 1. Xillia (was legit back in the day on markets) http://cjgxp5lockl6aoyg.onion 2. http://cjgxp5lockl6aoyg.onion/worldwide-cardable-sites-by-alex 3. http://cjgxp5lockl6aoyg.onion/selling-paypal-accounts-with-balance-upto-5000dollars 4. http://cjgxp5lockl6aoyg.onion/cloned-credit-cards-free-shipping 5. 6. ——————————————————————————————- 7. 8. 9. UNSORTED 10. 11. Amberoad http://amberoadychffmyw.onion 12. KognitionsKyrkan http://wd43uqrbjwe6hpre.onion 13. Malina http://malina2ihfyawiau.onion 14. BB Compendium http://jq.26zp5ygkpszripvv.onion 15. Hackbb pages index (cauti...

hacking tools and lab

Resources (Free) Virtual Networks (VPNs) • ChaosVPN: http://wiki.hamburg.ccc.de/ChaosVPN • Gh0st Networks: http://www.gh0st.net / • Hacking Lab: https://www.hacking-lab.com / • p0wnlabs: http://p0wnlabs.com / • pwn0: https://pwn0.com / • PentestIT: https://lab.pentestit.ru / Custom Personal Targets • Hack A Server: https://hackaserver.com / • Hack Me: http://hack.me / • Hack This: https://www.hackthis.co.uk / • Smash The Stack: http://smashthestack.org / • Hack The Box: https://www.hackthebox.gr / • SecAdvise: https://labs.secadvise.com / • DarkHive: http://darkhive.net / • Avatao: https://avatao.com / • Root-Me: https://www.root-me.org / Archive/Repository • Security Conference Library: http://archive.liquidmatrix.org / • Shell-Storm.org Repository: http://repo.shell-storm.org/CTF / Misc • Bug crowd: ht...

open a new bitcoin account and made double money

open a new bitcoin account and made double money MenuAbout UsContact Us Privacy Policy Disclaimer Sitemap  Main MenuBlogging tipsBlog designing  Blog traffic How TosMake Money Online  How to open a bitcoin account, earn, double your earnings and withdraw your money to physical cash. Bloggers Prof 11:12:00 AM  4 I recently discovered that people are now interested in bitcoin because of its high rate of popularity now in telegram, but nevertheless, I would be talking today on  how to get money into your bitcoin wallet  and how to go about your funds, weather you would withdraw it or you sell it to someone, I talked about everything you need to know about bitcoin and how to create your wallet, create your wallet let's move to today's deal. There are many ways to get  money into your wallet,   you can buy and you can also earn it , I want to show you list of sites you can earn bits from fast, Afte...

Tor Darkweb Link

Tor link max telegram big acker: https://cardedlxzxsphu5y.onion/ SHOP FOR BUYING CARDED PRODUCTS https://2or24opd2hkebadv.onion/index.php  TORBAY FORUM chickencaptain: http://kpynyvym6xqi7wz2.onion/ parazite files and links max telegram big acker: https://kr5hou2zh4qtebqk.onion.cab/ezines/ ARCHIEVE OF SOME VINTAGE AS WELL AS NEW STUFFS https://superkuhbitj6tul.onion/library/ LIBRARY OF BOOKS ON VARIOUS TOPICS https://yuxv6qujajqvmypv.onion/ GUIDE ON USING AN SECURE OPERATING SYSTEM https://bpo4ybbs2apk4sk4.onion/en A COLLECTION OF TOOLS RELATED TO SECURITY P4RN3R: https://ondemand5xot4hdw.onion/  Tor On Demand max telegram big acker: https://f3mnl42ax3qtu3a7.onion/ GOVT LEAKS https://kzspryu63qbjfncp.onion/  DIGITAL PAWN SHOP https://yniir5c6cmuwslfl.onion/ STRANGE WEBSITE, CANT DESCRIBE https://vrimutd6so6a565x.onion.cab/index.php/Board ANONYMOUS POSTING https://h2am5w5ufhvdifrs.onion/ CRYPTOME ARCHIVE OF GOV CONSPIRACY FILES https://torc5bhzq6xorhb4.o...