<?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 Ali Azam on Medium]]></title>
        <description><![CDATA[Stories by Ali Azam on Medium]]></description>
        <link>https://medium.com/@aliazam60?source=rss-ee5e35a23526------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wnK3ysesBDQpuyMF55UbBQ.jpeg</url>
            <title>Stories by Ali Azam on Medium</title>
            <link>https://medium.com/@aliazam60?source=rss-ee5e35a23526------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 23:43:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aliazam60/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[Implementing Rock Paper Scissors in Solidity]]></title>
            <link>https://aliazam60.medium.com/implementing-rock-paper-scissors-in-solidity-989db92126af?source=rss-ee5e35a23526------2</link>
            <guid isPermaLink="false">https://medium.com/p/989db92126af</guid>
            <category><![CDATA[rock-paper-scissors]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[privacy]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Ali Azam]]></dc:creator>
            <pubDate>Mon, 23 Nov 2020 00:01:11 GMT</pubDate>
            <atom:updated>2020-11-23T00:01:11.391Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Opu8gC1P5ABCoN9X" /><figcaption>Photo by <a href="https://unsplash.com/@marcus_wallis?utm_source=medium&amp;utm_medium=referral">Marcus Wallis</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Implementing Rock Paper Scissors in Solidity</strong></p><p>Have you ever thought about playing rock paper scissors on the blockchain? In this tutorial, we will build a privacy focussed rock paper scissors application on Ethereum using Solidity.</p><p>The aim is to understand the differences between a web2 application and web3 application also known as DApp (Decentralised Application). In a web2 application, the database is private and the server is trusted whereas in a web3 application, there is no server, there is no one database, there is only a blockchain which has state and trust isnt really present, asking a blockchain node about the state can only be trusted if other nodes agree on that as well, these are all sort of topics I have discussed in my privacy course which you can watch here: <a href="https://www.newline.co/courses/newline-introduction-to-privacy-on-ethereum">Introduction to privacy on Ethereum</a>.</p><p><strong>Motivation</strong></p><p>Rock paper scissors may sound simple to you at first but implementing it on a blockchain has its concerns and can teach you more than what you would think, we dont want to use a library or any other means to achieve privacy, the goal is to keep it as simple as possible and learn about privacy and smart contracts by implementing it yourself.</p><p><strong>Concept</strong></p><p>Blockchains such as Bitcoin and Ethereum are public by nature so while in the database world, we dont have to worry about the database being public, this is casual for blockchain, so as you will see in the first iteration of the game, the moves are store publicly, so this means that we have to dig deeper into what we store, storing plaintext is very dangerous since the entire world can read it so we have to seek help from our cryptography toolbox.</p><p><strong>Requirements</strong></p><p>The requirements are simple:</p><p>1. Two users must be able to play rock paper scissors</p><p>2. No user should have an advantage because of their turn</p><p>3. Any user can check who has won the game</p><p>Optional:</p><ul><li>The game can be extended such that both players have to deposit eth and the winner takes it all (could also deposit ERC20 tokens as well)</li><li>The game can support multiple parallel games</li><li>The game can be played off chain with state channels</li></ul><p><strong>Basic Rock Paper Scissors</strong></p><p>In the basic rock paper scissors, we want to implement the game without thinking about privacy and this can be done in many different ways and to give you a chance to implement it yourself, here is the interface of the contract:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50e78b8113b3e356761dcda4b2aea6e9/href">https://medium.com/media/50e78b8113b3e356761dcda4b2aea6e9/href</a></iframe><p>Lets dive into the implementation</p><p>First of all, we need a way to store the rock paper scissor values so we can verify the moves later, this can be done in many ways and we will change it as we go along, to begin with, lets use `uint8` to begin with since ROCK, PAPER, SCISSORS can be the only three acceptable choices.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/21ae24bcfb69095d20195139b273a819/href">https://medium.com/media/21ae24bcfb69095d20195139b273a819/href</a></iframe><p>Now that we have a way of representing the valid moves (ROCK, PAPER, SCISSORS), we need a way to store the values played by the players and the simplest ways to do that is by using a mapping, like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1191d2f23354c33cbeab3fbf8fa8f064/href">https://medium.com/media/1191d2f23354c33cbeab3fbf8fa8f064/href</a></iframe><p>Now that we have the mapping, we can now start implementing the play function, this is a simple function which should check that a move is valid and store move along with the users address in the `choices` mapping. Lets do this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0a1fa96375ca8000c9967b1741b31c7/href">https://medium.com/media/c0a1fa96375ca8000c9967b1741b31c7/href</a></iframe><p>Thats all needed for the play function, now we can look at implementing the evaluate function which can take two addresses and return the winning address, this essentially implements rock paper scissors game rules.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9f902bbe04166e46df3445bc2d348bb/href">https://medium.com/media/c9f902bbe04166e46df3445bc2d348bb/href</a></iframe><p>Congratulations! Now we have a fully working game, go ahead and you can play it by copy pasting the code on [Remix](https://remix.ethereum.org/), it gives you multiple addresses so you can play it against yourself too!</p><p><strong>Rock Paper Scissors with hashes</strong></p><p>In the previous section, our goal was just to implement a rock paper scissors game without worrying about any privacy concerns, lets talk about them now,</p><p>Remember this?</p><pre>mapping(address =&gt; uint8) public choices;</pre><p>Yes, the choices mapping, it stores the users moves, and its public, yup, so the player who plays second can always take advantage because they always can see the move played by the first player and therefore can always play the move which will make them win the game.</p><p>The only way this game would work in its current state is if both users play the moves simultaneously, however thats not an option with blockchains in general because the transactions are ordered and nothing can happen within Ethereum. But we can try to hide the values by using a hash function, like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/71a1d68dfa771f625cb63a14f9bf6d70/href">https://medium.com/media/71a1d68dfa771f625cb63a14f9bf6d70/href</a></iframe><p>We now have the hashed versions of ROCK, PAPER, SCISSORS and users now play a `<em>bytes32</em>` choice instead of the `<em>uint8</em>` from before.</p><p>Think about the problems with this before moving onto the next section!</p><p><strong>Rock Paper Scissors with Randomness</strong></p><p>If you are wondering that hash functions dont really hide anything and the same attack can still be used, you are absolutely right, hash functions are a deterministic one way functions which can take an input and always return the same output but if you know the inputs, the outputs are the same and therefore you can still use that to your advantage.</p><p>How do we go about making this work in a public setting <em>_without adding too much complexity_</em> and by <em>_complexity_</em> I mean, no Oracles, Enigma, ZKPROOFS, or any sophisticated means to achieve a very simple goal. Whats the answer? You guessed it! <em>*Randomness*</em>!</p><p>How do we go about adding randomness and how would that help? Remember we used `bytes32` for the choice, now its time to put that choice to good use and we do that by combining the users move and a random hashed string picked by the user, lets see how this changes our implementation.</p><p>Hint: Follow the CHANGED comments to see what has changed</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/68bafed11a0cf2a602fefff7f79687a2/href">https://medium.com/media/68bafed11a0cf2a602fefff7f79687a2/href</a></iframe><p><strong>Conclusion</strong></p><p>By adding the randomness into the mix, we have prevented the attack but it comes with its caveats, the current implementation assumes that an application built on top of the smart contracts will be managing the randomness and making sure its truly random, many things can be broken if there are enough incentives and what we achieve with this solution is simplicity, we are only using simple cryptography which is already used a lot in web applications to store user passwords and much more and achieve privacy. There are cases where we have to use fancy cryptography like ZK-SNARKS but this certainly isnt a use case for it!</p><p>If you would like to learn about something else, please message me on Twitter @aliazam2251 or email me aliazam2251@gmail.com. I hope you had fun building rock paper scissors on Blockchain!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=989db92126af" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introducing a privacy focussed course on blockchains]]></title>
            <link>https://aliazam60.medium.com/introducing-a-privacy-focussed-course-on-blockchains-8d3a45bb1917?source=rss-ee5e35a23526------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d3a45bb1917</guid>
            <category><![CDATA[courses-and-training]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[privacy]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Ali Azam]]></dc:creator>
            <pubDate>Thu, 03 Sep 2020 17:14:41 GMT</pubDate>
            <atom:updated>2020-09-03T17:14:41.140Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*Xmy_aco3-JalJ3RKNJOofQ.png" /></figure><p>TLDR; If you want to learn about privacy and how you can design your blockchain applications with privacy, I am working on a course which will go through the most widely used privacy techniques and add them to your applications in a very hands on fashion.</p><p>Privacy is very fundamental concept to developing blockchain applications, yet there are very little resources out there to learn from, especially knowing all the different techniques used for privacy and there pros and cons, also there is bias within different communities for privacy techniques if they have developed them or have any affiliation with them.</p><p>In this course, we want to look at all the privacy techniques and use them first hand to get a feel of when they should and should not be used, the idea is to keep it as simple as possible and develop some cool applications like rock paper scissors on blockchain and more to see how these privacy techniques can be used within your application.</p><p>Most of the time, Privacy is regarded as some moon math but the architecture of it is rather simple, take hashes for example, they are the recommended way to store user passwords and have great advantages but often they can be terrifying to software engineers, what hash function to use? how does it work and generally libraries fullfill these needs but we want to look under the blanket and see at a higher level what their properties are and why are they useful without going into maths rabbit hole. Also, just by knowing the various techniques of privacy, one can greatly benefit from them especially when implementing blockchain applications.</p><p>The contents of the course are as follows:</p><ol><li>Intro to privacy on blockchain <br>1.1 Intro and getting started<br>1.2 What is a blockchain?<br>1.3 What is mining in blockchain<br>1.4 What is privacy in blockchain ?<br>1.5 Will quantum computing break privacy?<br>1.6 A brief look at privacy techniques used in blockchains<br>1.6.1 Zcash<br>1.6.2 Monero<br>1.6.3 Dash<br>1.6.4 Mixers<br>1.6.5 One time addresses<br>1.6.6 Stealth addresses</li><li>Implementing a rock paper scissors game on Ethereum<br>2.1 Setting up the Environment<br>2.2 Writing our first smart contract for rock paper scissors<br>2.3 Deploying the contract and playing rock paper scissors on blockchain<br>2.4 Implementing basic privacy on our smart contract using hashes<br>2.5 A twist in rock paper scissors<br>2.6 Conclusion and wrapping up</li><li>A deep dive into current privacy blockchains<br>3.1 Looking at how ZCash works<br>3.2 Looking at how Moneoro works<br>3.3 Looking at how Dash works<br>3.4 Looking at how MimbleWimble works</li><li>Cryptography 101<br>4.1 Understanding Hashes/Hash Functions<br>4.2 Understanding Signatures<br>4.3 Symmetric key and Asymmetric key encryption<br>4.4 Commitment Schemes<br>4.5 Generating randomnesss<br>4.6 Ring Signatures<br>4.7 Stealth addresses<br>4.8 Zero knowledge Proofs<br>4.9 Homomorphic encryption<br>4.10 Multiparty computation<br>4.11 Merkle Trees</li><li>A deep dive into bitcoin privacy<br>5.1 Understanding how bitcoin transactions work<br>5.2 Bitcoin transaction graph<br>5.3 Bitcoin mixers<br>5.4 Lightening network</li><li>Privacy solutions on ethereum<br>6.1 Mixers on Ethereum: Tornado.cash<br>6.2 One time addresses<br>6.3 Private blockchains<br>6.4 Zokrates<br>6.5 Aztec<br>6.6 EY’s Nightfall</li></ol><p>To keep posted about the course and release date, please submit your email here: <a href="https://upscri.be/ormtak">https://upscri.be/ormtak</a></p><p>If you would like to learn about something which is not on the list, please message me on Twitter @aliazam2251 or email me aliazam2251@gmail.com.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d3a45bb1917" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Who called my contract?]]></title>
            <link>https://aliazam60.medium.com/who-called-my-contract-71c434edc50?source=rss-ee5e35a23526------2</link>
            <guid isPermaLink="false">https://medium.com/p/71c434edc50</guid>
            <category><![CDATA[smart-contract-security]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Ali Azam]]></dc:creator>
            <pubDate>Thu, 07 Feb 2019 23:50:23 GMT</pubDate>
            <atom:updated>2019-02-07T23:50:23.607Z</atom:updated>
            <content:encoded><![CDATA[<p>At the time of writing, there is no secure way of knowing if a contract was called by Another Contract or an Externally Owned Account, there has been 2 ways but both both of them are easily hackable and I will discuss each of them below.</p><p><strong>EXTCODESIZE:</strong></p><pre>function isContract(address _addr) private returns (bool isContract){<br>  uint32 size;<br>  assembly {<br>    size := extcodesize(_addr)<br>  }<br>  return (size &gt; 0);<br>}</pre><pre>Taken from: <a href="https://ethereum.stackexchange.com/questions/15641/how-does-a-contract-find-out-if-another-address-is-a-contract">https://ethereum.stackexchange.com/questions/15641/how-does-a-contract-find-out-if-another-address-is-a-contract</a></pre><p>As the stackExchange answer already mentions, this way is not secure because doing construction time, the code at the address of contract is still 0 and there are many articles describing the exploit in detail. (Check references below).</p><p><strong>TX.ORIGIN == MSG.SENDER</strong></p><p>While many of the websites say that this way is secure, its not and the only resource I found saying its not secure is <a href="https://www.reddit.com/r/ethdev/comments/8r6b93/is_txorigin_msgsender_a_secure_option_to_prevent/e0ow2jx">this</a> reddit comment, lets dive into how this can be exploited.</p><p>tx.origin refers to the originator of the transaction that is the Externally Owned Account (EOA)</p><p>msg.sender refers to the callee, it can be a contract or EOA.</p><p>The whole point of this check is to ensure that whoever called this contract was an EOA, and this would be correct if it wasn’t for DELEGATECALL.</p><p>DELEGATECALL is a function which delegates the call to the specified request while passing in the same msg.sender and msg.value, this means when your contract does this check:</p><blockquote>require(tx.origin == msg.sender);</blockquote><p>This check will pass as Tx.origin is the EOA and so is msg.sender since the call was delegated.</p><p>The easiest way to test this is using a Proxy contract where in remix you call the “At Address” of remix with the address of Proxy and Interface of the other contract.</p><p>I am researching on secure ways on finding whether the caller was EOA or a contract as well as designing new patterns for Trustless Smart Contract Upgradability, if you want to collaborate or talk more, reach out on twitter: aliazam2251.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71c434edc50" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Journey to Mainnet]]></title>
            <link>https://aliazam60.medium.com/a-journey-to-mainnet-83c2a67800c?source=rss-ee5e35a23526------2</link>
            <guid isPermaLink="false">https://medium.com/p/83c2a67800c</guid>
            <category><![CDATA[decentralization]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[consensus]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[ipfs]]></category>
            <dc:creator><![CDATA[Ali Azam]]></dc:creator>
            <pubDate>Wed, 19 Sep 2018 14:18:04 GMT</pubDate>
            <atom:updated>2018-09-19T14:18:04.902Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TsBmToCzhQ3yTG3U6-NQPQ.png" /></figure><p>Going to Mainnet is the dream of every Crypto startup, being able to say that its all public and real and we are out of the safe environment to face the transaction fees, network congestion and high-security risks. But with all that comes trust, motivation to contribute to the ecosystem and to solve all these problems. Not just for ourselves, but for everyone ~ it’s open source after all.</p><p>While it may seem that moving to mainnet is as simple as changing the Web3 provider to a Mainnet node and using the right chain ID within transactions. it’s actually much more than that. Mainnet involves dealing with real ETH, which means with every move, you’ve got one eye on transaction fees. If its too low then it will never be executed, but if its too high then business won&#39;t be able to survive. One of the decisions we made at <a href="http://zinc.work/">Zinc</a> is to pay for users transaction fees and open the ecosystem to the mass instead of just the crypto enthusiasts and take away all of the complications through design abstractions. I personally believe that it&#39;s not a matter of finding the right answers but asking the right questions and that was the goal from the beginning.</p><p>Building a system which is <strong>fast</strong>, <strong>secure</strong>, <strong>trustless</strong> and <strong>decentralised</strong> remains an unsolved technical challenge. It may take a long time before we get there, so it’s important that we share every step of progress we make towards achieving it. To understand the complexity of the issues at hand, we had to get our hands wet diving into Mainnet and using this opportunity to learn and grow and give back to the community ~ without which, we wouldn&#39;t be here today.</p><p>Let&#39;s look at some of the problems which left us miserable zombies for days, if not weeks.</p><p>Last week, we switched to Mainnet using <a href="https://infura.io/">Infura</a>, the same provider we were using for Ropsten over the last couple of months, however; things didn&#39;t go as planned.</p><blockquote>whatever can go wrong, will go wrong — <a href="https://en.wikiquote.org/wiki/Murphy%27s_law">Murphy’s law</a></blockquote><p>As soon as we switched to Mainnet, with all the precautions we could have possibly taken, we saw that our transactions started failing and the error was “nonce too low” but how could it be? it works on Ropsten fairly well and the only reason we tested on Ropsten for months despite it being slow was that its the only network which simulates the mainnet with a proper PoW algorithm. Then why was the <strong><em>Nonce </em></strong>too low?</p><p>To find the answer, let&#39;s look at how we get the nonce. The general way is to get the transaction count for the account sending the transaction and use that as the nonce and that&#39;s exactly what we were doing. The only problem was that if two users call the function at the same time, they both will get the same nonce meaning only one of 2 transactions can succeed and other will fail. The situation is the same even if there are a thousand calls to the function, only one transaction at max will be able to succeed. To counteract this issue, we looked at the documentation and added the keyword “pending” to the request which at the time seemed like it will give all transactions including the ones which are pending (we ensured that one transaction is broadcasted before we try to get the next transaction count), and this seemed to work fine on Ropsten TestNet, so why did it fail on Mainnet?</p><p>The first theory we had is that Infura loads balancing with its nodes and every node has its own memory pool. Because the synchronisation is eventual consistency, it means that those two nodes may return different answers to the same question due to various reasons such as network delays, different hardware specification and many more. This made sense as Infura may have been running a single node on Ropsten and therefore we had consistent results. To test this, we used <a href="http://quiknode.io/">quiknode</a> to spin up our own Mainnet Ethereum node and after 30 mins of wait, were ready to test, so we wrote a simple script to run the following web3 function call</p><blockquote>web3.eth.getTransactionCount(</blockquote><blockquote>“0x6d……”,</blockquote><blockquote>“pending”</blockquote><blockquote>).then(console.log)</blockquote><p>The key point to note here is that using the “<strong><em>latest</em></strong>” keyword returned consistent results whereas using the “<strong><em>pending</em></strong>” keyword returned inconsistent results. This was very odd…we were missing part of the puzzle and after researching for several hours and trying to make sense of things, I came to the following understanding of how the “pending” is implemented. (Note that this is my best understanding and it could be wrong, but please do let me know if I have missed something).</p><p>When we asked for the transaction count with the pending keyword, the node looks at all transactions for that account, <em>including</em> the ones in the memory pool of the node. It then makes a <strong><em>prediction</em></strong> whether or not the pending transaction will get into the block currently being mined. Wow, that&#39;s super smart right? Not quite. The prediction is made based upon the gas fees of the transaction. If your transaction has the highest fees then there is a high probability that a <em>rational</em> miner will put that transaction in the block currently being mined. Unfortunately, not all miners are rational, some just pick at random but let&#39;s assume for now they are rational and the probability of your transaction being included in the next block is quite high, what happens now?</p><p>The transaction count will be all confirmed transactions (already mined) + the pending transactions for which the prediction is true. New transactions come in which may have higher gas fees than yours and now the transaction count returned is lower than you previously got when the prediction was true. As you can imagine, using that as a nonce will result in the error “transaction nonce too low” and the system becomes really unstable.</p><p>You may think that&#39;s all, but there is another problem. The memory pool of the full Ethereum node has a maximum number of transactions it can keep and again. It keeps the ones which are more likely to be mined ( high transaction fees) which means that your transaction can even be kicked off the memory pool of pending transactions. (Note that it doesn&#39;t mean they will never be mined because they may still be in other nodes memory pools). The question at this point is how do you know? Well, you don’t, unless you run your own node with specified configurations and remember even in that case if the transaction isn’t sent from one of the accounts that the node controls, it will be treated just like any other transaction and will be kicked off when memory pool gets full.</p><p>Luckily Infura has really big memory pools. It doesn’t matter how big it is simply because someone could send out million transactions to the same Infura node with a higher transaction fee than yours and yours will still be kicked off. Coming back to how Infura does load balancing and first theory we had… It turns out that its true and even just calling the transaction count function fluctuates the results because of the load balancing and desynchronisation of nodes they control, but hey, its a free service, what do you expect.</p><p>It turns out that “pending” was only implemented to make the UX/UI better by showing the users a progress bar of how long their transaction will take before its mined and it makes sense but documentation isn&#39;t clear. I would suggest to only ever use “pending” for this scenario alone and nowhere else, as its inconsistent. Especially never use it to get a nonce.</p><p>Here is the summary of what we have learned from this experience</p><ol><li>Trust no one. Run your own node</li><li>Keep the schedule free for a week at least when going to mainnet</li><li>Get plenty of sleep before going live (who knows when you will get a chance again)</li><li>Test out everything and be very skeptical</li><li>Have Microservices in place which notifies you when something goes wrong (trust me that things will go wrong)</li><li>Enjoy the experience and share it with others.</li></ol><p>Its been an incredible week with lots of learning and sleepless nights but its all worth it. If you have any questions or comments, please leave below or message me on twitter @aliazam2251</p><p><strong>Website</strong>: <a href="https://zinc.work/">https://zinc.work</a></p><p><strong>Twitter: </strong><a href="https://twitter.com/zinc_work">https://twitter.com/zinc_work</a></p><p><strong>Telegram</strong>: <a href="https://t.me/zinc_work">https://t.me/zinc_work</a></p><p><strong>Reddit</strong>: <a href="https://www.reddit.com/r/zinc_work/">https://www.reddit.com/r/zinc_work/</a></p><p><strong>References:</strong></p><ul><li><a href="https://github.com/ethereum/go-ethereum/issues/15994">why the return eth.getTransactionCount decrease · Issue #15994 · ethereum/go-ethereum</a></li><li><a href="https://ethereum.stackexchange.com/questions/42598/whats-the-difference-between-pending-block-and-txpool">What&#39;s the difference between &quot;pending&quot; block and txpool?</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83c2a67800c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Entering the world of IPFS]]></title>
            <link>https://medium.com/zinc_work/entering-the-world-of-ipfs-6755cd10c462?source=rss-ee5e35a23526------2</link>
            <guid isPermaLink="false">https://medium.com/p/6755cd10c462</guid>
            <category><![CDATA[filecoin]]></category>
            <category><![CDATA[ipfs]]></category>
            <category><![CDATA[data-storage]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[node]]></category>
            <dc:creator><![CDATA[Ali Azam]]></dc:creator>
            <pubDate>Fri, 07 Sep 2018 08:52:22 GMT</pubDate>
            <atom:updated>2018-09-07T08:52:22.664Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rbxA1yGHXt0JYjNuzZUibA.png" /></figure><p>IPFS — Interplanetary File System is awesome for storing data in a decentralised fashion and it’s one of the most commonly used tools for storing data within the blockchain space. Storing data within a Blockchain is expensive and slow, storing in IPFS is free and fast. IPFS does not allow duplication of data by hashing it and hashing the same data twice will give back the same hash.</p><p>IPFS seems to work really well. You can add data and it stays in this global network of nodes. Anyone with a hash can access the data (note that all data on IPFS is public unless you use a private IPFS node) and the same data is not duplicated. The question that you might be asking at this point is, “Can I change my database with IPFS and become fully decentralised?”</p><p>While IPFS is great at storing your data, it does not give any guarantees of the data being available if your IPFS node goes down. Confused? Imagine this. You start your IPFS node, run it for a month and have very important data within it. Your machine breaks, you’re thankful it&#39;s a public network so other people will have your data, <em>right? </em>Not quite, IPFS never guaranteed your data will always be available. No other node was interested in it and therefore no one else <em>pinned </em>your data except your loyal node. Consequently your data is lost since no other node has it.</p><p>This is where <a href="https://filecoin.io/">Filecoin</a> comes in, Filecoin allows other nodes to be incentivized for storing your data in case your node goes down and a small fee on your end to avoid losing your private data. Filecoin is awesome, let&#39;s use it! Well, it&#39;s not there yet… Filecoin is under development and will be available at some point in the future. For now, we have to work with current solutions, which include:</p><ol><li>Running multiple IPFS nodes</li><li>Backing up ~/.ipfs folder</li><li>Running IPFS-cluster</li><li>Using something else (ie Storj)</li></ol><p>There are more solutions than this but the one I want to talk about is the <a href="https://cluster.ipfs.io/">Ipfs-cluster</a>. The Ipfs-cluster lets you run many nodes which each replicates the data and keeps the nodes synchronised by using <a href="http://thesecretlivesofdata.com/raft/">RAFT</a> consensus. Lets look at how many nodes we need to keep the system secure. A general case is that a node may go down or lose internet connection. Assuming we have <strong>t </strong>nodes, we need at least <strong>t+1</strong> to keep the system running, in simple terms; it just means there should be at least 1 node up and running even if all others are down. So if you think 5 nodes can never be down at once then your risk factor <strong>t</strong> is 4.</p><p>IPFS cluster uses IPFS nodes to store data and its built on top of standard IPFS which means using the cluster does not mean running a different IPFS node but the exact same node you will run if you were using plain IPFS. IPFS cluster has a proxy node which is used to store all pin requests and implements RAFT algorithm (Leader based approach).</p><p>The idea is that you would interact with the IPFS cluster proxy node which handles synchronisation and backups so you can treat it exactly as an IPFS node. IPFS-Cluster nodes exchange messages between each other such as a request to pin a hash or sending out heartbeat messages to know if a node is down. One of the biggest advantages of this approach is that once a node comes back up, it can receive all the messages it has missed and be up to date in no time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*VAxbIwtCMegOOWw64CJ7tA.png" /><figcaption>Fig.1 IPFS Cluster Architecture</figcaption></figure><h3>Thats awesome! Lets use IPFS for everything? Not so fast!</h3><p>Well, while IPFS is awesome in many ways (there is even a <a href="https://github.com/ipfs/awesome-ipfs">repo</a>) it has its problems too. IPFS node can get quite hungry in terms of memory usage as it connects to more and more nodes continuously - not to mention the amount of bandwidth it consumes! 1 GB of memory is not enough for IPFS nodes and what happens is that the Operating System (Ubuntu) kills the IPFS daemon once it starts using too much memory and all you will see when you look at it is a word <em>“Killed” . </em>It is as devastating as it sounds and if your application depends on IPFS being up full time then you would need a machine with more memory and bandwidth capacity. However; there are other solutions on solving this problem. (Note that this is a problem with IPFS node and not IPFS-cluster).</p><p>Limiting the number of nodes that IPFS connects to can resolve this problem and this can be done in one of two ways (everything discussed here is in the config file for ipfs found at ~/.ipfs/config).</p><ol><li>Manually: By changing the config file to disable MDNS Discovery or setting the interval too high (not recommended, it essentially isolates your node from rest of the network and there is a probability that other IPFS nodes will be able to get content from your node but its very low).</li><li>By using the IPFS connection manager to limit the number of connections your node makes. This has three attributes: <br> — Max Connections:<br>Maximum number of connections that your node will allow and start dropping connections after that.<br> — Min Connections:<br>Minimum number of connections that your node will try to maintain<br> — Interval:<br>The amount of time after which max and min constraints will be checked, for example, if its a minute then every minute your node will ensure that <strong>Min ≤ number of peers (<em>ipfs swarm peers | wc -l</em> ) ≤ Max Connections</strong></li></ol><p>Most of the problems with IPFS can be solved with updating the config file or reading the docs, if you have any questions or suggestions, please comment below or message me on twitter <a href="https://twitter.com/aliazam2251"><strong>@aliazam2251</strong></a></p><p><strong>Website</strong>: <a href="https://zinc.work/">https://zinc.work</a></p><p><strong>Twitter: </strong><a href="https://twitter.com/zinc_work">https://twitter.com/zinc_work</a></p><p><strong>Telegram</strong>: <a href="https://t.me/zinc_work">https://t.me/zinc_work</a></p><p><strong>Reddit</strong>: <a href="https://www.reddit.com/r/zinc_work/">https://www.reddit.com/r/zinc_work/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6755cd10c462" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zinc_work/entering-the-world-of-ipfs-6755cd10c462">Entering the world of IPFS</a> was originally published in <a href="https://medium.com/zinc_work">Zinc blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Zinc Smart Contracts Architecture]]></title>
            <link>https://aliazam60.medium.com/zinc-smart-contracts-architecture-56d751a02824?source=rss-ee5e35a23526------2</link>
            <guid isPermaLink="false">https://medium.com/p/56d751a02824</guid>
            <category><![CDATA[identity]]></category>
            <category><![CDATA[decentralization]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Ali Azam]]></dc:creator>
            <pubDate>Fri, 17 Aug 2018 10:29:08 GMT</pubDate>
            <atom:updated>2018-09-07T15:41:37.571Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vbc0QTjbKTiAiUOMOV4y9g.png" /></figure><p>Over the past month, we have been busy designing and implementing trustless smart contracts written in Solidity. This post will walk through the architectural decisions made and lessons learnt along the way.</p><p>Smart contracts play an important role in applications by giving the guarantee that everyone executes the same code all over the world, However; they must be designed with the right set of goals in mind. The goal for us was to have <strong><em>trustless</em></strong> smart contracts where there is no <em>Owner</em> in the contract and Zinc only ever has the rights explicitly granted by the user. In general, most dApp’s smart contracts are <strong><em>Pausable</em></strong> in order to avoid situations like the DAO hack. It introduces trust within the company that they will not pause the contract without a <em>critical</em> event and the definition of an event being critical is a topic for another day.</p><p>Smart contracts <strong><em>can’t</em></strong> be upgraded once they are deployed, there are however ways around it which makes it easy to update the logic of the contract without having to use a different address. A commonly used pattern is <a href="https://blog.zeppelinos.org/proxy-patterns/">Proxy Upgrade Pattern</a> which uses a proxy contract to delegate the call to another contract which can be changed as per upgrades. Once again, this adds the trust factor that the company will not upgrade the contract to an evil version without your consent and steal your money.</p><p>With that being said, lets dive into Zinc’s contracts:</p><p>Zinc contracts are inspired by the <a href="http://ens.domains/">ENS</a> architecture where the upgradability is left for the user to decide and users may be perfectly happy with the current logic and are free not to upgrade and still use the system. The philosophy of the contract is very simple: every user will have an Identity Contract which only they <strong>control </strong>and can revoke permissions of other apps as they wish. The idea is that dApp contracts can <strong><em>ask</em></strong> the user for permission to interact with their identity contract and the user can allow for certain permissions. The dApp contract’s address gets added to the users Identity Contract. One important thing to note here is that interaction among contracts is encouraged in this framework as we can have well-defined behaviours within the contracts which can be audited by the community.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*M7izNZaRNzspFvGXS3ljHw.png" /><figcaption>Abstract view of Identity Framework</figcaption></figure><p>The idea behind the Zinc contract was: How can we make a users life easier and incentivise them to try our platform? This is why we started developing our own version of <strong>Transaction Relay </strong>which will facilitate the user to use our platform without using gas/ether. Zinc will relay the transactions in a trustless fashion. This meant that we needed to provide strong guarantees that there isn&#39;t anything we can do with their identity (such as stealing their money).</p><p>ECDSA signatures to the rescue! Just like many other dApps, we decided to use signatures within the smart contract to verify user’s consent for interacting with their Identity or performing any function on their behalf. The transaction relay works by asking the user to sign a message through <a href="http://metamask.io/">MetaMask</a>, the signed message then gets relayed to the ZincAccessor contract which verifies the contents of the <em>message</em> through the Encoder contract and verifies the signature by using SignatureValidator, once these checks are performed, the action is performed with the Identity Contract.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*6Et1D7hdfdg1ItU5JI2m5w.png" /><figcaption>Zinc contracts interaction diagram</figcaption></figure><p>To facilitate creation of user Identity Contracts, a function “constructUserIdentity” has been implemented which creates an Identity Contract for a given user following the same signature verification as described above. The Identity Contract created from this function adds the ZincAccessor contract with key management privileges and the user with <strong>ALL</strong> purpose privileges. This means that the user can revoke ZincAccessor permissions at any time by sending a transaction to their Identity Contract.</p><p>The Identity Contract permissions scheme is inspired by <a href="https://www.linux.com/learn/understanding-linux-file-permissions">Linux Permissions</a> where the specific bit is checked. For example, we have the following permissions:</p><p>0 : None<br>1 : Read_Only<br>2 : Write_Only<br>4: Key_Management <br>8: Funds Management</p><p>The permissions are checked in bits so 1 in binary is 0001, 2 in binary in 0010, 4 is 0100 and 8 is 1000. Now, as you can see, only the necessary <a href="https://whatis.techtarget.com/definition/bit-binary-digit"><em>bits</em></a> are on per permission. Users can have multiple permissions and that is as simple as just adding the permissions together. For instance, if someone wanted to have Read_Only and Write_Only permissions, their permissions would be 1+2 = 3 and for someone who needs all permissions, they have 1+2+4+8 = 15. The user always has all permissions within our contracts and ZincAccessor will only ever have Key_Management permissions (4).</p><p>Can Zinc abuse Key_Management permissions to steal users money? Not quite. Zinc cannot ever call any function which requires Funds_Management privileges. How about Zinc removing users keys from their Identity Contract just because it can? Well, technically it’s possible but the user will have to sign a message saying they <em>approve this action and ZincAccessor </em>contract will verify this before performing any actions.</p><p>ZincAccessor contract is upgradable in the sense that we can deploy a new version of ZincAccessor but the existing users will need to sign a message to add it to their Identity Contract, the Identity Contract is deliberately kept simple so it doesn&#39;t have to be upgraded and will be audited by several people before it goes live.</p><p>The contracts are currently deployed on Ropsten and a bug bounty program will follow shortly after.</p><p>If you need any more information or have any questions, comment below or ask me on twitter @<a href="https://twitter.com/aliazam2251">aliazam2251</a>.</p><p><strong>Website</strong>: <a href="https://zinc.work/">https://zinc.work</a></p><p><strong>Twitter: </strong><a href="https://twitter.com/zinc_work">https://twitter.com/zinc_work</a></p><p><strong>Telegram</strong>: <a href="https://t.me/zinc_work">https://t.me/zinc_work</a></p><p><strong>Reddit</strong>: <a href="https://www.reddit.com/r/zinc_work/">https://www.reddit.com/r/zinc_work/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56d751a02824" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>