<?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 gimre on Medium]]></title>
        <description><![CDATA[Stories by gimre on Medium]]></description>
        <link>https://medium.com/@ncosigimcitynre?source=rss-7e9451722789------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*38_yTV8vsyoy-Gm3.jpg</url>
            <title>Stories by gimre on Medium</title>
            <link>https://medium.com/@ncosigimcitynre?source=rss-7e9451722789------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 21:11:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ncosigimcitynre/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[Verifying Symbol account state proofs (part 2)]]></title>
            <link>https://ncosigimcitynre.medium.com/verifying-symbol-account-state-proofs-part-2-d28cbb859fd0?source=rss-7e9451722789------2</link>
            <guid isPermaLink="false">https://medium.com/p/d28cbb859fd0</guid>
            <dc:creator><![CDATA[gimre]]></dc:creator>
            <pubDate>Wed, 30 Jun 2021 12:32:13 GMT</pubDate>
            <atom:updated>2021-06-30T12:32:13.508Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://ncosigimcitynre.medium.com/verifying-symbol-account-state-proofs-for-fun-and-profit-part-1-3dfedfc19cb4">Previous part</a> analyzed how account states are serialized in Symbol blockchain and how the state can be verified using merkle tree path. The account in part 1 was simple account, in this part I’m going to walk you through slightly more complicated example.</p><h3>Serializing state</h3><p>This time account of interest will be TCIAR4BDWLX22WGIHU3OQSJKUOAJZTP6HO2XLQI. This is second richest account in testnet as of now. It’s visible on explorer screenshot below, that it has enormous importance of 29%.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RHbsBuri0OMIgjwpnmJHaw.png" /><figcaption>TCIAR4BDWLX22WGIHU3OQSJKUOAJZTP6HO2XLQI account details as seen in block explorer</figcaption></figure><p>Querying /accounts/TCIAR4BDWLX22WGIHU3OQSJKUOAJZTP6HO2XLQI, yields following data:</p><pre>{<br>  &quot;account&quot;: {<br>    &quot;version&quot;: 1,<br>    &quot;address&quot;: &quot;989008F023B2EFAD58C83D36E8492AA3809CCDFE3BB575C1&quot;,<br>    &quot;addressHeight&quot;: &quot;1&quot;,<br>    &quot;publicKey&quot;: &quot;D1A549D23F22C912169105C4A57AC82D82BC07B1F7F1AA092B14E03B8E2DDCF9&quot;,<br>    &quot;publicKeyHeight&quot;: &quot;30818&quot;,<br>    &quot;accountType&quot;: 0,<br>    &quot;supplementalPublicKeys&quot;: {},<br>    &quot;activityBuckets&quot;: [<br>      { &quot;startHeight&quot;: &quot;206820&quot;, &quot;totalFeesPaid&quot;: &quot;0&quot;, &quot;beneficiaryCount&quot;: 0, &quot;rawScore&quot;: &quot;2331691338220390&quot; },<br>      { &quot;startHeight&quot;: &quot;206640&quot;, &quot;totalFeesPaid&quot;: &quot;0&quot;, &quot;beneficiaryCount&quot;: 0, &quot;rawScore&quot;: &quot;2331698263781336&quot; },<br>      { &quot;startHeight&quot;: &quot;206460&quot;, &quot;totalFeesPaid&quot;: &quot;0&quot;, &quot;beneficiaryCount&quot;: 0, &quot;rawScore&quot;: &quot;2331707744132286&quot; },<br>      { &quot;startHeight&quot;: &quot;206280&quot;, &quot;totalFeesPaid&quot;: &quot;0&quot;, &quot;beneficiaryCount&quot;: 0, &quot;rawScore&quot;: &quot;2331717124895476&quot; },<br>      { &quot;startHeight&quot;: &quot;206100&quot;, &quot;totalFeesPaid&quot;: &quot;0&quot;, &quot;beneficiaryCount&quot;: 0, &quot;rawScore&quot;: &quot;2331724850931849&quot; }<br>    ],<br>    &quot;mosaics&quot;: [<br>      { &quot;id&quot;: &quot;091F837E059AE13C&quot;, &quot;amount&quot;: &quot;2465300037570560&quot; }<br>    ],<br>    &quot;importance&quot;: &quot;2331691338220390&quot;,<br>    &quot;importanceHeight&quot;: &quot;206820&quot;<br>  },<br>  &quot;id&quot;: &quot;&lt;node-based, not important&gt;&quot;<br>}</pre><p>This account clearly has non-zero importance, which means account serialization from previous part will require some fixes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*owcultD13bGEP_yn7PYIIw.png" /><figcaption>python code for serializing account state</figcaption></figure><p>Serialized account state is bit longer and looks like following (data in bold is related to importance):</p><pre>0100989008f023b2efad58c83d36e8492aa3809ccdfe3bb575c10100000000000000d1a549d23f22c912169105c4a57ac82d82bc07b1f7f1aa092b14e03b8e2ddcf9627800000000000000<strong>01</strong>0000<strong>66c3f031a9480800e427030000000000e42703000000000000000000000000000000000066c3f031a94808003027030000000000000000000000000000000000d86fbcceaa4808007c26030000000000000000000000000000000000be1ccf03ad480800c825030000000000000000000000000000000000f432f232af4808001425030000000000000000000000000000000000892874ffb04808000100</strong>3ce19a057e831f09001001652dc20800</pre><p>And resulting account state sha3 hash is</p><pre>5bef848aa6adf5825f01a2aac836dccaf1f00cbca8440d1d49bb335e2068ba36</pre><h3>Verifying state tree</h3><p><em>Current</em> (at the time of writing) merkle tree path looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*THWU9Wp5A6EYuY8UcsvmJQ.png" /><figcaption>merkle path of account TCIAR4BDWLX22WGIHU3OQSJKUOAJZTP6HO2XLQI</figcaption></figure><p>It’s instantly clear, that calculated account state hash, matches value of a leaf (below):</p><pre>{<br>  &quot;type&quot;: 255,<br>  &quot;path&quot;: &quot;41DE874FE84AA7F3ED022A73F6F6762C439A45C15A7BA9F1A9F075E93690&quot;,<br>  &quot;encodedPath&quot;: &quot;341DE874FE84AA7F3ED022A73F6F6762C439A45C15A7BA9F1A9F075E9369&quot;,<br>  &quot;nibbleCount&quot;: 59,<br>  &quot;value&quot;: &quot;5BEF848AA6ADF5825F01A2AAC836DCCAF1F00CBCA8440D1D49BB335E2068BA36&quot;,<br>  &quot;leafHash&quot;: &quot;DCE07E21C58F85B79F1F588637FB39CE024D23A885CEF7868879D69B83B9E5B0&quot;<br>}</pre><p>Path of the account is: 4D25C41DE874FE84AA7F3ED022A73F6F6762C439A45C15A7BA9F1A9F075E9369 (<a href="https://bob.nem.ninja/sha3/#989008f023b2efad58c83d36e8492aa3809ccdfe3bb575c1">verify here</a>), path fragments leading to leaf are 4, D, 2, 5, C</p><p>I will not describe in details how to verify whole path, as it is the process is the same as in previous part, I’m only providing links to verify calculations at subsequent levels:</p><ul><li><a href="https://bob.nem.ninja/sha3/#341DE874FE84AA7F3ED022A73F6F6762C439A45C15A7BA9F1A9F075E9369%0A5BEF848AA6ADF5825F01A2AAC836DCCAF1F00CBCA8440D1D49BB335E2068BA36">Leaf hash</a></li><li><a href="https://bob.nem.ninja/sha3/#00%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A2687882B14F6A90FAF764E461098013855A7E73047B18C9A91E2C543741273AE%0A0000000000000000000000000000000000000000000000000000000000000000%0ADCE07E21C58F85B79F1F588637FB39CE024D23A885CEF7868879D69B83B9E5B0%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000">level 5</a></li><li><a href="https://bob.nem.ninja/sha3/#00%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A0994E85AF3D37B841EC2F9390FC40A10DF4242D19E1268A114202D709E36E1A0%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0AE2D2226C95D9B5DD4A9111A297208DD4C14453A2F31362FF1B882AC620BA798A%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A36E1B20BDB20EE92C36004621D0B188F6C64E03CBD758FECE16D2B0C444AB9C5%0A0000000000000000000000000000000000000000000000000000000000000000">level 4</a></li><li><a href="https://bob.nem.ninja/sha3/#00%0ABD4685989FFEB35AFEA27ABFDCBE2A3CFCC6E2FF56B77118D4D5B86534584913%0AE3224280AD27BCA70E217B347C1743F21658F9F85D644C1A649EA4DE150900E5%0A5E3776025723AFD484805D7014D6F13B38289F3BD6DC9839E7B4EA05370A38DB%0A6FCC39B4D2A3513210EAFE66E081388F9496B0E1430AAA42E5B9647B8ECACD03%0AC5304DE707773D3C23C607AE42D254100D2F8E16E9E1EFC5163A74E22B84AC64%0AB51F65FF9DADCF0E8FEAD5053C0A2CD461DFC6758847173CFF919F37407E80EC%0A410103F4E0C1D0349201948DB056999835D6B3228EB31832F03BEA413426CEDD%0A6095FCA0EE3FC0CAF94A933B0EDDAD45A1DA4C06823BE1B9AF2AFC1732D4A912%0A39346E3BFFE8DD9B6A215C2E7D28DD3730A839BE93E60413398E4A6F28E015AA%0A96002ECAC43501313413BE42F5644E3C7853A2E62DD6B684ECACB9B3065464CC%0A335127F2DC8826C82F0D2AC4918E9C256C9A2B01FE54D09D6486DDD2EA2ECDBF%0A0545487F04FC1208516E8F9F31E54FE1B44145D89234522DEEEEA76591DCC9D2%0AE9B6A2D84607B4CEEB3214E55AE283E15EB39774BED294D6F8596AF45687B28F%0AEC67C68B1871A996B55068F5B637F4812E73F473936DE0107A429F5C15D6B0A5%0A13820D99934C9A48FE9BF3E7C16963B9E6EF5291298200B4CDA2D874D7878FBC%0A5AB9DE7C898D15CB88EC7C3FD5D574715DD14A4E9DCAD0C69A7ED973CFFB551C">level 3</a></li><li><a href="https://bob.nem.ninja/sha3/#00%0A65A6BD7863AD4E4E809EE59D99E077F3BD2DBA60D9D9E027E2C316DF03E091B0%0A601B573951048FA465E02688270C26C37BE8F3F4359860D04FA8A071F6588129%0AFEFF294904E54B56B574A62005876C54ED625EF51016766E873E0654D8C2D660%0AE74F3D2C45408079939F00C0BCA6E80F824DBA2EA199130170376D9BF8D25306%0A152AB9E1B97067A5961D310673367F460C7084F359E12996252C06D3CDD5DF89%0AA6A74392340C7E538DE243594CADF75185CF688C10924BFD4E826D38799503B4%0A8CB8A6044E0AA4B2B5307AA5C950D9BDD92A5A0DE76E433CD512FD1431FF3111%0AC2C78CA54E2A52F6694DBB0D8D10DDAE4D996B196F45AE4F8492669C2052B5B7%0A14E35CDCF4316C7044FF11302D86393E3407EE8FAA962C57DA766F75F2FA79A3%0AD2A4E038E5ACE1FEAD48CAA9B16E35E7B71C53B088FC644AD35F72A6258BCCC7%0AD97B75608690173986EF46C160BF7DDDB9C74ADD1D8E8C20D68D3307B2FE8993%0AA12A7D117D4DA01E89B7DFC32804DA94DD3A6C4F039037BCD6982A462DC49D0C%0A8CAC51CCBB1A5AB6E00D6AAA5D0B2F05F70ADF92F4D9DFEB5DDF2692F0DCBA92%0A84996D733C7C780104CD8FEF2C12C498940EA1EB3EF51E5BD61446CDD97BADC4%0A79E416695E23FF11547B4FC2549E726F19E2F7B8C9E823D732AA902DFBA41398%0AF2B2C717D843D5AEF8CBC885F2439E685432B530DBE2079718A8C05BFD3D2BCE">level 2</a></li><li><a href="https://bob.nem.ninja/sha3/#00%0A5A83CC6F1AA7A7C183EFF80A79F3C3C1F68DEA5D4C65B16D322E16D5E5BD1135%0A070D55F6C58304B41520B7B085CF7BDA76DC52433F1EF1B1FB311EF6D749AB03%0A76E606C525B31B02B92C5AAFF86312FA758A5FCF0A6DB3D609EC22FA391CEB0B%0A68927C71C6ED2DF82D5C8F3340CA760CE0AFFF19DFE8E403819F1705C0FEABAD%0AE820E01837E142BC0C3AB2DB112BAAF8B3F114511602F42B755B8ED60596E4D0%0AC73117E6E40164B1C224D264D49D062C5ABE495651DE46B0162583EB9651DB71%0A85F606C5C47A2C0B2E6710514452EAF992B854CA77A81BA7384C0FC2127ABFB1%0A781AA36FE6CD6D13D400F4F2559E583D07D5F98DC3884076BA77DFF396750D5D%0A6F733BCE6EA123CDBD5988D82680A41C32A925F646F6AA727B31841D71F19D94%0A03D8CEA77573E81CA0E774631DE60A90218360E0BF2B829315293B5E3C409183%0A2CB9EBECCC04E5BD155A4A19F63C485ED50F870B02C83D705EEDA497BAD0E437%0ACB22B1F94A789C8292A6F9053CB526BD0E7A018ED1BE6509BCF5401A2F7B3478%0A331298B52661BF6FA45781BF95B7FA4EFAB6CD4CEF57F289597ADB7F8B7D39D6%0A2C71C6D58F2EC11645E385A8FA6B475AC7E9A4A5987A1D2E8609B693541AA5B0%0A7A49F7BA135000789E557991FF10A2E4C7CDC856E193E4994D65F849FE652269%0A272174607F2E8FC3503E51167682E5D65FE3B04D978012F547BDEED5CACBC485">root level (1)</a></li></ul><p>Calculated root level hash is 7CEEF324D7817C6C58DFE0A04D1318B13BD3773CC5BCFE00BC48D6A12F135025</p><p>That matches account state root hash in block <a href="http://explorer.testnet.symboldev.network/blocks/206834">http://explorer.testnet.symboldev.network/blocks/206834</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*00EoMbi7lKZHY2IrC_Phkw.png" /><figcaption>Block explorer information for block at height 206834</figcaption></figure><h3>Missing pieces</h3><p>There are some information that have not been presented in this or previous part:</p><ul><li>serialization of keys (remote, node, vrf and voting keys), but this is quite straightforward</li><li>how non-empty paths inside branches are treated; there’s a low chance of this happening naturally — that is explained in more details in whitepaper, in short, encoded path part (of a branch) is first element that is hashed</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d28cbb859fd0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Verifying Symbol account state proofs for fun and profit (part 1)]]></title>
            <link>https://ncosigimcitynre.medium.com/verifying-symbol-account-state-proofs-for-fun-and-profit-part-1-3dfedfc19cb4?source=rss-7e9451722789------2</link>
            <guid isPermaLink="false">https://medium.com/p/3dfedfc19cb4</guid>
            <category><![CDATA[nem]]></category>
            <category><![CDATA[merkle-tree]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[symbols]]></category>
            <category><![CDATA[merkle-patricia-trie]]></category>
            <dc:creator><![CDATA[gimre]]></dc:creator>
            <pubDate>Thu, 17 Jun 2021 12:38:43 GMT</pubDate>
            <atom:updated>2021-06-17T12:38:43.934Z</atom:updated>
            <content:encoded><![CDATA[<h4>But mostly for fun.</h4><p>Public network has magic feature called state proofs. I don’t think this has been described with enough details or I don’t think most users realize what this feature gives.</p><p>State proofs allow to PROVE to some third party, that at height X, your account state (or mosaic state, or namespace state, or any other state) was equal to Y.</p><p>There is one small catch here: right now there is no easy way to retrieve via APIs the state at <strong>given</strong> height, so assumption is the state was saved at proper height. Best part is, that such state can be validated by verifier in a trustless manner.</p><h3>Serializing state</h3><p>What is inside the state? Short answer is: “probably too much”. But let’s dive in.</p><p>Let’s take a look at following Symbol testnet account: TAKUOCDJH4KUDYP7ZH5HMW43QXYXTLFEDQUR4MI</p><figure><img alt="Symbol block explorer screenshot" src="https://cdn-images-1.medium.com/max/1024/1*2hGOznB8589oxvlPxYhSnw.png" /><figcaption>TAKUOCDJH4KUDYP7ZH5HMW43QXYXTLFEDQUR4MI account details as seen in testnet block explorer</figcaption></figure><p>Account details can be retrieved by querying REST API endpoint /accounts/&lt;account-id&gt;, at the time of writing this, the data returned looks like this:</p><pre>{<br>  &quot;account&quot;: {<br>    &quot;version&quot;: 1,<br>    &quot;address&quot;: &quot;98154708693F1541E1FFC9FA765B9B85F179ACA41C291E31&quot;,<br>    &quot;addressHeight&quot;: &quot;119481&quot;,<br>    &quot;publicKey&quot;: &quot;13182CF21C0C13BA3FB5401EEED94D274C4305A54017ABCA7CDDEB85A173F765&quot;,<br>    &quot;publicKeyHeight&quot;: &quot;119490&quot;,<br>    &quot;accountType&quot;: 0,<br>    &quot;supplementalPublicKeys&quot;: {},<br>    &quot;activityBuckets&quot;: [],<br>    &quot;mosaics&quot;: [<br>      {<br>        &quot;id&quot;: &quot;091F837E059AE13C&quot;,<br>        &quot;amount&quot;: &quot;8539426394&quot;<br>      }<br>    ],<br>    &quot;importance&quot;: &quot;0&quot;,<br>    &quot;importanceHeight&quot;: &quot;0&quot;<br>  },<br>  &quot;id&quot;: &quot;&lt;node-based, not important&gt;&quot;<br>}</pre><p>Currently symbol python core-sdk, does not allow to serialize account state, but account state has it’s definition inside <a href="https://github.com/nemtech/catbuffer-schemas">catbuffer-schemas</a>. So let’s do pretty ugly, manual serialization of the data above.</p><p>The account above has importance = 0, which means this is not a high-value accounts, which makes things much easier.</p><figure><img alt="Python code for serializing account state (naive version, only for simple cases)" src="https://cdn-images-1.medium.com/max/1024/1*-tBcjsXtd3xTkYtdvDUzng.png" /><figcaption>serializing account state like there’s no tomorrow</figcaption></figure><p>Last thing needed before verifying account state, is to calculate sha3 hash of the serialized data</p><pre>010098154708693f1541e1ffc9fa765b9b85f179aca41c291e31b9d201000000000013182cf21c0c13ba3fb5401eeed94d274c4305a54017abca7cddeb85a173f765c2d20100000000000000000001003ce19a057e831f095a4efdfc01000000</pre><p>Resulting account state sha3 hash is: 9532475d9217848ca629e690c89470f18c95497d8913233e74fa32b802b3c5d5 <br>It will be verified later.</p><h3>Verifying state tree</h3><p>There’s a pretty detailed description of merkle trees in <a href="https://docs.symbolplatform.com/catapult-whitepaper/main.pdf">chapter 4 in catapult-whitepaper</a>, so I’m not gonna repeat that here.</p><p>Let’s query <em>current</em> <strong>merkle tree path</strong> of that account. The REST API endpoint for this is /accounts/&lt;account-id&gt;/merkle, returned data looks like following:</p><figure><img alt="REST API account merkle path response" src="https://cdn-images-1.medium.com/max/1024/1*7fpl3bmoZKkX0yU23TMOvQ.png" /><figcaption>merkle path of account in question (click to zoom in)</figcaption></figure><p>REST API returns the tree both in “raw” format — which needs parsing and in “parsed” format which is easier to process.</p><p>Returned merkle tree path is from the top of the tree to the bottom (leaf). The verification can be in either direction — either from bottom to the top, or from top to the bottom.</p><p>When visualized, the tree will look like so (I deliberately shortened the links==hashes . This is full tree, so missing links are exchanged with 00-hashes)</p><figure><img alt="Merkle tree path: 16 branches at first level, branch taken at 0xe, 16 branches at second level, branch taken at 0x2, 16 branches at 3rd level, branch taken at 0x0, finally a leaf." src="https://cdn-images-1.medium.com/max/1024/1*Feou-qw-rgs3-KVvJFkhXQ.png" /><figcaption>Full merkle tree path visualized</figcaption></figure><p>Let’s start with a path. Path is simply hash of a key. In case of account state cache, key is simply account address. So in case of account TAKUOCDJH4KUDYP7ZH5HMW43QXYXTLFEDQUR4MI the path is:</p><pre>&gt;&gt;&gt; sha3_256(unhexlify(&#39;98154708693F1541E1FFC9FA765B9B85F179ACA41C291E31&#39;)).hexdigest()</pre><pre>E220E4E4BCF533F0E0082F28E65B8EA5A278D255DB22D61D097A2F9008676F3A</pre><p>Every branch in a tree might contain non-empty path, but in example above it’s always empty, so going from the top to the bottom, proper nibbles (half of a byte is called a nibble) from account path must be taken. In order: E, 2, 2, 0, so “leftover” path is E4E4BCF533F0E0082F28E65B8EA5A278D255DB22D61D097A2F9008676F3A</p><p>Note: if it’s not possible to traverse the tree from the top to the bottom using proper branches, it means tree has been manipulated.</p><p>Now, it’s easy to notice that the leaf (“type”: 255) value is equal to sha3 hash calculated previously, yay! one check done.</p><pre>{<br>  &quot;type&quot;: 255,<br>  &quot;path&quot;: &quot;E4E4BCF533F0E0082F28E65B8EA5A278D255DB22D61D097A2F9008676F3A&quot;,<br>  &quot;encodedPath&quot;: &quot;20E4E4BCF533F0E0082F28E65B8EA5A278D255DB22D61D097A2F9008676F3A&quot;,<br>  &quot;nibbleCount&quot;: 60,<br>  &quot;value&quot;: &quot;9532475D9217848CA629E690C89470F18C95497D8913233E74FA32B802B3C5D5&quot;,<br>  &quot;leafHash&quot;: &quot;39D61E874BE3A301D1FEE4DDA1D2F6D53030004A51E6399BFB6F58EE35218EC4&quot;<br>}</pre><p>Now, what verifier needs to do is to check all the hashes on the way. Let’s start from the bottom as it will be easier.</p><p>leafHash is a hash of concatenated encodedPath(*) and value, so:<br>(* — how to obtain encodedPath from path is bit outside of the scope of this post, curious readers should take a look at chapter 4 in catapult whitepaper)</p><pre>&gt;&gt;&gt; sha3_256(unhexlify(&#39;20E4E4BCF533F0E0082F28E65B8EA5A278D255DB22D61D097A2F9008676F3A&#39;) + unhexlify(&#39;9532475D9217848CA629E690C89470F18C95497D8913233E74FA32B802B3C5D5&#39;)).hexdigest()</pre><pre>39D61E874BE3A301D1FEE4DDA1D2F6D53030004A51E6399BFB6F58EE35218EC4</pre><p>Yay! It matches.<br>Path nibble that took us to this leaf had value 0. That means that “link” at 0th element at level 4 must equal to that hash and indeed it does.</p><p>In a similar fashion, branchHash — is hash of concatened encodedPath and all the links at given level. As noted earlier missing elements must be filled with 00-hash. So for level 4, encodedPath is equal to ‘00’ and that gives us:</p><pre>&gt;&gt;&gt; zero = unhexlify(&#39;00000000000000000000000000000000000000000000000000000000000000&#39;)<br>&gt;&gt;&gt; sha3_256(unhexlify(&#39;00&#39;) + u(&#39;39D61E874BE3A301D1FEE4DDA1D2F6D53030004A51E6399BFB6F58EE35218EC4&#39;) + zero * 3 + unhexlify(&#39;6A69ADA0538FC9582D813619288B400038286522206FEA14D231F0D9775900E3&#39;) + zero * 11).hexdigest()</pre><pre>B1508023DFF34155479B81C93EE43926F590E59E0CEA66F4633D5929B809AC34</pre><p>This can also be verified <a href="https://bob.nem.ninja/sha3/#00%0A39D61E874BE3A301D1FEE4DDA1D2F6D53030004A51E6399BFB6F58EE35218EC4%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A6A69ADA0538FC9582D813619288B400038286522206FEA14D231F0D9775900E3%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000%0A0000000000000000000000000000000000000000000000000000000000000000">here</a>. And you can check that this matches branchHash at level 4.</p><p>Path nibble that leaded here was 2 and link at level 3 at position 2, matches calculated hash.</p><p>Now we need to tediously repeat the process, I’ll just paste links that calculate proper branchHashes:</p><ul><li><a href="https://bob.nem.ninja/sha3/#00%0ACD2BE13E0F7EF766360004AB58452CBFBF7CED45D3527D6F7CD5F6A0C630016B%0A0000000000000000000000000000000000000000000000000000000000000000%0AB1508023DFF34155479B81C93EE43926F590E59E0CEA66F4633D5929B809AC34%0ACD8B2E4A4E398D25A967D90F3A32E8C61E5CACD437C23A6F9BCA751A5B7130B7%0A7F73567DD856D794E44579A4101EC0E2C9561B9379DD2A1426E0844552412888%0A17444E42BA6A1173169321417F42E376FDFC6A80AE1006CB4FA8E4E4430F8199%0AB741898A45F4030E8E5DB8CE7948009568F6EB96F055A0D9F373FD0607603E3D%0A119B061861D1FD84EAC88B775D4166D64B2DAE782B2D211A74140556D44D4362%0AF34867572A9EA07C56CF85F4CDD842E81A2F369A2680CC58EF6D3604F1E6E86C%0A96D981DEA0194C2FC3CA5E619378E856311CEE1734AFBAD8D592A66D8502BAF2%0A1905D65E59E573AD1E8F2CF1C23F6412CFE28EB4C50D7BDBADBD842A0652E751%0A1B7703785D5DCCFAA93AB4CF618F47F237D6E3F3BB11299AAE51D89F07ABDBC8%0AD1D2C6EFED54EF0B2329AC4C42F0A1DD0B10CE7EC92C830FAB1918EBCDCAD1DF%0AED75C64EAE9AA3BEAEB37AEB3256C15C302D3D83D557518D7270BB9D9FDA4E31%0A18D96A739A4A1F28EBA6AA219C929759FBFC7FE14B1E41F5882AB5AE3A019CF5%0A69A9539DADCAE97ABE4B69401482B4E53BBF6C2522AFDD27CBDE5D01A309FFA4">level 3</a></li><li><a href="https://bob.nem.ninja/sha3/#00%0AC13C8F996B2C4EEE07D59C56600B96F2BD7ED529E8D7776A5A621D7C9BFF233B%0AD7EED5287CFAD28CD00BF7900F1254C7BB7DEFD2DEAF1CA9B26734BA68486255%0AF1106FBDAFB76579696055E42B70130080CCEB682E6C9BB7365F820275416CB7%0A70F8328E4E26916D36531472D85992D547FCB3A1DB2451CEDB0F895D9DD0565A%0A5E759D72D32EB7BA01FFEB961EC867547B2600B8D614CCA435BA07A21E491237%0A94D17B655C022DF540226BA75CD233421E4FD266A34B38C661B7BFD0EA90D24E%0A18BCA3BF8FDF002A34AF7B03FF257B23A8D9E8924529B99F179755DFC64BC88A%0A7B85128D49393DDD79235BCD2891322ADED89385FB2C0289ED4DAB5933B3291F%0A842A3DF0E67867464866DF9E96961BFBAE2A359706400C9F4416FBCFF4115E0C%0A5FEB4A575EE269E33890B39DBF366D8B0AC5E1A4A3D4538DEDE7C4EDB4AF70D4%0A75C493E3DACB4AA93E955962BE100DF64752EC0F530B1165A27B878303715349%0A3B5F72609B84599BADC4E194EE664C396D88315910276D05F1E1757687F62338%0ADF67A38E1721EABF8A25B53C0D19953CB7C5195D5D652FBB47A38BDEF2776F80%0A5ED3C9879E92A90D77E9C1EC03D53209B7642DB1A70A4C5D5AB80D15476C5834%0A9318AE18554B82821C4C2AEF58268916384BD766C146DB1D7550FF1723D80C13%0A7A515DE21830CC7749155015C42D06E41613CB790888B84FAC15A3FDAE3C5E17">level 2</a></li><li><a href="https://bob.nem.ninja/sha3/#00%0AAEA61533C145D5B8F69D14446B11345A55C034724CFB308F1EDC0799A13DD41C%0A66032B0BC2EC34205CE44D93FE4E0178504C6FBE2AFF4401D022F5E59A148AF6%0AD7906691DAD9B8E95F7E59CB738CE5AE545E88F72388357D76E61670C2F4C1D1%0A832E2C283BEB2A665AB6296398FFDAC27B4AC5A455AB4542D4F7A0F8B9A95840%0ADED6FC5ED2AAB173D469449EAB64FA60E77EF2C147A4DCED4CA669A52B12761C%0AF6C3F3B867A0D32F3E3507DBD995D936F541598CBCD548E5245C8272A262F0B0%0AA6D22D7E0A3647F293C887D79C1C351B5541DB4D276D22AF2D9C108ECC209EFD%0A91B225331EF7E24BE72DCDD3C903CEAF5740B54E1573F4C3B0E4F05ADFE49B5C%0AAD19A111546263D46F0CD5822E29A6867E3FD784F74BD711EA8E35DE4A14799D%0A483A08860F7E4ADD67CCA115E52C24FA481E1B89D75187CD7550FFBEF8B761A3%0A8CB12E4EB87F17BB408F19AFA0131F95858C4624972E90466400B22F8B38ECAB%0AE0E431DAC43E46EDB316367DD17C1F58D60811F434E1E74AF14CEA5168BCA691%0A32344339B1EE0EA6AF7F363AF7BD95004A9B69EB8B68955985C10D0C141A077E%0AC21F2EEA25D8CE25D7BE0BF43DCD3E7EA425135253E482025BD34BAE0FD1E9B8%0A684FBE51599766482ECB51F76B9867F00DDC92D285A4F4493E7B4091D577ABE1%0AFF33A7AC483A54A5E6B772B215D7DEDDCB4EBC6132A878B5E722C35F699D6B60">level 1</a></li></ul><p>Calculated root hash is B6B9F48079B27914FFE030B8CBBE6C81ED30FEB4E007946962C4283CBD99C581</p><p>Finally, prover can check, that the calculated hash matches state tree hash at that concrete height, for which merkle tree path was obtained:</p><p><a href="http://explorer.testnet.symboldev.network/blocks/173056">http://explorer.testnet.symboldev.network/blocks/173056</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*DySPErG4d3ybovwW4nIBvQ.png" /><figcaption>Block explorer information for block at height <a href="http://explorer.testnet.symboldev.network/blocks/173056">173056</a></figcaption></figure><p>Now, <strong>I took a shortcut</strong> and referenced block explorer, but to do this <strong>fully</strong> trustlessly, the verifier should gather all block headers — only headers, no need to actually verify their contents — check that they form a chain, and then can validate that account state hash in that block actually matches computed one.</p><p>That last part can be optimized a lot, by checking only blocks at multiples of finalization epoch.</p><h3>Summary:</h3><p>Prover provides:</p><ul><li>account state</li><li>merkle tree path at given height</li></ul><p>Verifier:</p><ul><li>serializes account state,</li><li>validates serialized state against merkle tree path</li><li>validates state root hash against block header</li></ul><p>The title is blatant reference to <a href="http://phrack.org/issues/49/14.html">(in)famous 25 years old article</a>.</p><h3>References:</h3><ul><li>account information — <a href="https://docs.symbolplatform.com/symbol-openapi/v1.0.1/#operation/getAccountInfo">https://docs.symbolplatform.com/symbol-openapi/v1.0.1/#operation/getAccountInfo</a></li><li>account merkle path — <a href="https://docs.symbolplatform.com/symbol-openapi/v1.0.1/#operation/getAccountInfoMerkle">https://docs.symbolplatform.com/symbol-openapi/v1.0.1/#operation/getAccountInfoMerkle</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3dfedfc19cb4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>