無知

갈 길이 먼 공부 일기

기술 공부/블록체인

도대체 블록체인이 뭐야? | WTF is The Blockchain?

moozii 2021. 12. 30. 19:17

https://hackernoon.com/wtf-is-the-blockchain-1da89ba19348

 

블록체인: 이렇게 복잡한 게 왜 필요한 걸까?

Blockchain: why do we even need something this complex?

 

해외의 유명한 글을 따라가보며, 공부해보자. (인용문은 모두 해당 글의 원문이다)

 

블록체인이 필요한 이유를 설명하기 위해, 하나의 상황을 이야기해보자. 

타인에게 송금을 해야 할 때, 우리는 은행에 이야기한다.

"제 잔고에서 $1000을 OOO에게 옮겨주세요."

그러면 은행에서는 내 잔고에 충분한 돈이 있는지를 살피고 나서, 아래와 같이 장부를 작성한다.

The Transaction Register

 

우리는 모두 제3의 기관인 은행을 신뢰해서,
물리적으로 돈이 옮겨지지 않아도 송금되었다고 믿는다.

이 거래 장부가 소실된다면? 은행이 기록을 잘못한다면? 은행이 고의로 거래 내역을 조작한다면?

타인에게, 제3자에게 이를 맡기게 되면 위와 같이 끝없이 위험요소가 발생하고,
그래서 더욱 신뢰할 수 있는 주체를 찾기 마련이다. 

 

하지만, 만약 우리 스스로 기술적으로 그 문제를 해결할 수 있다면?

그 해결책으로 등장한 것이 바로 블록체인이다.

 

Is there a way to maintain the register among ourselves instead of someone else doing it for us?

Now, that is a question worth exploring. And the answer is what you might have already guessed. The blockchain is the answer to the profound question.

 

 

블록체인의 작동 방식

거래 장부를 은행 같은 제3의 기관이 아니라 우리 손으로 직접 작성하자!

 

그러면, 거래가 발생할 때마다 우리의 장부에 직접 기록하자. 

대신, 거래 당사자만 기록하면 조작의 위험이 있으니까 공동체 전체가 그 장부 내역을 확인하고 기록하자.

Everyone checks whether #2 has enough balance to transfer $10 to #9. If she has enough balance, everyone then makes a note of the transaction on their blank pages.

 

그렇게 거래 내역을 장부에 작성 중인데, 

장부가 가득 찬 시점이 도래하면?

"기록이 완료된 장부에 다른 사람이 손을 못 대도록 봉인하자."

Before we put away the page in our folders, we need to seal it with a unique key that everyone in the network agrees upon. By sealing it, we will make sure that no one can make any changes to it once its copies have been put away in everyone’s folder — not today, not tomorrow and not even after a year. Once in the folder, it will always stay in the folder — sealed. Moreover, if everyone trusts the seal, everyone trusts the contents of the page. And this sealing of the page is the crux of this method.

 

조작되지 않았음을 보장할 수 있고,
공동체 모두가 신뢰할 수 있는 봉인 방식은 무엇일까?

 

Earlier the third-party/middleman gave us the trust that whatever they have written in the register will never be altered. In a distributed and decentralized system like ours, this seal will provide the trust instead.

 

봉인 방식의 기초 : HASH 함수

The Magic Machine (aka Hashing Function)

해쉬 함수는 위와 같은 "마법 상자" 같은 함수다. 

입력 값을 넣으면, 암호화된 출력 값이 나온다. 

그 누구도 어떻게 암호화가 된 건지, 그 중간 과정은 알 수가 없다. 역산이 안되기 때문이다.

 

 

그러면 해쉬 함수의 출력 값 N자리 중에서,
앞 M자리가 0으로 시작하는 출력 값이 나오는 입력값은 무엇일까?
“Can you tell me what should I send from the left side of the machine such that I get a word that starts with three leading zeroes from the right side of it? For example, 000ab or 00098 or 000fa or anything among the others.”

 

앞에서 말했다시피, 어떤 과정을 거쳐서 출력 값이 나오는지를 모르기 때문에, 

위에서 설명한 문제를 맞히기 위해서는, "모든 경우를 시도하는 수밖에 없다"

 

이 문제는, 정답을 맞히기는 어렵지만, 정답인지 아닌지 채점하기는 쉽다.

정답이라고 주장하는 입력 값을 그냥 해쉬 함수에 넣어보면 되기 때문이다. 

이게, 해쉬 함수가 블록체인에 쓰이는 가장 중요한 이유다. 

The most important property of such machines is that — “Given an output, it is extremely difficult to calculate the input, but given the input and the output, it is pretty easy to verify if the input leads to the output.”

 

 

근데 이 해쉬 함수를 블록체인에 어떻게 활용한다는 거야?

 

거래 장부에는 각각의 고유 값, 고유번호가 있다고 하자.

그러면 이런 질문을 만들어볼 수 있다. 

 

저 거래장부 고유 값에 얼마를 더하면,
앞자리 M개가 0으로 시작하는 출력 값이 나오도록 하는 입력값이 될까?

 

그 더하게 되는 정답 값을 거래 장부 위에 붙이면, 그 거래장부는 봉인된다. 

이렇게 거래 장부를 봉인하기 위해 구해서 붙인 정답 값을 우리는 작업 증명이라고 한다. (Work of Proof)

 

그 값을 구하면 왜 봉인된 거야?

거래 장부의 고유 값은 거래 장부의 내용을 기반으로 한다. 

즉, 거래 장부의 내용이 변경되고 조작되면 거래 장부 고유 값이 자동으로 변경된다. 

그래서 그 변경된 값과, 우리가 처음 봉인할 때 만들어둔 정답 값을 넣고 해쉬 함수에 넣으면, 

