<?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 Dmitry Khovratovich on Medium]]></title>
        <description><![CDATA[Stories by Dmitry Khovratovich on Medium]]></description>
        <link>https://medium.com/@khovratovich?source=rss-7cb5e9dfcb81------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_TckDKo9GbgTKB4WGtJqBw.jpeg</url>
            <title>Stories by Dmitry Khovratovich on Medium</title>
            <link>https://medium.com/@khovratovich?source=rss-7cb5e9dfcb81------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 15:55:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@khovratovich/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[Cryptography in Your House: 10 Mistakes You Probably Make and How to Avoid Them]]></title>
            <link>https://medium.com/sikoba-network/in-this-post-i-talk-about-a-few-mistakes-that-are-often-made-by-those-who-work-with-cryptography-f9e312ebea34?source=rss-7cb5e9dfcb81------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9e312ebea34</guid>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[zero-knowledge-proofs]]></category>
            <category><![CDATA[security-breach]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[software]]></category>
            <dc:creator><![CDATA[Dmitry Khovratovich]]></dc:creator>
            <pubDate>Thu, 05 Sep 2019 09:31:53 GMT</pubDate>
            <atom:updated>2019-09-05T09:47:26.586Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post, I will talk about a few mistakes that are often made by those who work with cryptography. This happens more often than you think, even when you do not design cryptographic protocols explicitly: when you work with authentication, communication channels, plan the architecture for your project or discuss scalability issues — cryptography is involved.</p><p>Of course, you want to avoid mistakes. You have heard many hacking stories where million-dollar thefts were made possible by webmaster mistakes. With cryptography, it is even worse. If you have weak crypto, attackers will read your communications, log into your servers, take your money — and you will never notice it until it is too late. Mistakes in cryptography are often exploited without leaving a footprint.</p><p><em>This article summarises a presentation made at </em><a href="https://www.zklux.eu/"><em>ZKLux#1 — Luxembourg Zero Knowledge Days</em></a><em> on 27 June. A video of the presentation is available </em><a href="https://www.youtube.com/watch?v=pqCnbtDKUfQ"><em>here</em></a><em>.</em></p><h3>Mindset</h3><p>First, you have to change your mindset. Crypto tools are not just another framework — they are rather the <em>skeleton </em>of your application upon which the rest sits. As with the framework of a building, cryptography involves higher risks (you lose more in case of error), is more expensive to work with and is difficult to repair during the lifetime of the finished product. Worse yet, if there is a problem, you will only know about it after everything falls to pieces.</p><p><strong>Mistake 1: Inventing your own crypto</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*JvzwTH-V85rUKn9Y" /></figure><p>Creating a new crypto scheme is surprisingly hard, error-prone and risky. Even professional cryptographers often fail at it. Academic conferences are full of attack papers that break cryptographic designs, both in theory and practice. 80% of cryptographic schemes designed by cryptographers get broken, and this rate reaches 99% for those designed by non-cryptographers. Of course, sometimes you do need your own cryptography, for example, when you need a new protocol. Then you have to hire a specialist.</p><p><strong>Mistake 2. Security by obscurity</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/0*gcg225PrMZjJ2prI" /></figure><p>Are you often tempted to design an algorithm or protocol but hesitant to tell others the details? You might think that a mistake might damage your reputation. However, this is wrong-headed: the details of the scheme are often easy to reverse-engineer. Instead, ask for third-party analysis. The more such reviews you get, the better protocol you obtain. Later, reveal your design to a wider audience and ask for feedback (it might even come for free). Remember, after centuries, cryptographers have come to a conclusion: “<em>the only secret part of a scheme should be the secret key</em>”.</p><h3>Protocol Design</h3><p>Sometimes you need a new protocol that is tailor-made for your business, and you have checked that no analogue is available. Then indeed, you need a cryptographer.</p><p><strong>Mistake 3. One cryptographer is enough.</strong> You hired a good guy, gave him the task and the money, and you are now waiting for the result. Apparently, even the best cryptographers do not work alone. A big part of security comes from public scrutiny, so first, review the crypto design with other team members, even non-cryptographers. Then, go to the public, using rewards or competitions if you can. In the design, favour clarity and brevity over complexity (this can be asserted even by a non-cryptographer; see something complex — ask for simplification).</p><p><strong>Mistake 4. It works, so it is good</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*80AJSBZ45OnwFOq6" /></figure><p>Suppose you mentioned a serious problem to a friend, and in a week he suddenly came up with a solution. It works and is reasonably fast. Should you accept it right away?</p><p>In cryptography design, the answer is often “No”. The solution might not be optimal, or it may be less secure than potential alternatives. And it turns out that a week is too short, particularly if the implementation is also done and optimized in that time.</p><p><strong>Mistake 5. Just some privacy is enough</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tqmNnf3U_pCVkVi1" /></figure><p>Suppose you design a privacy-preserving money transfer system. However, transfers are not fully anonymous because it would be too expensive (computationally, in internal currency, etc.) to make it so. A cheaper system allows the candidate senders to be narrowed down to 10,000. Is it good enough?</p><p>Apparently not, as there are many ways to amplify the privacy loss. Suppose an attacker saturates the network with dummy transactions, sending 99.9% of all of the traffic. Then the problem of identifying one sender is only 1-in-10.</p><p>The rule is that there is no ‘some privacy’ — there is privacy or no privacy.</p><p><strong>Mistake 6. Complex setup</strong></p><p>Your team comes up with a fast and secure solution. However, it requires a lot of time and work to initialize. Should you adopt it?</p><p>Probably not. A sophisticated setup may be difficult to repair. For example:</p><ol><li>In March 2018, a researcher for the anonymous cryptocurrency Zcash found out how to print fake coins. The problem was in the setup phase, which used some privately-generated random numbers, and some of them were present in the public setup data due to poor design.</li><li>A call for a new setup would reveal the problem with the old one, which could then be identified and exploited. The Zcash team decided to keep the problem secret for a few months (!) until a scheduled new setup, risking an attacker finding the problem himself and exploiting it covertly.</li></ol><p>If the setup had been easy to change and roll out, it would not have been necessary to take this risk.</p><h3>Implementation</h3><p>OK, the problem has been solved: a beautiful and secure protocol has been found. Now it is time to implement it.</p><p><strong>Mistake 7. Key stored everywhere</strong></p><p>You deal with secret keys in many components. Should you store them everywhere where they are used to minimize the risks of transmission?</p><p>Apparently not. A better solution is to design a special component that stores all keys and to guard it properly.</p><p><strong>Mistake 8. Old libraries and old coding style</strong></p><p>You see a set of well-established open-source libraries for cryptography in a familiar programming language. Should you use them?</p><p>First, check the following:</p><ul><li>Support of the primitives (curves or ciphers) that you need</li><li>Protection from recent attacks (proper key and nonce length, data format, etc.)</li><li>Side-channel protection, if applicable</li><li>Conformance with standards</li><li>As usual: support and licensing</li></ul><p>Also, open-source does not imply the absence of bugs.</p><p><strong>Mistake 9. Programmers who design and optimize</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/0*Tw0NpQEOoRapLa95" /></figure><p>Good programmers are keen on cryptographic design, often thinking it is as easy as regular architecture design.</p><p>Crypto designed by good coders has cleaner code but has questionable design decisions.</p><p>A cryptographer and programmer should work in a pair and review each other’s work.</p><p><strong>Mistake 10. Wrong source of randomness</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*RYmXxUDYDmaKjUq6" /></figure><p>Most programming languages have built-in randomness generators.</p><p>However, these might be enough for statistical tests only.</p><ul><li>Use one master seed from a proper randomness source, or ideally a combination of sources.</li><li>Derive further randomness deterministically and irreversibly from the seed using standard techniques (like HKDF).</li></ul><h3>Summary</h3><ol><li>Do not invent your own crypto.</li><li>Make the design public and auditable.</li><li>One person is never enough.</li><li>Working does not mean `good`.</li><li>A little privacy means no privacy. The same goes for security.</li><li>Secure your keys in one place.</li><li>Reevaluate third-party code.</li><li>Good programmers are not crypto designers.</li><li>Use cryptographically strong randomness and derive further randomness from it.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9e312ebea34" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sikoba-network/in-this-post-i-talk-about-a-few-mistakes-that-are-often-made-by-those-who-work-with-cryptography-f9e312ebea34">Cryptography in Your House: 10 Mistakes You Probably Make and How to Avoid Them</a> was originally published in <a href="https://medium.com/sikoba-network">Sikoba Network</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unclonable transactions in the post-fork Ethereum or how to protect against replay attacks]]></title>
            <link>https://medium.com/@khovratovich/unclonable-transactions-or-how-to-protect-against-replay-attacks-5e1be6f4012c?source=rss-7cb5e9dfcb81------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e1be6f4012c</guid>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Dmitry Khovratovich]]></dc:creator>
            <pubDate>Fri, 22 Jul 2016 09:33:04 GMT</pubDate>
            <atom:updated>2016-07-22T12:16:08.319Z</atom:updated>
            <content:encoded><![CDATA[<p>We <a href="https://medium.com/@khovratovich/insecurity-of-split-contracts-42cb41a1a94d#.ii74hdkfi">have just explained</a> how to split your money between the <a href="https://blog.ethereum.org/2016/07/20/hard-fork-completed/">two branches of Ethereum</a> properly so that you can operate your wallets in the branches independently. Now we explain how to split transactions, i.e. how to guarantee that the transaction will be executed in only one branch.</p><p>Recall that the ``hard fork’’ effectively created two universes of Ethereum: the HF one and the ``classic’’ one. Every account holder found himself with two copies of the account and thus two balances, each valid in the respective universe. It is natural to operate independently in each universe so that the actions taken into one universe could not have been reproduced in another one against our will.</p><p>The main obstacle to independent operations is that the transactions are not inherently bound to any branch. As long as the balance of the sender exceeds GasLimit*GasPrice and the transaction nonce equals sender’s transaction counter, the transaction is accepted for execution by the virtual machine.</p><p>The first countermeasure is to split the accounts in the way <a href="https://medium.com/@khovratovich/insecurity-of-split-contracts-42cb41a1a94d#.ii74hdkfi">we have described </a>in the previous post so that instead of a single account A with balance E (denote it by [A,E]) in both universes you would have [A,E] in one universe and {[A,0]; [B,E]} in another, where B is your new account. Then any transaction T coming from A will not be accepted in the second universe because of gas shortage.<strong> </strong><em>However, an attacker can send A some ethers in the second universe to make it payable, then copy T from the first universe to the second, and then get T executed</em><strong>.</strong> Other attack vectors were described by Vessenes <a href="http://vessenes.com/hard-fork-and-replay-concerns/">here</a>. He also suggests increasing countermeasures such as massive nonce increase in one of the universes, but they seem to not working against the attacker above.</p><p>Another situation is that we might want to stick to the original account A in both universes for some reason. For example, there could be a multisig wallet accepting commands from A only, or another contract bound to A. We do not want that our transaction we send to such a contract C can be used in another universe unless we want that. Other consequences of the replay attack were described by Gun Sirer <a href="http://hackingdistributed.com/2016/07/17/cross-chain-replay/">here</a>.</p><p>OK, so how we gonna do it? Suppose we want transaction T to be sent from account A in universe 1 only. For the sake of simplicity assume that A has equal balance E in both universes. Let the transaction counter of A be N1 in universe 1 and N2 in universe 2. Then we proceed as follows:</p><ol><li>Create a secondary account B and send all money from A to B in universe 1 only using <a href="https://medium.com/@khovratovich/insecurity-of-split-contracts-42cb41a1a94d#.ii74hdkfi">the split contract</a>. Since you usually have some gas refunded, the A will have non-zero (but small) balance X in universe 1, and balance E in universe 2.</li><li>If N1&gt;=N2, i.e. the second universe is aware of fewer transactions, we make (N1-N2+1) dummy transactions from account A using the nonce in universe 2 (e.g., by using the client from universe 2). The transactions should have high GasLimit so that GasLimit*GasPrice&gt;X and the transactions will be invalid in universe 1 and thus not copyable. The actual cost of the transactions should be small though (for instance, they may simply send money to the same account) in order to not to drain our balance.</li><li>Now universe 2 has higher value (N1+1 or higher) of the transaction counter and we wait till the transactions above have settled in the chain. Then we return the money from B to A using the split contract in universe 1 only. The A’s nonce remains the same.</li><li>We create transaction T and send it from account A using the nonce value N1 (by using the client from universe 1) . It won’t be accepted by universe 2 since nonce N1 is already in use. Thus it becomes unclonable as we required.</li></ol><p>The best the attacker can do is to slow down the procedure at the cost of some money. If he carefully track our sendings, he can try to insert the money transfer from his account Z to A before our step 4. In this case A will have larger balance, and the adversary can copy our transactions from step 2 and apply them in universe 1. This will increase the counter, but will cost him so much money that is needed to overcome the GasLimit restrictions we set in step 2. The more money he sends us, the larger limit we can set. And the transaction T remains unclonable. Note however, that we should manually set the nonce value in step 4, otherwise the attacker who succeeds in the counter increment may fool our client into the wrong nonce value.</p><p>This technique works in both directions as long as counters are almost synched.</p><p>To avoid this sort of hacks, some extra functionality in the transactions would be helpful. For instance, if a transaction contains some code that is executed before the message processing, it would make transaction split much easier. So we call for <em>smart transactions</em>.</p><p>Dmitry Khovratovich</p><p>Mikhail Vladimirov</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e1be6f4012c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Insecurity of split contracts]]></title>
            <link>https://medium.com/@khovratovich/insecurity-of-split-contracts-42cb41a1a94d?source=rss-7cb5e9dfcb81------2</link>
            <guid isPermaLink="false">https://medium.com/p/42cb41a1a94d</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Dmitry Khovratovich]]></dc:creator>
            <pubDate>Thu, 21 Jul 2016 09:00:14 GMT</pubDate>
            <atom:updated>2016-07-21T17:24:19.388Z</atom:updated>
            <content:encoded><![CDATA[<p>The just happened hard fork raised an important question of how to deal with money on private accounts and contracts, which are still valid in both branches. For instance, we may want to send money from our account to another account or contract A only in the new (HF) branch and keep the money in the original branch intact.</p><p>There is a couple ways to do that. First, we recall that every transaction must come with an incremented counter value (nonce); a transaction with nonce being larger or smaller than the number of previously sent transactions is discarded. Secondly, we may create a proxy contract that forwards money to the recipient but only in a certain branch. This contract is also called a split contract. It can, for instance, be used to split the money of user’s account between branches so that operations on user’s money in distinct branches are completely independent.</p><p>Several such contracts have been proposed so far, and we have found some of them too complicated and even insecure. The first problem comes from identifying in which branch we are. Since the entire purpose of the hard fork is too deal with the DAO heist, it might sound reasonable to check the balance of the WithdrawDAO account, which is fixed differently in both branches. However, this is not a bulletproof solution. Indeed, the balance of any account in any branch can be updated in the future for whatever reason, and the seemingly secure split method will stop being so. We personally believe that the WithdrawDAO balance will go below 2M ether soon.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f4281fe14b2853a70b6acdb6ca508ddb/href">https://medium.com/media/f4281fe14b2853a70b6acdb6ca508ddb/href</a></iframe><p><a href="http://etherscan.io/address/0xb671c3883307cf05bb3dff77a9754e87b4347195">Buterin’s contract</a> (0xb671c3883307cf05bb3dff77a9754e87b4347195)</p><p>Another problem is the possible outcomes of the contract. Let us look at the split contract HFConditionalTransfer <a href="https://www.reddit.com/r/ethereum/comments/4t9jv5/a_contract_to_conditionally_send_ether_to_another/">proposed by Buterin</a>. It detects in which branch it is by looking into external account’s balance (note that it costs the caller extra gas). Then it sends the money to the recipient or back to the sender depending on this check. Note that there is no failure check in the contract. For instance, the send() call may fail, which would leave all money in the possession of the contract. Worse enough, there will be no way to withdraw the money after the failure, as the contract can not send its money to anyone. The same happens if the branch is wrong but the send-to-the-sender fails. Therefore, there are at least three outcomes of the contract call: move money to the recipient, return to the sender, and acquire. By the time of writing, the split contract by Buterin has already acquired 0.08 ETH.</p><p>The idea of sending back the money in the classic branch seems insecure too. Consider a multiple-wallet contract, which holds ethers of several users and is responsive to the commands of its shareholders. Suppose that shareholder A wants to send money to some recipient B in the hard fork only via HFConditionalTransfer calling its transferIfHF. In the HF branch the transfer will be fine, but in the classic branch the money will be sent back to the wallet contract, which can not determine whose they are, and will assign them to HFConditionalTransfer’s account. This is the fourth possible outcome of Buterin’s contract.</p><p>An alternative <a href="https://medium.com/@timonrapp/how-to-deal-with-the-ethereum-replay-attack-3fd44074a6d8#.dgwjgun8i">approach by Timon Rapp</a> is just the oracle contract AmIOnTheFork with a single public variable ‘forked’ (see below). The contract was deployed before the fork, and has to be called within the first 1200 blocks after the fork. The update() function checks the balance of the darkDAO account and sets the fork flag to ‘true’ if it is too low. An external contract is supposed to ch</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0ab543803430840c34917598ef4e937/href">https://medium.com/media/b0ab543803430840c34917598ef4e937/href</a></iframe><p>The intention was clearly to update the contract before the darkDAO balance can be reduced in the classic branch. However, this again assumes the security of the DAO contract. If the hacker finds a way to reduce the balance of darkDAO before the block 1921200, he can call update() and the contract becomes useless. Worse enough, calling update() earlier does not help: the function can be called (and the variable can be updated) multiple times, so before the block 1921200 there is always a chance the contract becomes obsolete. Currently the classic mining rate dropped 5–7-fold, so the DAO hacker has plenty of time to find a way to reduce the balance of the darkDAO.</p><p>We suggest a more careful approach. First, we use the mere fact of the chain differences as the distinctive property. Recall that the Ethereum language has limited (but sufficient for our purpose) functionality of working with blockchain itself. For instance, it can look up the hash of any last 256 blocks using the blockhash() command. The contract BranchSender (see below) at the time of creation checks if in the current branch the block with the given number has the given hash and updates the internal variable IsRightBranch accordingly. In reality it checked the block with number 1920000 against the hard fork hash. This contract was deployed in the HF branch in the block 1920012 and got the variable assigned with ‘true’, whereas the same contract in the (still alive) classic branch got ‘false’ in the block 1920160.</p><p>Secondly, the special care was taken to limit possible outcomes. In the case of any failure the contract throws, which guarantees that the transaction does not finalize. Thus there is no way for the contract to acquire the money. This applies also to the default function, which always throws.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fae775894971ee34d93ce97fe384c585/href">https://medium.com/media/fae775894971ee34d93ce97fe384c585/href</a></iframe><p><a href="https://etherscan.io/address/0x23141df767233776f7cbbec497800ddedaa4c684">Vladimirov’s contract</a> (0x23141df767233776f7cbbec497800ddedaa4c684)</p><p>The contract BranchSender sends money in the hard fork only; this is sufficient to split the account between them. To make the classic-only send, another copy of this contract should be created with the constructor taking the value of any recent ``classic’’ block.</p><p>We have also prepared a simple script that uses the contract and splits the account for the user. It will be ready to use as soon as the classic branch accepts the contract too. It is sufficient to insert the account number in the following command:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ecf1a97ac9f284dd06da766e14e739e8/href">https://medium.com/media/ecf1a97ac9f284dd06da766e14e739e8/href</a></iframe><p>Write secure contracts and prosper.</p><p>Dmitry Khovratovich,</p><p>Mikhail Vladimirov</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42cb41a1a94d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>