블록체인

[Mastering Bitcoin] Cp.2

달모드 2020. 10. 5. 00:48

Transactions, Blocks, Mining, and the Blockchain

Bitcoin system: based on decentralized trust
interactions of different participants
“trusted”

in bitcoin, trust is achieved as an emergent property from the interactions of different participants in the bitcoin system. a high level by tracking a single transaction through the bitcoin system and watch as it becomes “trusted” and accepted by the bitcoin mechanism of distributed consensus and is finally recorded on the blockchain

Bitcoin Overview

Wallets containing keys

a bitcoin address, transaction hash, block number, or block hash and retrieve corresponding information from the bit‐ coin network

Buying a Cup of Coffee

a payment request = a QR-encoded URL a human-readable description
(contains a destination address, a payment amount, and a generic description such as “Bob’s Cafe.”)

Bitcoin Transactions

a transaction tells the network that the owner of some bitcoin value has authorized the transfer of that value to another owner.

new owner can now spend the bitcoin by creating another transaction that authorizes transfer to another owner

Transaction Inputs and Outputs

Each transaction contains one or more “inputs,”

there are one or more “outputs,” which are like credits added to a bitcoin account.

outputs add up to slightly less than inputs and the difference represents an implied transaction fee

also contains proof of ownership for each amount of bitcoin (inputs) whose value is being spent, in the form of a digital signature , independently validated by anyone

In bitcoin terms, “spending” is signing a transaction that transfers value from a previous transaction over to a new owner identified by a bitcoin address

Transaction Chains

created a bitcoin value locked by Alice’s key

Her new transaction references the previous transaction as an input and creates new outputs to pay

Alice’s key provides the signature that unlocks those previous transaction outputs, thereby proving to the bitcoin network that she owns the funds

She attaches the pay‐ ment for coffee to Bob’s address, thereby “encumbering” that output with the require‐ ment that Bob produces a signature in order to spend that amount

Making Change

transactions will include outputs that reference both an address of the new owner and an address of the current owner, called the change address.

transaction inputs cannot be divided

the change address does not have to be the same address as that of the input and for privacy reasons

Different wallets may use different strategies when aggregating inputs

transactions move value from transaction inputs to transaction outputs

Common Transaction Forms

1.     a simple payment from one address to another: “change”

2.     aggregates several inputs into a sin‐ gle output

3.     distributes one input to multiple outputs representing multiple recipients

 

Constructing a Transaction

only needs to specify a destination and an amount, and the rest happens in the wallet application without showing the details

a wallet application can construct transactions even if it is completely offline

 

Getting the Right Inputs

1. have to find inputs that can pay: wallet would contain a copy of the transac‐ tion output
(* a bitcoin wallet app
contains a copy of every unspent output from every transaction in the blockchain most user wallets run “lightweight” clients that track only the user’s own unspent outputs. If the wallet application does not maintain a copy of unspent transaction outputs, it can ask the info-API request)

Creating the Outputs

1.     only Bob has the wallet with the keys corresponding to that address, only Bob’s wallet can present such a signature to redeem this output. Alice will therefore “encumber” the output value with a demand for a signature from Bob.

2.     Alice’s wallet breaks her funds into two payments: one to Bob and one back to herself.
* a second output; Alice’s funds are in the form of a 0.10 BTC output, too much money for the coffee

 

Adding the Transaction to the Ledger

the transaction must be transmitted to the bitcoin network where it will become part of the blockchain

a transaction becomes part of a new block and how the block is “mined.”

Transmitting the transaction

The bitcoin network is a peer-to-peer network

The purpose of the bitcoin network: to propagate transactions

How it propagates

bitcoin node: any system that participates in the bitcoin network by “speaking” the bitcoin protocol

flooding: technique that any bitcoin node that receives a valid transaction it has not seen before will immediately forward it to all other nodes to which it is connected


Bob’s view

A common misconception about bitcoin transactions is that they must be “confirmed” by waiting 10 minutes for a new block, or up to 60 minutes for a full six confirmations. such a delay is unnecessary for small-value items

Bitcoin Mining

Mining achieves a fine balance between cost and reward.

A successful miner will collect a reward in the form of new bitcoin and transaction fees

the reward will only be collected if the miner has correctly validated all the transactions: the rules of consensus

Proof-of-Work (PoW), requires quadrillions of hashing operations per second across the entire bitcoin network - repeatedly hashing the header of the block and a random number with the SHA256 cryptographic algorithm

Mining Transactions in Blocks

As miners construct a new block, they add unverified transactions from this pool to the new block and then attempt to prove the validity of that new block, with the mining algorithm (Proof-of-Work)

Each miner includes a special transaction in his block, one that pays his own bitcoin address the block reward

If he finds a solution that makes that block valid, he “wins” this reward because his successful block is added to the global blockchain

included in a new block, called a candidate block

when added even more computation to the blockchain strengthening the trust in those transactions

Spending the Transaction

Full-node clients can track the source of the funds from the moment the bitcoin were first generated in a block

 

 

 

Six confirmation:

Mining의원리 : 만든 transaction들이. Block broadcast

 

이중지불 공격

Six confirmation이 필요한 이유: block chain depth은 신뢰도에  비례. Transaction broadcast되어 main chain에 등록되기 위해서는 miner..6개의 블록이 있으면 확률적으로 이중지불 공격의 리스크가 없어진다.(확률적으로 낮아지는 구간)

이것에 대한 증명: bitcoin white paper; 푸아송분포 등. 왜 확률론적으로 6개인지.

 

Spv node: Spv node는 블록 헤더만 가지고 있다.full block 아니다.(Utxo 검증 불가능하다.)

 

나의 transaction이 올라갔는지아닌지 모른다. 그래서 인접 블록에게 물어서 블록 깊이를 통해 검증을 할 수 있다.

Transaction validation

Tx -> 검증한다
1.utxo
상으로 문제가 없는가
2.
믿을만한가 -> 블록깊이가 충분한가

 

인접 블록에게 물어본다. 이ㅣ 트랜젝션에 대한 정보를 물어보고 알아낸다.

그 뒤에 붙어있는 블록 헤더를 알아낸다음 깊이를 알아낸다