SlideShare a Scribd company logo
1 of 17
13th Dec 2017
Brian Yap
A Simplified Bitcoin
transaction implementation in
Go
2
Agenda
Describe how Bitcoin works.
Create a fictitious coin – Scrooge Coin
Transaction in Scrooge Coin
Sample code snippet of transaction
How to verify transaction?
Sample code snippet of transaction verification
A look into Bitcoin transaction and verification
3
4
Scrooge coin
Let's create your own cryptocurrency called Scrooge* coins.
It is a simplified version of Bitcoin.
To starts with, Scrooge creates 1M value in Scrooge coins and
distribute to his friends.
In order to distribute to his friend Scrooge will need to creates
Transaction to transfer Scrooge coin to each of his friend.
Transaction is the way to transfer Scrooge value from one
person to another.
Transaction are like a double-entry book-keeping ledger. On
the one side, it has the 'inputs' representing the amount you
want to spend (amount that you own). On the other side, it has
the 'outputs' representing the different amount to be paid to
various people.
Transaction also contains proof of ownership for each 'inputs' in
the form of digital signature from the owner.
* NOTE: this is based on a fictitious coin created in cryptocurrency course runs in Princeton
University.
5
How do you spend your scrooge coin?
Transaction #99
INPUTS
From: Tx #50, Index #0
(amount received from Scrooge)
Signature: h3d53aaa3....a93
Output #0:
Recipient: Alice's Public Key
Amount: 400 (spent)
OUTPUTS
Transaction #150
INPUTS
From: Tx #99, Index #0
(amount receive from Alice)
Signature: da5543123....fdd
Output #0:
Recipient: Albert's Public Key
Amount: 200 (unspent)
OUTPUTS
Output #1:
Recipient: Charlie's Public Key
Amount: 200 (unspent)
Alice would like to pay Albert and Charlie each 200.
This tx shows Scrooge gave Alice 400.
This tx shows Alice gave Albert and
Charlie each 200.
6
Transaction Representation
TInput:
Previous Transaction Hash to
spend and its position in the
Previous Transaction.
Signature to prove Previous
Transaction is owned by you.
TOutput:
Amount to be given to the
recipient.
Public Key of the recipient.
7
Create Transaction
8
Transaction Class
9
Transaction class
10
How is transaction verified?
Unspent transaction output (UTXO) is an output that can be
spent as an input in a new transaction.
All UTXO are maintained in a UTXO pool.
Within the UTXO pool, it also provides ability to retrieve
TOutput associated with the UTXO.
Scrooge transaction rules:
1. All outputs claimed by a transaction must be in the current
UTXO pool.
2. Signature of each input of a transaction must be valid.
3. Unspent transaction output must not be claimed multiple times.
4. All of transaction output values are non-negative
5. The sum of transaction input values is greater than or equal to
the sum of its output values.
11
How is transaction verified?
12
Testing code....
13
Bitcoin Transaction
14
Bitcoin Transaction
Usage of scripts in transaction.
For instance Pay-to-Public-Key-Hash (P2PKH) pubkey script
ScriptPubKey
Used in Transaction Output as a means to 'lock' the amount. It
can only be 'unlock' with the right key.
Thinks of it as a puzzle with a missing piece.
ScriptSig
Used in Transaction Input as the key to unlock the Transaction
Output.
Thinks of it as the missing piece to solve a puzzle.
Transaction fee - it is implied being the different of sum of
inputs and the sum of outputs.
15
Bitcoin Transaction
P2PKH Script validation
16
Bitcoin Transaction
Bitcoin Address representation:
Base58Check(RIPEMD160(SHA256(Public Key)))
Base58Check
Remove identical looking characters (0OIl)
Suffix with four bytes of SHA256-based error checking code.
Prefix with one byte of application information, e.g. P2PKH
address starts with leading 1
https://blockchain.info/address/18fKRJCvLNsYgihqnhuh7nJ9CCz6SvmXq6
https://en.bitcoin.it/wiki/List_of_address_prefixes
Transaction (ScriptSig) is signed using Elliptic Curve Digital
Signature Algorithm (ECDSA). Signed transaction are encoded
using DER encoding.
17
Bitcoin Transaction Rules
1. Check syntactic correctness
2. Make sure neither in or out lists are empty
3. Size in bytes <= MAX_BLOCK_SIZE
4. Each output value, as well as the total, must be in legal money range
5. Make sure none of the inputs have hash=0, n=-1 (coinbase transactions)
6. Check that nLockTime <= INT_MAX[1], size in bytes >= 100[2], and sig opcount <= 2[3]
7. Reject "nonstandard" transactions: scriptSig doing anything other than pushing numbers on the stack, or scriptPubkey
not matching the two usual forms[4]
8. Reject if we already have matching tx in the pool, or in a block in the main branch
9. For each input, if the referenced output exists in any other tx in the pool, reject this transaction.[5]
10. For each input, look in the main branch and the transaction pool to find the referenced output transaction. If the output
transaction is missing for any input, this will be an orphan transaction. Add to the orphan transactions, if a matching
transaction is not in there already.
11. For each input, if the referenced output transaction is coinbase (i.e. only 1 input, with hash=0, n=-1), it must have at
least COINBASE_MATURITY (100) confirmations; else reject this transaction
12. For each input, if the referenced output does not exist (e.g. never existed or has already been spent), reject this
transaction[6]
13. Using the referenced output transactions to get input values, check that each input value, as well as the sum, are in
legal money range
14. Reject if the sum of input values < sum of output values
15. Reject if transaction fee (defined as sum of input values minus sum of output values) would be too low to get into an
empty block
16. Verify the scriptPubKey accepts for each input; reject if any are bad.
17. Add to transaction pool.
18. …... many more rules ….. Source: https://en.bitcoin.it/wiki/Protocol_rules#.22tx.22_messages

