Re:How does blockchain really work? I built an app to show you
by phaemon on Tuesday September 05, 2017 @06:32AM
(#15173888)
A good and interesting explanation. Though, since it doesn't mention transactions at all, it might leave folk thinking, "So great, I've got a chain of hashes. How is that in any way a `coin`"? A Part 2 with that concept would be excellent.
Also, tiny nitpick, but `bc` is a common unix command, so maybe a different shortname would be better.
Re:How does blockchain really work? I built an app to show you
by libertymcateer on Tuesday September 05, 2017 @11:59AM
(#15176449)
I actually would very much appreciate that. I was just reading Nakamoto's whitepaper on Bitcoin [1] and I understand the hashing. However, the coinebase transaction is still a bit confusing to me. Specifically, to get at precisely this issue - what does the bitcoin itself consist of? It is just the summation of the history of transactions to and from an address? Or is there a numerical value or token that is actually issued during a coinbase transaction, and, if so, how is it generated? This is not apparent to me. I understand that during a coinbase transaction, there is a transaction registered that is issued to the miner and the 'from' address is null - but it is still not clear to me, other than the balance of that transaction, if there is an actual token associated with those coins.
Re:How does blockchain really work? I built an app to show you
by Jasper_ on Wednesday September 06, 2017 @12:54AM
(#15181323)
The core idea is that there are a number of coins "floating out there in the open" which you can use in your transactions, as Inputs. These Inputs can be used in transactions as long as you publish data which can solve a riddle put forth by a Script. So, your balance is basically any those which you can easily use as Inputs. The most traditional way of tracking this is that you use a standardized script format called P2PKH (Pay 2 Public Key Hash), and software like a wallet scans the transactions for any scripts that have your public key mentioned in a P2PKH template.
So, once you want to send money to someone else's wallet, you answer the riddle of the script (in P2PKH's case, by signing something and proving you own the public key) allowing you to do whatever you want to that Input. A key thing is that if someone pays you 3BTC and someone else pays you 2BTC, then you have 5BTC in combined inputs. To pay someone else 4BTC, you use both those Inputs and make two new ones: 4BTC P2PKH to someone else's public key, and 1BTC back to your own "change address", which is just an Input that you can reuse again.
A wallet broadcasts transactions into the network, where they float around until a miner takes those transactions, puts N of them into a block, then, as part of that block, they can use an extra magical coinbase Input which gives them 12.5BTC out of thin air (originally 50BTC, halves every so often) which they can lock under any script they want.
Re:How does blockchain really work? I built an app to show you
by Doxin on Wednesday September 06, 2017 @09:50AM
(#15183620)
> It is just the summation of the history of transactions to and from an address?
It is. Imagine the blockchain as a democratic ledger. As long as most people agree a certain transaction is valid it then is valid. This allows for tricks like creating bitcoins out of thin air as long as everyone agrees you "deserve" those bitcoins. For example if you confirm enough of other peoples transactions (which you can do because the ledger is public) most everyone will agree that a transaction from nowhere to an address of your choosing is valid.
The amount of bitcoins in your possession is just the amount of bitcoins ever transfered to addresses to which you own the private key, minus the transactions out of those adresses.
You shouldn't think of bitcoin as a virtual coin. That's a fairly bad metaphor. It's not some actual thing, It's more like the balance in a ledger.
Re:How does blockchain really work? I built an app to show you
by libertymcateer on Wednesday September 06, 2017 @10:08AM
(#15183764)
Right, that was my instinct, it is just that the documentation I have seen, including the O'Reilley bitcoin manual, on the coinbase transaction, glosses over this point.
Re:How does blockchain really work? I built an app to show you
by ringaroundthetx on Tuesday September 05, 2017 @11:29AM
(#15176177)
Well coin was always a misnomer and skeumorph, because chain of hashes is even less relatable.
But hey since it is a decade later now, and iphones no longer show pictures of an address book for your contact list, maybe we can also drop the -coin and -currency monikers and call it distributed hash chain accounting networks!
Re:How does blockchain really work? I built an app to show you
by atonse on Tuesday September 05, 2017 @10:35AM
(#15175585)
I understand the cryptographic concept of a blockchain but have a bunch of "real-world scenarios" type questions on how it actually works.
Like for example, it's a chain. I get that. But if there are thousands of people adding to the chain all the time, how do they coordinate to make sure they're always adding to the last block?
Because this might happen:
- I sync and have the latest block
- I build another block off the latest block (takes 1 second)
- In that time, I no longer have the latest block.
Do I have to get the newest block again from the "world" and then recompute?
Wouldn't this just be never-ending? And how would this work as more people add to the chain? Would I constantly be out of sync?
That's the kind of stuff where I'm completely lost and haven't found a good explanation for it.
Re:How does blockchain really work? I built an app to show you
by hanbura on Tuesday September 05, 2017 @11:04AM
(#15175888)
This happens fairly frequently.
Whenever you see a new block that forms a longer chain than the chain you currently know, you throw your work away and use that block as your new starting point. But you only do that if the new block has a longer chain, not for a chain of equal length.
So if two miners both mine a new block that follows the same block, one will be seen first by some miners, the other will be seen first by others. That gives them different mining power, meaning the chains grow with different speed. After 1-3 blocks this mining power difference will lead to one of both chains being longer from everyone's point of view. At that point the longer chain won, the shorter is forgotten and all work put into it becomes worthless.
That encourages miners to make sure they use new blocks as fast as possible. Unless of course you have more mining power than everyone else combined.
Re:How does blockchain really work? I built an app to show you
by jackhack on Tuesday September 05, 2017 @11:23AM
(#15176095)
>the shorter is forgotten and all work put into it becomes worthless
Then one can commit work to (what is believed to be) the current, longest chain, only to find later that a branch occurred and the work was lost? As such it is then incumbent upon the contributor to follow the chain for some period of time until other work has contriubted to the chain?
So how long is long enough? one contribution? ten? Serious question. How does one know with certainty that work was accepted by group consensus?
This uncertainty seems to undermine the idea that blockchain is a trustworthy, predictable, verifiable ledger of activity if the work contributed cannot be known as reliably preserved at the time it is submitted, only later in review.
I admit I'm fairly ignorant of the details of this, just attempting to understand. I hope I am misunderstanding something; somebody please steer me back onto the path.
Re:How does blockchain really work? I built an app to show you
by JamesLeonis on Tuesday September 05, 2017 @12:59PM
(#15177015)
> So how long is long enough? one contribution? ten? Serious question.
The formal name of this is Proof Of Work (PoC). The idea is to make "mining" blocks take non-trivial amount of computational work in order to forge another transaction block. When a miner finds a valid nonce, it announces it to the rest of the network so others can begin working on that chain.
When I say non-trivial amount of work, it would take my computer (nVidia 1080 @ 20MH/s) ~3.5 years to mine one Ethereum block as of now. Comparatively, the combined power in the Ethereum network (119.4 TH/s) mines blocks every 24 seconds.
Additionally, the miner that finds the correct nonce that makes a valid block is rewarded. This incentivizes each miner to keep up to date with the latest blockchain and abandon lagging branches and work.
> How does one know with certainty that work was accepted by group consensus?
Through these rewards and the large computational work involved in mining new blocks, the majority of the miners aggressively gravitate to the longest chain. That means that the longer chain continues to grow longer much faster than the other branches. It's this aggressive growth combined with the reward incentives on the longest chain that keeps the whole network honest. Why mine a block that the network won't reward you for? For the individual miner, it's in their best interests to always be working on the longest chain.
> This uncertainty seems to undermine the idea that blockchain is a trustworthy, predictable, verifiable ledger of activity if the work contributed cannot be known as reliably preserved at the time it is submitted, only later in review.
This is part of the security of the blockchain. This prevents malicious agents from pushing "valid" blocks, even if they manage to get all the dots in a row. The computational work involved in building the next block is vastly outpaced by the general network; by the time you minted you "attack" block, many many many new blocks were already minted by the network and they won't accept your block. This "consensus" keeps these attacks from happening.
However, this still can be attacked. If an agent gained control of the majority of the network computational power, then they can mine blocks faster than the honest miners, thus growing the longest chain and thus control exactly what transactions/blocks are mined. This is referred to as the 51% attack because they become the Consensus.
But, using my calculations above, I would need somewhere around ~6*10^6 nVidia 1080 cards all working for me to gain majority in the Ethereum network. So I sleep comfortably at night knowing my ETH is safe.
Re:How does blockchain really work? I built an app to show you
by hdhzy on Tuesday September 05, 2017 @12:45PM
(#15176873)
If you find a valid block then it's more profitable to switch to this block as a base. Chain splits happen when someone finds a block but is not aware of other valid block.
Re:How does blockchain really work? I built an app to show you
by hdhzy on Tuesday September 05, 2017 @12:41PM
(#15176837)
Usually the second miner also saw and included the same transactions so they are not lost. If they didn't the transaction is undone in a sense that it just didn't happen. Of course it can still be picked by the next miner.
The chain that is longest (by difficulty) is by definition a log of everything that happened. Transactions that are not part of that chain are just candidates, nothing less nothing more.
Re:How does blockchain really work? I built an app to show you
by hdhzy on Tuesday September 05, 2017 @01:04PM
(#15177066)
Well in a distributed system you are in a way always out of sync. The primary achievement of Bitcoin was taking already exiting pieces (hash cash, Merkle trees, signatures etc.) and assembling them in a way that solves consensus in such a system (see [0]). What's interesting is the combination of these pieces. They were known a long time before. Actually I had CS lessons where we were creating virtual currencies with these exact elements long before Bitcoin happened (of course no one got Bitcoin in the process :(... or maybe they did but never told me :) ).
How to know Bitcoin better? The best approach is the same as with everything else: reverse engineer and recreate a small coin in your language of choice (chain using hashes plus a simple proof of work using N leading 0s). Remember Satoshi's genius was in assembling pieces in a way nobody thought of, you just need to copy a small version of that. It's not that difficult.
For me the most interesting aspect is smart contracts [1]. That's the one underutilized element of the system that is quite versatile.
Re:How does blockchain really work? I built an app to show you
by rtkwe on Tuesday September 05, 2017 @11:09AM
(#15175954)
Currently that's solved because transactions aren't added live by every user but instead get batched together and added as a group so individually you just have to wait for some block to pickup your transaction from the pool of available transactions. What you're suggesting could potentially become a problem for a technology if new block propagation takes longer than new block discovery.
Today orphan blocks aren't exactly rare there're several a month where two different pools will announce new blocks within a couple seconds of each other and one gets abandoned because it was the later one or because the other block had a new block mined from it faster.
Re:How does blockchain really work? I built an app to show you
by atonse on Tuesday September 05, 2017 @12:47PM
(#15176888)
"What you're suggesting could potentially become a problem for a technology if new block propagation takes longer than new block discovery."
But that's an inevitability. New block discovery only takes longer over time, and block propagation will only get more complicated as you add more users to chain.
Re:How does blockchain really work? I built an app to show you
by nonidit on Tuesday September 05, 2017 @10:33AM
(#15175566)
In your explanation you say that "The SHA256 algorithm will calculate a unique hash, given those inputs.".
Obviously, this can't be the case (since the number of possible hashes is smaller than the number of inputs). It is just very unlikely, that the same hash appears twice.
Re:How does blockchain really work? I built an app to show you
by lambdaxdotx on Tuesday September 05, 2017 @11:33AM
(#15176228)
this is quite the nitpick... for all intents and purposes, sha3_256 will _not_ collide; it's infeasible to the point that it can be said that the resulting hash is unique. I mean, of course you are technically right, but sometimes all the details are not worth mentioning when explaining a lot of small parts of a bigger picture.
Re:How does blockchain really work? I built an app to show you
by andrewfromx on Tuesday September 05, 2017 @10:11AM
(#15175337)
Love this stuff but I want to make it even easier to explain to non programmers. I just registered the domain lowsec.coin and I want to build a new currency from start to finish in a way kids can grok. Working domain is https://higher.team
Also, tiny nitpick, but `bc` is a common unix command, so maybe a different shortname would be better.
Any explanation would be greatly appreciated!
[1] https://bitcoin.org/bitcoin.pdf
So, once you want to send money to someone else's wallet, you answer the riddle of the script (in P2PKH's case, by signing something and proving you own the public key) allowing you to do whatever you want to that Input. A key thing is that if someone pays you 3BTC and someone else pays you 2BTC, then you have 5BTC in combined inputs. To pay someone else 4BTC, you use both those Inputs and make two new ones: 4BTC P2PKH to someone else's public key, and 1BTC back to your own "change address", which is just an Input that you can reuse again.
A wallet broadcasts transactions into the network, where they float around until a miner takes those transactions, puts N of them into a block, then, as part of that block, they can use an extra magical coinbase Input which gives them 12.5BTC out of thin air (originally 50BTC, halves every so often) which they can lock under any script they want.
It is. Imagine the blockchain as a democratic ledger. As long as most people agree a certain transaction is valid it then is valid. This allows for tricks like creating bitcoins out of thin air as long as everyone agrees you "deserve" those bitcoins. For example if you confirm enough of other peoples transactions (which you can do because the ledger is public) most everyone will agree that a transaction from nowhere to an address of your choosing is valid.
The amount of bitcoins in your possession is just the amount of bitcoins ever transfered to addresses to which you own the private key, minus the transactions out of those adresses.
You shouldn't think of bitcoin as a virtual coin. That's a fairly bad metaphor. It's not some actual thing, It's more like the balance in a ledger.
This is the best explanation I've seen so far: https://bitcoin.stackexchange.com/questions/10050/how-balanc...
But hey since it is a decade later now, and iphones no longer show pictures of an address book for your contact list, maybe we can also drop the -coin and -currency monikers and call it distributed hash chain accounting networks!
There is a known quantity of hashes.
https://twitter.com/LIL_ICEBUNNY/status/887667332562202624/v...
Do we have Blockchain tutorials timeline akin to https://wiki.haskell.org/Monad_tutorials_timeline ?
Like for example, it's a chain. I get that. But if there are thousands of people adding to the chain all the time, how do they coordinate to make sure they're always adding to the last block?
Because this might happen:
- I sync and have the latest block
- I build another block off the latest block (takes 1 second)
- In that time, I no longer have the latest block.
Do I have to get the newest block again from the "world" and then recompute?
Wouldn't this just be never-ending? And how would this work as more people add to the chain? Would I constantly be out of sync?
That's the kind of stuff where I'm completely lost and haven't found a good explanation for it.
Whenever you see a new block that forms a longer chain than the chain you currently know, you throw your work away and use that block as your new starting point. But you only do that if the new block has a longer chain, not for a chain of equal length.
So if two miners both mine a new block that follows the same block, one will be seen first by some miners, the other will be seen first by others. That gives them different mining power, meaning the chains grow with different speed. After 1-3 blocks this mining power difference will lead to one of both chains being longer from everyone's point of view. At that point the longer chain won, the shorter is forgotten and all work put into it becomes worthless.
That encourages miners to make sure they use new blocks as fast as possible. Unless of course you have more mining power than everyone else combined.
Then one can commit work to (what is believed to be) the current, longest chain, only to find later that a branch occurred and the work was lost? As such it is then incumbent upon the contributor to follow the chain for some period of time until other work has contriubted to the chain?
So how long is long enough? one contribution? ten? Serious question. How does one know with certainty that work was accepted by group consensus?
This uncertainty seems to undermine the idea that blockchain is a trustworthy, predictable, verifiable ledger of activity if the work contributed cannot be known as reliably preserved at the time it is submitted, only later in review.
I admit I'm fairly ignorant of the details of this, just attempting to understand. I hope I am misunderstanding something; somebody please steer me back onto the path.
I think in practice, they would ignore such a rewrite of history.
The formal name of this is Proof Of Work (PoC). The idea is to make "mining" blocks take non-trivial amount of computational work in order to forge another transaction block. When a miner finds a valid nonce, it announces it to the rest of the network so others can begin working on that chain.
When I say non-trivial amount of work, it would take my computer (nVidia 1080 @ 20MH/s) ~3.5 years to mine one Ethereum block as of now. Comparatively, the combined power in the Ethereum network (119.4 TH/s) mines blocks every 24 seconds.
Additionally, the miner that finds the correct nonce that makes a valid block is rewarded. This incentivizes each miner to keep up to date with the latest blockchain and abandon lagging branches and work.
> How does one know with certainty that work was accepted by group consensus?
Through these rewards and the large computational work involved in mining new blocks, the majority of the miners aggressively gravitate to the longest chain. That means that the longer chain continues to grow longer much faster than the other branches. It's this aggressive growth combined with the reward incentives on the longest chain that keeps the whole network honest. Why mine a block that the network won't reward you for? For the individual miner, it's in their best interests to always be working on the longest chain.
> This uncertainty seems to undermine the idea that blockchain is a trustworthy, predictable, verifiable ledger of activity if the work contributed cannot be known as reliably preserved at the time it is submitted, only later in review.
This is part of the security of the blockchain. This prevents malicious agents from pushing "valid" blocks, even if they manage to get all the dots in a row. The computational work involved in building the next block is vastly outpaced by the general network; by the time you minted you "attack" block, many many many new blocks were already minted by the network and they won't accept your block. This "consensus" keeps these attacks from happening.
However, this still can be attacked. If an agent gained control of the majority of the network computational power, then they can mine blocks faster than the honest miners, thus growing the longest chain and thus control exactly what transactions/blocks are mined. This is referred to as the 51% attack because they become the Consensus.
But, using my calculations above, I would need somewhere around ~6*10^6 nVidia 1080 cards all working for me to gain majority in the Ethereum network. So I sleep comfortably at night knowing my ETH is safe.
The chain that is longest (by difficulty) is by definition a log of everything that happened. Transactions that are not part of that chain are just candidates, nothing less nothing more.
How to know Bitcoin better? The best approach is the same as with everything else: reverse engineer and recreate a small coin in your language of choice (chain using hashes plus a simple proof of work using N leading 0s). Remember Satoshi's genius was in assembling pieces in a way nobody thought of, you just need to copy a small version of that. It's not that difficult.
For me the most interesting aspect is smart contracts [1]. That's the one underutilized element of the system that is quite versatile.
[0]: https://en.m.wikipedia.org/wiki/Byzantine_fault_tolerance#By...
[1]: https://en.bitcoin.it/wiki/Contract
Today orphan blocks aren't exactly rare there're several a month where two different pools will announce new blocks within a couple seconds of each other and one gets abandoned because it was the later one or because the other block had a new block mined from it faster.
But that's an inevitability. New block discovery only takes longer over time, and block propagation will only get more complicated as you add more users to chain.
Obviously, this can't be the case (since the number of possible hashes is smaller than the number of inputs). It is just very unlikely, that the same hash appears twice.