<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jungpil Yu on Medium]]></title>
        <description><![CDATA[Stories by Jungpil Yu on Medium]]></description>
        <link>https://medium.com/@jungpil.yu?source=rss-67367b55c716------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Rx7n0tFolOXisDmL.</url>
            <title>Stories by Jungpil Yu on Medium</title>
            <link>https://medium.com/@jungpil.yu?source=rss-67367b55c716------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 19:49:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jungpil.yu/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[NiPoPow 알고리즘이란?]]></title>
            <link>https://medium.com/@jungpil.yu/nipopow-%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98%EC%9D%B4%EB%9E%80-537a781a24b2?source=rss-67367b55c716------2</link>
            <guid isPermaLink="false">https://medium.com/p/537a781a24b2</guid>
            <category><![CDATA[sidechains]]></category>
            <category><![CDATA[spv]]></category>
            <category><![CDATA[nipopow]]></category>
            <category><![CDATA[coinswap]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Jungpil Yu]]></dc:creator>
            <pubDate>Mon, 29 Jul 2019 07:08:27 GMT</pubDate>
            <atom:updated>2019-07-29T07:08:27.278Z</atom:updated>
            <content:encoded><![CDATA[<h3>NiPoPow 알고리즘</h3><h3>알고리즘의 배경</h3><p>NiPoPow 란 Non Interactive Proof of Proof-of-Work의 줄인말로서 PoW (Proof-of-Work) 합의 알고리즘을 사용하는 블록체인의 풀 노드(full node)에 대해 라이트 노드(light node)가 최소한의 대역폭과 단 한번의 질의(Query)로 필요한 거래 검증을 할 수 있게 하는 알고리즘입니다. 2016년에 유사한 개념이 소개되었고 최근인 2018년 초에 3명(A. Kiayias, A. Miller, and D. Zindros)에 의해 발표(참고문서1)되었다. 이들은 이전의 약식결제확인(SPV) 방식에서 필요했던 대역폭의 90%이상을 줄일 수 있다고 주장합니다. 본 기사는 수학을 최대한 사용하지 않고 참고문서1의 내용을 설명하고자 합니다.</p><h4>알고리즘의 활용 예</h4><ul><li>약식결제확인 (SPV, Simple Payment Verification) 지갑에서 특정 거래가 특정 블록에 존재하는지 확인하는 경우</li><li>ICO에서 A 코인를 모금 받고 B 코인을 발행(coin swap)하는 경우</li><li>채굴기가 포크된 블럭체인상에 새로운 블럭을 붙일 때 어떤 가지에 붙일지 결정하는 경우</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*qGLzz0OfF0PyIGRBhA1iUw.png" /><figcaption>SPV 노드에서의 Tx 증명과 A 체인과 B 체인의 코인 교환</figcaption></figure><h4>본 알고리즘 사용 효과</h4><p>비트코인의 SPV 지갑은 특정 블록속에 특정 거래가 포함되어 있는지 검사하기 위해 블록체인의 헤더 정보만을 가지고 있습니다. 비트코인 블럭체인 전체는 2018년 초에 153 GiB 수준이고 80bytes 크기의 헤더정보는 전체의 약 2.3%에 해당하는 35MiB 정도이다. (2019년초 현재 46MiB로 늘어남)이다. 메모리가 극히 제한적인 IoT기기가 SPV지갑을 담기에는 35MiB도 부담이 될 수 있다. 이와 같이 메모리 제약이 심한 환경에서 평소에는 메모리에 헤더 정보를 가지고 있지 않고 검증이 필요할 경우 일시적으로 풀 노드로 부터 헤더 정보를 가져오는 경우(이하 임시 SPV 지갑)와 본 알고리즘을 적용하는 경우(이하 NiPoPoW SPV지갑)를 비교해 보겠습니다.</p><p>먼저 임시 SPV지갑을 구현할 경우 매번 검증이 요할 경우 매번 35MiB를 이웃에 있는 풀노드에 요청하여 가져오게 되고 악의적 노드의 존재를 생각해서 적어도 5개의 서로 다른 풀노드에게 요청한다고 하면 총 175MiB의 헤더 블록정보를 요청해야 한다.</p><p>한편, NiPoPow SPV 지갑을 구현할 경우 풀노드 하나로 부터 받을 정보는 같은 시기 비트코인 블럭수를 450K로하고 파라미터 <em>m</em> 값을 다양하게 했을 때 다음의 표로 요약할 수 있다. (<em>m</em> 값은 큰 수록 검증 오류 가능성이 낮아짐)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3b956e29707f8ed026aa454be0d75ef/href">https://medium.com/media/e3b956e29707f8ed026aa454be0d75ef/href</a></iframe><p>한편 <em>m </em>값에 따른 오류 가능성은 다음 그래프로 확인할 수 있다. 가운데 수평선은 비토코인의 사토시 논문에서 언급하고 있는 오류 문턱값이고 이를 기준으로 보면 대략 <em>m </em>값은 15이상인 경우 10⁻³ 이하의 오류확률을 얻을 수 있다. 자세한 사항은 참고문서1을 참고한다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*nlQkTxvt_C6XvB5E877wVw.png" /><figcaption>참고문서1((<a href="https://eprint.iacr.org/2017/963.pdf">https://eprint.iacr.org/2017/963.pdf</a>))의 그림6에서 인용</figcaption></figure><h3>알고리즘 이해를 위한 기본 정의</h3><h4>인터링크 포인터 데이터 구조</h4><p>NiPoPow 알고리즘을 사용하는 블록체인은 내부 블럭마다 인터링크 포인터를 포함하도록 되어 있습니다. 작업증명(PoW)이란 각 블럭의 어떤 필드(비트코인에서는 nonce 필드)를 임의값으로 치환하여 블럭 해시값을 계산할 때 그 값이 어떤 기준 해시값(target 값이라고 함) 이하가 되도록 그 필드의 값(nonce값)을 구하는 과정입니다. 인터링크는 일정 범위의 해시값을 가지는 블럭끼리 연결하는 링크이며 이렇게 연결된 블럭들은 기존 블럭체인상의 블럭들의 부분집합으로 구성된 또다른 블럭체인을 구성합니다. 여기서 일정 범위의 해시값은 다음과 같이 분류합니다.</p><ul><li>level 0 : 기준 해시값(target value)을</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/45/0*EklWQZ1wLMjxec-f" /></figure><p>(여기서 t는 보통 256이하의 자연수)라고 할때 계산된 해시값이</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/14/0*HFhvq7AhngYUgWcW" /></figure><p>이하인 경우</p><ul><li>level 1 : 계산된 해시값이</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/61/0*Ox2vlB6rmdTpybGe" /></figure><p>이하인 경우</p><ul><li>level 2 : …</li><li>…</li><li>level μ -1 : …</li><li>level μ : 계산된 해시값이</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/63/0*3OMMOwtNiyTVoiA4" /></figure><p>이하인 경우</p><p>즉 레벨0 블럭들은 그 해시값이 블럭을 생성할 때 주어진 기준 해시값(target 값)을 만족하는 블럭들을 의미하고 따라서 기저 블럭체인을 의미한다. 그리고, 일반적으로 Genesis 블록은 풀 노드나 지갑의 소스코드에 그대로 들어가 있어서 모든 블록들이 Genesis 블록에 대한 링크를 가지고 있다고 간주합니다.</p><p>아래 그림은 위의 설명을 토대로 어떤 블록체인의 인터링크 포인터 데이터 구조를 도시한 모습입니다. 각 블록들에 대해 앞서 기술한 방법에 의해 레벨을 결정하고 레벨에 따라서 인터링크의 수가 정해집니다. 블록내의 숫자는 이렇게 정해진 레벨값을 의미합니다. 그리고 각 인터링크는 인접한 같은 레벨의 블록에 대한 포인터를 가지고 있게 됩니다. 같은 레벨의 블록끼리 연결한 블록체인을 기저 블록체인상의 레벨 μ 수퍼체인 이라고 정의합니다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kqHTIaxtZCfO_hbOYhzITg.png" /></figure><p>한편, 같거나 더 높은 레벨의 블록끼리 연결한 블록체인을 업체인(up-chain)이라고 또한 정의하며 기호로는</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/25/0*knB7QHLcRIvEeUl2" /></figure><p>표시합니다. 아래 그림은 레벨 μ 에 따른 업체인을 도시한 그림입니다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5dgTYoKkMyFanMsuNBWEuA.png" /></figure><p>이후에 제시되는 유사 코드(pseudo-code)로 기술된 알고리즘을 이해하기 위해서 몇가지 기호를 설명합니다.</p><ul><li><em>C</em> 는 블록체인을 의미하며 인덱싱은 Python 코드의 list 데이터 타입과 같다. 예를 들면 <em>C</em>[-1] 은 맨 마지막 블록을 의미한다.</li><li><em>C</em>[0] 는 Genesis블록을 의미한다.</li><li><em>C</em>[: <em>j</em>] 는 Genesis블록부터 j번째 블록 전까지의 블록체인을 의미한다.</li><li><em>C</em>[<em>k</em> :] 는 <em>k</em>번째 블록을 포함하여 이후 맨 마지막 블록까지를 의미한다.</li><li>id(<em>B</em>) 함수는 블록<em> B</em> 의 id를 반환하는 함수이고 비트코인에서는 블럭의 해시값으로 볼 수 있다.</li></ul><p>아래는 이러한 인터링크를 업데이트하는 방법을 설명합니다. 주어진 블록의 인터링크는 링크되는 블록의 id를 저장합니다. 즉 interlink[μ]는 레벨값(μ) 에 대해 가리키는 블록의 id(해시값)를 저장합니다. 프로그램상에서는 링크되는 블록을 가리키는 포인터로 간주할 수 있습니다. 왜냐하면 블록의 id는 모든 블록에서 어떤 블록을 특정하는 데 사용할 수 있기 때문입니다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X9DZ6sCRCMuc9V3_KjklJA.png" /></figure><h4>Prover와 Verifier의 정의</h4><p>NiPoPoW은 Prover와 Verifier 사이에서 작동합니다. Verifier는 어떤 명제(predicate)을 검증하기 위해 블록 정보 데이터가 필요합니다. (주: predicate이란 주어진 데이터를 계산하여 참과 거짓을 판정할 수 있는 명제라고 할 수 있고 여기서는 이를 명제라고 번역하겠습니다.) Verifier의 요청을 받고 블록을 보내주는 쪽을 Prover라고 한다. Prover는 Verifier의 요청에 대해 적절한 블럭 데이터를 보내주게 됩니다. SPV 지갑에서 특정 거래를 확인하는 상황에서 지갑은 Verifier가 되고 지갑에게 블록정보를 제공하는 블록체인 네트워크상의 노드는 Prover가 됩니다.</p><p>한편, 검증하려는 진술이 블럭의 마지막 <em>k </em>블록정보로만 참, 거짓을 결정할 수 있을 때 그러한 블록들을 suffix proof 라고 하고 블럭체인내 특정 블록이 있어야 계산이 가능한 경우에 필요한 블록들을 infix proof 라고 합니다. 몇가지 예외를 제외하고 대부분의 명제는 infix proof를 필요로 하며 suffix proof는 infix proof를 위한 알고리즘의 중간 과정에서 사용됩니다.</p><h3>Prover의 블록 선정 방법</h3><p>Prover의 입장에서 Verifier의 블록 요청을 suffix proof와 infix proof로 나누어 어떻게 수행하는지 설명합니다.</p><h4>Suffix Proof 선정</h4><p>Suffix proof를 제공하는 Prover는 마지막 <em>k </em>개의 블록을 보내주고 이에 덧붙여 전체 블록에서 마지막 <em>k </em>개의 블록을 제외한 부분에서 일부 선별된 블록을 함께 보내준다. 이들 블록을 χ 와 π 로 표시한다.</p><ul><li>χ : 블록체인의 마지막 <em>k </em>개의 블록 (<em>C</em>[-<em>k</em>:])</li><li>π : Genesis 블록에서 χ 를 제외한 블록들(<em>C</em>[:-<em>k</em>]) 중에서 선정되며 상세 과정은 아래의 알고리즘3에 의해 설명된다.</li></ul><p><em>C</em>[ -<em>k - </em>1]블록의 레벨 μ 의 업체인상 블록들로 α배열을 구성하고 이 배열의 블록을 π 에 포함시킵니다. 만약 α 집합의 블록수가 <em>m </em>이라는 파라미터값보다 크다면 α[-<em>m</em>] 블록을 B에 저장합니다.</p><p>이후 1 감소된 레벨 (μ - 1)의 업체인상의 블록들 중 B보다 큰 높이(height)를 가지는 블록들로 α 배열을 구성하고 그 배열의 블록들을 π 에 포함시킨다. 이러한 과정은 레벨이 0이 될 때까지 반복하면서 π 를 갱신합니다. 이와 같이 구한 π, χ 를 반환합니다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ur0TuJEVb7zkoLHydi3OFQ.png" /></figure><p>아래는 인터링크 포인터 구조가 있는 블럭체인상에서 위의 알고리즘3을 적용하는 경우를 예시합니다. 알고리즘을 따라가면서 그림을 이해하면 이해가 쉽습니다. <em>k</em> = 3, <em>m</em> = 3 인 경우의 예이며 맨 오른쪽 18, 19, 20번째 블록은 χ 집합을 나타내고 나머지 3, 7, 9, 11, 13, 14, 15, 16, 17 블록들이 위 알고리즘에 의해 구해진 π 집합을 의미합니다. 레벨3 업체인의 블록들은 그 개수가 2개로 α 에 모두 포함됩니다.</p><p>이후 레벨2 업체인의 경우 또한 모두 α 에 포함되고 그 개수가 4개로 <em>m </em>보다 크기 때문에 α[-3] 에 해당하는 <em>C</em>[7] 이 B에 저장되고 이후 레벨1 업체인에서는 B보다 높이(height)가 큰 블록으로만 제한하여 α 를 업데이트합니다.(line 4) 따라서 이때 새로 α 에 포함되는 블록이 <em>C</em>[9],<em>C</em>[13],<em>C</em>[17] 이 됩니다. 그리고 마찬가지로 레벨1 업체인의 블록개수(5)가 <em>m </em>보다 크기 때문에 이 업체인의 α[-3] 에 해당하는 <em>C</em>[13] 으로 B를 다시 쓰고 마지막 레벨0 업체인 (기저체인)에서 π 에 들어갈 블록들을 선택하는 과정에서<em>C</em>[13] 이후의 블록으로 제한합니다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f5HwwNMrbwt6JW1q5Yww8g.png" /></figure><h4>Infix Proof 선정</h4><p>이번에는 Infix proof를 제공하는 Prover의 동작을 알아보겠습니다. 이는 아래의 알고리즘5에 의해 수행됩니다. 여기서 <em>C</em>’ 은 verifier가 요청하는 특정 블록의 집합이며, height 는 블럭이 주어지면 블록체인상 몇번째 블럭인지를 알려주는 Python의 dictionary type과 같은 변수로 생각할 수 있습니다.</p><p>먼저 Prover는 Suffix proof(π, χ)를 앞서의 방법에 의해 구합니다. 이후 <em>C</em>’ 집합의 각 블록 <em>B </em>에 대해 Suffix proof에서 구한 π 집합의 각 블록중에서 <em>B </em>보다 높이(height) 값이 큰 <em>E</em> 에 대해서 followDown함수를 호출합니다. (followDown 함수의 동작은 알고리즘6에서 이해할 수 있습니다.) 최종적으로 반환하는 infix proof의 π 는 이러한 과정에서 followDown 함수가 반환하는 블록들을 포함하게 됩니다. 한편, followDown 함수는 기본적으로 매개변수 E의 레벨 μ 에서 보는 업체인에서 블럭 B가 E와 이의 바로 인접 조상 블럭사이에 있는지 조사하여 그 사이에 있다면 B까지의 블록을 포함시킵니다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_tLcOfRFcmThfaGTC3oUgw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Toxtk3UnSbACSApQSAia2A.png" /></figure><p>아래 그림은 이러한 과정을 suffix proof의 경우처럼 도시한 예입니다. Infix proof 알고리즘을 통해 기존 Suffix proof 알고리즘에서 구한 π 에서 2개의 블록(<em>C</em>[4], <em>C</em>[5])이 추가된 것을 알 수 있습니다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t73VVcaI3Zzq9JIM92diPw.png" /></figure><p>아래 그림은 최종 반환되는 Infix proof를 보여줍니다. 반환되는 블록들은 그 자체로 체인으로 연결되는 온전한 블록체인인 것을 알 수 있습니다. Genesis블록은 실제로는 반환되지 않으나 verifier가 이미 알고 있는 블록이므로 개념상 그림에서는 점선으로 도시되었습니다. 기존 SPV 방식에서는 prover의 경우 모든 블럭을 보내주는 데 반해 본 알고리즘을 채용한 prover는 6개의 블럭(<em>C</em>[1],<em>C</em>[2],<em>C</em>[6],<em>C</em>[8],<em>C</em>[10],<em>C</em>[12]) 은 보내주지 않게 됩니다. 따라서, 그만큼 통신 대역폭 및 verifier쪽의 메모리 요구사항을 줄일 수 있게 됩니다. 도시한 예에서는 20개의 블럭으로 구성된 짧은 블록체인이기에 그 이득이 많지 않지만 많은 블럭으로 이루어진 긴 블럭체인의 경우 그 이득이 매우 커지게 됩니다. 얼마나 커지는 지에 대해서는 앞선 알고리즘 사용 효과 섹션에서 설명했습니다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_NTO2gZTtbPB3A4wHWQVOg.png" /></figure><h3>Verifier 의 수신 블록 처리 방법</h3><p>Verifier의 입장에서 여러 Prover가 보내온 블록들을 suffix proof와 infix proof로 나누어 어떻게 처리하여 명제(predicate)를 계산하기 위한 데이터로 확정하는지 설명합니다.</p><h4>Suffix Proof 처리</h4><p>이번에는 Verifier쪽에서의 알고리즘을 살펴보겠습니다. Verifier는 악의적인 Prover의 존재를 가정하고 최대한 올바른 결정을 내리기 위해 여러 Prover들에게 proof를 요청합니다. 이때, Suffix proof에 대한 검증은 아래와 같이 이루어집니다. 기본적으로 Prover들이 보내온 각각의 proof에 대해 평가하고 가장 정직할 것으로 생각되는 Prover의 suffix proof를 선정하고 이를 통해 명제(predicate)을 검증합니다. 여기서 정직함의 기준은 투입된 해시파워의 양으로 보고 블록체인중에서 가장 많은 해시파워가 투입되어진 블록체인을 보낸 Prover가 가장 정직하다고 판정합니다. 아래 알고리즘2는 각 Suffix proof중에서 끊어지지 않은 올바른 체인인지 검사하며, χ 안의 블록 개수가 <em>k </em>개인 블록체인 중에서 해시파워가 가장 큰 것을 선정하는 알고리즘 코드입니다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Oua5B69EF-vlsqYFwwmDw.png" /></figure><p>아래 알고리즘4는 두개의 블록체인중에서 투입된 해시파워가 많은 체인을 추정합니다. 두개의 블록체인중에서 분기(fork)가 일어나기 시작한 블록들(</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/98/0*RAAK9-LVoJun8AWM" /></figure><p>) 만으로 비교합니다. 여기서</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/130/0*5ltMO8MuFlQn2cWB" /></figure><p>입니다. 즉 <em>b</em>는 공통 블럭들중 가장 마지막 블럭을 의미합니다. 레벨 μ 업체인에서 추정하는 기저 블록체인에 투입된 해시파워는 μ 업체인의 분기가 일어나기 시작한 블록들 중 다음의 두 조건을 만족하는 값입니다.</p><ul><li>블록개수(</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/62/0*g3tBnh35BQRYhivD" /></figure><p>)가 <em>m</em> 이상인 레벨 μ 중에서 (line 2)</p><ul><li>가장 크게 계산되는</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/100/0*FCTV8PssAGUG9k9V" /></figure><p>값이 추정 해시파워이다.</p><p>위 계산 근거는 앞서 설명한 레벨의 정의를 통해 이해할 수 있습니다. 이렇게해서 구한 블럭체인들의 추정 해시파워중 가장 큰 값을 가지는 블럭체인을 선택합니다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vKbA6syh2ze852gev4hFPw.png" /></figure><h4>Infix Proof 처리</h4><p>앞서 Suffix proof를 이용한 verifier에 이어 이번에는 Infix proof를 이용하는 명제(predicate) 검증을 생각합니다. 아래의 알고리즘7은 매우 간단하게 아래와 같이 설명됩니다.</p><p>먼저 알고리즘의 14 line 이후부터 보면 입수한 모든 proof을 통해서 블록의 id(비트코인의 경우 블록해시값)에 대해 블록을 반환하는 Python의 dictionary 타입 변수 blockById를 생성합니다. (line 15~20)</p><p>이후 suffix proof verify 알고리즘을 통해 가장 정직하다고 생각되는 Prover의 블록체인(</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/10/0*p8Yuumxc5HJKe27o" /></figure><p>)을 선정(line 21)하고 ancestors() 함수를 호출합니다. ancestors() 함수는 선정된 블록체인의 맨 끝의 블록(</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/39/0*SASWPlsWP5ZV1T9R" /></figure><p>)에서부터 조상 블록들을 Genesis블록까지 찾아가면서 수집한 블록들을 반환합니다. 최종적으로 ancestors() 함수에서 반환된 블록들로 명제(predicate)를 계산하고 그 값(참, 거짓)을 반환합니다.</p><p>조상 블록을 찾는 과정은 blockById 변수를 통해 깊이 우선 탐색(Depth-first Search) 알고리즘으로 수행합니다. 즉 시작 블록(</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/42/0*mJRtrnNb51QoQ-pD" /></figure><p>)의 인터링크로 조상블록을 방문하고 그 조상블록의 조상블록을 재귀 호출로 방문합니다. 최종적으로 Genesis 블록까지 방문하면 Genesis블록을 반환하면서 방문한 모든 블록들을 수집하여 조상 블록들을 최종 반환합니다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7nSMdEuF4z_xDK6wskVGZA.png" /></figure><p>여기서 blockById 변수는 분기가 일어날 수 있는 모든 블록체인으로 생성했기 때문에 DAG(Directed Acyclic Graph) 형태의 데이터 구조가 될 수 있습니다. 이러한 blockById 변수에서 조상 블록을 찾아가는 이유는 선택된 블록체인만 반환할 경우 혹시나 여기에 누락된 블럭이 있다면 그 블록을 다른 (비록 악의적인 노드가 보냈더라도) 블록체인에서 찾을 수 있지 않을까 기대하기 때문입니다.</p><p>예를 들어 아래 그림과 같이 노드가 보낸 2개의 블록체인A와 B가 있다고 하겠습니다. 10번 블록에서 분기가 발생해서 10번 블록 앞까지는 동일하지만 그 이후에는 블록의 내용도 그 길이도 다릅니다. suffix proof에 대한 verifier 알고리즘에 의해 블록체인B를 그래도 가장 정직한 노드가 보낸 블록체인으로 결정했다고 가정하겠습니다. 그러나 블록체인B도 6번 블록이 불행하게도 누락되어 있습니다. (블록체인A는 2번, 8번, 10번 블록이 누락되어 있다.) 만약 블록체인 B를 그냥 명제 검증에 사용한다면 누락된 6번 블록으로 정확한 검증이 불가능할 수 있습니다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*_tssL23n3lTnFzlH2sgw4w.png" /></figure><p>아래는 블록체인A, B를 사용하여 생성한 blockById 변수가 표현하고 있는 블록체인입니다. 포크가 일어나기 전의 블록들은 서로 동일하기 때문에 블록들이 겹쳐져서 도시되었습니다. 각각의 블록에서 누락된 블록들은 동시에 누락되어 있지는 않기 때문에 온전한 블럭체인으로 되어 있고 infix proof에 대한 verifier 알고리즘에 의해 블록체인B의 맨 마지만 블록 (</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/47/0*QExCh_Wk6gHG4Xxa" /></figure><p>)에서 조상 블록들을 찾아갈 때 원래 누락된 6번 블록은 찾을 수 있게 됩니다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*Hig4V3pyXecGRFPXY7X-pg.png" /></figure><h3>참고 문서</h3><ol><li>Technical Paper, Non-Interactive Proofs of Proof-of-Work (<a href="https://eprint.iacr.org/2017/963.pdf">https://eprint.iacr.org/2017/963.pdf</a>) : 오리지날 논문으로 본 기사의 바탕이 된 문서임</li><li>Site, <a href="https://nipopows.com/">https://nipopows.com/</a> : NiPoPow알고리즘에 대한 설명을 많은 링크를 통해 안내하는 사이트</li><li>Youtude, <a href="https://www.youtube.com/watch?v=Bky_YlzToSA">https://www.youtube.com/watch?v=Bky_YlzToSA</a> : 기술 논문을 자세하게 (3시간동안!) 열심히 설명한 동영상</li><li>Github, <a href="https://github.com/dionyziz/popow">https://github.com/dionyziz/popow</a> : 위 논문의 3저자인 D. Zindros의 개인 소스 저장소로 논문의 원본 소스(LaTeX화일)와 실험에 사용한 소스 코드를 얻을 수 있음</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=537a781a24b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ESP-IDF based Development Environment for ODROID-GO]]></title>
            <link>https://medium.com/@jungpil.yu/esp-idf-based-development-environment-for-odroid-go-e27ff41b4adf?source=rss-67367b55c716------2</link>
            <guid isPermaLink="false">https://medium.com/p/e27ff41b4adf</guid>
            <category><![CDATA[embedded]]></category>
            <category><![CDATA[development-environment]]></category>
            <category><![CDATA[esp32]]></category>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[odroid]]></category>
            <dc:creator><![CDATA[Jungpil Yu]]></dc:creator>
            <pubDate>Thu, 25 Jul 2019 06:52:52 GMT</pubDate>
            <atom:updated>2019-07-26T05:13:50.341Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://www.hardkernel.com/shop/odroid-go/">ODROID-GO</a> is a small <a href="https://en.wikipedia.org/wiki/ESP32">ESP32</a>-based device with a display, speaker, battery, buttons, micro-sd reader for $32. There is an emulator firmware available which makes it look like the original <a href="https://en.wikipedia.org/wiki/Game_Boy">Gameboy</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*-Ue6RKe5Y7VK41lF0P-3Zg.jpeg" /><figcaption>ODROID-GO image from https://www.hardkernel.com/shop/odroid-go/</figcaption></figure><p>However, its use case is not limited to a game device. It can be programmed like one of a ESP32 device. The vendor has provided <a href="https://wiki.odroid.com/odroid_go/odroid_go">the wiki page</a> where some example codes are presented in C or micro-python. The development environment in the wiki page is <a href="https://www.arduino.cc/en/main/software">Arduino IDE</a> which is somewhat disappointing choice for a serious developer. In order to unlock the full power of a ESP32 micro-controller, it is preferable to work on a development environment based on <a href="https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html">ESP-IDF</a>(Espressif IoT Development Framework). ESP-IDF allows dual cores to be exploited by freeRTOS. More minute details can be manipulated by ESP-IDF than by Arduino IDE.</p><p>Unfortunately, <a href="https://github.com/hardkernel/ODROID-GO/issues/3">ODROID-GO library doesn’t support ESP-IDF</a>. This article is intended to show how to remedy this problem by presenting a step-by-step guideline to construct a development environment using ESP-IDF.</p><h3>Setting up ESP-IDF environment</h3><p>ESP-IDF is a framework based on the ESP32 compiler and build tools. So the compiler and build tools should be also installed and set up. To do this, it’s enough to follow the <a href="https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html#installation-step-by-step">instructions</a> provided by espressif.</p><p>From now on, it is assumed that ESP-IDF and build tools are properly installed on <strong><em>Linux</em></strong> based host computer and the environment variable such as IDF_PATH and PATH is properly set up too. The tested toolchain version in this article was as follows.</p><pre>$ make help<br>Toolchain path: /home/pi/Projects/odroid/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc<br>Toolchain version: crosstool-ng-1.22.0-80-g6c4433a<br>Compiler version: 5.2.0<br>Welcome to Espressif IDF build system. Some useful make targets:</pre><pre>....</pre><h3>Cloning ESP-IDF template</h3><p>Espressif provides the template project for ESP-IDF applications in the <a href="https://github.com/espressif/esp-idf-template">github repository</a>. This will be cloned to instantiate a project.</p><pre>$ git clone https://github.com/espressif/esp-idf-template.git ./medium<br>$ cd medium<br>$ rm -fr .git &amp;&amp; git init</pre><p>Since we are not intended to maintain the template in itself, we reset the .git directory in the project root directory.</p><h3>Editing project name in Makefile</h3><p>To change the project name in the Makefile, open Makefile (using vi for example) and edit the project name.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/153d0e9d7c2fa62da8a926a16f8b7ff4/href">https://medium.com/media/153d0e9d7c2fa62da8a926a16f8b7ff4/href</a></iframe><p>The PROJECT_NAME is originally app-template in the Makefile. The PROJECT_NAME above was changed with medium.</p><h3>Downloading submodules</h3><p>Now, it is time to fetch necessary submodules for the project. To do this, a components directory is created. The necessary modules are arduino-esp32 and ODROID-GO here. The former is the arduino core library for ESP32 and the latter is that for use of ODROID-GO specific features.</p><pre>$ mkdir components<br>$ git submodule add https://github.com/espressif/arduino-esp32.git components/arduino<br>$ git submodule add https://github.com/jungpilyu/ODROID-GO.git components/odroid-go<br>$ cd components/arduino &amp;&amp; git submodule update --init --recursive<br>$ cd -</pre><p>The original ODROID-GO library should be modified to be used under the ESP-IDF environment. So I forked from the original repository and modified. I will ask a pull-request soon, so that it can be downloaded directly from the vendor repository.</p><h3>Configuring menuconfig</h3><p>Run the project configuration utility menuconfig by executing make menuconfig command. When exiting, this tool saves the configuration options in the sdkconfig file in the project root directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*7mZNVNseFOmU3NteRBj9zw.png" /><figcaption>Configuration Menu shown by `make menuconfig`</figcaption></figure><p>There are several options to be modified as follows. First of all, go to Serial flasher config → Flash size and set it 16MB which is ODROID-GO internal flash memory size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*QE4xii57tcqMJcrjAFVDOw.png" /></figure><p>Then, go to Component config → mbedTLS → TLS Key Exchange Methods → Enable PSK based ciphersuite modesand set it enable like the following figure. This feature is necessary for WiFi-related function compilations in the Arduino core library. To enable this feature, the feature of Enable pre-shared-key ciphersuites should be enabled in advance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*0k29p1lzI4BByJTkpVz5_g.png" /></figure><p>Then, go to Arduino configuration → Autostart Arduino setup and loop on bootand set it enable like the following figure. This option allows a programmer to write only two setup() and loop() functions which is the Arduino based coding style.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*hE8tXJT_ZxlbqKWl_GYKpQ.png" /></figure><p>All done! Now it is time to write an application.</p><h3>Testing example projects</h3><p>ODROID-GO module accompanies some example projects in a ./examplesdirectory. Let us try to compile and execute one of them. For example, type them to make image of the button test app. The default source file main.c of the template project is deleted before copying the button test app source file.</p><pre>$ rm main/main.c<br>$ cp components/odroid-go/examples/Buttons/Buttons.ino main/main.cpp<br>$ make</pre><p>Then after plugging ODROID-GO into a USB port, turn on it and flash the image onto the device by make flash. The following figure shows the successful operation of this example project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*Ad0OS74WfbXX1MIVv8ewsw.png" /></figure><h3>Developing apps for ODROID-GO</h3><p>In order to get the most out of ESP32 microcontroller, Autostart Arduino setup and loop on boot feature can be disabled. Then, main function can be written with app_main() as is a usual freeRTOS program.</p><p>For example, the following main.cpp file allows to develop an app without Autostart Arduino... option in Arduino coding style by defining bothsetup() and loop().</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/274a8b505b0ed015f6b549bd92b18083/href">https://medium.com/media/274a8b505b0ed015f6b549bd92b18083/href</a></iframe><p>ESP-IDF development environment enables to use dual cores in ESP32 micro-controller with more degree of freedom in the programming.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e27ff41b4adf" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>