<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Solidity on Ash Tewari</title><link>https://www.tewari.info/tag/solidity/</link><description>Recent content in Solidity on Ash Tewari</description><generator>Hugo -- gohugo.io</generator><language>en-US</language><lastBuildDate>Sun, 22 May 2022 23:32:20 +0000</lastBuildDate><atom:link href="https://www.tewari.info/tag/solidity/feed.xml" rel="self" type="application/rss+xml"/><item><title>Security Analysis of Etheruem Smart Contracts with Mythril</title><link>https://www.tewari.info/2022/05/22/security-analysis-of-etheruem-smart-contracts-with-mythril/</link><pubDate>Sun, 22 May 2022 23:32:20 +0000</pubDate><guid>https://www.tewari.info/2022/05/22/security-analysis-of-etheruem-smart-contracts-with-mythril/</guid><description>&lt;p&gt;&lt;a class="link" href="https://github.com/ConsenSys/mythril" target="_blank" rel="noopener"&#10; &gt;Mythril&lt;/a&gt; is an open-source security analysis tool for EVM bytecode, courtesy of &lt;a class="link" href="https://consensys.net/diligence/tools/" target="_blank" rel="noopener"&#10; &gt;ConsenSys&lt;/a&gt;. It is also a component of their Security Analysis Service - &lt;a class="link" href="https://mythx.io/" target="_blank" rel="noopener"&#10; &gt;Mythx&lt;/a&gt;. Mythril detects security vulnerabilities in smart contracts built for Ethereum and other EVM-compatible blockchains.&lt;/p&gt;&#10;&lt;p&gt;Vulnerabilities found by Mythril are reported with reference to the weaknesses listed on the Smart Contract Weakness Classification Registry (&lt;a class="link" href="https://swcregistry.io/" target="_blank" rel="noopener"&#10; &gt;SWC Registry&lt;/a&gt;). I will use two entries from SWC Registry for the examples in this article:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;a class="link" href="https://swcregistry.io/docs/SWC-106#simple_suicidesol" target="_blank" rel="noopener"&#10; &gt;SWC-106&lt;/a&gt; - Due to missing or insufficient access controls, malicious parties can self-destruct the contract.&lt;/li&gt;&#10;&lt;li&gt;&lt;a class="link" href="https://swcregistry.io/docs/SWC-107#simple_daosol" target="_blank" rel="noopener"&#10; &gt;SWC-107&lt;/a&gt; - One of the major dangers of calling external contracts is that they can take over the control flow. In the reentrancy attack (a.k.a. recursive call attack), a malicious contract calls back into the calling contract before the first invocation of the function is finished.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h3 id="install-mythril-on-windows"&gt;Install Mythril on Windows&#10;&lt;/h3&gt;&#10; &lt;blockquote&gt;&#10; &lt;p&gt;&amp;gt; docker import mythril/myth&lt;/p&gt;&#10;&lt;p&gt;&lt;a class="link" href="https://mythril-classic.readthedocs.io/en/master/installation.html" target="_blank" rel="noopener"&#10; &gt;https://mythril-classic.readthedocs.io/en/master/installation.html&lt;/a&gt;&lt;/p&gt;&#10;&#10; &lt;/blockquote&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-16.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;h3 id="get-test-files-from-github"&gt;Get test files from github&#10;&lt;/h3&gt;&lt;p&gt;Source code for these tests is on github : &lt;a class="link" href="https://github.com/ashtewari/mythril-tests" target="_blank" rel="noopener"&#10; &gt;mythril-tests&lt;/a&gt;. Clone the repo locally and adjust the paths in the commands below to match your local environment.&lt;/p&gt;&#10;&lt;h3 id="analyze-a-local-smart-contract"&gt;Analyze a local smart contract&#10;&lt;/h3&gt;&lt;h5 id="analysis-of"&gt;&lt;strong&gt;Analysis of &lt;a class="link" href="https://github.com/ashtewari/mythril-tests/blob/master/mythx-tests/05222022-25/SelfDestructMultiTxFeasible.sol" target="_blank" rel="noopener"&#10; &gt;SelfDestructMultiTxFeasible.sol&lt;/a&gt;&lt;/strong&gt;&#10;&lt;/h5&gt;&#10; &lt;blockquote&gt;&#10; &lt;p&gt;&amp;gt; docker run -v E:\share\:/data mythril/myth -v4 analyze /data/mythx-tests\05222022-25/SelfDestructMultiTxFeasible.sol&lt;/p&gt;&#10;&#10; &lt;/blockquote&gt;&#10;&lt;p&gt;Mythril reports an instance of SWC-106 vulnerability:&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-17.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;h5 id=""&gt;&#10;&lt;/h5&gt;&lt;p&gt;&lt;strong&gt;Analysis of &lt;a class="link" href="https://github.com/ashtewari/mythril-tests/blob/master/mythx-tests/05222022-25/SimpleDAO.sol" target="_blank" rel="noopener"&#10; &gt;SimpleDAO.sol&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;&#10;&#10; &lt;blockquote&gt;&#10; &lt;p&gt;&amp;gt; docker run -v E:\share\:/data mythril/myth -v4 analyze /data/mythx-tests\05222022-25/SimpleDAO.sol&lt;/p&gt;&#10;&#10; &lt;/blockquote&gt;&#10;&lt;p&gt;Mythril reports three instances of SWC-107 and one instance of SWC-105:&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-18.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;h5 id="analysis-of-a"&gt;&lt;strong&gt;Analysis of a &lt;a class="link" href="https://github.com/ashtewari/mythril-tests/blob/master/mythx-tests/05222022-25/flatenned-01.sol" target="_blank" rel="noopener"&#10; &gt;flatenned contract file&lt;/a&gt;&lt;/strong&gt;&#10;&lt;/h5&gt;&lt;p&gt;File containing the two test contracts returns five instances of vulnerabilities of both contracts:&lt;/p&gt;&#10;&#10; &lt;blockquote&gt;&#10; &lt;p&gt;&amp;gt; docker run -v E:\share\:/data mythril/myth -v4 analyze /data/mythx-tests\05222022-25/flatenned-01.sol&lt;/p&gt;&#10;&#10; &lt;/blockquote&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-19.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;h5 id="analyze-a-contract-with-imported-contract"&gt;&lt;strong&gt;Analyze a contract with imported contract&lt;/strong&gt;&#10;&lt;/h5&gt;&lt;p&gt;Most smart contracts import other contracts to reuse functionality. You do not have to flatten the contracts into one file. Mythril can work with contracts with imports specified in them : &lt;a class="link" href="https://github.com/ashtewari/mythril-tests/blob/master/mythx-tests/05222022-26/SimpleDAOWithImport.sol" target="_blank" rel="noopener"&#10; &gt;SimpleDAOWithImport.sol&lt;/a&gt;&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-20.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&#10; &lt;blockquote&gt;&#10; &lt;p&gt;&amp;gt; docker run -v E:\share\:/data mythril/myth -v4 analyze /data/mythx-tests\05222022-26/SimpleDAOWithImport.sol&lt;/p&gt;&#10;&#10; &lt;/blockquote&gt;&#10;&lt;h5 id="analyze-a-contract-with-openzeppelin-style-import"&gt;&lt;strong&gt;Analyze a contract with @OpenZeppelin style import&lt;/strong&gt;&#10;&lt;/h5&gt;&lt;p&gt;Mythril relies on &lt;a class="link" href="https://github.com/ethereum/solc-js" target="_blank" rel="noopener"&#10; &gt;solc&lt;/a&gt; for compiling contract source code. For @OpenZeppelin style imports, you have to specify &amp;ndash;solc-json file containing remapping for solc to locate the referenced files : &lt;a class="link" href="https://github.com/ashtewari/mythril-tests/blob/master/mythx-tests/05222022-26/SimpleDAOWith-OzImport.sol" target="_blank" rel="noopener"&#10; &gt;SimpleDAOWith-OzImport.sol&lt;/a&gt;&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-22.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&#10; &lt;blockquote&gt;&#10; &lt;p&gt;&amp;gt; docker run -v E:\share\:/data mythril/myth -v4 analyze /data/mythx-tests\05222022-26/SimpleDAOWith-OzImport.sol &amp;ndash;solc-json=/data/solc-args.json&lt;/p&gt;&#10;&#10; &lt;/blockquote&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-21.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;h3 id="analyzing-on-chain-contracts"&gt;Analyzing On-Chain Contracts&#10;&lt;/h3&gt;&lt;p&gt;Mythril can &lt;a class="link" href="https://mythril-classic.readthedocs.io/en/master/security-analysis.html#analyzing-on-chain-contracts" target="_blank" rel="noopener"&#10; &gt;analyze contracts deployed on the blockchain&lt;/a&gt; directly. You do not need source code of the contract. Support for &lt;a class="link" href="https://infura.io/" target="_blank" rel="noopener"&#10; &gt;infura&lt;/a&gt; is built-in, you can also use custom RPC endpoint. Replace INFURA_ID with your Infura project id and CONTACT_ADDRESS with the address of your contract on the blockchain :&lt;/p&gt;&#10;&#10; &lt;blockquote&gt;&#10; &lt;p&gt;&amp;gt; docker run mythril/myth -v4 analyze &amp;ndash;rpc infura-rinkeby &amp;ndash;infura-id INFURA_ID -a CONTACT_ADDRESS&lt;/p&gt;&#10;&#10; &lt;/blockquote&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/image-23.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;</description></item><item><title>KHEL Coin on Ethereum</title><link>https://www.tewari.info/2022/05/09/khel-coin-on-ethereum/</link><pubDate>Tue, 10 May 2022 01:41:59 +0000</pubDate><guid>https://www.tewari.info/2022/05/09/khel-coin-on-ethereum/</guid><description>&lt;p&gt;KhelCoin (KHEL) is an &lt;a class="link" href="https://ethereum.org/en/developers/docs/standards/tokens/erc-20/" target="_blank" rel="noopener"&#10; &gt;ERC-20 token&lt;/a&gt; available on &lt;a class="link" href="https://ethereum.org/en/" target="_blank" rel="noopener"&#10; &gt;Ethereum&lt;/a&gt; blockchain. It is a &lt;a class="link" href="https://ethereum.org/en/smart-contracts/" target="_blank" rel="noopener"&#10; &gt;Smart Contract&lt;/a&gt; created with &lt;a class="link" href="https://docs.soliditylang.org/en/latest/" target="_blank" rel="noopener"&#10; &gt;Solidity&lt;/a&gt;, &lt;a class="link" href="https://www.openzeppelin.com/contracts" target="_blank" rel="noopener"&#10; &gt;OpenZeppelin&lt;/a&gt;, &lt;a class="link" href="https://trufflesuite.com/" target="_blank" rel="noopener"&#10; &gt;Truffle&lt;/a&gt;, &lt;a class="link" href="https://trufflesuite.com/ganache/" target="_blank" rel="noopener"&#10; &gt;Ganache&lt;/a&gt;, &lt;a class="link" href="https://remix.ethereum.org/" target="_blank" rel="noopener"&#10; &gt;Remix&lt;/a&gt;, &lt;a class="link" href="https://web3js.readthedocs.io/" target="_blank" rel="noopener"&#10; &gt;web3.js&lt;/a&gt; and &lt;a class="link" href="https://code.visualstudio.com/" target="_blank" rel="noopener"&#10; &gt;VSCode&lt;/a&gt;. It is currently available on &lt;a class="link" href="https://rinkeby.etherscan.io/token/0x15AFeB0A2caD2caC3A8140c342789C310Ad82A83" target="_blank" rel="noopener"&#10; &gt;Rinkeby&lt;/a&gt; test network. It will be launched on the Mainnet in the near future.&lt;/p&gt;&#10;&lt;p&gt;You can get KHEL coins from this website - &lt;a class="link" href="https://ashtewari.github.io/khelcoin" target="_blank" rel="noopener"&#10; &gt;KHEL Coin ICO&lt;/a&gt;&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/khelcoin-ico-metamask.png"&#10;&#9;&#9;&#9;alt="KhelCoin ICO page prompting to install Metamask"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;p&gt;Head over to the ICO website. You will be prompted to install &lt;a class="link" href="https://metamask.io/" target="_blank" rel="noopener"&#10; &gt;Metamask&lt;/a&gt; and connect to your account on Rinkeby testnet. Click on &amp;ldquo;Buy KHEL Coins&amp;rdquo; button to get your own coins!&lt;/p&gt;&#10;&lt;figure&gt;&lt;img src="https://www.tewari.info/wp-content/khelcoin-ico-buy.png"&gt;&#10;&lt;/figure&gt;&#10;&#10;&lt;p&gt;Source code is on github - &lt;a class="link" href="https://github.com/ashtewari/khelcoin" target="_blank" rel="noopener"&#10; &gt;https://github.com/ashtewari/khelcoin&lt;/a&gt;&lt;/p&gt;&#10;&lt;p&gt;Puzzle Icon Credit: &lt;a class="link" href="https://www.flaticon.com/free-icons/puzzle" target="_blank" rel="noopener"&#10; &gt;https://www.flaticon.com/free-icons/puzzle&lt;/a&gt;&lt;/p&gt;&#10;</description></item><item><title>TRINUG - Programming Smart Contracts on Ethereum Blockchain</title><link>https://www.tewari.info/2018/08/08/programming-smart-contracts-on-ethereum-blockchain-2/</link><pubDate>Wed, 08 Aug 2018 21:30:50 +0000</pubDate><guid>https://www.tewari.info/2018/08/08/programming-smart-contracts-on-ethereum-blockchain-2/</guid><description>&lt;p&gt;TRINUG - Main Meeting : Programming Smart Contracts on Ethereum Blockchain - August 2018&lt;/p&gt;&#10;&lt;p&gt;In this session, Ash will introduce you to the world of Blockchain programming. You will learn about Ethereum and how to program Smart Contracts for Ethereum Blockchain. You will learn how to deploy and test your Contracts on a public Ethereum Testnet. Ash will share best practices for Smart Contract development. You will be able to participate in a hands-on walk-through in the latter half of the session.&lt;/p&gt;&#10;&lt;p&gt;&lt;a class="link" href="https://www.meetup.com/TRINUG/events/253120923/" title="TRINUG-Blockchain-PPT"&#10; target="_blank" rel="noopener"&#10; &gt;&lt;img alt="ppt-20180808" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://www.tewari.info/wp-content/ppt-20180808.png"&gt;&lt;/a&gt;&lt;/p&gt;&#10;</description></item><item><title>Charlotte IOT - Programming Smart Contracts on Ethereum Blockchain</title><link>https://www.tewari.info/2018/07/10/programming-smart-contracts-on-ethereum-blockchain/</link><pubDate>Tue, 10 Jul 2018 22:00:00 +0000</pubDate><guid>https://www.tewari.info/2018/07/10/programming-smart-contracts-on-ethereum-blockchain/</guid><description>&lt;p&gt;Charlotte IOT - July 2018&lt;/p&gt;&#10;&lt;p&gt;You will not want to miss this chance to learn about &lt;em&gt;Blockchain&lt;/em&gt;, a technology enabling an entire IoT ecosystem! It has a distributed database for all the transactions, which eliminates the need for the third party to authenticate the transactions. The database ledger is a continuously growing list of records, called blocks, which are linked and secured using cryptography.&#10;Charlotte IoT wants to thank Ash Tewari for traveling from Raleigh to share his extensive knowledge and experience around &lt;em&gt;Blockchain&lt;/em&gt;. In this session, Ash will introduce you to the world of &lt;em&gt;Blockchain&lt;/em&gt; programming. You will learn about Ethereum and how to program Smart Contracts on Ethereum &lt;em&gt;Blockchain&lt;/em&gt;. You will learn how to deploy and test your code on a public Ethereum Testnet. Ash will complete the session with sharing some best practices for Smart Contract development. You will be able to participate in a hands-on walkthrough in the latter half of the session.&lt;/p&gt;&#10;&lt;p&gt;&lt;a class="link" href="https://www.tewari.info/wp-content/ppt-20180710.png" &gt;&lt;img alt="ppt-20180710" loading="lazy" sizes="(max-width: 767px) calc(100vw - 30px), (max-width: 1023px) 700px, (max-width: 1279px) 950px, 1232px" src="https://www.tewari.info/wp-content/ppt-20180710.png"&gt;&lt;/a&gt;&lt;/p&gt;&#10;</description></item><item><title>Getting Started with Smart Contracts on Ethereum Blockchain using Visual Studio</title><link>https://www.tewari.info/2016/09/30/getting-started-with-smart-contracts-on-ethereum-blockchain-using-visual-studio/</link><pubDate>Fri, 30 Sep 2016 21:19:11 +0000</pubDate><guid>https://www.tewari.info/2016/09/30/getting-started-with-smart-contracts-on-ethereum-blockchain-using-visual-studio/</guid><description>&lt;p&gt;&lt;a class="link" href="https://en.wikipedia.org/wiki/Smart_contract" target="_blank" rel="noopener"&#10; &gt;Smart Contracts&lt;/a&gt; are an exciting innovation built on blockchain technology. It is a way to execute code in a trustless, decentralized and transparent system. &lt;a class="link" href="https://www.ethereum.org/" target="_blank" rel="noopener"&#10; &gt;Ethereum&lt;/a&gt; is a decentralized platform to run smart contracts using a variation of Bitcoin&amp;rsquo;s blockchain technology.&lt;/p&gt;&#10;&lt;p&gt;In this session, you will learn how to write smart contracts in Visual Studio. You will learn how to deploy them to public Ethereum blockchain and a private/consortium blockchain as a service in Azure. You will be introduced you to &lt;a class="link" href="https://solidity.readthedocs.io/en/develop/" target="_blank" rel="noopener"&#10; &gt;Solidity&lt;/a&gt;- the programming language used to write smart contracts. You will get familiar with the tools and technology around this exciting, promising and relatively new innovation.&lt;/p&gt;&#10;&lt;p&gt;Presentation Slides are here: &lt;a class="link" href="https://1drv.ms/b/s!Asey4wYZPY_tgZWFQLwValH3lwAbbkE" target="_blank" rel="noopener"&#10; &gt;download&lt;/a&gt;.&lt;/p&gt;&#10;</description></item></channel></rss>