블록체인을 만들어봅시다. by hskang9

View this thread on steempeak.com
· @hskang9 · (edited)
$3.20
블록체인을 만들어봅시다.
Daniel Van Flymen이 오픈소스로 블록체인 프로젝트를 만든 이후 많은 사람들이 그의 글을 기반으로 튜토리얼들을 올렸습니다.

[Learn Blockchains by Building One: The fastest way to learn how Blockchains work is to build one](https://hackernoon.com/learn-blockchains-by-building-one-117428612f46)

[dvf/blockchain](https://github.com/dvf/blockchain)

[그의 오픈소스 프로젝트에 참가하는 개발자들을 위한 슬랙 단톡](https://nyc-crypto.slack.com/)


그리고 이것은 그의 오픈소스 프로젝트로 저는 자바스크립트로 포팅하는 작업(part 1)을 진행 후 현재 transaction verification을 위해 asymetric cryptography로 만들어지는 디지털 서명을 이용한 protocol을 pyNaCl으로 개발해보면서 part2에 기여중입니다.

그런데... 


[[블록체인] 파이썬으로 블록체인을 구현해보자 - 1](https://blog.naver.com/PostView.nhn?blogId=pjt3591oo&logNo=221181592127&redirect=Dlog&widgetTypeCall=true)

[golbin/g-coin](https://github.com/golbin/g-coin)
[골빈해커님의 g-coin 분석 1부](https://tykimos.github.io/2018/01/21/g_coin_analysis_part1/) 
[골빈해커님의 g-coin 분석 2부](https://tykimos.github.io/2018/01/21/g_coin_analysis_part2/)
- 골빈해커님의 g-coin은 암호화폐라고 부르기 애매한 부분이 있습니다. 바로 채굴을 서버에서 하고 보상도 주지 않는다는 점입니다. 김태영님께서 언급한 마이너에 대한 블록은 그저 블록체인의 보안을 지켜주는 previous_hash를 위한 genesis block입니다.

---

위 튜토리얼들에는 여러가지 아쉬운 점들이 있습니다.
- **heartbeat loop이 없습니다.**
매번 REST API 서버에서 /mine 으로 request처리하는 것으로 마이닝이 되긴 하지만 만약 request를 안 보내면 소는 누가....
- **'previous_chain' property를 다루지 않습니다.**
보안에 있어서 블록체인의 **최고 존엄**은 바로 얘입니다. 체인이라는 단어가 얘가 없으면 붙지를 않습니다. 얘가 없으면 consensus과정에서 그냥 가장 체인이 긴 마이닝 노드가 어떻게 거래를 해놨던 간에 맞는 블록체인으로 되어버립니다. 
- **디지털 서명**을 이용해 transaction을 verify하지 않습니다.
블록을 보낼 때 transaction verification과정에서 체크해봐야할 게 있습니다.
    1. 과연 transaction이 **거래자 본인**이 보낸 것인지(**Authentication**)
    2. **거래자가 정말 취소 안하고 보낸 것**인지 확인할 수 있는지(**non-repudation**)
    3. 전송 도중에 **데이터가 손상**되지는 않았는지(**integrity**)

     bitcoin은 디지털 서명을 위해 [타원 곡선 암호](https://en.bitcoin.it/wiki/Elliptic_Curve_Digital_Signature_Algorithm)를 사용하고 있습니다. 그래서 해쉬를 돌려서 만드는 거 외에도 api server에 보낼 때 만든 해쉬값을 private key로 encrypt해서 전자 서명을 한 다음 public key랑 같이 넣어서 블록체인 서버에 보냅니다. 그러면 블록체인 서버는 받은 public key를 가지고 전자 서명된 해쉬값을 decrypt할 테고 전송 도중에 데이터가 깨지거나 다른 사람이 이 거래내용을 보내지 않는 한 해독한 해쉬값이 보낸 내용을 해쉬 함수로 돌린 해쉬값과 일치하게 되는 것입니다.

# **그리고 사실.... 이 튜토리얼에서 제공한 코드는 완전한 블록체인이 아닙니다.** 
아직 part 2 article이 남아있습니다(위와 같이 말한 transaction verification, 나중에 도입될지도 모르는 uPnP protocol). 

---
따라서 저는 이번에 제가 전에 글로벌 제주 해커톤에서 블록체인 프로젝트를 통해 같이 뜯어보고 **종합적으로** 설명하고자 합니다.(물론 도중에 피드백 주시면 감사합니다...)
일단 레퍼런스부터 밝히자면

# Reference 

![해커톤.jpg](https://steemitimages.com/DQmUv9k4ELNjSuyQErwFN6MbJkJFPGYvrnSMB9Rd7iaPbyG/%E1%84%92%E1%85%A2%E1%84%8F%E1%85%A5%E1%84%90%E1%85%A9%E1%86%AB.jpg )

저희 팀은 왼쪽에서부터

- [Crystal Chow](https://www.linkedin.com/in/crystal-chow-capm-7a2a0b90/)(PM, 비즈니스 모델)
- [강형석](https://www.linkedin.com/in/hyungsuk-kang-5217a7103/)(팀장, 서버 개발)
- [김소진]()(일러스트레이터)
- [홍승의](https://github.com/zaeval)(Android, 클라이언트 개발)
- [정다혜]()(UI/앱 디자인, 일러스트레이터)

로 되어있고요.

- [heroku에 올린 블록체인 겸 얼마나 많은 **유저**가 얼마나 많은 **코인**들을 **몇 회** 교환했는지 보여주고 체인도 덤으로 아래에 달려있는 백엔드 웹 앱](http://naturecoin.herokuapp.com/visualize) request나 response는 다른 튜토리얼들이랑 동일합니다.
- [안드로이드 지갑 앱](https://github.com/zaeval/Naturecoin/tree/master/muzimuzi)
- [그리고 추후에 UN이 개최한 Asia Pacific Low Carbon Lifestyles Challenge에 top 50로 shortlist된 project](https://www.slideshare.net/ssuser27ef07/nature-coin-81741560)

들을 만들었습니다.

일단 기존에 있었던 코드들부터 차근차근 설명해드리도록 하겠습니다.
그럼 시작합니다!

# 참고

댓글에 javascript로 배우고 싶은 사람은 알려주세요. javascript로 튜토리얼을 쓰는 게 좋은지, python으로 튜토리얼을 쓰는 게 좋은지 궁금합니다.
👍  , , , , , , , , , , , ,
properties (23)
post_id33,424,669
authorhskang9
permlink34zraz
categoryblockchain
json_metadata"{"app": "steemit/0.1", "format": "markdown", "links": ["https://hackernoon.com/learn-blockchains-by-building-one-117428612f46", "https://github.com/dvf/blockchain", "https://nyc-crypto.slack.com/", "https://blog.naver.com/PostView.nhn?blogId=pjt3591oo&logNo=221181592127&redirect=Dlog&widgetTypeCall=true", "https://github.com/golbin/g-coin", "https://tykimos.github.io/2018/01/21/g_coin_analysis_part1/", "https://tykimos.github.io/2018/01/21/g_coin_analysis_part2/", "https://en.bitcoin.it/wiki/Elliptic_Curve_Digital_Signature_Algorithm", "https://www.linkedin.com/in/crystal-chow-capm-7a2a0b90/", "https://www.linkedin.com/in/hyungsuk-kang-5217a7103/", "https://github.com/zaeval", "http://naturecoin.herokuapp.com/visualize", "https://github.com/zaeval/Naturecoin/tree/master/muzimuzi", "https://www.slideshare.net/ssuser27ef07/nature-coin-81741560"], "image": ["https://steemitimages.com/DQmUv9k4ELNjSuyQErwFN6MbJkJFPGYvrnSMB9Rd7iaPbyG/%E1%84%92%E1%85%A2%E1%84%8F%E1%85%A5%E1%84%90%E1%85%A9%E1%86%AB.jpg"], "tags": ["blockchain", "cryptocurrency", "tutorial", "kr"]}"
created2018-02-18 04:02:57
last_update2018-02-18 07:43:33
depth0
children7
net_rshares559,696,938,088
last_payout2018-02-25 04:02:57
cashout_time1969-12-31 23:59:59
total_payout_value2.780 SBD
curator_payout_value0.418 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length3,322
author_reputation21,654,868,736
root_title"블록체인을 만들어봅시다."
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (13)
@ribai ·
좋은 프로젝트네요 추천합니다^^
👍  
properties (23)
post_id33,514,697
authorribai
permlinkre-hskang9-34zraz-20180218t134135974z
categoryblockchain
json_metadata"{"app": "steemit/0.1", "tags": ["blockchain"]}"
created2018-02-18 13:41:36
last_update2018-02-18 13:41:36
depth1
children1
net_rshares615,320,000
last_payout2018-02-25 13:41:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length17
author_reputation23,927,035,221,506
root_title"블록체인을 만들어봅시다."
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@hskang9 ·
감사합니다! 배우고 싶은 언어를 파이썬이나 자바스크립트 중 골라서 댓글에 달아주십시오!
properties (22)
post_id33,519,944
authorhskang9
permlinkre-ribai-re-hskang9-34zraz-20180218t140918838z
categoryblockchain
json_metadata"{"app": "steemit/0.1", "tags": ["blockchain"]}"
created2018-02-18 14:09:21
last_update2018-02-18 14:09:21
depth2
children0
net_rshares0
last_payout2018-02-25 14:09:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length48
author_reputation21,654,868,736
root_title"블록체인을 만들어봅시다."
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@jinsukim ·
좋은 프로젝트네요 ㅎ
python으로 튜토리얼 써주시면 감사하겠습니다.
👍  
properties (23)
post_id33,527,469
authorjinsukim
permlinkre-hskang9-34zraz-20180218t144750376z
categoryblockchain
json_metadata"{"app": "steemit/0.1", "tags": ["blockchain"]}"
created2018-02-18 14:47:51
last_update2018-02-18 14:47:51
depth1
children1
net_rshares615,320,000
last_payout2018-02-25 14:47:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length39
author_reputation379,217,952,383
root_title"블록체인을 만들어봅시다."
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@hskang9 · (edited)
알겠습니다.
properties (22)
post_id33,629,298
authorhskang9
permlinkre-jinsukim-re-hskang9-34zraz-20180219t005520528z
categoryblockchain
json_metadata"{"app": "steemit/0.1", "tags": ["blockchain"]}"
created2018-02-19 00:55:21
last_update2018-02-19 00:55:33
depth2
children0
net_rshares0
last_payout2018-02-26 00:55:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length6
author_reputation21,654,868,736
root_title"블록체인을 만들어봅시다."
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@astriker ·
python 추천할게요 ㅎㅎ
👍  
properties (23)
post_id33,614,878
authorastriker
permlinkre-hskang9-34zraz-20180218t231113947z
categoryblockchain
json_metadata"{"app": "steemit/0.1", "tags": ["blockchain"]}"
created2018-02-18 23:11:12
last_update2018-02-18 23:11:12
depth1
children1
net_rshares603,013,600
last_payout2018-02-25 23:11:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length15
author_reputation0
root_title"블록체인을 만들어봅시다."
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@hskang9 ·
알겠습니다.
properties (22)
post_id33,629,368
authorhskang9
permlinkre-astriker-re-hskang9-34zraz-20180219t005551029z
categoryblockchain
json_metadata"{"app": "steemit/0.1", "tags": ["blockchain"]}"
created2018-02-19 00:55:51
last_update2018-02-19 00:55:51
depth2
children0
net_rshares0
last_payout2018-02-26 00:55:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length6
author_reputation21,654,868,736
root_title"블록체인을 만들어봅시다."
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@steemitboard ·
Congratulations @hskang9! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

[![](https://steemitimages.com/70x80/http://steemitboard.com/notifications/firstpayout.png)](http://steemitboard.com/@hskang9) You got your First payout

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click [here](https://steemit.com/@steemitboard)

If you no longer want to receive notifications, reply to this comment with the word `STOP`

> Upvote this notification to help all Steemit users. Learn why [here](https://steemit.com/steemitboard/@steemitboard/http-i-cubeupload-com-7ciqeo-png)!
properties (22)
post_id35,266,117
authorsteemitboard
permlinksteemitboard-notify-hskang9-20180226t064247000z
categoryblockchain
json_metadata"{"image": ["https://steemitboard.com/img/notifications.png"]}"
created2018-02-26 06:42:45
last_update2018-02-26 06:42:45
depth1
children0
net_rshares0
last_payout2018-03-05 06:42:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length673
author_reputation38,705,954,145,809
root_title"블록체인을 만들어봅시다."
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000