<?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 Aleksey Studnev on Medium]]></title>
        <description><![CDATA[Stories by Aleksey Studnev on Medium]]></description>
        <link>https://medium.com/@astudnev?source=rss-bef2ad41224e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*jK0KZilHwDZ0v61rltbRUA.jpeg</url>
            <title>Stories by Aleksey Studnev on Medium</title>
            <link>https://medium.com/@astudnev?source=rss-bef2ad41224e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 00:31:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@astudnev/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[Smart Contract Anti-Patterns: Why sending Ether is not always a good idea?]]></title>
            <link>https://medium.com/bloxy/smart-contract-anti-patterns-why-sending-ether-is-not-always-a-good-idea-6ea5975164ff?source=rss-bef2ad41224e------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ea5975164ff</guid>
            <category><![CDATA[pull-payment]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[ether]]></category>
            <category><![CDATA[daoready]]></category>
            <dc:creator><![CDATA[Aleksey Studnev]]></dc:creator>
            <pubDate>Mon, 08 Jan 2018 17:33:21 GMT</pubDate>
            <atom:updated>2018-01-08T17:33:21.098Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*aEtDAaLZKgzQPSpr5w7FaQ.png" /></figure><p>Some smart contract sometimes need to send ether, for example:</p><ol><li>ICO crowd sale contract sends ether to a vault, where the funds are collected;</li><li>Returning ether as the change for performing operations. Sender may send uneven ( or exceeding ) amount of ether to the contract, and the contract should send the change back;</li><li>Blockchain game makes a payout to a winner in Ether;</li><li><a href="http://daoready.com/info/interactive-ico">Interactive ICO</a> returns funds to token buyers on request;</li><li>Distributed fund payouts dividends to participants;</li><li><a href="http://daoready.com/product/cpa-crowdsale">CPA Reward Contract</a> makes payments to affiliates;</li><li>Many other cases, when smart contract is responsible for distributing money between people and/or other contracts.</li></ol><p>Apparently, the code similar to the following appears in the contract:</p><pre>/// now it is time to send some_amount to receiver...<br>receiver.transfer(some_amount);</pre><p>In most cases, this code will not cause problems, but let’s discuss the cases when it does. The problems with this code can be caused by it’s usage in the contract, and the nature of the receiver.</p><h3>Problem #1: Applicable Gas Limit</h3><p>Imagine, that the receiver is not an external address, but rather another contract, which has something like this:</p><pre><strong>function</strong>() <strong>public</strong> <strong>payable</strong> { <br>/// do something very important... and consume gas<br>}</pre><p>This function tells, that the contract is ready to receive ether, but it is also going to make something with it, say store some data or calculate some values based on it. This kind of functions are typical in ICO crowd sale contracts, decentralized funds, multi-signature wallets and other greedy creatures.</p><p>What is important from the sender point of view, is that this function will consume gas, and then, the line in your sending contract:</p><pre>receiver.transfer(some_amount);</pre><p>will fail. Transfer function can use only a limited “gas stipend” (2300) amount of gas to make a transfer. Any more or less complex processing at receiving side will just make raise the error in your smart contract.</p><p>Solution for this particular problem is to use another function, <strong>call</strong> :</p><pre>receiver.call.value(some_amount)();</pre><p>This is different from the transfer function is that it forwards <em>all remaining gas </em>as a limit for a function call. This allows the caller of your contract to raise the gas limit and still execute the transfer in case Out of gas error happens.</p><p>This function has ability to specify the gas limit, if “<em>all remaining gas</em>” is unsecure:</p><pre>receiver.call.value(some_amount).gas(100000)();</pre><h3>Problem #2: Lack of check the result of transfer</h3><p>If you have the following line in your contract, you may be in a big problem:</p><pre>receiver.send(some_amount);</pre><p>The problem is that send does not raise any errors in case the transfer did not happen ( for example, because of Out of gas). You should change it to one of the following ( the last is the best option):</p><pre>require(receiver.send(some_amount); // check the result, or</pre><pre>receiver.transfer(some_amount); // raise exception in case, or</pre><pre>receiver.call.value(some_amount)(); // get rid of gas limit</pre><h3>Problem #3: Mixing transfer and logic in contract</h3><p>Generally, mixing the logic or cycles with ether transfer is <strong>always</strong> a bad idea. But in some cases it is even worse:</p><pre>/// DO NOT DO THIS!<br>address[] lovers;</pre><pre>for(uint i=0;i&lt;lovers.length;i++){<br>  lovers[i].transfer(some_amount);<br>}</pre><p>Or:</p><pre>/// DO NOT DO THIS!<br>winner.transfer(some_amount);<br>publisher.transfer(other_amount);<br>developer.transfer(other_amount);</pre><p>In general, try to avoid sending ether with logic, as the transfer operation may fail, and this is not what you expect from your logic. However, there may be more significant problems:</p><ol><li>One “bad” receiver may completely block your function in contract, if it has an error in his contract on payable function ( or consuming too much gas). Thing get worse, if you rely on your smart contract to change the state of your contract, and then you will never be able to do this.</li><li>Ethereum has a limit of stack depth 1024. It means, that if you send ether to other contract and in summary you exceed stack trace depth, the transfer will also fail.</li><li>Re-entrancy problem appears, when receiving contract calls your contract back, when your function <em>is not yet completed</em>.</li></ol><p>The later allows an attacker to withdraw more money than you may expect. For example, if your code looks like:</p><pre><strong>function</strong> withdraw() <strong>public</strong> {<br>        <strong>if</strong> (msg.sender.call.value(shares[msg.sender])())<br>            shares[msg.sender] <strong>=</strong> 0;<br>    }</pre><p>and the attacker, calling withdraw() has the code like:</p><pre>uint<strong> </strong>need_more;</pre><pre>function() public payable { <br>   if(need_more&lt;1000){<br>     msg.sender.withdraw();<br>     need_more += 1;<br>   }<br>}<br>function attack(address fund) public {<br> fund.withdraw();<br>}</pre><p>Then attacker can withdraw 1000x times more that you expected.</p><p>These types of errors are extremely hard to diagnose, find and test and better to completely avoid them by <em>not mixing code and ether transfer</em>.</p><p>What can be done instead? There are at least two solutions to the problem:</p><ol><li>Use pull payment pattern</li><li>Transfer tokens instead of ether</li></ol><h3>Pull Payment Pattern</h3><p>Idea is quite simple — when you want to transfer money to a receiver, do not make an actual transfer, but store the balance in contract store map.</p><p>Receiver will then need to call “withdraw” method to “pull” money to his address. The pattern is published in <a href="https://github.com/OpenZeppelin/zeppelin-solidity">Zeppelin</a> library, and essentially it consists of 2 functions ( simplified ):</p><pre>/// make a deposit on dest account<br>function asyncSend(address dest, uint256 amount) internal {           payments[dest] = payments[dest].add(amount);  <br>}</pre><pre>/// let account to withdraw:<br>  function withdrawPayments() public { <br>   .... some checks here ...<br>   assert(payee.send(payment));  <br>}</pre><p>The full source is available at <a href="https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/payment/PullPayment.sol">https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/payment/PullPayment.sol</a></p><p>The only real minus for this scheme is that the payee require to call non-standard contract function withdrawPayments and it may be not available in his or her favourite wallet or software.</p><p>Example of this pattern can be found in IZX game platform contract:</p><p><a href="https://github.com/izetex/contracts/blob/master/contracts/game/RevShareGame.sol">izetex/contracts</a></p><h3>Transfer tokens instead of ether</h3><p>Instead of transferring ether, you can give ERC-20 tokens to receiver, in the same amount as ether. The tokens will represent “the debt” to the receiver.</p><p>Receiver then can send tokens to the contract and get back the Ether using standard wallet software, supporting ERC-20 tokens.</p><p>This model used in <a href="http://daoready.com/product/interactive-ico">DAO Ready</a> interactive ICO contract:</p><p><a href="https://github.com/daoready/interactive-ico/blob/master/contracts/crowdsale/InteractiveCrowdsale.sol">daoready/interactive-ico</a></p><h3>Resume</h3><p>There is a number of rules that you should follow to successfully operate Ether values in your Smart Contracts:</p><ol><li>Expect that the receiving side can be <strong>another contract,</strong> consuming gas, executing code, and calling your contract back;</li><li>Always <strong>check the result </strong>of the transfer if using send method;</li><li>Use <strong>call</strong>() method to pass all remaining gas to the payable function of receiver;</li><li><strong>Do not mix logic</strong> and ether send. Instead use one of approaches mentioned above ( <strong>token debt transfer </strong>or <strong>pull payment patterns </strong>)</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ea5975164ff" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bloxy/smart-contract-anti-patterns-why-sending-ether-is-not-always-a-good-idea-6ea5975164ff">Smart Contract Anti-Patterns: Why sending Ether is not always a good idea?</a> was originally published in <a href="https://medium.com/bloxy">Bloxy</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Blockchain — an effective mechanism for stimulating economic cooperation for BRICS countries]]></title>
            <link>https://medium.com/bloxy/blockchain-an-effective-mechanism-for-stimulating-economic-cooperation-for-brics-countries-9068ead62b4a?source=rss-bef2ad41224e------2</link>
            <guid isPermaLink="false">https://medium.com/p/9068ead62b4a</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[brics]]></category>
            <category><![CDATA[ip]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <dc:creator><![CDATA[Aleksey Studnev]]></dc:creator>
            <pubDate>Tue, 19 Dec 2017 16:28:35 GMT</pubDate>
            <atom:updated>2017-12-19T16:44:26.770Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*isCjaho3vahicU6VfqJNBg.png" /></figure><p><strong>What is the blockchain?</strong></p><p>Blockchain is the technology for building a decentralized registry ( or ‘ledger’).</p><p>In the blockchain you can store records of bank transfers, documents, contracts, legal rights, patents, and so on.</p><p>There is no central trust authority in the blockchain, which would ensure the safety and correctness of this information. The trust in blockchain is ensured by the inherent properties of the blockchain network, based on mathematics, cryptography and game theory.</p><p>The primary blockchain properties, which extends the current internet experience, are:</p><ol><li>Trust relationship between the parties transmitting data in the blockchain is formed on the basis of mathematics. Prior to the appearance of the blockchain, trust was secured by personal acquaintance, organization’s fame and other subjective indicators, which are often overlooked. Blockchain changed this paradigm, largely influencing the notion of “trust” in the digital world. Confidence in the blockchain is formed mathematically, with the participation of a large number of participants, reaching an agreement (consensus), that is, it is objective, not subjective.</li><li>Transparency of interaction and safety of information on computers distributed around the globe and, generally speaking, not trusting each other.</li><li>Possibility of fulfilling pre-determined agreements (smart contracts) between parties that do not trust each other or have diverse interests</li></ol><p><strong>Successful Blockchain Applications</strong></p><p>The developed projects in the field of blockchain can be identified in several areas:</p><ul><li><strong>Cryptocurrency</strong> is the very first and most successful application of the blockchain. The network of the first cryptocurrency — bitcoin — was the first confirmation of the applicability of the blockchain ideas, and is still the most significant application of it.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/517/1*GK52P8ZIh31X15eJATQUOQ.png" /></figure><ul><li><strong>Registries</strong> on the blockchain are being introduced in many areas of activity, where openness, reliability and the decentralized trust are needed. We can say that in such registers “data belong to the people”. They are organized at various levels — worldwide, the scale of the country, enterprise or community:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/1*7OQuoeia9mFMRDSi2hxOFQ.png" /></figure><ul><li>Georgia introduced a register of storage of property rights (an analogue of the Russian regalata) on the basis of a blockchain;</li><li>Diamond miners in Africa store data on more than 2 million diamonds in the blockchain and trace them from mining to cutting and selling;</li><li>Estonia keeps data on citizens in a decentralized blockchan registry, on the way to a “digital passport”.</li><li><strong>Ensuring the fulfillment</strong> of obligations based on smart contracts. For example, lawyers are looking for ways to transfer legal relationships to smart contracts in the blockchain network. Outstanding feature of smart contracts is that they are executed even in the event of conflicting interests of the parties that originally participated in it.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*IHmogFhoCcBFXglLnxICGA.png" /></figure><ul><li><strong>Cooperation</strong> and crowd-funding networks. Blockchain enables to involve the active community of participants in projects that need expert or financial support. This property is actively used by many startups, which issue their own cryptocurrency (tokens) and conduct their initial coin offering (ICO). In addition to purely monetary interest, the projects receive support from the community, valuable employees and publicity at the expense of the ICO.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*9mKIsAllW91i55VIAmKNYw.png" /></figure><p>It should be noted that successful block-projects exist at different levels of coverage of participants: world-wide, national, corporation and organisation.</p><p><strong>Value for BRICS from the blockchain applications</strong></p><p>BRICS, like the block, has a decentralized nature. For this reason, BRICS projects can easily use blockchain and at the same time benefit from its properties in the very near future.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*YUMlJ3DVqaDVX_K4t7hADw.png" /></figure><p>The projects of BRICS participants can receive the following benefits from the introduction of blockchain into their processes:</p><ol><li>effective economic interaction, fast, open, without barriers and borders, without intermediaries</li><li>financial instruments and services for direct support of projects that meet the needs of organizations and are independent of external factors</li><li>opportunities to expand the labor market and joint activities for organizations and their employees, overcoming the borders of countries, currencies, continents</li><li>protection of copyright, intellectual property for citizens and organizations working outside</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*8BVBGJCzwKlTq9cciXnG_A.png" /></figure><p>Economic cooperation will become faster, more transparent, more efficient and more interesting for participants due to:</p><ol><li>Elimination of intermediaries and superfluous hierarchy of management and central regulation. The direct relationship between peer-to-peer (peer-to-peer) in a decentralized system has proved itself in many examples as a more progressive, economical model;</li><li>Overcoming barriers between countries, political, economic and financial systems through openness, an objective degree of trust, security of data storage. Blockchain can serve as a unifying factor, the credibility of which is objective and does not require additional confirmation from individuals or organisations;</li><li>Introducing a suitable system of values for the interests of the participants in the cooperation. Tokens produced by companies in the conduct of ICO are a special case of such value. Within the BRICS, such values can be formed within consortium between participants, individual industries to ensure transactions of value transfer between them;</li><li>Rapid and effective achievement of an agreement (consensus) between participants in economic interactions. This applies to voting procedures, decision-making, conclusion of contracts, consideration of disputed issues;</li><li>Organization of a decentralized exchange of goods and services within the BRICS. The agreements on this exchange will be recorded in the network of blockchain in the form of smart contracts, and settlements in specialized crypto-currencies.</li></ol><p>The following <strong>financial instruments and services</strong> on blockchain can be introduced in BRICS:</p><ul><li>Loans in the internal crypto currency, tied to the assets of participating organizations. This will make the economic model independent of external factors (such as the dollar rate), reduce the degree of risk and speed up the development of joint ventures credited in this crypto currency;</li><li>Investment in the crypto currency, which will grow in value in proportion to the development of organizations or entire industries. This will open up opportunities for investors and significantly expand the range of fundraising and interest of foreign investors;</li><li>Decentralization of the banking system for instant, transparent and secure exchange of funds between BRICS organizations;</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*RMweg5R11YG3tr1UIGWaaQ.png" /></figure><p>The following blockchain solutions to <strong>employment, expertise sharing and cooperation</strong> can be introduced in BRICS:</p><ul><li>Decentralized labor exchange in the BRICS countries can be built with a specialized crypto-currency. It will inherit all the positive properties of technology and will be governed by agreements between the participants.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*PvHhJCJlquNJgAQP4d0U2g.png" /></figure><p>The following projects in the area of <strong>protection of copyrights, trademarks and objects of intellectual property</strong> will be valuable for BRICS countries:</p><ul><li>Decentralized register that keeps “casts” from objects of cultural, copyright and intellectual rights will help significantly simplify the procedure for registering rights and dispute settlement procedures;</li><li>Blockchain record can serve as evidence on the basis of the fundamental properties of the block of data on the consistency and consistency of data;</li><li>For BRICS countries, the introduction of such a registry will help to organize a common space of law in the field of intellectual property, which is now the main asset driving high-tech industries.</li></ul><p>The combination of projects that benefit directly from the implementation of blockages and the world experience of its implementation is a key factor in stimulating economic cooperation in the BRICS countries.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9068ead62b4a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bloxy/blockchain-an-effective-mechanism-for-stimulating-economic-cooperation-for-brics-countries-9068ead62b4a">Blockchain — an effective mechanism for stimulating economic cooperation for BRICS countries</a> was originally published in <a href="https://medium.com/bloxy">Bloxy</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>