More Related Content

Similar to A simplified Bitcoin Implementation in GO

PRESENTATION.pptx
PRESENTATION.pptxPRESENTATION.pptx
PRESENTATION.pptxFaiZiTricks
 
Bitcoin : A fierce Decentralized internet currency
Bitcoin : A fierce Decentralized internet currencyBitcoin : A fierce Decentralized internet currency
Bitcoin : A fierce Decentralized internet currencyShivek Khurana
 
“Technical Intro to Blockhain” by Yurijs Pimenovs from Paybis at CryptoCurren...
“Technical Intro to Blockhain” by Yurijs Pimenovs from Paybis at CryptoCurren...“Technical Intro to Blockhain” by Yurijs Pimenovs from Paybis at CryptoCurren...
“Technical Intro to Blockhain” by Yurijs Pimenovs from Paybis at CryptoCurren...Dace Barone
 
BlockChain_and _cryptocurrency_technology (1).ppt
BlockChain_and _cryptocurrency_technology (1).pptBlockChain_and _cryptocurrency_technology (1).ppt
BlockChain_and _cryptocurrency_technology (1).pptFaiZiTricks
 
Dappsmedia smartcontract _write_smartcontracts_on_console_ethereum
Dappsmedia smartcontract _write_smartcontracts_on_console_ethereumDappsmedia smartcontract _write_smartcontracts_on_console_ethereum
Dappsmedia smartcontract _write_smartcontracts_on_console_ethereumTomoaki Sato
 
The bitcoin blockchain
The bitcoin blockchainThe bitcoin blockchain
The bitcoin blockchainSalah Hawila
 
Cryptocurrencies for Everyone (Dmytro Pershyn Technology Stream)
Cryptocurrencies for Everyone (Dmytro Pershyn Technology Stream)Cryptocurrencies for Everyone (Dmytro Pershyn Technology Stream)
Cryptocurrencies for Everyone (Dmytro Pershyn Technology Stream)IT Arena
 
Payment Protocols - Block Chain & Beyond
Payment Protocols - Block Chain & BeyondPayment Protocols - Block Chain & Beyond
Payment Protocols - Block Chain & BeyondAlexander Kiriakou
 
Starkware: Account Abstraction
Starkware: Account AbstractionStarkware: Account Abstraction
Starkware: Account AbstractionTinaBregovi
 
DevDay: Getting Started with Tokens and Accounts, R3
DevDay: Getting Started with Tokens and Accounts, R3DevDay: Getting Started with Tokens and Accounts, R3
DevDay: Getting Started with Tokens and Accounts, R3R3
 
DevDay: Have Your Cake and Eat it Too, Privacy and Security with ZKP, ING
DevDay: Have Your Cake and Eat it Too, Privacy and Security with ZKP, INGDevDay: Have Your Cake and Eat it Too, Privacy and Security with ZKP, ING
DevDay: Have Your Cake and Eat it Too, Privacy and Security with ZKP, INGR3
 
Shabakat Pitch Deck
Shabakat Pitch DeckShabakat Pitch Deck
Shabakat Pitch DeckCryptoware
 
Wallets and Transactions #2
Wallets and Transactions #2Wallets and Transactions #2
Wallets and Transactions #2BCWorkspace
 
Cryptocurrency Mixing
Cryptocurrency MixingCryptocurrency Mixing
Cryptocurrency Mixingashmoran
 
以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)
以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)
以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)Nicholas Lin
 