당연히 원래대로라면 출력 값이 앞자리 M개가 0으로 이루어지겠지만, 

입력되는 거래장부 고유 값이 변경되었으니까, 아예 다른 출력값이 나오는 것이다. 

If anyone wants to verify whether the page was altered, all he would have to do is — add the contents of the page with the sealing number and feed to the magic machine. If the machine gives out a word with three leading zeroes, the contents were untouched. If the word that comes out doesn’t meet our requirements, we can throw away the page because its contents were compromised, and are of no use.

 

그래서 우리가 봉인했다고 확신할 수 있는 정답 값은, 

가장 먼저 구한 사람이 공동체 전체에 알리면, 

공동체 일원들은 그 값을 넣어서 기준에 충족되는지 (출력 값 앞자리 M개가 0으로 시작하는지) 확인하고, 

맞다는 것을 확인하면 모두 봉인 값으로 그 값을 똑같이 기록한다.

 

 

 

그러면 만약 다른 사람이 "저 정답 값은 틀렸어요"라고 한다면?

경우의 수는 크게 3가지이다. 

1. 다른 사람이 정답 값을 잘못 들었을 경우

2. 다른 사람이 그동안의 거래 내역 중 일부를 잘못 작성했을 경우

3. 다른 사람이 조작을 하거나 속이기 위해 거짓말을 하는 경우

 

정답 값이 틀렸다고 주장하는 사람은,

무조건 자신의 기존 거래장부를 삭제하고, 남들이 작성해둔 거래 장부를 복사해와 사용하게 된다. 

그렇지 않을 경우에는 네트워크에서 배제된다. 

 

블록체인의 철학이 아래와 같기 때문이다.

 

다수가 동의하는 봉인 값이 가장 진실된 봉인 값이다.
Whatever sealing number the majority agrees upon, becomes the honest sealing number.

 

 

다른 사람이 알아서 봉인 값을 구해주는데, 왜 나서서 계산해야 할까?

 

Then why does everyone spend resources doing the calculation when they know that someone else will calculate and announce it to them? Why not sit idle and wait for the announcement?

Great question. This is where the incentives come in the picture. Everyone who is the part of the Blockchain is eligible for rewards. The first one to calculate the sealing number gets rewarded with free money for his efforts (i.e. expended CPU power and electricity).

 

그 봉인 값을 모두가 나서서 계산하도록 하기 위해, 

공동체는 인센티브를 부여하는데, 그 보상으로서 등장하는 것이 코인이다.

계산하는 데 사용한 컴퓨팅 파워와 전기에 대한 보상과 같은 개념이다.

 

 

근데 그 봉인 값도 거래장부 단위니까 조작이 가능하지 않나?

 

예전의 거래 내역을 바꾸기 위해 장부에 손을 댄 뒤 새로운 봉인 값을 구한다면?

조작 후 봉인이 가능하지 않을까?

Imagine there are five pages in the folder already — all sealed with a sealing number. What if I go back to the second page and modify a transaction to favor myself? The sealing number will let anyone detect the inconsistency in the transactions, right? What if I go ahead and calculate a new sealing number too for the modified transactions and label the page with that instead?

 

그렇기 때문에 실제 거래 장부 봉인 방식은 입력 값으로, 

"앞서서 봉인된 다른 장부의 봉인 값"을 포함한다. 

To prevent this problem of someone going back and modifying a page (Block) as well as the sealing number, there’s a little twist to how a sealing number is calculated.

 

1. 봉인할 대상인 지금 장부의 내용

2. 이전 거래 장부의 봉인 값

3. 우리가 구해야 할 정답 값

 

이 3개를 합쳐서 입력하면 앞자리 M개가 0이 되도록 하는 정답을 찾도록 하는 것이다. 

 

실제 블록체인에서는, 이전 거래 장부의 값을 참고하여 계산하도록 한다.

Remember how I told you that I had given you two boxes — one containing the number 20893 and another empty for you to calculate? In reality, to calculate the sealing number in a Blockchain, instead of two boxes, there are three — two pre-filled and one to be calculated.

 

이 방식을 통해 모든 거래 장부는 이전 거래 장부의 값에 따라 달라지게 된다.

즉, 거래 내역을 조작하기 위해서는 장부끼리 연결된 하나의 긴 사슬 전체를 모두 변경해야 하는 번거로움이 생긴다.

With this neat little trick, we have made sure that every page depends on its previous page. Therefore, if someone has to modify a historical page, he would also have to change the contents and the sealing number of all the pages after that, to keep the chain consistent.

 

그래서 장부를 조작하려는 한 사람이 블록체인 사슬을 처음부터 다 변경하려고 하면, 

그 속도는 기존에 장부를 사용하던 공동체 사람들이 새로운 장부를 계속 생성해나가면서

블록체인 사슬이 길어지는 속도를 따라잡을 수 없다. 

What will happen is, from the page the dishonest guy tries to cheat, he would be creating another chain in the network, but that chain would never be able to catch up with the honest chain — simply because one guy’s efforts and speed cannot beat cumulative efforts and speed of nine. Hence, guaranteeing that the longest chain in a network is the honest chain.

 

가장 긴 사슬이 가장 정직한 사슬이라는 뜻이다.

 

 

그러면 공동체의 다수가 정직하지 않다면?

 

그럴 경우에는 당연히 그 블록체인 프로토콜과 공동체는 실패하고 만다. 

애초에 블록체인 공동체와 그 기술의 근간에는, 
"다수는 언제나 옳다"는 생각이 있기 때문이다.

 

 

 

 

 

 

출처 : https://hackernoon.com/wtf-is-the-blockchain-1da89ba19348

 

WTF is The Blockchain? | Hacker Noon

 

hackernoon.com