<?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 Manoj P R on Medium]]></title>
        <description><![CDATA[Stories by Manoj P R on Medium]]></description>
        <link>https://medium.com/@manojpramesh?source=rss-756ec247329------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Z37XwdZTM3mc4O6Tf0ggBA.png</url>
            <title>Stories by Manoj P R on Medium</title>
            <link>https://medium.com/@manojpramesh?source=rss-756ec247329------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 00:46:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@manojpramesh/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[Most common smart contract bugs of 2020]]></title>
            <link>https://medium.com/solidified/most-common-smart-contract-bugs-of-2020-c1edfe9340ac?source=rss-756ec247329------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1edfe9340ac</guid>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[security-audit]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[ethereum-security]]></category>
            <dc:creator><![CDATA[Manoj P R]]></dc:creator>
            <pubDate>Mon, 30 Nov 2020 16:24:41 GMT</pubDate>
            <atom:updated>2020-11-30T16:24:41.350Z</atom:updated>
            <content:encoded><![CDATA[<h4>Based on our audit results — <a href="https://github.com/solidified-platform/audits">https://github.com/solidified-platform/audits</a></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YtQhF3SXL5-WGsIehUxBfw.jpeg" /></figure><p>2020 has been an unprecedented year thus far. Bugs in Ethereum smart contracts are not less of a disaster and don’t seem to be going away anytime soon. The sheer number of vulnerabilities and their severity indicates how important it is to have an audit before deploying smart contracts to the Ethereum main network.</p><p>As a blockchain security firm that has done many audits since the inception of Ethereum, we have seen a lot of repetitive but sometimes easily avoidable issues. Since we’re in Q4, we thought we would walk you through the most common bugs and security vulnerabilities we found in our audits during 2020.</p><p>We performed over 40 audits this year and reported 35 Critical and high severity vulnerabilities. For the purpose of this article, we listed every issue found in our audits and sorted them by severity, highlighting the most commonly discovered bugs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*R-5wNFHVqQTS0L0-aNS9iQ.png" /></figure><p>We also wanted to be discreet about which smart contracts contained the specific issues, so we intentionally did not include the project names or the exact code where these issues were found. You can always find the complete audit reports on our GitHub repo (<a href="https://github.com/solidified-platform/audits">solidified-platform</a>).</p><p>We hope this information becomes useful to developers in order to build better quality code, users to be aware of the potential risks, and security auditors to compare notes.</p><p><strong>Reentrancy</strong></p><p>It came as no surprise that one of the most infamous bugs in Ethereum is still a common issue to look for while writing a smart contract. The DAO hack caused by the reentrancy bug happened more than four years ago. Since then, many smart contracts fell victim to this issue including the recent ERC777 Uniswap exchange. It is also worth noting that the commonly recommended fix (transfer &amp; send methods) for this issue earlier is no longer valid for all use cases after Ethereum’s Istanbul hard fork with updated opcode pricing.</p><p>Reentrancy bugs were present in a few audits we considered for this review and all of them were classified as critical or major bugs since it involved loss of funds in one way or another. Reentrancy bug occurs when an attacker can call a function in the smart contract multiple times before the first execution of the function is completed. Let’s run through an example from one of our audits:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7afad3e0f2b7a43dcfb8a4de840a8b78/href">https://medium.com/media/7afad3e0f2b7a43dcfb8a4de840a8b78/href</a></iframe><p>Here in this example, the deposits mapping of the caller is updated only after the external call. This allows the caller to re-enter the function update from safeTransferETH allowing them to withdraw the balance multiple times. Moreover, the safe in the function name safeTransferETH may mislead the developers to assume it is “SAFE” to call this function without any precautions.</p><p>The best way to avoid the reentrancy bug is to follow the Checks-Effects-Interaction pattern. This pattern ensures that the code does not make an external call until it has completed all the state changes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1020bb65f87c288e8a64e178d674fcba/href">https://medium.com/media/1020bb65f87c288e8a64e178d674fcba/href</a></iframe><p>Another simple and easy fix to avoid this bug is to use a mutex in functions with possible reentrancy. This may not be the most efficient solution always, but it protects the function from being called again before the lock is released. Using a mutex can sometimes cause other bugs like DoS when used in more complex contracts with multiple interactions. A simple mutex can be implemented as follows.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3784858f7c9591beae62b1041e9e364c/href">https://medium.com/media/3784858f7c9591beae62b1041e9e364c/href</a></iframe><p>Here in this implementation, the lock will prevent the function from being called again before the first execution finishes.</p><p><strong>Unauthorized access</strong></p><p>A mistake as simple as not restricting an important function from unauthorized access can lead to a disaster. We saw a few contracts this year which missed checking if the caller is authorized to perform a specific action.</p><p>The most common place where we found these unrestricted functions were in oracle callback implementations. Let’s take a look at an example which is similar to what we came across.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c82a5bc69978f78450957b23812296c6/href">https://medium.com/media/c82a5bc69978f78450957b23812296c6/href</a></iframe><p>The price update callback in this contract is intended for the oracle service to callback when a price update is requested. Since the function is not restricted to an oracle service, it can be called by anyone to manipulate the price. To avoid any side effects, it is recommended to restrict such functions to a certain number of trusted callers.</p><p>A different variant of this issue can happen when a value in the smart contract (like price) is sourced from the crowd. If there is no penalty on updating to the wrong value, it can be greatly misused.</p><p><strong>External calls - DoS</strong></p><p>External contract interactions have become essential to many smart contracts in Ethereum. With an increase in the number of interactions the chance of overlooking a vulnerability is also at higher risk. We are always cautious about external calls in smart contracts and we verify them diligently in order not to miss an attack vector.</p><p>One such common issue is the Denial of Service bug during ETH transfer. Not all recipients are addresses or contracts with minimal fallback functions. Since the transfer and send function forwards exactly <em>2300</em> gas to the recipient, a contract with a fallback function will throw an out-of-gas exception. The intention of this upper limit is to prevent reentrancy vulnerabilities, but it requires gas usage to be constant.</p><p>Consider the following example from one of our audits:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/043adb829d0a886d8a59b42516090f75/href">https://medium.com/media/043adb829d0a886d8a59b42516090f75/href</a></iframe><p>This function tries to send ETH to an address and will fail to succeed if the recipient consumes more than 2300 gas. It is recommended to use call instead of transfer/send to avoid possible DoS.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/89517f4f4a056954da6e6d642676d660/href">https://medium.com/media/89517f4f4a056954da6e6d642676d660/href</a></iframe><p>Using the call function comes with its own risks since all the available gas is forwarded. It is recommended to check the return value of the call method. It is also recommended to always follow the Checks-Effects-Interaction pattern to avoid the reentrancy bug.</p><p><strong>Logical errors in the code</strong></p><p>This category is not something that is solely related to Ethereum smart contracts or even DApps in general. Logical errors and functional specification mismatch are common issues found in all applications and in smart contracts, this can cause loss of funds or make the application vulnerable to other serious attacks. We decided to include this as part of this report since we found a few serious issues in the audits we performed.</p><p>Let’s look at a simple error that makes the contract behave completely opposite to what was initially intended in the whitepaper.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5126b685e49201804ff8060ac0f2c2c0/href">https://medium.com/media/5126b685e49201804ff8060ac0f2c2c0/href</a></iframe><p>The function calculates the fee based on the amount. If the value is greater than the maximum amount set, a fee is charged. This looks simple and straightforward and should not cause any issue. According to this particular project’s whitepaper, a fee will be collected only if the value is less than the maximum value set — which is the exact opposite of what is being done here. These kinds of simple errors are easily overlooked and the intended code for this function will look something like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b3d89edc194160eff67986db2319743/href">https://medium.com/media/4b3d89edc194160eff67986db2319743/href</a></iframe><p>These bugs are unique to each smart contract and there is no one straightforward solution to fix this. Understanding the detailed specification of the project and writing enough test cases that cover the complete specification and code can help verify the functionality and avoid related bugs. Having an extra developer or an auditor to test the code is also recommended. We at Solidified consider spending time on understanding the specification of the project to be an important step in any audit. For more complex projects, we often jump on a call with the client to make sure that we are on the same page about the specification and intent of the code.</p><p><strong>Integer overflow/underflow</strong></p><p>The number of overflow and underflow errors was relatively low this year compared to what we have seen before. It was not completely non-existent however, we could still find it in some unexpected places.</p><p>The integer overflow occurs when the integer value reaches the maximum (2⁸ for uint8, 2²⁵⁶ for uint256 etc) supported by the data type, causing the value to circle back to 0. This is more common for data types with a smaller maximum value like uint8 and uint32. But in some use cases with large enough values, uint256 can overflow too.</p><p>The case with underflow is very similar. When the value of a uint is set to be less than zero, the value underflows and will be set to the maximum possible value of that data type. Consider the following example of a simple token transfer. If the balance reaches the maximum value, it will be set automatically back to zero.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cca3101756ef207d5c1374eb0d2dfe14/href">https://medium.com/media/cca3101756ef207d5c1374eb0d2dfe14/href</a></iframe><p>The easiest and simple solution is to use the <a href="https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/math/SafeMath.sol">SafeMath</a> library which provides functions to perform arithmetic operations with built-in overflow/underflow validations. You can choose to implement the checks yourself but should be extra careful while doing so.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/712b3865dac7a66df8afec9eb9df368b/href">https://medium.com/media/712b3865dac7a66df8afec9eb9df368b/href</a></iframe><p><strong>Storing private data</strong></p><p>The fact about everything being public on Ethereum is sometimes a bit confusing for new developers. With keywords like private and internal used in the Solidity language, the developer can easily mistake them to store private data with restricted visibility.</p><p>We have seen many instances where the developer assumes that the contract will store private data and no one in the network can read it. Even worse, some contracts try to implement a monetization model over this. These contracts will allow the user to read the “private” data stored after collecting a certain fee.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/61b97d3fd612dc8d7748213afc8124de/href">https://medium.com/media/61b97d3fd612dc8d7748213afc8124de/href</a></iframe><p>The value stored in the secret cannot be accessed from the smart contract — which makes sense for any general-purpose application. However, in Ethereum, storing a value in a private variable does not restrict anyone from reading it from the contract’s state or the transaction which was used to store the same value in the first place.</p><p>In short, do not store any sensitive information in Ethereum smart contracts. You can choose to store encrypted or hashed data but it is not recommended.</p><p><strong>Gas overflow during iteration — DoS</strong></p><p>In some scenarios, loop execution can cost more than the maximum gas allowed on each block and when it happens, the transaction will fail to execute. This can be temporary and will affect only a specific transaction or can be permanent if the iteration count grows overtime. We have come across a few such DoS cases which can occur with or without the presence of an intentional attack.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d8a2ebd801e886cfb05a6821467a8fe/href">https://medium.com/media/9d8a2ebd801e886cfb05a6821467a8fe/href</a></iframe><p>Let’s assume the function compute is used in an essential function to dynamically calculate a value. Since the array size can grow to a very large number, the contract will eventually come to a standstill because of the block gas limit.</p><p>These are hard to catch during testing since the developers tend to use smaller datasets as inputs and some test networks are often forgiving when it comes to gas limits. It is strongly recommended to avoid loops of unknown size. If looping is necessary for your smart contract, then split the transaction into multiple blocks by keeping track of how far the loop got executed so far. This will help to resume the iteration in subsequent blocks.</p><p><strong>In Summary</strong></p><p>Ethereum is a platform which promises to revolutionize a lot of industries, but when compared to other non-Blockchain platforms, it is still in its early stage. A bug-free code is nice to have in other applications, while in a decentralized blockchain like Ethereum where it is designed to be immutable, it is essential.</p><p>We covered the most common bugs we came across during our audits this year. Even though these are the frequent ones, you cannot stop looking for other types of bugs. Each contract is unique in its own way and the one non-common bug in your contract can be the most serious one. This makes auditing smart contracts for bugs an essential step before deploying to the main network.</p><p><strong>Reminder about testing</strong></p><p>Ensuring your smart contract is safe on Ethereum’s main network is not a one-step process. It should be considered from the beginning when the requirements are defined and should be carried out throughout the development phase till the end. The developer should spend enough time to understand the specifications in detail and write enough test cases to cover them in the code. In addition to testing the contract in mock networks, it is encouraged to test them in larger networks like Ropsten to simulate real-world use.</p><p><strong>Not all audits are equal</strong></p><p>Even with careful planning, development and testing, the resulting contract may still contain some unexpected vulnerabilities. This is more apparent from the number of exploits identified in the deployed smart contracts and the audits we published. Having an experienced team of experts to test and audit the contract will help find such vulnerabilities. There are many firms that can help audit your contracts. But using the traditional methods of auditing may not always yield the best results when it comes to unique problems and that is why at Solidified we use a more decentralized and multi-layered approach to auditing. We employ a multi-layered and decentralized audit technique, involving three or more independent auditors with complementary expertise performing an isolated and unbiased 1:1 audit of smart contracts. Once the independent audits are completed, the auditors come together to have a consensus meeting and combine the results of each audit. This debrief session ensures everyone agrees with the discovered bugs, recommended fixes for each bug and the bug severity. The final report is then published publicly to maintain transparency.</p><p><strong>About Solidified</strong></p><p>Solidified is the largest smart contract auditor in the US having secured popular projects like Loopring, Kyber, Argent, Gnosis, Nexus Mutual, Polymath and many others, total 450M+ in assets under audit. We are also known for our bug bounty platform where anyone can post their smart contracts to get it reviewed by our community of 250+ security experts.</p><p>To learn more about us or request an audit, check out <a href="https://www.solidified.io/">https://www.solidified.io/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1edfe9340ac" width="1" height="1" alt=""><hr><p><a href="https://medium.com/solidified/most-common-smart-contract-bugs-of-2020-c1edfe9340ac">Most common smart contract bugs of 2020</a> was originally published in <a href="https://medium.com/solidified">Solidified</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Keeping secrets on Ethereum]]></title>
            <link>https://medium.com/solidified/keeping-secrets-on-ethereum-5b556c3bb1ee?source=rss-756ec247329------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b556c3bb1ee</guid>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[audit]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Manoj P R]]></dc:creator>
            <pubDate>Sun, 08 Apr 2018 15:17:13 GMT</pubDate>
            <atom:updated>2018-04-08T15:17:13.450Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mVHDOFTl9sWQvXq9sa9rhQ.jpeg" /></figure><p>Many contracts, like game contracts, usually need to keep some values as private. For example, storing the player’s next move or a number that has to be guessed. Private variables are not directly readable by a user or a contract, but that still doesn’t guarantee secrecy.</p><p>In solidity, using private may look like a very straightforward option for storing secret values. However, this doesn’t restrict anyone from reading the state of the contract. This is because the data that is stored in the transactions made to a contract is readable.</p><p>Let’s consider an example of an odd-even multiplayer game contract, which chooses the winner based on the numbers guessed. Each player chooses a number and if the sum is even then the first player wins, otherwise the second player wins.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d983834f0989e5b60a4a9561001c0f8f/href">https://medium.com/media/d983834f0989e5b60a4a9561001c0f8f/href</a></iframe><p>The game contract stores the bets of two players in players mapping. Since this variable is declared as private, the second player cannot read the data. Each player has to transfer 1 Ether to the contract in order to play. This condition is checked using require.</p><p>Once the second player places his bet, the winner is selected based on the odd-even logic and gets the whole bet amount of both players. A malicious player can carry on an attack, which always allows him to win a game. The attacker waits for someone to make a first move and plays as a second player. Now, although the variable is private, the attacker can read the first player’s bet by decoding the Ethereum transaction used. This allows the second player to choose a value that always makes him the winner.</p><blockquote>The contract code in the above example is used only for illustration purposes and may contain bugs. It is strongly recommended to audit this code prior to any use.</blockquote><h3>How to read private state variables</h3><p>State changes in Ethereum are usually done through a transaction. If the receiving account is a contract in a transaction, the EVM runs the contract’s code either to completion or until the execution runs out of gas.</p><p>Details, such as which method to call and input parameters are specified in the data field of each transaction. For example, for modifying a private state variable in the contract, you need to pass the “private” value to the setter method through a transaction. Considering the fact that every transaction data is visible to all the nodes, you could easily read private variables if you know the transaction.</p><p>Let’s look into the odd-event contract that we discussed above and see how you can decode the transaction data.</p><p>For every method call, the transaction data will have 2 fields:</p><ol><li>Method selector</li><li>Method parameters</li></ol><p>In our smart contract, call to the method will have the following transaction data. Let’s try to decode this.</p><pre>0x6587f6ec0000000000000000000000000000000000000000000000000000000000000064</pre><p>First 4 bytes of the transaction data always points to the method signature. It is calculated by taking the first 4 bytes of keccak hash of the method signature. In our example, it is bytes4(keccak256(&#39;play(uint)&#39;)) which is 0x6587f6ec.</p><p>The following characters point to the parameter of the specified method. Each parameter is represented by the hex value of the input padded to 32 bytes. If 100 is the input parameter to play method, then the transaction data for that parameter is:</p><pre>0x0000000000000000000000000000000000000000000000000000000000000064</pre><p>This can get more complex if there are more parameters and they are dynamic. You can get more details about argument encoding from the official <a href="http://solidity.readthedocs.io/en/v0.4.21/abi-spec.html#function-selector-and-argument-encoding">solidity documentation</a>.</p><h4>Recommendations for storing private information</h4><p>You may have requirements to store private variables in your contract, but that’s a rather complex problem. There have been a lot of attempts to simulate a private store of information and one interesting approach is the use of a <a href="https://karl.tech/learning-solidity-part-2-voting/">commit reveal pattern</a>. In this method, users first submit the hash of a secret information and when everyone else has submitted theirs, each participant reveals their vote, which can be back verified.</p><p>This is not suited for all the applications, and it adds a lot of complexity on users, but it’s a starting point for further explorations.</p><p>This article has been contributed by a <a href="https://solidified.io/">Solidified</a> expert. We are the largest (150+) community of Solidity auditors and security experts, developing a full-service audit platform. Come join our <a href="https://slack.solidified.io/">Slack</a> or apply to become an auditor with us <a href="https://solidified.io/?audit=onboarding">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b556c3bb1ee" width="1" height="1" alt=""><hr><p><a href="https://medium.com/solidified/keeping-secrets-on-ethereum-5b556c3bb1ee">Keeping secrets on Ethereum</a> was originally published in <a href="https://medium.com/solidified">Solidified</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>