Similar to A simplified Bitcoin Implementation in GO (20)

PRESENTATION.pptx
PRESENTATION.pptxPRESENTATION.pptx
PRESENTATION.pptx
 
Bitcoin : A fierce Decentralized internet currency
Bitcoin : A fierce Decentralized internet currencyBitcoin : A fierce Decentralized internet currency
Bitcoin : A fierce Decentralized internet currency
 
bitcoin_presentation
bitcoin_presentationbitcoin_presentation
bitcoin_presentation
 
“Technical Intro to Blockhain” by Yurijs Pimenovs from Paybis at CryptoCurren...
“Technical Intro to Blockhain” by Yurijs Pimenovs from Paybis at CryptoCurren...“Technical Intro to Blockhain” by Yurijs Pimenovs from Paybis at CryptoCurren...
“Technical Intro to Blockhain” by Yurijs Pimenovs from Paybis at CryptoCurren...
 
BlockChain_and _cryptocurrency_technology (1).ppt
BlockChain_and _cryptocurrency_technology (1).pptBlockChain_and _cryptocurrency_technology (1).ppt
BlockChain_and _cryptocurrency_technology (1).ppt
 
Malleability and SegWit
Malleability and SegWitMalleability and SegWit
Malleability and SegWit
 
Dappsmedia smartcontract _write_smartcontracts_on_console_ethereum
Dappsmedia smartcontract _write_smartcontracts_on_console_ethereumDappsmedia smartcontract _write_smartcontracts_on_console_ethereum
Dappsmedia smartcontract _write_smartcontracts_on_console_ethereum
 
Bitcoin
BitcoinBitcoin
Bitcoin
 
The bitcoin blockchain
The bitcoin blockchainThe bitcoin blockchain
The bitcoin blockchain
 
Cryptocurrencies for Everyone (Dmytro Pershyn Technology Stream)
Cryptocurrencies for Everyone (Dmytro Pershyn Technology Stream)Cryptocurrencies for Everyone (Dmytro Pershyn Technology Stream)
Cryptocurrencies for Everyone (Dmytro Pershyn Technology Stream)
 
Payment Protocols - Block Chain & Beyond
Payment Protocols - Block Chain & BeyondPayment Protocols - Block Chain & Beyond
Payment Protocols - Block Chain & Beyond
 
Intro to blockchain
Intro to blockchainIntro to blockchain
Intro to blockchain
 
Starkware: Account Abstraction
Starkware: Account AbstractionStarkware: Account Abstraction
Starkware: Account Abstraction
 
DevDay: Getting Started with Tokens and Accounts, R3
DevDay: Getting Started with Tokens and Accounts, R3DevDay: Getting Started with Tokens and Accounts, R3
DevDay: Getting Started with Tokens and Accounts, R3
 
DevDay: Have Your Cake and Eat it Too, Privacy and Security with ZKP, ING
DevDay: Have Your Cake and Eat it Too, Privacy and Security with ZKP, INGDevDay: Have Your Cake and Eat it Too, Privacy and Security with ZKP, ING
DevDay: Have Your Cake and Eat it Too, Privacy and Security with ZKP, ING
 
Shabakat Pitch Deck
Shabakat Pitch DeckShabakat Pitch Deck
Shabakat Pitch Deck
 
Bitcoin.pdf
Bitcoin.pdfBitcoin.pdf
Bitcoin.pdf
 
Wallets and Transactions #2
Wallets and Transactions #2Wallets and Transactions #2
Wallets and Transactions #2
 
Cryptocurrency Mixing
Cryptocurrency MixingCryptocurrency Mixing
Cryptocurrency Mixing
 
以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)
以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)
以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)
 

Recently uploaded

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

