{"id":17293,"date":"2019-12-24T13:30:02","date_gmt":"2019-12-24T21:30:02","guid":{"rendered":"http:\/\/www.palada.net\/index.php\/2019\/12\/24\/news-11029\/"},"modified":"2019-12-24T13:30:02","modified_gmt":"2019-12-24T21:30:02","slug":"news-11029","status":"publish","type":"post","link":"https:\/\/www.palada.net\/index.php\/2019\/12\/24\/news-11029\/","title":{"rendered":"GUSD smart contract allows for theft of antispam payments"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/media.kasperskydaily.com\/wp-content\/uploads\/sites\/92\/2019\/12\/24152018\/gemini-front-running-featured.jpg\"\/><\/p>\n<p><strong>Credit to Author: Alexey Malanov| Date: Tue, 24 Dec 2019 20:30:19 +0000<\/strong><\/p>\n<p>The <a href=\"https:\/\/en.wikipedia.org\/wiki\/Winklevoss_twins\" target=\"_blank\" rel=\"noopener noreferrer\">Winklevoss twins<\/a> are best known as the alleged founding fathers of Facebook \u2014 and even received <a href=\"https:\/\/www.law.com\/almID\/1202428141988\/\" target=\"_blank\" rel=\"noopener noreferrer\">$65 million<\/a> in compensation from Mark Zuckerberg in 2008. In 2013 they invested heavily in Bitcoin, buying about 1% of all existing coins at $120 apiece.<\/p>\n<p>Soon after, the brothers opened the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Gemini_(company)\" target=\"_blank\" rel=\"noopener noreferrer\">Gemini<\/a> cryptocurrency exchange, and in 2018 they <a href=\"https:\/\/medium.com\/gemini\/gemini-launches-the-gemini-dollar-62787f963fb4\" target=\"_blank\" rel=\"noopener noreferrer\">launched<\/a> the stablecoin <a href=\"https:\/\/gemini.com\/dollar\/\" target=\"_blank\" rel=\"noopener noreferrer\">Gemini dollar<\/a> (GUSD). A stablecoin is a fixed-rate cryptocurrency \u2014 1 GUSD token always costs 1 US dollar. Stablecoins are handy for &#8220;digitizing&#8221; real dollars. They make moving blockchain dollars between exchanges quick and easy. The guarantor of the reverse conversion to dollars is the company that issued and sold them to you.<\/p>\n<p>Under the <a href=\"https:\/\/www.kaspersky.com\/enterprise-security\/ico-sto-security\" target=\"_blank\" rel=\"noopener noreferrer\">Kaspersky Smart Contract Source Code Review<\/a> service, we analyzed a <a href=\"https:\/\/etherscan.io\/token\/0x056Fd409E1d7A124BD7017459dFEa2F387b6d5Cd\" target=\"_blank\" rel=\"noopener noreferrer\">smart contract<\/a> that provides GUSD functionality, and we detected a flaw.<\/p>\n<div style=\"background-color: #e5f0ec;padding: 10px 25px;margin-bottom: 10px\">\n<h2>Disclaimer<\/h2>\n<p>Note that the given smart contract had already been <a href=\"https:\/\/gemini.com\/wp-content\/themes\/gemini\/assets\/img\/dollar\/gemini-dollar-trailofbits-audit.pdf\" target=\"_blank\" rel=\"noopener noreferrer\">reviewed<\/a>, although we do not know if any code flaws were described in the report.<\/p>\n<p>In line with our Responsible Disclosure Policy, we contacted Gemini&#8217;s security team to report the problem. They informed us the issue was considered during the design phase but presented no risk to GUSD. <\/p>\n<\/div>\n<p>For a simple explanation of how smart contracts work, see our <a href=\"https:\/\/www.kaspersky.com\/blog\/ethereum-ico\/19846\/\" target=\"_blank\" rel=\"noopener noreferrer\">post on smart contracts, Ethereum, and ICOs<\/a>.<\/p>\n<h2>Gemini dollar smart contracts<\/h2>\n<p>Generally speaking, when someone wants to create new tokens based on the Ethereum blockchain, they write a smart contract (a miniprogram) that specifies the following:<\/p>\n<ol>\n<li>Data (&#8220;this many tokens are at such-and-such address),<\/li>\n<li>Methods (&#8220;please transfer my tokens to such-and-such address,&#8221; plus a few others).<\/li>\n<\/ol>\n<p>The creators of the Gemini dollar system <a href=\"https:\/\/gemini.com\/wp-content\/themes\/gemini\/assets\/img\/dollar\/gemini-dollar-whitepaper.pdf\" target=\"_blank\" rel=\"noopener noreferrer\">implemented<\/a> the following enhancements as well:<\/p>\n<ol>\n<li>They separated the contract into three components: Proxy (the permanent interface with which token holders can interact and perform operations), store (the mapping of token holders to their balances), and Impl (the underlying logic);<\/li>\n<li>The component describing the logic can be updated and supplemented with new features such as the ability to freeze funds. Meanwhile, the data and interface remained unchanged; the update is transparent to everyone;<\/li>\n<li>For updating and control, a separate, &#8220;Custodian&#8221; smart contract is used that is managed by several people (custodians) for additional protection. If one custodian proposes an action, the others must confirm before the action can take place.<\/li>\n<\/ol>\n<p>The enhancements are sound and increase overall security and flexibility.<\/p>\n<h2>Antispam payments<\/h2>\n<p>If someone other than the primary custodian enters a proposal in a custodian contract, they must pay a 1 ETH stake (about $200 at the current exchange rate). As noted in the <a href=\"https:\/\/github.com\/gemini\/dollar\/blob\/master\/Custodian.sol#L151\" target=\"_blank\" rel=\"noopener noreferrer\">comments<\/a> to the contract itself, this antispam measure aims to dissuade participants from creating too many requests.<\/p>\n<p>The antispam payments ultimately <a href=\"https:\/\/github.com\/gemini\/dollar\/blob\/master\/Custodian.sol#L264\" target=\"_blank\" rel=\"noopener noreferrer\">go<\/a> to one person: the one who announces the approval of a particular proposal\/request. This implementation may not look terrifically fair, but the comments clearly indicate that its creators conceived it that way.<\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 } else {<\/strong><br \/> <strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (address(this).balance &gt; 0) {<\/strong><br \/> <strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ reward sender with anti-spam payments<\/strong><br \/> <strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ ignore send success (assign to \u02b9success\u02b9 but this will be overwritten)<\/strong><br \/> <strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 success = msg.sender.send(address(this).balance);<\/strong><\/p>\n<p>For our part, we recommend using the <a href=\"https:\/\/solidity.readthedocs.io\/en\/v0.5.10\/common-patterns.html\" target=\"_blank\" rel=\"noopener noreferrer\">Solidity Withdrawal Pattern<\/a> approach.<\/p>\n<h2>Front-running attackers can steal all antispam payments<\/h2>\n<p>The person who determines the approval of the request thus also receives all ETH antispam payments. To do so, he or she calls the smart contract function <strong>completeUnlock<\/strong> and passes the signatures of two custodians in the parameters.<\/p>\n<p>The problem is that Ethereum, like any other blockchain, executes requests on a delay. A client transaction (transferring money or calling a function) waits in line for some time (usually 15 seconds or longer). During this time, absolutely anyone can view the planned transfers of other Ethereum users, including amounts, recipients, and parameters. And the peeper can use this information to create their own transaction and push it to the front by paying a higher commission to the miner.<\/p>\n<p>Any advantage gained through peeping is considered front-running, a form of attack (<a href=\"https:\/\/consensys.github.io\/smart-contract-best-practices\/known_attacks\/#front-running-aka-transaction-ordering-dependence\" target=\"_blank\" rel=\"noopener noreferrer\">Known Attacks: Front-Running<\/a>).<\/p>\n<div style=\"background-color: #e5f0ec;padding: 10px 25px;margin-bottom: 10px\"> From <a href=\"https:\/\/www.investopedia.com\/terms\/f\/frontrunning.asp\" target=\"_blank\" rel=\"noopener noreferrer\">investopedia.com<\/a>:<\/p>\n<p>Front-running is when a broker or other entity enters into a trade because they have foreknowledge of a big nonpublicized transaction that will influence the price of the asset, resulting in a likely financial gain for the broker. It also occurs when a broker or analyst buys or sells shares for their account ahead of their firm&#8217;s buy or sell recommendation to clients. <\/p>\n<\/div>\n<p>In our case, a complete outsider can set up a robot to monitor the <a href=\"https:\/\/etherscan.io\/address\/0x9a7b5f6e453d0cda978163cb4a9a88367250a52d\" target=\"_blank\" rel=\"noopener noreferrer\">custodian contract<\/a>. If it sees that someone called the <strong>completeUnlock<\/strong> function (that is, a custodian is interacting with Gemini dollar), it immediately copies all of the parameters and calls the function to extract the Ether that has accumulated there.<\/p>\n<p>To counter such an attack, we again recommend using the popular <a href=\"https:\/\/solidity.readthedocs.io\/en\/v0.5.10\/common-patterns.html\" target=\"_blank\" rel=\"noopener noreferrer\">Solidity Withdrawal Pattern<\/a> approach.<\/p>\n<p>On top of that, we recommend blocking <a href=\"https:\/\/github.com\/gemini\/dollar\/blob\/master\/Custodian.sol#L233\" target=\"_blank\" rel=\"noopener noreferrer\">unknowns<\/a> from calling a function intended for custodians.<\/p>\n<h2>Practical implementation of an attack<\/h2>\n<p>Although dangerous in theory, the detected vulnerability is fairly benign in practice. Here&#8217;s why:<\/p>\n<ol>\n<li>Antispam payments are of little concern to custodians of such a major venture as the Gemini dollar. GUSD capitalization (the total volume of issued tokens) at one point topped $100 million. Even now it exceeds $5 million.<\/li>\n<li>Antispam payments have not yet appeared in <a href=\"https:\/\/etherscan.io\/address\/0x9a7b5f6e453d0cda978163cb4a9a88367250a52d\" target=\"_blank\" rel=\"noopener noreferrer\">this contract<\/a> and may never do so, because the primary custodian is in no way obliged to deposit them (all others are).<\/li>\n<li>Knowing about the vulnerability, users can simply avoid the vulnerable function, or update the contract.<\/li>\n<li>During the review, we found no vulnerabilities that threaten GUSD tokens.<\/li>\n<\/ol>\n<p>Gemini comments: &#8220;We chose this design because Gemini does not intend to stake ether under normal conditions, and, as a result, we made a risk-based decision not to materially expand the complexity of our codebase solely for the immaterial benefit of a more robust recovery mechanism for a theoretical, and nominal, anti-spam stake. Prioritizing secure, simple code remains the best solution for the Gemini dollar and its users. In the future we may revisit this decision if the risk changes and a more costly and complex contract becomes appropriate.&#8221;<\/p>\n<p>We decided to publish this post in coordination with Gemini, given that antispam stakes are at risk only through a combination of specific and unlikely circumstances, and GUSD is not at risk.<\/p>\n<p>Again, we remind everyone of the need for a holistic security approach to ICOs and other activities related to <a href=\"https:\/\/www.kaspersky.com\/enterprise-security\/ico-sto-security\" target=\"_blank\" rel=\"noopener noreferrer\">cryptocurrencies and blockchains<\/a>.<\/p>\n<p><a href=\"https:\/\/www.kaspersky.com\/blog\/gemini-front-running\/31924\/\" target=\"bwo\" >https:\/\/blog.kaspersky.com\/feed\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/media.kasperskydaily.com\/wp-content\/uploads\/sites\/92\/2019\/12\/24152018\/gemini-front-running-featured.jpg\"\/><\/p>\n<p><strong>Credit to Author: Alexey Malanov| Date: Tue, 24 Dec 2019 20:30:19 +0000<\/strong><\/p>\n<p>Exploring front-running to capture the Gemini dollar\u2019s antispam stake.<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[10425,10378],"tags":[1001,14147,12177,13662,13664,12321,23832,17399],"class_list":["post-17293","post","type-post","status-publish","format-standard","hentry","category-kaspersky","category-security","tag-business","tag-cryptocurrencies","tag-enterprise","tag-ether","tag-ethereum","tag-smb","tag-stablecoins","tag-tokens"],"_links":{"self":[{"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/posts\/17293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/comments?post=17293"}],"version-history":[{"count":0,"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/posts\/17293\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/media?parent=17293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/categories?post=17293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.palada.net\/index.php\/wp-json\/wp\/v2\/tags?post=17293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}