<?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[SECBIT Media - Medium]]></title>
        <description><![CDATA[SECBIT was founded by a group of cryptocurrency-enthusiasts. We are doing research on smart contract security, smart contract formal verification, crypto-protocols, compilation, contract analysis, game theory and crypto-economics. - Medium]]></description>
        <link>https://medium.com/secbit-media?source=rss----a857700d0fa0---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>SECBIT Media - Medium</title>
            <link>https://medium.com/secbit-media?source=rss----a857700d0fa0---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 09:45:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/secbit-media" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Redundant Check in ERC20 Smart Contracts’ approve()]]></title>
            <link>https://medium.com/secbit-media/redundant-check-in-erc20-smart-contracts-approve-5a675bb88261?source=rss----a857700d0fa0---4</link>
            <guid isPermaLink="false">https://medium.com/p/5a675bb88261</guid>
            <category><![CDATA[secbit]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[erc20]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <dc:creator><![CDATA[Frank]]></dc:creator>
            <pubDate>Fri, 15 Jun 2018 12:52:52 GMT</pubDate>
            <atom:updated>2018-06-15T13:18:20.268Z</atom:updated>
            <content:encoded><![CDATA[<p>We saw many smart contract issues during past months: BEC, SMT, HXG plus the most recent FXE, and they shared a common vulnerability: integer overflow. Are we becoming too jittery about overflow problem with imaginary fear? Is it a good practice to add as many safety checks as possible to avoid attacks?</p><p>Here comes a snippet:</p><pre>function approve(address _spender, uint _amount) returns (bool success) {<br>    // approval amount cannot exceed the balance<br>    require ( balances[msg.sender] &gt;= _amount );<br>    // update allowed amount<br>    allowed[msg.sender][_spender] = _amount;<br>    // log event<br>    Approval(msg.sender, _spender, _amount);<br>    return true;<br>  }</pre><p>This is one implementation of approve() in ERC20. The code seems perfect at first glance. But there is one strange line of code at the beginning, if you inspect carefully:</p><p>require ( balances[msg.sender] &gt;= _amount );</p><p>It checks the current balance by requiring the approved _amout not exceeding the current balance when it is time to approve a transaction. Does this sentence really make sense?</p><p>First we would determine if this is essential to the function:</p><p>Suppose the program satisfies the condition above when executing approve(), it is safe to say that such check is meaningless given that the following code could possibly lead to a scenario which contradicts with this condition.</p><p>In fact, there are certain circumstances where approved allowance would exceed the account balance:</p><ol><li>Token holders call transfer() to move tokens after approval, thus the final balance becomes less than the allowance.</li><li>Given multiple users approval first, and one of them, after calling transferFrom(), might get a smaller balance than the value approved before.</li></ol><p>Now we can come to a conclusion that adding such a requirement is pointless since we cannot assure the approved allowance exceeding the balance with operations afterwards.</p><p>Someone would disagree with this opinion, saying that no severe problems would emerge aside from consuming more gas. Is that really the truth?</p><p>We are cooperating with <a href="https://ddex.io/">DDEX</a>(a decentralized exchange) on assessing ERC20 contracts on its platform lately and we uncovered a critical problem. Many decentralized exchange has already employed contracts like <a href="https://0xproject.com/pdfs/0x_white_paper.pdf">0x protocol</a>, and it would call fillOrder() in <a href="https://etherscan.io/address/0x12459c951127e0c374ff9105dda097662a027093#code">Exchange Contract</a> to transfer tokens when delivering.</p><p>Code for transferring in fillOrder() is shown below:</p><pre>require(transferViaTokenTransferProxy(<br>    order.makerToken,<br>    order.maker,<br>    msg.sender,<br>    filledMakerTokenAmount<br>));<br>require(transferViaTokenTransferProxy(<br>    order.takerToken,<br>    msg.sender,<br>    order.maker,<br>    filledTakerTokenAmount<br>));</pre><p>An intermediate account is necessary for the decentralized exchange and it functions as the msg.sender above initiating a trade. Here is the detailed process:</p><ol><li>Transfer tokens from the order form to an intermediate account of a exchange</li><li>The intermediate account transfers WETH to the seller</li><li>The buyer transfers WETH to the intermediate account</li><li>The intermediate account transfers tokens to the buyer</li></ol><p>The contract <a href="https://github.com/0xProject/0x-monorepo/tree/development/packages/contracts/src/contracts/current/protocol/TokenTransferProxy">TokenTransferProxy</a> finishes all 4 steps alone and the intermediate account needs to approve abundant allowance for it, while the 0x contract does not offer approve(), thus the intermediate account of the exchange should prepare for this approving process in advance.</p><p>Without tokens to be transferred holding ahead by the intermediate account, due to the check,</p><p>require ( balances[msg.sender] &gt;= _amount );</p><p>the account would not be able to get approving done in advance.</p><p>We have observed many similar situations in decentralized and even centralized exchanges, so SECBIT team strongly request leaving out this check when developing ERC20 contracts.</p><p>What if someone has already done adding it and deployed the contract? Is there a way out?</p><p>When it comes to exchanges, they could only ensure a successful approve by letting the project developing team send a great number of tokens to the intermediate account and restrict the transaction volume within the given range.</p><p>By using an internal tool, SECBIT team scanned through all 22681 ERC20 Token smart contracts and found that 21 of them had this trouble, and 3 contracts had already conducted many transactions. Here is a list of Token contracts involved:</p><p>IDH</p><p>GZR</p><p>ADE</p><p>SAINT</p><p>BULB</p><p>ZZZ</p><p>KTM</p><p>ETI-P</p><p>ZORRO01</p><p>ZORRO02</p><p>With a growing number of decentralized exchanges, we suggest that all token contracts should inspect this issue carefully and fix as early as possible to guarantee the future trading liquility of your project tokens.</p><p><a href="https://secbit.io/">SECBIT Labs</a> provides statistics and data above. If interested, please send an email to <a href="/service/mailto:info@secbit.io">info@secbit.io</a>.</p><blockquote><em>SECBIT Labs</em> was founded by a group of cryptocurrency-enthusiasts. We are doing research on smart contract security, smart contract formal verification, crypto-protocols, compilation, contract analysis, game theory and crypto-economics.</blockquote><blockquote><em>SECBIT Labs</em> aims to build a trustworthy and thriving blockchain economy.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a675bb88261" width="1" height="1" alt=""><hr><p><a href="https://medium.com/secbit-media/redundant-check-in-erc20-smart-contracts-approve-5a675bb88261">Redundant Check in ERC20 Smart Contracts’ approve()</a> was originally published in <a href="https://medium.com/secbit-media">SECBIT Media</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bugged Smart Contract FuturXE: How Could Someone Mess up with Boolean? (CVE-2018–12025)]]></title>
            <link>https://medium.com/secbit-media/bugged-smart-contract-f-e-how-could-someone-mess-up-with-boolean-d2251defd6ff?source=rss----a857700d0fa0---4</link>
            <guid isPermaLink="false">https://medium.com/p/d2251defd6ff</guid>
            <category><![CDATA[token]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[p0n1]]></dc:creator>
            <pubDate>Wed, 06 Jun 2018 12:34:30 GMT</pubDate>
            <atom:updated>2018-06-09T11:22:49.813Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TM_MIyWhJQuQcgSgzjA8Tg.png" /></figure><p>Recently SECBIT team found a serious bug about the if condition in a deployed ERC20 smart contract called <a href="https://etherscan.io/address/0x9653cfd0865ad8313bea2f0c2ec0584bfd05115b#code">FuturXE (FXE)</a> and here is the bugged part:</p><pre>//Function for transer the coin from one address to another<br>function transferFrom(address from, address to, uint value) returns (bool success) {</pre><pre>    //checking account is freeze or not<br>    if (frozenAccount[msg.sender]) return false;</pre><pre>    //checking the from should have enough coins<br>    if(balances[from] &lt; value) return false;</pre><pre>    //checking for allowance<br>    if( allowed[from][msg.sender] &gt;= value ) return false;</pre><pre>    //checking for overflows<br>    if(balances[to] + value &lt; balances[to]) return false;</pre><pre>    balances[from] -= value;<br>    allowed[from][msg.sender] -= value;<br>    balances[to] += value;</pre><pre>    // Notify anyone listening that this transfer took place<br>    Transfer(from, to, value);</pre><pre>    return true;<br>}</pre><p>Pay attention to this line: if( allowed[from][msg.sender] &gt;= value ) return false; It has a serious bug: the developer messed up with the boolean judgment - if the input value is smaller than or equal to allowed value, the transfer session would stop execution by returning false. This makes no sense because the transferFrom() requires the transferring value not exceeding the allowed value in the first place. Suppose this function asks the allowed value to be smaller than the input, the attackers could easily ignore the allowance: after this condition, the allowed[from][msg.sender] -= value; would cause an underflow for that the allowed part is smaller than the value. The attacker could transfer any amount of tokens of any accounts to an appointed account (the _toaddress) because the allowed value is initialized to 0 and the attacker could bypass this restriction even without the victim&#39;s private key.</p><p>Comparing to this one, we could take the UET bug as a reference (see Reference 1, 2 and 4 for details):</p><pre>function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {<br>    // mitigates the ERC20 short address attack<br>    if(msg.data.length &lt; (3 * 32) + 4) {<br>        throw;<br>    }<br>    if (_value == 0) {<br>        return false;<br>    }<br>    uint256 fromBalance = balances[_from];<br>    uint256 allowance = allowed[_from][msg.sender];<br>    bool sufficientFunds = fromBalance &lt;= _value;<br>    bool sufficientAllowance = allowance &lt;= _value;<br>    bool overflowed = balances[_to] + _value &gt; balances[_to];<br>    if (sufficientFunds &amp;&amp; sufficientAllowance &amp;&amp; !overflowed) {<br>        balances[_to] += _value;<br>        balances[_from] -= _value;<br>        allowed[_from][msg.sender] -= _value;<br>        Transfer(_from, _to, _value);<br>        return true;<br>    } else {<br>        return false;<br>    }<br>}</pre><p>With every necessary condition checked, the only problem here is that the programmer was so careless that every judging condition got set as the opposite, e.g. let fromBalace &lt;= _value means the transferred money should be no less than the balance. If we just set this condition, there is no doubt that an underflow will occur.</p><p>Now some deployed contracts like RemiCoin(RMC) and RoyalClassicCoin(RCL) (see Reference 3 for details) have this kind of bug as well. SECBIT strongly suggest anyone in concern be extremely careful when trading. Sadly we SECBIT team have tried but could not get in touch with the developer team.</p><h4>Reference</h4><ol><li>CVE-2018–10468: <a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-10468">http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-10468</a></li><li>UselessEthereumToken(UET), ERC20 Token, allows attackers to steal all victim’s balances (CVE-2018–10468): <a href="https://medium.com/@jonghyk.song/uselessethereumtoken-uet-erc20-token-allows-attackers-to-steal-all-victims-balances-543d42ac808e">https://medium.com/@jonghyk.song/uselessethereumtoken-uet-erc20-token-allows-attackers-to-steal-all-victims-balances-543d42ac808e</a></li><li>RemiCoin: <a href="https://etherscan.io/address/0x7Dc4f41294697a7903C4027f6Ac528C5d14cd7eB#code">https://etherscan.io/address/0x7Dc4f41294697a7903C4027f6Ac528C5d14cd7eB#code</a></li><li>UET: <a href="https://etherscan.io/address/0x27f706edde3aD952EF647Dd67E24e38CD0803DD6#code">https://etherscan.io/address/0x27f706edde3aD952EF647Dd67E24e38CD0803DD6#code</a></li><li>FXE: <a href="https://etherscan.io/address/0x9653cfd0865ad8313bea2f0c2ec0584bfd05115b#code">https://etherscan.io/address/0x9653cfd0865ad8313bea2f0c2ec0584bfd05115b#code</a></li></ol><p><strong>SECBIT<em> was founded by a group of cryptocurrency-enthusiasts. We are doing research on smart contract security, smart contract formal verification, crypto-protocols, compilation, contract analysis, game theory and crypto-economics.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2251defd6ff" width="1" height="1" alt=""><hr><p><a href="https://medium.com/secbit-media/bugged-smart-contract-f-e-how-could-someone-mess-up-with-boolean-d2251defd6ff">Bugged Smart Contract FuturXE: How Could Someone Mess up with Boolean? (CVE-2018–12025)</a> was originally published in <a href="https://medium.com/secbit-media">SECBIT Media</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mechanism Design in Cryptoeconomics]]></title>
            <link>https://medium.com/secbit-media/mechanism-design-in-cryptoeconomics-6630673b79af?source=rss----a857700d0fa0---4</link>
            <guid isPermaLink="false">https://medium.com/p/6630673b79af</guid>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[cryptoeconomics]]></category>
            <category><![CDATA[mechanism-design]]></category>
            <category><![CDATA[nash-equilibrium]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Bai Wei]]></dc:creator>
            <pubDate>Thu, 31 May 2018 05:46:16 GMT</pubDate>
            <atom:updated>2018-05-31T05:46:15.688Z</atom:updated>
            <content:encoded><![CDATA[<p>As the emerging of cryptocurrency and the development of blockchain techniques, traditional economic models have the potentiality to be extended to apply in the <em>Crypto</em> scenario. One of the killer application in crypto-economics is implementing smart contracts in blockchain. Smart contracts can be treated as protocols that govern the transactions in a decentralized digital market. They are executed among two or more players under the transaction protocols. During the execution of a smart contract, a player can react based on his own strategy to maximize personal payoff. <strong>As a smart contract designer, he has the responsibility to design a system that guarantee the good performance of players</strong>. Remember that those players have their own strategies, and they prefer the strategy that will maximize their payoffs in an online trade. A system designer can use <em>mechanism design</em> to design a good trading protocol or a smart contract that guarantee good properties for rational players.</p><p>Mechanism design is a major breakthrough in modern economics, it has been used to analyze the behavior of individuals in different institutions and markets by considering incentives and private information. Because of the big influence of <strong>mechanism design theory</strong>, Leonid Hurwics, Eric Maskin, and Roger Myerson were awarded the 2007 Nobel Prize in Economics. Before introducing the advantages of mechanism design. I would like to introduce an interesting example to illustrate how different mechanisms can influence the behavior of rational participants.</p><h4><strong>Sponsored Search Auction</strong></h4><p>In 1997, Overture used a generalized <strong>first-price auction</strong> to sell Internet advertising. In this first-price auction, advertisements were in descendant order based on bids, the higher bid obtains higher position. The payment of each click of the advertisement is the bidding price of that position. Because of the transparency of first price auction, Overture successfully attracted lots of advertisers. However, Overture found that the first-price auction is <strong>unstable</strong> as shown in Figure 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*A5e8bqtIZWaWZj1ZEmzWPg.png" /><figcaption>Figure 1. Saw-tooth pattern. This picture is from a <a href="https://www.cs.cmu.edu/~sandholm/cs15-892F11/gsp051003.pdf">paper</a>.</figcaption></figure><p>Figure 1 shows the top bids for a keyword in 14 hours from Overture. In point A, the top bid begins from a price that is higher than the bid of second highest advertiser. Then, the second highest auctioneer finds that he can win the top position by adding $0.01 to current highest bid. When the first auctioneer finds he has been overbid, he increases his bid in turn. This will continue until the bid reach the maximum budget of one of these two auctioneers in point B. An auctioneer chooses to reduce his bid to obtain the second position through a bidding which is higher than the third auctioneer. In point C, the second highest bidder finds he can overbid to gain the position again. This phenomenon continues to generate a saw-tooth pattern for the given keyword. First-price auction mechanism encourages a bidder to react from other bidders’ actions while suffers from the problem that the winner is not always the bidder who has the highest valuation for the top position.</p><p>To overcome these disadvantages of first-price auction, Google invented the <strong>generalized second price auction (GSP)</strong>. In GSP, advertisers are sorted in descending order based on their bids. The advertiser in one position pays the bid of the advertiser in next position plus an increment ($0.01). For example, if you win the top position with bidding $2, and another bidder win the second position with bidding $1, you only need to pay $1.01. After several iterations of the auction, a bidder can find out all the bids of other bidders in previous auctions, that means the valuations of all participants become public information, and then GSP can reach to a <strong>stable status which is called “locally envy-free equilibrium”</strong>. In this equilibrium, all bidders have no intention to swap positions and payments with the bidder just above them. Currently, GSP is a dominant mechanism to sell Internet adverting for search engine companies.</p><p>The above example of sponsored search auctions tells us that <strong>the rules of a trading mechanism really matters</strong>. These rules can determine the behaviors of participants who are self-interested. Bad designed mechanisms will lead to unexpected behaviors and cause inefficient transactions. We need to avoid these shortages when we design and implement smart contract on the blockchain. Here comes an important question: Do we have a tool to design good smart contracts for strategic participants, and achieve the goals to predicate the behaviors of rational participants? YES! <strong>Mechanism design is a silver bullet to design smart contracts</strong>.</p><p><strong>Myerson’s Lemma</strong></p><p>To understand how mechanism design can be used to design systems that involved rational participants to generate desirable outcomes, we will introduce the Vickrey auction. As we mentioned in previous articles, the bidder in a Vickrey auction has a dominant strategy: bid his valuation to an item no matter what other bidders do. By bidding truthfully, the utility of a bidder will never be negative. The utility of a bidder is defined as a quasi-linear utility model. That is: if a bidder wins, he gets utility of <em>v -p</em>, where <em>v</em> is his valuation, <em>p</em> is his payment. All the losers get utility of <em>0</em>. Formally, the Vickrey auction has three desirable properties:</p><p>1. The Vickrey auction is <strong>dominant-strategy incentive-compatible (DSIC)</strong>.</p><p>2. If all bidders report truthfully, then the Vickrey auction maximizes the social welfare.</p><p>3. The Vickrey auction can be implemented in polynomial time.</p><p>These properties make the model of Vickrey auction an attractive mechanism to system designers. We would like to design some other mechanisms that possess the same properties as in the Vickrey auction: <strong>DSIC, Social welfare maximization, and Polynomial running time</strong>.</p><p>Now, the question becomes how to design a mechanism that have those properties? We can split the design into two phases: Winner determination to define the <strong>allocation rule</strong>, and Payment of participants to define the <strong>payment rule</strong>. To accomplish these two phases, I would like to introduce “Myerson’s Lemma”, which is a powerful tool to design incentive compatible mechanisms. Myerson’s Lemma requires a single-parameter environment.</p><p><strong><em>A single-parameter environment</em></strong> has n players (bidders), Each player <em>i </em>has a private type (valuation <em>v_i</em>), which describes his preference over outcomes. The outcome is represented as a feasible set X, each element of X is an n-vector (<em>x_1, x_2,…,x_n</em>), where <em>x_i</em> denotes the amount of stuff given to player (bidder) <em>i</em>. For example, in a single-item auction, the set X is a set of 0–1 vectors, such as vector = (0, 1, 0, 0), where only one winner that own the item has value of 1. Player i’s value for outcome X is <em>v_i</em> * <em>x_i</em>.</p><p>In addition, I would like to introduce two definitions here to help us understand the meaning of <em>Myerson’s Lemma</em>.</p><p><em>Implementable allocation rule</em>: An <em>allocation rule</em> for a single-parameter environment is implementable if there is a <em>payment rule</em> such the sealed-bid auction that is defined by the given rules is DSIC.</p><p><em>Monotone allocation rule</em>: An allocation rule for a single-parameter environment is monotone if for every bidder <em>i</em> and the bids by the other bidders, the allocation to <em>i </em>is non-decreasing in its bid, i.e. <strong>bidding higher can get you more stuff</strong>.</p><p><strong>Myerson’s Lemma</strong>: For a single-parameter environment,</p><p>1. An allocation rule is implementable if and only if it is monotone.</p><p>2. If the allocation rule is monotone, then there is a <em>unique</em> payment rule such that the mechanism is DSIC.</p><p>3. The payment rule is given by an explicit formula (the formula and proof can be found <a href="http://ls2-www.cs.tu-dortmund.de/grav/grav_files/people/kesselheim/AlgSpiel/skript08.pdf">here</a>).</p><p><strong>Design a DSIC Sponsored Search Auction</strong></p><p>As shown in Figure 2, for a given sponsored search auction there are <em>k </em>slots for sale, the click-through rate of a slot is <em>α</em>, bidder’s valuation for a slot is <em>v</em>. We would like to design an auction that satisfies the three properties of a Vickrey auction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*o8vQ9wLWzECrz9bpNxB3xw.png" /><figcaption>Figure 2. Sponsored Search Auction</figcaption></figure><p>Actually, the sponsored search auction satisfies the single parameter environment setting: <strong>each bidder only bids one amount</strong>. Although there are several slots, a bidder bids only one value, each slot is assigned to at most one bidder and each bidder is assigned at most one slot. If bidder <em>i</em> is assigned to slot <em>j</em>, then the component <em>x_i</em> equals the click-through rate (CTR) <em>α_j</em> of this slot.</p><p>Thus, the Myerson’s Lemma can be used to <strong>redesign the sponsored search auction</strong>, so that <strong>we can get a new auction that is incentive compatible</strong>. As shown in Figure 2, we have <em>n</em> bidders and <em>k</em> positions. Each position has an click-through rate <em>α</em>, we also assume that higher position has higher CTR, i.e <em>α_1&gt;α_2&gt;⋯&gt;α_k&gt;0</em>. In this auction, we would like to assign player <em>i</em> to position<em> j </em>by defining following <a href="https://theory.stanford.edu/~tim/f13/l/l3.pdf">two rules</a>.</p><p><em>The allocation rule</em>: we can use a greedy rule to allocate the slot. The bidder with the highest bid wins the top position. Remove the assigned bidder and slot, then iterate until all the slots be allocated.</p><p><em>The payment rule</em>: the payment of bidder <em>i</em> for each click for a slot is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*Lt2OMxsNHmumhUjMAClvNw.png" /><figcaption>Payment Formula for the new DSIC Sponsored Search Auction</figcaption></figure><p>The payment equation shows that when a link is clicked, an advertiser pays a suitable convex combination of the lower bids.</p><p>Although the GSP auction that has been used by Google has several desirable properties, it is not incentive compatible. Search engine companies not using the incentive compatible sponsored search auction model is caused by historical reason.</p><p>Generally, we need to define three components in a mechanism design problem: an <em>environment</em> (e.g. the single parameter environment) where the game designer operates; a <em>choice function</em> that describes the designer’s preferred outcomes (e.g. give an item to the person who values it most); a <em>solution concept</em> which describes the kinds of strategy profiles of games (e.g. dominant strategy equilibrium).</p><p><strong>Conclusion</strong></p><p>The challenge for a smart contract designer is to design a system that will lead to good performance for strategic participants. As the designer would like to design a mechanism that could maximize social welfare while the players prefer to maximize their utility, the Myerson’s Lemma guarantee that the player has a dominant strategy to maximize his utility, while also maximized the social welfare. Mechanism design can be used to solve the problem of misalignment between the participant goals and designer goals. In this article, we introduced the mechanism design theory in a single-parameter environment, and we can use this theory to design a mechanism that can be implemented in polynomial time. However, there are many cases where we can not implement a given mechanism in linear time. For example, compute the outcome of a combinatorial auction mechanism is NP hard. We will talk about more complex mechanisms in future articles.</p><p><strong>SECBIT<em> was founded by a group of cryptocurrency-enthusiasts. We are doing research on smart contract security, smart contract formal verification, crypto-protocols, compilation, contract analysis, game theory and crypto-economics.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6630673b79af" width="1" height="1" alt=""><hr><p><a href="https://medium.com/secbit-media/mechanism-design-in-cryptoeconomics-6630673b79af">Mechanism Design in Cryptoeconomics</a> was originally published in <a href="https://medium.com/secbit-media">SECBIT Media</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Smart Contract and Nash Equilibrium]]></title>
            <link>https://medium.com/secbit-media/smart-contract-and-nash-equilibrium-3ef947d87042?source=rss----a857700d0fa0---4</link>
            <guid isPermaLink="false">https://medium.com/p/3ef947d87042</guid>
            <category><![CDATA[nash-equilibrium]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[formal-verification]]></category>
            <category><![CDATA[game-theory]]></category>
            <category><![CDATA[cryptoeconomics]]></category>
            <dc:creator><![CDATA[Bai Wei]]></dc:creator>
            <pubDate>Tue, 22 May 2018 16:22:44 GMT</pubDate>
            <atom:updated>2018-05-22T16:22:44.070Z</atom:updated>
            <content:encoded><![CDATA[<p>Smart contracts are the application of blockchain, and they are on the center of the blockchain storm in the year of 2018. Smart contracts are used to launch Token, Initial Coin Offerings (ICO), exchange Tokens, and design games. Generally, a smart contract is a computer program that is capable of monitoring, executing and enforcing an agreement. It can improve the efficiency of transactions by removing of intermediaries, and establish trust through certainty of execution, tractable and irreversible transactions. All the players act based on the protocols that are defined in a specific smart contract. Meanwhile, the protocols of a smart contract can be modeled as a <strong>game</strong>. A game models a situation where two or more players have to take some <em>decisions</em><strong> </strong>that will influence one another&#39;s welfare in game theory. We may interest in finding the <strong>game-theoretic properties </strong>of a game. In this article, we will discuss the most influential concept in game theory: the Nash equilibrium.<br><br><strong>Prisoner’s Dilemma and the Definition of Nash Equilibrium</strong><em><br><br></em>Before describing the definition of Nash equilibrium, I would like to introduce the game of <strong>Prisoner’s Dilemma </strong>to illustrate the idea of Nash equilibrium. Assume that there are two prisoners Alice and Bob. They are interviewed separately so that they cannot communicate with each other. Each of them has two strategies, called “Confess” and “Deny”. They aim to minimize the year of imprisonment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*y139fZ4tX0X0xNO_kto5fw.png" /><figcaption>Table 1: Prisoner’s Dilemma</figcaption></figure><p>Table 1 shows the payoff of this game. If both of them choose “Deny”, they will both serve 2 years in prison. If one of them chooses “Confess”, the confessor will serve 1 year and the other will serve 5 years. If both of them choose “Confess”, both of them will serve 3 years. Remember that we assume that Alice and Bob cannot communicate with each other, and they are interested in their own payoff. If prisoner Alice chooses “Confess”, the better response of prisoner Bob is “Confess”. If prisoner Alice changed to choose “Deny”, the better choice for prisoner Bob is still “Confess”. The case of prisoner Bob is symmetric. According to this reasoning, both of them will choose “Confess”. In this game, (Confess, Confess) is a Nash equilibrium, which means that it is the set of strategies that maximize each prisoner’s payoff given the strategies of all the other players. The prisoner’s dilemmas game also indicates that <em>rational actions can lead to bad outcomes</em>. The state (Deny, Deny) is a better result for both of Alice and Bob compare to the state of (Confess, Confess), but rational choice will lead to a worse state which is the Nash equilibrium.</p><blockquote>A <strong>Nash equilibrium</strong> is a combination of strategies, one for each player, such that no player can increase her payoff by unilaterally changing her action.</blockquote><p>In next section, I will introduce Nash equilibrium in a specific Non-cooperative game, the Vickrey auction.<br><br><strong>Nash Equilibrium and Vickrey Auction</strong><em><br><br></em>The Vickrey auction, which is named after Nobel Laureate William Vickrey, is a type of sealed-bid auction where a bidder submits her bids without knowing the other bidders’ bid. The highest bidder wins, and the payment of the winner is the second highest bid in the auction. The dominant strategy in a Vickrey auction for each bidder is bidding their valuations, which means that <strong>bidding truthfully</strong> is the best strategy for a bidder no matter how others behave. Furthermore, bidding truthfully is a Nash equilibrium of the Vickrey auction. In this equilibrium, where each bidder submits her valuation, there is no incentive for a bidder to unilaterally deviate. The Nash equilibrium in a Vickrey auction relies upon the <strong>private values assumptions</strong> that each bidder’s valuation only depends on her own information. The lesson we can learn from this model is that well designed trading mechanism can achieve <strong>truthfulness</strong>.<br><br>To implement the Vickery auction as a smart contract, we could design two stages in this contract: the submission stage and the bid opening stage. In the submission stage, the bid that submitted by each bidder should be encrypted using a nonce to keep the bid sealed. Each bidder also should send a certain amount of deposit to the auctioneer. The deposit will be refund to the bidder when the submitted bid has been revealed. In the bid opening stage, each bidder sends their nonce to the auctioneer, so that their bid can be revealed. At last, the winner is the bidder has he highest bid and her payment is the second highest bid. All the deposit should be refund.<br><br>The property that every bidder can achieve their best payoffs by bidding their valuation is called <strong>incentive compatible</strong>. Another influential auction that has the property of incentive compatible is Vickrey-Clarke-Groves (VCG) auction. A VCG auction is a generalization of a Vickrey auction for multiple items. I will describe this model together with <strong>mechanism design</strong> in a future article. In the following section, I will describe another widely used auction, the Dutch auction.<br><br><strong>Symmetric Equilibrium and Dutch Auction</strong><em><br><br></em>The Dutch Auction is used to sell flowers in Holland, and it has been used in an IPO or to sell Treasury bills for government agencies. Dutch auctions are interactive auctions in which the seller gradually decreases the price of the item from a highest bidding amount. A Dutch auction ends when the first moment a bidder accepts the offered bidding price. The payment of the winner is the accepted price.<br><br>On the platform of Ethereum, Dutch auction was used by Gnosis to sell Tokens and they reached their goal of 250K ETH in less than 15 minutes. Meanwhile, the popular game CryptoKitties is using Dutch auction to sell their cats. We can imagine that Dutch auction will be used in more and more smart contracts to figure out the <strong>optimum price</strong> of various commodities. <br><br>A Dutch auction can also be modeled as a noncooperative game. Is truthful bidding a Nash equilibrium in a Dutch auction compared to the Vickrey auction? The answer is no. However, there exists another equilibrium by assuming the distribution of each bidder’s valuation in a Dutch auction: symmetric equilibrium. Symmetric means that the bidding values of two bidders are equal if they have the same valuations.</p><blockquote>In a Dutch auction with n risk-neutral (a bidder is indifferent to risk when making decision) bidders whose valuations are independently drawn from a uniform distribution on [0,1], a <strong>symmetric equilibrium</strong> is given by the strategy profile</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/254/1*BQ5jfiOhcBKrnxbhIBdRAw.png" /></figure><blockquote>, where <strong>v</strong> represents the valuation of a bidder.</blockquote><p>The Dutch auction used by GNOSIS is different from the standard model we talked above. They modified the payment mechanism. The GNOSIS Dutch auction starts at a high price for their token, and the price decreases with every block. In code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a5879e15979c8f2830305e4b4de1deb/href">https://medium.com/media/5a5879e15979c8f2830305e4b4de1deb/href</a></iframe><p>The parameter <em>priceFactor</em><strong> </strong>is initialized by the author of the code. The auction closes when the sale cap is reached, and the payment of each bidder is the same that equals to the value of the final bid in the auction. Here comes a question, is truthful bidding a dominant strategy in GNOSIS Dutch auction?<br><br>Since the smart contract that implements auctions are executed automatically, it is valuable to analyze the game-theoretic properties of a given smart contract before deploying it on blockchain.<br><br><strong>Verification of Game-theoretic Properties in a Smart Contract</strong><em><br><br></em>Vitalik Buterin mentioned the challenge of <strong>“differences between implementation and intent” </strong>for the security of smart contracts in his <a href="https://blog.ethereum.org/2016/06/19/thinking-smart-contract-security/">blog</a>. He also worried about the <strong>“game-theoretic vulnerability”</strong> in blockchain-based market. The potential solution for these challenges is <strong>combining game theory with formal verification</strong>. We can design a trading mechanism that has some desirable game-theoretic properties, and then <strong>verify </strong>that the smart contract implemented this mechanism really contain the declared game-theoretic property. For example, for a given smart contract of Vickrey auction, we can prove and verify that this program really contains a Nash equilibrium.<br><br><strong>Conclusion</strong><em><br><br></em>In this article, I illustrate that a smart contract can be modeled as a game, thus we can analyze the game-theoretic properties, such as Nash equilibrium, of the smart contract. Carefully designed mechanism that has desirable game <br>theoretic properties has been used by giants to make profit decades ago. The “generalized second price auction”, which has been used by Google and Yahoo! to sell online advertising, is a robust mechanism which has a locally envy-free equilibrium in static environment. Although we still need to adjust the standard game theory models to fit to the actual implementation of smart contracts in decentralized platforms such as Ethereum. It is a promising direction to apply <strong>game theory</strong> and <strong>formal verification</strong> to design and analyze smart contracts, so that we can eliminate the gap between intention and implementation. Furthermore, we can not only avoid the “game-theoretic vulnerability” but also bring “game-theoretic properties” into smart contracts.</p><p><strong>SECBIT<em> was founded by a group of cryptocurrency-enthusiasts. We are doing research on smart contract security, smart contract formal verification, crypto-protocols, compilation, contract analysis, game theory and crypto-economics.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ef947d87042" width="1" height="1" alt=""><hr><p><a href="https://medium.com/secbit-media/smart-contract-and-nash-equilibrium-3ef947d87042">Smart Contract and Nash Equilibrium</a> was originally published in <a href="https://medium.com/secbit-media">SECBIT Media</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Alert! Another integer overflow vulnerability just found in HXG smart contract.]]></title>
            <link>https://medium.com/secbit-media/alert-another-integer-overflow-vulnerability-just-found-in-hxg-smart-contract-ff2f69fdd242?source=rss----a857700d0fa0---4</link>
            <guid isPermaLink="false">https://medium.com/p/ff2f69fdd242</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Steven]]></dc:creator>
            <pubDate>Fri, 18 May 2018 16:31:16 GMT</pubDate>
            <atom:updated>2018-05-18T16:37:28.632Z</atom:updated>
            <content:encoded><![CDATA[<p>A security research team (360 0KEE) from China <a href="https://www.jianshu.com/p/c5363ffad6a7">found</a> an integer overflow vulnerability in a couple of <a href="https://etherscan.io/address/0xB5335e24d0aB29C190AB8C2B459238Da1153cEBA">deployed smart contract</a>.</p><pre>https://etherscan.io/address/0xB5335e24d0aB29C190AB8C2B459238Da1153cEBA https://etherscan.io/address/0xe37b0c4c42e02c82a023d79600dc6465cfb94eb9 https://etherscan.io/address/0xcae348eeb5d0b9fd59a8fd179d8b3e8a7b871b5f</pre><p>The smart contracts are similar, issuing ERC20 tokens for Hexagon (HXG/HEX). The vulnerability, in the transfer(...) function, may lead to unlimited token minting. Basically, anyone is able to mint a mass of tokens for any address.</p><p>The function calls another internal function, _transfer(...).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8yixFh7QtiFORqnc7l2g7w.png" /></figure><p>As shown below, the second line of the internal function _transfer(...) is supposed to ensure that the balance of _from be greater than _value, added by an addition constant burnPerTransaction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UHkM-KQUP5R19MrfXAZsew.jpeg" /></figure><p>Yes,you might notice that the odd constant, defined to 2, introduces the bug. If _value is given 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe, the sum will overflow to 0x0, smaller than any balance for sure. The attacker may call the function transfer(_to, 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe) to exploit the bug. Please make sure the balance of _to is zero so as to pass the third line of require checking.</p><p>The researcher made a successful [test] (<a href="https://etherscan.io/tx/0x129a321d4867b4144ff30865b87955def212d3f46b3973dd2c141978defa4e70">https://etherscan.io/tx/0x129a321d4867b4144ff30865b87955def212d3f46b3973dd2c141978defa4e70</a>) .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OW_xzDc_xr-xXJUiwOoHBg.png" /></figure><p>The integer overflow/underflow vulnerabilities would have been easily ruled out if the developers choosed <a href="https://openzeppelin.org/api/docs/math_SafeMath.html">SafeMath</a>. Fortunately, the HXG token is neither listed on exchanges nor active on Ethereum.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xx6j1S-uwta4P2_JakBbFg.jpeg" /></figure><p>Obviously, any smart contract developers ought to be serious about the security issues. Any small mistake can cause huge losses, like those happened to BEC and SMT tokens.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff2f69fdd242" width="1" height="1" alt=""><hr><p><a href="https://medium.com/secbit-media/alert-another-integer-overflow-vulnerability-just-found-in-hxg-smart-contract-ff2f69fdd242">Alert! Another integer overflow vulnerability just found in HXG smart contract.</a> was originally published in <a href="https://medium.com/secbit-media">SECBIT Media</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A disastrous vulnerability found in smart contracts of BeautyChain (BEC)]]></title>
            <link>https://medium.com/secbit-media/a-disastrous-vulnerability-found-in-smart-contracts-of-beautychain-bec-dbf24ddbc30e?source=rss----a857700d0fa0---4</link>
            <guid isPermaLink="false">https://medium.com/p/dbf24ddbc30e</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[token]]></category>
            <dc:creator><![CDATA[p0n1]]></dc:creator>
            <pubDate>Mon, 23 Apr 2018 12:02:13 GMT</pubDate>
            <atom:updated>2018-04-24T12:01:39.252Z</atom:updated>
            <content:encoded><![CDATA[<p>The team of <a href="https://www.beauty.io/">BeautyChain</a> announced yesterday that BEC tokens experienced abnormal fluctuations on 22 April. The team got noticed when attackers were dumping huge amount of BECs in an exchange. The attackers had successfully got 10^58 BECs exploiting a vulnerability caused by integer overflowing. <a href="https://etherscan.io/address/0xc5d105e63711398af9bbff092d4b6769c82f793d">Here</a> we can see the contract code. The buggy contract is an extension of a standard EIP20 token contract. The disastrous bug is very easy to nail down in the function of batchTransfer().</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8771aa0eecdf7ad6d62008a015309a05/href">https://medium.com/media/8771aa0eecdf7ad6d62008a015309a05/href</a></iframe><p>This function batchTransfer(..) allows users to invoke multiple transfers to different recipients in one step. The first argument is a dynamic array of address, and the other is the amount of tokens sent to each. Two &quot;require&quot; checkers try to ensure the balance of the sender be valid. It is obvious that the following line is susceptible to integer overflow.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9f081245f9266f3f081e788761bfd96/href">https://medium.com/media/b9f081245f9266f3f081e788761bfd96/href</a></iframe><p>In the attacking happened, the hacker invoked the function with an array of length 2, and _value=0x8000000000000000000000000000000000000000000000000000000000000000, According to ABI-Eth, the first uint256 denotes the address of the dynamic array, which actually starts from 3rd uint256 with the length of the array, 2. Then two addresses follows. Thus the value of amount becomes zero, which is obviously less than any balance. Yes, it goes through the checkers. In the loop, each of two receivers will get 0x8000000000000000000000000000000000000000000000000000000000000000 value of BEC. Theoretically, the bug allows users to withdraw unlimited BEC.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/caa2bd78979acfb676e51571c687a461/href">https://medium.com/media/caa2bd78979acfb676e51571c687a461/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aa6dbf39878534f248594eee5089d6a9/href">https://medium.com/media/aa6dbf39878534f248594eee5089d6a9/href</a></iframe><p>The attacking transactions can be found <a href="https://etherscan.io/tx/0xad89ff16fd1ebe3a0a7cf4ed282302c06626c1af33221ebe0d3a470aba4a660f">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rxQ0h7IngAXlc3MbyuGmPw.png" /><figcaption>Transactions</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nNl03K3dpXViVAhJj0naIQ.png" /><figcaption>Accounts</figcaption></figure><p>The tokens stolen would have been caused disasters, the price of BEC at that time was around $0.3 each. Fortunately, the hacker hadn’t sold much before the dev-team paused the contract. The market reacted by price-plunging.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U6MPsVbO6e-VpUBoDqwatw.png" /><figcaption>price-plunging</figcaption></figure><p>Today, BEC dev-team <a href="http://t.me/beautychain/960441">announced</a> that they will relaunch the patched contract.</p><blockquote><em>We (BeautyChain, quoted) will release new smart contracts as soon as possible. In order to safeguard the interests of everyone, we have reached an agreement with the OKEx Exchange. The trade fair will roll back to 13:18 on April 22, after this time all transactions generated in the Beauty Chain will be Cancellation …</em></blockquote><p>However, this isn’t the end of the whole story. We scanned all of the deployed smart contract on Ethereum by checking the function signature 0x83f12fec and found out that there are 12 more contracts that are identical to the buggy contract from BEC. Some of those are from different dev teams. We signaled them by dropping emails already. But it is weird. Presumably, all of the code might be from the same author, who unintentionally (or intentionally?) leaved only this important line of code unprotected by SafeMath. At least, the author knows of integer overflow issues.</p><p>Smart contract related vulnerabilities are unsurprisingly going to grow if Dapps get more developers and users. Despite the fact that the size of smart contracts are small, the intrinsic complexity is brought from both the language and the blockchain system. The smart contracts are needed to be audited, or even formally verified. In the case, integer-overflow is the origin of the issue, while the result is that the total supply of tokens is able to be increased unlimitedly.</p><p><em>SECBIT was founded by a group of cryptocurrency-enthusiasts. We are doing research on smart contract security, smart contract formal verification, crypto-protocols, compilation, contract analysis, game theory and crypto-economics.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbf24ddbc30e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/secbit-media/a-disastrous-vulnerability-found-in-smart-contracts-of-beautychain-bec-dbf24ddbc30e">A disastrous vulnerability found in smart contracts of BeautyChain (BEC)</a> was originally published in <a href="https://medium.com/secbit-media">SECBIT Media</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>