Recently uploaded (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

A simplified Bitcoin Implementation in GO

  • 1. 13th Dec 2017 Brian Yap A Simplified Bitcoin transaction implementation in Go
  • 2. 2 Agenda Describe how Bitcoin works. Create a fictitious coin – Scrooge Coin Transaction in Scrooge Coin Sample code snippet of transaction How to verify transaction? Sample code snippet of transaction verification A look into Bitcoin transaction and verification
  • 3. 3
  • 4. 4 Scrooge coin Let's create your own cryptocurrency called Scrooge* coins. It is a simplified version of Bitcoin. To starts with, Scrooge creates 1M value in Scrooge coins and distribute to his friends. In order to distribute to his friend Scrooge will need to creates Transaction to transfer Scrooge coin to each of his friend. Transaction is the way to transfer Scrooge value from one person to another. Transaction are like a double-entry book-keeping ledger. On the one side, it has the 'inputs' representing the amount you want to spend (amount that you own). On the other side, it has the 'outputs' representing the different amount to be paid to various people. Transaction also contains proof of ownership for each 'inputs' in the form of digital signature from the owner. * NOTE: this is based on a fictitious coin created in cryptocurrency course runs in Princeton University.
  • 5. 5 How do you spend your scrooge coin? Transaction #99 INPUTS From: Tx #50, Index #0 (amount received from Scrooge) Signature: h3d53aaa3....a93 Output #0: Recipient: Alice's Public Key Amount: 400 (spent) OUTPUTS Transaction #150 INPUTS From: Tx #99, Index #0 (amount receive from Alice) Signature: da5543123....fdd Output #0: Recipient: Albert's Public Key Amount: 200 (unspent) OUTPUTS Output #1: Recipient: Charlie's Public Key Amount: 200 (unspent) Alice would like to pay Albert and Charlie each 200. This tx shows Scrooge gave Alice 400. This tx shows Alice gave Albert and Charlie each 200.
  • 6. 6 Transaction Representation TInput: Previous Transaction Hash to spend and its position in the Previous Transaction. Signature to prove Previous Transaction is owned by you. TOutput: Amount to be given to the recipient. Public Key of the recipient.
  • 10. 10 How is transaction verified? Unspent transaction output (UTXO) is an output that can be spent as an input in a new transaction. All UTXO are maintained in a UTXO pool. Within the UTXO pool, it also provides ability to retrieve TOutput associated with the UTXO. Scrooge transaction rules: 1. All outputs claimed by a transaction must be in the current UTXO pool. 2. Signature of each input of a transaction must be valid. 3. Unspent transaction output must not be claimed multiple times. 4. All of transaction output values are non-negative 5. The sum of transaction input values is greater than or equal to the sum of its output values.
  • 14. 14 Bitcoin Transaction Usage of scripts in transaction. For instance Pay-to-Public-Key-Hash (P2PKH) pubkey script ScriptPubKey Used in Transaction Output as a means to 'lock' the amount. It can only be 'unlock' with the right key. Thinks of it as a puzzle with a missing piece. ScriptSig Used in Transaction Input as the key to unlock the Transaction Output. Thinks of it as the missing piece to solve a puzzle. Transaction fee - it is implied being the different of sum of inputs and the sum of outputs.
  • 16. 16 Bitcoin Transaction Bitcoin Address representation: Base58Check(RIPEMD160(SHA256(Public Key))) Base58Check Remove identical looking characters (0OIl) Suffix with four bytes of SHA256-based error checking code. Prefix with one byte of application information, e.g. P2PKH address starts with leading 1 https://blockchain.info/address/18fKRJCvLNsYgihqnhuh7nJ9CCz6SvmXq6 https://en.bitcoin.it/wiki/List_of_address_prefixes Transaction (ScriptSig) is signed using Elliptic Curve Digital Signature Algorithm (ECDSA). Signed transaction are encoded using DER encoding.
  • 17. 17 Bitcoin Transaction Rules 1. Check syntactic correctness 2. Make sure neither in or out lists are empty 3. Size in bytes <= MAX_BLOCK_SIZE 4. Each output value, as well as the total, must be in legal money range 5. Make sure none of the inputs have hash=0, n=-1 (coinbase transactions) 6. Check that nLockTime <= INT_MAX[1], size in bytes >= 100[2], and sig opcount <= 2[3] 7. Reject "nonstandard" transactions: scriptSig doing anything other than pushing numbers on the stack, or scriptPubkey not matching the two usual forms[4] 8. Reject if we already have matching tx in the pool, or in a block in the main branch 9. For each input, if the referenced output exists in any other tx in the pool, reject this transaction.[5] 10. For each input, look in the main branch and the transaction pool to find the referenced output transaction. If the output transaction is missing for any input, this will be an orphan transaction. Add to the orphan transactions, if a matching transaction is not in there already. 11. For each input, if the referenced output transaction is coinbase (i.e. only 1 input, with hash=0, n=-1), it must have at least COINBASE_MATURITY (100) confirmations; else reject this transaction 12. For each input, if the referenced output does not exist (e.g. never existed or has already been spent), reject this transaction[6] 13. Using the referenced output transactions to get input values, check that each input value, as well as the sum, are in legal money range 14. Reject if the sum of input values < sum of output values 15. Reject if transaction fee (defined as sum of input values minus sum of output values) would be too low to get into an empty block 16. Verify the scriptPubKey accepts for each input; reject if any are bad. 17. Add to transaction pool. 18. …... many more rules ….. Source: https://en.bitcoin.it/wiki/Protocol_rules#.22tx.22_messages