<?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 Joran Honig on Medium]]></title>
        <description><![CDATA[Stories by Joran Honig on Medium]]></description>
        <link>https://medium.com/@joran-honig?source=rss-d79eb100a476------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wmujhCc-RPLUHez7E_Mn_g.jpeg</url>
            <title>Stories by Joran Honig on Medium</title>
            <link>https://medium.com/@joran-honig?source=rss-d79eb100a476------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 15:09:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@joran-honig/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[Shift Left and DevSecOps — What does it even mean?]]></title>
            <link>https://medium.com/swlh/shift-left-and-devsecops-what-does-it-even-mean-314f7fb0a555?source=rss-d79eb100a476------2</link>
            <guid isPermaLink="false">https://medium.com/p/314f7fb0a555</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Joran Honig]]></dc:creator>
            <pubDate>Tue, 01 Dec 2020 20:07:44 GMT</pubDate>
            <atom:updated>2020-12-01T20:07:44.580Z</atom:updated>
            <content:encoded><![CDATA[<h3>Shift Left and DevSecOps — What does it even mean?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*zUEsWVqB5yGmcPEK.png" /><figcaption>By Valentin Sajia on unsplash</figcaption></figure><p>DevSecOps and Shift Left are often used in the same sentence. But the difference between the two is not always clear. So in this article, I will introduce both topics and talk about their connection.</p><h3>⬅️ Shift Left</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wPfOd7AXZs72Fk0O.jpg" /><figcaption>By Nick Fewings on Unsplash</figcaption></figure><p>When we’re talking about shift left, we’re talking about shifting left security in the software development lifecycle. Instead of focusing testing efforts towards the end of development, “shift left” proposes that security is integrated into the earlier stages.</p><p>Let’s explore some arguments for shifting left!</p><h4>Deleting or re-writing flawed code</h4><p>By not keeping security in mind during development, you run the risk of building on top of fundamentally flawed code. As a result, you might need to re-write or even delete chunks of your codebase. Early security evaluations will reduce the chances of a fundamental flaw going unnoticed for too long.</p><h4>Catching bugs early is cheap</h4><p>IBM performed a study a while ago looking into the relative costs of fixing bugs in the various stages of software development. Unsurprisingly, they found that the further you get in the development process, the more expensive it gets to fix bugs.</p><h4>Releasing on time is nice</h4><p>Only starting to think about security near the deadline for a project introduces some serious business risk. Security auditors can find significant flaws that require some time to mitigate. As a result, launch dates might need to be moved, which can have severe strategic consequences.</p><h3>🔒 DevSecOps</h3><p>You’re probably familiar with the term DevOps, which has taken software development by storm. DevSecOps builds on top of DevOps and makes the inclusion of security explicit.</p><blockquote><em>Check out “The DevOps Handbook” for an excellent introduction to DevOps concepts.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qGnO1o1sMDVjJF-8.jpg" /><figcaption>By Annie Spratt on Unsplash</figcaption></figure><h4>DevOps Primer</h4><p>In short, DevOps is a methodology that’s closely related and based on Lean and Agile. In DevOps, concepts and techniques from manufacturing are applied to software development, which turns out to be very productive.</p><p>The “The DevOps Handbook” talks about the importance of having (tight) feedback loops. The effect? Turn around times improve, teams learn efficiently, and information doesn’t get lost.</p><p>This is why Dev and Ops are connected. Instead of “throwing work over the fence” for the other team to look at, teams are unified. Operations are included in the development process for early and direct feedback on architecture and approach. Additionally, deployments are automated and integrated from the beginning (CI/ CD) instead of at the end.</p><h4>Dev &amp; Sec &amp; Ops 🤝</h4><p>Some will argue that security is already part of DevOps, and they are right. DevSecOps formalises this inclusion and allows us to refer to the tools, practices and approaches for security in DevOps.</p><p>With DevOps, operations was pulled into the software development team. DevSecOps means the same happens for security.</p><ol><li>Security concerns and best practices will be part of design discussions, as well as final code reviews.</li><li>We can extend CI and CD automating as many (high confidence) security checks as possible.</li></ol><p>Both these changes, and more, will create tight feedback loops, making sure that security is built-in, rather than patched on!</p><h3>⚖️ Difference</h3><p>So, how do DevSecOps and Shift Left relate to one another?</p><p>Shift left is about the benefit of starting to think about security at an earlier stage of the development. In DevSecOps, security is part of every iteration and feedback loops are tight. So, with DevSecOps, you’ll shift-left security.</p><p>There is no doubt that you should <em>shift-left</em>, and <em>DevSecOps</em> provides an effective set of practices to do so. Make sure to automate as much as possible, and think about security early and often!</p><p><em>I hope you found this article on shift left and DevSecOps useful, let me hear your thoughts on Twitter (</em><a href="https://twitter.com/joranhonig"><em>@JoranHonig</em></a><em>)!</em></p><p>This article was originally published here: <a href="https://joranhonig.nl/shift-left-and-devsecops-what-does-it-even-mean/">https://joranhonig.nl/shift-left-and-devsecops-what-does-it-even-mean/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=314f7fb0a555" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/shift-left-and-devsecops-what-does-it-even-mean-314f7fb0a555">Shift Left and DevSecOps — What does it even mean?</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mutation Testing for Smart Contracts - A step by step guide]]></title>
            <link>https://medium.com/swlh/mutation-testing-for-smart-contracts-a-step-by-step-guide-68c838ca2094?source=rss-d79eb100a476------2</link>
            <guid isPermaLink="false">https://medium.com/p/68c838ca2094</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[program-analysis]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Joran Honig]]></dc:creator>
            <pubDate>Thu, 05 Dec 2019 21:58:43 GMT</pubDate>
            <atom:updated>2020-02-20T14:39:18.843Z</atom:updated>
            <content:encoded><![CDATA[<p>In my <a href="https://medium.com/swlh/introduction-into-mutation-testing-d6512dc702b0">previous article</a>, I wrote about the core concepts of mutation testing. With this post, I will show you the mutation testing theory can be applied in practice using the mutation testing tool <a href="https://github.com/JoranHonig/vertigo">Vertigo</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5zd-XPr0st9ZTXIC" /><figcaption>Photo by <a href="https://unsplash.com/@bitcloudphotography?utm_source=medium&amp;utm_medium=referral">Bit Cloud</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Setup</h3><p>To start with mutation testing, we need to do three things:</p><ul><li>Install Truffle and Ganache</li><li>Install Vertigo</li><li>Get a project to test</li></ul><p>Install Truffle and ganache by executing the following commands:</p><pre>$ npm install -g truffle<br>$ npm install -g ganache-cli</pre><p>Then install Vertigo by executing the following command:</p><pre>$ pip3 install eth_vertigo</pre><p>With that out of the way, the only thing left to do is to get a Truffle project to run our mutation testing on.</p><p>In this article, I will use the <a href="https://github.com/truffle-box/metacoin-box">MetaCoin truffle box</a> as the target of the mutation testing run. You can easily download this project by executing the following commands in your terminal:</p><pre>$ mkdir metacoin<br>$ cd metacoin<br>$ truffle unbox metacoin</pre><h3>Configuration</h3><p>We need to do a minor configuration tweak to ensure that Vertigo can run optimally. Vertigo can run the analysis for multiple mutants in parallel if there are enough test networks configured. Unfortunately, the default configuration for the MetaCoin box does not yet provide these networks, so you’ll have to add them yourself.</p><p>The following snippet shows my truffle-config.jsafter I’ve added two networks to use with mutation testing. Go ahead and copy-paste this snippet into the truffle-config.js file in the metacoin directory. <br>You can also just add the two networks, if you already have some values configured in your project’s truffle-config.js.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/86d05dcd1b390f442ee8f8b4441acead/href">https://medium.com/media/86d05dcd1b390f442ee8f8b4441acead/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1wz2cPY6CpiVZIQ_" /><figcaption>Photo by <a href="https://unsplash.com/@art_maltsev?utm_source=medium&amp;utm_medium=referral">Artem Maltsev</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Let the magic happen</h3><p>First, we need to start the two networks that will be used by Vertigo. You can do so by running the following commands in separate terminal windows (bonus: You can try to use <a href="https://github.com/tmuxinator/tmuxinator">tmuxinator</a> with <a href="https://gist.github.com/JoranHonig/bd99f08529d372ebdc851486166e7b11">this config</a>, to make life a bit easier):</p><pre>$ ganache-cli -p 8545<br>$ ganache-cli -p 8546</pre><p>With everything set up, we can start the mutation testing by simply running the following command:</p><pre>$ vertigo run --network vertigo_test_network_1 --network vertigo_test_network_2</pre><p>The next step is very important!</p><blockquote>Sit back. Enjoy. Drink some ☕</blockquote><p>PS. You can optionally add the commandline option --output output.txt to the command, to write the analysis results to a file named output.txt.</p><p><strong>Interpreting The Results</strong></p><p>Once the analysis is finished you will be presented with the following information:</p><pre>...<br>[*] Running analysis on 5 mutants<br>100%|████████████████████████████████████████████████████| 5/5 [00:17&lt;00:00,  4.38s/mutant]<br>[*] Done with campaign run<br>[+] Report:<br>Mutation testing report:<br>Number of mutations:    5<br>Killed:                 4 / 5</pre><pre>Mutations:</pre><pre>[+] Survivors<br>Mutation:<br>    File: /Users/walker/Development/metacoin/contracts/MetaCoin.sol<br>    Line nr: 19<br>    Result: Lived<br>    Original line:<br>         if (balances[msg.sender] &lt; amount) return false;</pre><pre>Mutated line:<br>         if (balances[msg.sender] &lt;= amount) return false;<br>...</pre><p>The important bit is the line that says Killed: 4/5. This line shows the number of killed mutants (4 in this case), compared to the total number of valid mutants (5 for MetaCoin). See <a href="https://medium.com/swlh/introduction-into-mutation-testing-d6512dc702b0">my previous article</a> for an explanation of these terms. <br>Just one mutation slipped through the cracks! The mutation score for this project is 80%; pretty good.</p><p>Stay tuned for a deep dive into the detailed analysis results that Vertigo provides and how you can use them to improve your test suite’s quality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*InZ_WSLHIFQu5dmm" /><figcaption>Photo by <a href="https://unsplash.com/@ninjason?utm_source=medium&amp;utm_medium=referral">Jason Leung</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Looking to the future</h3><p>Vertigo is a brand new mutation testing tool, and while features like parallelization and equivalent mutant detection help improve usability, there are still some things to improve:</p><p><strong>Test Networks</strong></p><p>The current setup process requires you to add network configurations to `truffle-config.js` and directly run ganache instances.</p><p>One of the next things that will be added to Vertigo is a <a href="https://github.com/JoranHonig/vertigo/issues/1">feature</a> that automates all this and gives a more streamlined experience.</p><p><strong>Analysis Speed</strong></p><p>For big projects like <a href="https://github.com/OpenZeppelin/openzeppelin-contracts">openzeppelin-contracts</a> the mutation testing process can take some time. And sure, you can use features like mutant sampling to reduce the number of mutants that you need to test. However, it would be better if we spend less time on each mutant altogether. A soon-to-be-added <a href="https://github.com/JoranHonig/vertigo/issues/20">feature</a> achieves just that, by leveraging fine-grained coverage data and optimizing which unit tests to execute.</p><p>Of course, there is more in the pipeline! But you will have to stay tuned to hear about that!</p><p>Thanks to <a href="https://medium.com/u/c9c016683f17">Bernhard Mueller</a> for reviews on drafts of this article!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68c838ca2094" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/mutation-testing-for-smart-contracts-a-step-by-step-guide-68c838ca2094">Mutation Testing for Smart Contracts - A step by step guide</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction into Mutation Testing]]></title>
            <link>https://medium.com/swlh/introduction-into-mutation-testing-d6512dc702b0?source=rss-d79eb100a476------2</link>
            <guid isPermaLink="false">https://medium.com/p/d6512dc702b0</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[mutation-testing]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[solidity]]></category>
            <dc:creator><![CDATA[Joran Honig]]></dc:creator>
            <pubDate>Wed, 09 Oct 2019 08:45:48 GMT</pubDate>
            <atom:updated>2020-06-11T14:39:51.081Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I released a mutation testing tool for smart contracts on GitHub called <a href="https://github.com/joranhonig/vertigo"><strong>Vertigo</strong></a>.</p><p>In this series of blog posts, I hope to do the following things:</p><ul><li>Show you how powerful Mutation Testing is</li><li>Explain how you can use mutation testing in your <a href="https://en.wikipedia.org/wiki/Systems_development_life_cycle">SDLC</a></li><li>Demonstrate how you can use Vertigo on some example projects</li></ul><p>Vertigo is accompanied by <a href="https://link.springer.com/chapter/10.1007%2F978-3-030-31500-9_19">a research paper</a> that was presented at <a href="http://deic.uab.cat/conferences/cbt/cbt2019/">CBT’19</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HgQT8BsnzOBosBjF" /><figcaption>by <a href="https://unsplash.com/@yvesalarie">Yves Alarie</a></figcaption></figure><h4><strong>Why Mutation Testing?</strong></h4><p>In this first post, we will review the concepts, and more importantly, the motivation behind mutation testing.</p><p>There is no shortage of stories on the security incidents that have occurred with smart contract systems (<a href="https://medium.com/swlh/the-story-of-the-dao-its-history-and-consequences-71e6a8a551ee">the DAO Hack</a>, <a href="https://github.com/paritytech/parity-ethereum/issues/6995">Parity Wallet Hack</a>, <a href="https://medium.com/@peckshield/alert-new-batchoverflow-bug-in-multiple-erc20-smart-contracts-cve-2018-10299-511067db6536">batchOverflow</a>, … ). The high stakes, high-risk environment has sparked the development of many tools and techniques that help increase the security of smart contract projects ( e.g. <a href="https://github.com/ConsenSys/mythril">Mythril</a>, <a href="https://mythx.io/">the MythX platform</a>, the K framework, Verisol, etc.).</p><p>Many of these tools deserve their place in your development life cycle, improving the security of smart contracts across the spectrum. <br>Another method that is already actively being applied in smart contract development is unit testing.<br>Unit tests can be used to make sure that a program or smart contract performs as expected on a set of concrete inputs. While this does not exclude the presence of bugs, a passing test suite does give a sense of confidence in the correctness and security of a smart contract.</p><p>This raises the question: How confident should a passing test suite make you feel?<br>Most development teams use code coverage as a metric to answer this question. As the name suggests, code coverage counts the percentage of lines, statements, branches, etc.. covered by the tests in a test suite.</p><p>Unfortunately, there are some problems with this metric:</p><ul><li>Firstly, one can write tests that cover a lot of code at once; they can improve the measured code coverage while not actually adding many assurances. Test quality will seem to increase, but in reality, it stays the same.</li><li>Secondly, unit tests may lack proper assertions. As a result, parts of the code may seem to be well covered, whereas the business logic itself is insufficiently tested.</li></ul><p>In short, you should not be using code coverage as a metric for the security or correctness of your smart contracts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KhGkMx_7ZJ17s57A" /><figcaption>by <a href="https://unsplash.com/@yogipurnama">Yogi Purnama</a></figcaption></figure><h4><strong>Mutation Testing to the Rescue</strong></h4><p>Mutation Testing is an approach that can help with the evaluation of a test suite’s quality.<br>It specifically tries to answer the following question:</p><blockquote>“How good is this test suite at finding bugs in the smart contracts.”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/0*GDjyC-j9RUwrvl6i" /><figcaption><a href="http://Heterochromia by Amelia Barklid">by Amelia Barklid</a></figcaption></figure><p>It does so by generating slightly changed versions of the smart contract called mutants.<br>Each of these mutants represents a potential bug in the smart contracts.<br>For each mutant, we can check whether at least one of the tests fails (this is called “killing a mutant”).</p><h4><strong>Mutation Operators</strong></h4><p>The mutants are generated based on mutation strategies, called “Mutation Operators”. <br>A mutation operator implements specific translation rules that try to introduce faulty behaviour.<br>The following figure shows some mutation rules that transform comparison operators into their exact opposite.<br>E.g. An equals operator becomes a not equals operator.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e34dee3fd3e0b58e2f991baaf16e8b5/href">https://medium.com/media/8e34dee3fd3e0b58e2f991baaf16e8b5/href</a></iframe><p>Vertigo implements a series of these mutation operators targeting different parts of the contract like arithmetic operations, modifiers and comparisons.</p><h4><strong>Evaluating Mutation operators</strong></h4><p>Determining whether a mutation is killed ( a mutation is killed when one of the tests fail for the mutation) or not is quite straightforward. You run the test suite on the mutated program and find if one of the tests fail.</p><p>However, besides a test that survives or is killed, we can end up in two other situations:</p><ul><li>The first additional class is <em>timed out</em>; we encounter this case of mutations in situations where a mutant creates an infinite loop or otherwise slows down the execution of the test suite by a lot.</li><li>The second class is <em>errored</em>, which can occur whenever the compilation of the mutant was not successful, or the testing framework encountered some unexpected error (other than a failing test ofc.)</li></ul><h4><strong>Equivalent mutations</strong></h4><p>Sometimes a mutated version of a program is equivalent to the original program.<br>Take for example the function max from openzeppelin’s <em>contracts/math/math.sol</em>, and the mutated function mutated_max().</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0190d16687b07cff2746d557b70b516a/href">https://medium.com/media/0190d16687b07cff2746d557b70b516a/href</a></iframe><p>Even though there is a syntactic change in the program ( “&gt;=” is changed to “&gt;”), it will still give the same correct results for all possible inputs.<br>As a result, this mutant will `survive` an execution of the test suite. In the evaluation of the performance of a test suite, we prefer to ignore these cases, as there is no actual fault introduced in the tested smart contract.</p><p>These mutants are called “Equivalent Mutations”, and they form one of the main weaknesses of mutation testing. Existing approaches to automatic detection of these equivalent mutations are not perfect, and often a developer will have to review mutation testing results to filter the equivalent mutations.</p><h4><strong>In conclusion</strong></h4><p>After generating, testing, and filtering all equivalent mutations, we end up with a number of surviving mutants, using this number, we can compute the mutation score:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*X751kuYPGH9jTVXj4BIraA.png" /></figure><p>You can use this mutation score to answer the question from the beginning of this post</p><blockquote>“How good is this test suite at finding bugs in the smart contracts”.</blockquote><p>Furthermore, the surviving mutants give you valuable information about which parts of the code are insufficiently tested.</p><p>Thanks for reading this all the way through to the end!<br>In this post, we looked at the main concepts used in mutation testing: mutation operators, killed and surviving mutations, equivalent mutations and the mutation score.<br>In the following post, I will show you how to apply these concepts using <a href="https://github.com/joranhonig/vertigo"><strong>Vertigo</strong></a>.</p><p>Thanks to <a href="https://github.com/tintinweb">tintin</a> and <a href="https://medium.com/u/c9c016683f17">Bernhard Mueller</a> for providing feedback on drafts of this article</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6512dc702b0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/introduction-into-mutation-testing-d6512dc702b0">Introduction into Mutation Testing</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Mythril Classic and Symbolic Execution]]></title>
            <link>https://joran-honig.medium.com/introduction-to-mythril-classic-and-symbolic-execution-ef59339f259b?source=rss-d79eb100a476------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef59339f259b</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Joran Honig]]></dc:creator>
            <pubDate>Thu, 03 Jan 2019 14:01:01 GMT</pubDate>
            <atom:updated>2019-07-31T11:41:19.871Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction to Mythril and Symbolic Execution</h3><p><a href="https://github.com/ConsenSys/mythril">Mythril</a> is a cool symbolic execution tool that comes pre-loaded with several detection modules that check for bugs like integer overflows and reentrancy vulnerabilities. I’m one of the core team members of the MythX platform team; maintaining, improving, and buidling Mythril.</p><p>One of the main design goals in Mythril is to make the interaction with the analysis tool simple and effortless. In other words, you don’t have to get a PhD in computer science in order to start using and benefiting from formal methods like symbolic analysis. <a href="https://medium.com/u/c9c016683f17">Bernhard Mueller</a> has written <a href="https://hackernoon.com/practical-smart-contract-security-analysis-and-exploitation-part-1-6c2f2320b0c">several posts </a>showing how you can use Mythril to up your security game.</p><p>This specific post aims to reveal some of the magic happening behind the scenes, later articles will go more in-depth on the detection module system of Mythril, ultimately providing enough information to start rolling your own custom analysis modules.</p><h3>Symbolic execution</h3><p>To explain how Mythril works we will need to start with symbolic execution, the core technique used in Mythril. If you are already comfortable with the general idea of symbolic execution, then this post will recap already familiar concepts.</p><p>I think the easiest way to explain symbolic execution is by applying it and graphically showing what happens during execution. To help with that, we’ll be using the following solidity function as a target of our analysis.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f598c59f065957b57eb5441dc521d3e1/href">https://medium.com/media/f598c59f065957b57eb5441dc521d3e1/href</a></iframe><p>Our goal will be to see if we can use symbolic analysis to show that it is possible to get the result of the function to be 10.</p><h4>Concrete Example</h4><p>Before we start with actual symbolic execution let’s first look at concrete execution. We can execute the function execute(uint256) with multiple different inputs. Take for example the input 4, which will result in the following execution trace for the function execute (I&#39;ve added the memory state for each step):</p><pre>Initial state (function entry): <br>- currently executing: line 1 <br>- input = 4 <br>step1: <br>- currently executing: line 2 <br>- input = 4 <br>- result = uninitialized <br>step2: <br>- currently executing: line 3 <br>- input = 4 <br>- result = 0 <br>step3: <br>- currently executing: line 6: <br>- input = 4 <br>- result = 0</pre><p>And here is a graphical representation of the same trace:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/193/1*E11Umf3apkKl3QzYqjlH0A.jpeg" /></figure><p>We can keep trying different inputs until we find an input that makes the function return 10. This approach is called fuzzing, and <a href="https://medium.com/u/4e81a7415404">Valentin Wüstholz</a> has done <a href="https://medium.com/consensys-diligence/finding-vulnerabilities-in-smart-contracts-175c56affe2">an awesome writeup</a> of how Harvey, a state-of-the-art fuzzer, works and is used in the MythX-platform. In this case, however, we are looking at how symbolic execution can be used to solve the problem.</p><h4>Symbolic Example</h4><p>Finally, we’re at the part where we’ll be executing the program symbolically. This means that instead of executing the program with the input 4 we’ll execute the program with a symbol, let&#39;s call that symbol x. The symbol x can take on any valid value that a uint256 could possibly have. Now, we’ll execute the program again.</p><p>Executing the first two steps is still rather straightforward:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/192/1*Avo2klxmjAxyMAMEJVyx6g.jpeg" /></figure><p>This is where it gets interesting. At line 3 the input is compared to a number 10, but the input is x, so it could take on any concrete value. Therefore, both options x &gt; 10 and x &lt;= 10 are possible. If this happens, we <em>branch</em> <em>out</em> and create two new states. One where x &gt; 10 must hold, and one where x &lt;= 10 must hold. We&#39;ll also keep track of these <em>constraints</em> in our states. We do this so we can determine what inputs would follow specific paths.</p><p>Let&#39;s extend the state graph with the next steps of the execution:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*pPG7_8gwqN8IsnNMkJJzXQ.jpeg" /></figure><p>These are the states generated by symbolically executing the function. Given these symbolic states, we can write a simple program that tries to find an input for which the function will return 10.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/07c27028bbf1fe8b5baf2dba3ede19f1/href">https://medium.com/media/07c27028bbf1fe8b5baf2dba3ede19f1/href</a></iframe><p>If we look at the execution of this piece of code then we can clearly see that it will only consider state 3 and state 5.</p><p>For the analysis of state 3, the function is_possible(result_constraint and state.constraints) will return false, because for this state result = 0.</p><p>Looking at state 5, we’ll see something more interesting. Let&#39;s look at the two constraints that are considered here: result == 10 and x &gt; 10. It&#39;s easy to see that the first constraint must be satisfied, because for this state result = 10. We can also easily determine that x &gt; 10 can be satisfied; take for example the input 11. I just manually found a value that satisfies the constraints. In Mythril itself, actually checking if it is possible to satisfy these constraints is handled by an SMT solver (Z3 in our case). It uses <a href="https://en.wikipedia.org/wiki/Satisfiability_modulo_theories"><em>black magic</em></a> and tells us if it is possible to satisfy the constraints. <br>But Z3&#39;s magic doesn&#39;t stop there. It can even give you an example that satisfies the constraints; this will allow us to construct a concrete input that will make the function return 10.</p><p>As a conclusion to the analysis of the function execute, we were able to say that</p><ol><li>It is possible that the output of the program is 10</li><li>To get the output of the program to be 10, you could use the input 11</li></ol><h4>What next?</h4><p>In this post, we saw how we can apply symbolic execution to a small example function and saw how to write a trivial analysis module.</p><p>While this is already cool, in further posts we’ll look at more interesting properties and bugs. For example, we can search for states where we can force the value of a send call to be 10 ether. Something you might not want your contract to allow.</p><p>Thanks to <a href="https://medium.com/u/4e81a7415404">Valentin Wüstholz</a> and <a href="https://medium.com/u/336eb74a5043">Dominik Muhs</a> for feedback on a draft version of this article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef59339f259b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>