<?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 Hunter Prendergast on Medium]]></title>
        <description><![CDATA[Stories by Hunter Prendergast on Medium]]></description>
        <link>https://medium.com/@nelsonhprendergast?source=rss-37aa89dfc455------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*QFPmEBBWr9QDPg8cuecJkQ.png</url>
            <title>Stories by Hunter Prendergast on Medium</title>
            <link>https://medium.com/@nelsonhprendergast?source=rss-37aa89dfc455------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 21:26:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nelsonhprendergast/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[Smashing the EVM for Fun and…Extensibility]]></title>
            <link>https://medium.com/mimir-blockchain/smashing-the-evm-for-fun-and-extensibility-ff36c2d7b389?source=rss-37aa89dfc455------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff36c2d7b389</guid>
            <category><![CDATA[parity]]></category>
            <category><![CDATA[hacks]]></category>
            <category><![CDATA[evm]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[wallet]]></category>
            <dc:creator><![CDATA[Hunter Prendergast]]></dc:creator>
            <pubDate>Mon, 13 Nov 2017 19:09:21 GMT</pubDate>
            <atom:updated>2017-12-04T22:03:47.260Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*tJSqvLfewwbNwW-Vnb8-AA.jpeg" /></figure><p>I began this blog with the intent of speaking about the recent Parity Wallet <a href="https://paritytech.io/blog/security-alert.html">event</a>. After dissecting the code fully, and reading what else had been written by others, I felt there was little more to say. Short of brute forcing the address of the deleted code, we are not likely to see those funds recovered without a fork.</p><p>Instead, I decided to write about the first thought I had while considering the Parity Wallet hack. As I was trying to think of possible solutions, I asked myself the question, “What if I could make a contract that would allow me to run any code, any time, without the need for a library?”</p><p>Many contracts allow a user to interact with arbitrary code through the use of a proxy. This can be seen below:</p><pre>function () payable {someAddress.delegatecall(msg.data);}</pre><p>This function allows a user to call external code, but what I wanted was to simply call a contract and execute the code I passed in as an argument. Essentially, shellcode for the EVM.</p><p>This is obviously NOT a good idea in most places. DAOs, token contracts, or any shared state contract would have no security with this code written into place. That said, it was fun to build.</p><p>Disclaimer: This code was thrown together over a few hours, and is in no way optimized or even fully tested. This is a simple proof of concept. Do not use or deploy this code into any contract, for any reason.</p><p>The first step to building EVM shellcode was to build a model. I settled on creating a stack machine inside of memory, using Solidity Assembly. Once I had a model, I had to build a loader. The loader I built can be seen on lines 5, 6, and 7.</p><p>These lines of code set up an instruction pointer, an argument pointer, and finally the stack pointer. This setup assumes the first bytes32 object from the passed in array is a number specifying the total number of arguments. Thus, the arguments may be found isolated from the instructions. The instructions are loaded in code starting with index 1, and are read one bytes32 at a time. Granted this is a huge waste, since each opcode is only 2 bytes, but it was easier.</p><pre>1.  contract meta{<br>2.    function run(bytes32[] code){<br>3.      require(msg.sender == owner);<br>4.      assembly{<br>5.        mstore(add(calldatasize,60),160)<br>6.         mstore(add(calldatasize,92),<br>7.         add(sub(sub(calldatasize,4),<br>8.         mul(byte(0,mload(128)),32)),64))<br>9.        mstore(add(calldatasize,124), add(calldatasize,1148))<br>10.       loop:<br>11.         switch byte(0,mload(mload(add(calldatasize,60))))<br>12.           case 0x00{<br>13.             stop<br>14.           }<br>15.           case 0x01{<br>16.             mstore(add(mload(add(calldatasize,124)),32),<br>17.              add(mload(mload(add(calldatasize,124))),<br>18               mload(add(mload(add(calldatasize,124)),32))))<br>19.             mstore(add(calldatasize,124),<br>20.              add(mload(add(calldatasize,124)), 32) )<br>21.           }</pre><p>Once a loader was built, and the stack machine created, I needed a way to get instructions to be executed based on the code I was passing in. The easiest way to facilitate this was to build a big ugly switch case inside of a loop. The switch case parses the next instruction by resolving the opcode from the instruction pointer. It then seeks out the case and executes the opcode specified, using the memory based stack machine.</p><p>Each case represents the actual EVM opcode values and emulates the operation out of the memory based stack machine. This can be seen on line 16, 17, and 18 where an addition is performed from the memory based stack. Lines 19 and 20 then increment the stack pointer.</p><p>This seems like a nice trick, but it is very cumbersome unless you can get in some variables. To solve this problem, I built a push instruction to put arguments on the memory based stack. This can be seen below under case 0x60:</p><pre> case 0x60{ //load argument 0 <br>   mstore(sub(mload(add(calldatasize,124)),32),<br>    mload(mload(add(calldatasize,92))))<br>   mstore(add(calldatasize,124),<br>    sub(mload(add(calldatasize,124)), 32) )<br>  }<br>.<br>.<br>.<br>mstore(add(calldatasize,60),add(mload(add(calldatasize,60)),32)) <br>jump(loop)<br>}</pre><p>Finally, I needed a way to increment the instruction pointer, and jump back up the loop to read the next instruction. This last snippet of code performs this task quite nicely.</p><p>After running a few tests, I proved to myself that an arbitrary user could call any opcode he/she desired, using this code. Some of the instructions do not make sense when using a memory based stack, but others translate just fine. For instance, selfdestruct could be called using this method.</p><p>Just in case you missed the point, using this code you could call selfdestruct on a contract that did not explicitly define a selfdestruct method. This may have been handy in a recent wallet hack. Then again, this code would probably be an even bigger security flaw than an unlocked instantiater.</p><p>The most exciting application of this hack, in my opinion, is the ability to load bytecode from storage. It may be possible to build a framework that allows for extensible code by modification of storage.</p><p>In the coming weeks, I will follow up with more code from this experiment and more details about the methods used. For now, I just wanted to get a few minds thinking about the possibilities of using memory, calldata, and storage to execute arbitrary bytecode. These methods may make for a system that allows code to be dynamically updated and recovered from malicious acts. This code may also cause terrible damage if used improperly.</p><p>Do you believe current #blockchain infrastructure is antiquated? If you said yes and you’re developer, please join our community as we eagerly prepare for our MIMIR Blockchain to Internet (B2i) Bridge Alpha Test. <a href="https://mimir.rocket.chat/">https://mimir.rocket.chat</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fb27681%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fb27681%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/564dd7f2ad03bec8b61766be68f1b96b/href">https://medium.com/media/564dd7f2ad03bec8b61766be68f1b96b/href</a></iframe><p>DISCLAIMER: The content provided on this site is opinion and commentary on topics related to the blockchain universe. IT IS NOT INTENDED TO BE NOR SHOULD IT BE RELIED ON BY YOU FOR ANY REASON AND IS PROVIDED “AS IS” WITH NO WARRANTIES OF ANY KIND. You are responsible for your own decisions and for properly analyzing and verifying any content.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff36c2d7b389" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mimir-blockchain/smashing-the-evm-for-fun-and-extensibility-ff36c2d7b389">Smashing the EVM for Fun and…Extensibility</a> was originally published in <a href="https://medium.com/mimir-blockchain">MIMIR Blockchain Publication</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Value of a Hash: How Cryptocurrencies are Secured by Hardware]]></title>
            <link>https://medium.com/mimir-blockchain/the-value-of-a-hash-how-cryptocurrencies-are-secured-by-hardware-fb5167679131?source=rss-37aa89dfc455------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb5167679131</guid>
            <category><![CDATA[ico]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[bitcoin-mining]]></category>
            <category><![CDATA[bitcoin]]></category>
            <dc:creator><![CDATA[Hunter Prendergast]]></dc:creator>
            <pubDate>Thu, 05 Oct 2017 19:31:00 GMT</pubDate>
            <atom:updated>2017-10-26T16:37:06.860Z</atom:updated>
            <content:encoded><![CDATA[<p>As a former nuclear reactor operator, computer engineer, and a co-founder of a blockchain technology firm, <a href="https://www.mimirblockchain.solutions/">MIMIR Blockchain Solutions</a>, I think it’s pretty safe to say that, many conversations taking place around blockchain are simply too granular for mainstream thinking to easily absorb. In order for blockchain to truly be more integrated into society, this needs to quickly change, and basic questions around this emerging topic need to be more clearly addressed.</p><p>One particular question I repeatedly find myself being asked is why is a cryptocurrency worth X, or even, anything at all? Truth being told, this is not a question easily answered in just a few minutes of conversation. For instance, one of the best explanations I have read to date is a well-done argument made by Adam Hayes (The New School for Social Research) in “<a href="http://www.economicpolicyresearch.org/econ/2015/NSSR_WP_052015.pdf">A Cost of Production Model for Bitcoin</a>”. In this work, Hayes raises an important question on the value of Bitcoin as a commodity using the marginal cost of production to establish the useful price. Although this article is very insightful, the writing is more technical than the average reader needs to comprehend. Therefore, it may make greater sense for interested parties to first take a step back and consider examining the value of a cryptocurrency from a completely different perspective, namely infrastructure and security.</p><p>When evaluating a “useful price”, it is critically important to consider that a cryptocurrency is, frankly, worthless without security. If anyone was capable of creating coins outside the defined rules of the system, cryptocurrencies would not act as a viable mechanism for exchange. Therefore values are only as secure as the infrastructure they are supported by.</p><p>For those who do not know already know, the single biggest attack vector, in decentralized systems like cryptocurrencies, is the 51% attack. This type of attack may only occur when a single individual or entity has more than 51% of the mining (computational) power in a cryptocurrency network. For a deeper understanding of this topic you can read a publication by Mario Dian titled, “<a href="https://freedomnode.com/blog/86/cost-of-51-attack-and-security-of-bitcoin-monero-litecoin-and-other-cryptocurrencies">Cost of a 51% Attack and Security of Bitcoin, Monero, Litecoin and other Cryptocurrencies.</a>” The critical point to understand is that during a 51% attack, the blockchain could be manipulated to allow the same coin to be spent more than once, something called a “Double Spend” problem. Additionally, the system could also be manipulated to prevent some individuals from transferring any value whatsoever. This sort of manipulation would not only undermine the security and usefulness of the system, it would ultimately cause the value stored to be untrustworthy. Thus, the price of a cryptocurrency would plummet following any successful 51% attack.</p><p>Given the immense value stored in cryptocurrencies as evident by current trading levels, something my colleague Nick Fierro <a href="https://medium.com/mimir-blockchain/why-bitcoin-investors-need-to-focus-on-the-bull-market-case-not-the-bull-b571eb97bf74">recently discussed</a>, you may be wondering why we haven’t seen a 51% attack on Bitcoin or Ethereum. Simply put, the cost of attacking the system supersedes the amount of value that could be gained by actually attacking it in the first place. In order to have 51% of the computational power in a large cryptocurrency network, an immense amount of money must be spent to acquire the computing hardware. Most of this hardware is custom built for this type of work, but it has little use elsewhere. Due to this specialization, an attacker would incidentally be diminishing the value of his/her investment in hardware and the underlying value of his/her cryptocurrency holdings relative to the attacked network.</p><p>The idea of hardware supporting cryptocurrencies simply doesn’t get enough focus. In fact, in Dian’s article, he gives rough calculations of this hardware cost that err on the low side (see Dian’s table of values below). This table summarizes the cost of hardware and electricity necessary to attack the largest cryptocurrency networks for a single day in August of 2017. This table is presented below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*XAkeP6JDz3oyHXO9CmxuDA.png" /></figure><p>In reality, the cost of attacking a cryptocurrency network per day is not limited to the cost of electricity and the devaluation of equipment alone, it also includes the marginal cost of opportunity lost due to an attack — and this could be large. For example, compare the values from the above table with the following graph of total Bitcoin revenue paid to miners each day from <a href="https://blockchain.info/">October 4th, 2017</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*0ttBG-cR2B-a_NcW12xN1g.png" /></figure><p>One can clearly recognize that revenues derived from mining bitcoin dwarfs power and hardware costs. This further supports my strong belief that hardware must be more secure to ensure the value of cryptocurrencies.</p><p>Keep in mind, an attacker would need more than 50% of the mining power to attack the system. This means the attacker would be winning at least 50% of the mining revenue each day, even during the attack, but those winnings would become useless once confidence had been eroded in the system. Looking at this idea more deeply again based on the graph above, for the worst day in August of 2017, this number is approximately 3 million USD. So the realistic total cost per day is the cost of the reduced value of the coins, the cost of the reduced value of the hardware, and the cost of the electricity to power the computers. This is one reason why cryptocurrencies have value: <em>They are secured by the infrastructure that supports them</em>, <em>and this infrastructure is of non-trivial cost.</em></p><p>At the end of the day, when asking whether or not a cryptocurrency is worth its face value, one should understand that these systems are only as useful as their security. For the largest networks, it is clear that the barrier to entry to perform an attack is immense. For these networks, it is also evident that the marginal cost of an attack, is greater than the theoretical benefit. This may not always be the case, for smaller systems in particular. However, one thing’s for sure, the infrastructure behind cryptocurrencies is more critical to preserving the value of cryptocurrencies than one may understand. Hopefully that is considered the next time someone asks why a cryptocurrency is worth X.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fb27681%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fb27681%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/564dd7f2ad03bec8b61766be68f1b96b/href">https://medium.com/media/564dd7f2ad03bec8b61766be68f1b96b/href</a></iframe><p>DISCLAIMER: The content provided on this site is opinion and commentary on topics related to the blockchain universe. IT IS NOT INTENDED TO BE NOR SHOULD IT BE RELIED ON BY YOU FOR ANY REASON AND IS PROVIDED “AS IS” WITH NO WARRANTIES OF ANY KIND. You are responsible for your own decisions and for properly analyzing and verifying any content.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb5167679131" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mimir-blockchain/the-value-of-a-hash-how-cryptocurrencies-are-secured-by-hardware-fb5167679131">The Value of a Hash: How Cryptocurrencies are Secured by Hardware</a> was originally published in <a href="https://medium.com/mimir-blockchain">MIMIR Blockchain Publication</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>