Day 72 of #100DaysOfDeFI 🚀 Today I looked at arithmetic Over/Under Flows in #Solidity 👾 This vulnerability been secured by the current Solidity version 🦸♂️ Nevertheless, it is important to understand what it is and how to avoid it 👩🏻💻 #womenwhocode#100DaysOfCode
Summary 🧵
1/ An overflow in Solidity occurs when a number is incremented beyond its maximum value. For example, if we have a uint8 with a value of 255 and increment it by 1, it will “reset” and set a value to 0. Remember, the maximum value for uint8 is 255❗
2/ Similar thing happens when we decrease a value beyond its minimal level. Taking the same example, if a uint8 is set to 0 and we decrease it by 1, it will set to 255, since 0 is the minimal value of uint8❗
3/ Let’s check it with code 👩🏻💻
4/ Deploy contract and check the value → it should be set to 0️⃣ Try to decrease a value and it will return 255 👇
5/ Increase it and it will be set back to 0 👇
6/ To avoid this vulnerability the best option is to use the latest version of Solidity 👾 There is also an option to use SafeMath library by OpenZeppelin that helps preventing overflows and underflows 👩🏻💻
• • •
Missing some Tweet in this thread? You can try to
force a refresh
Day 73 of #100DaysOfDeFI 🚀 Learned about Self Destruct vulnerability in #Solidity 🦹🏼♀️ Selfdestruct deletes the contract from the blockchain and and sends all Ether to a designated address 💸 In some scenarios it can lead to unexpected problems ❌ #100DaysOfCode
How it works 🧵
1/ Let’s see how it works with an example of a simple game 🎲 Players send to the contract 1 token 🪙 the one who deposits the fifth token wins 🏆
Game code 👇
Day 71 of #100DaysOfDeFI 🚀 looked at Re-Entrancy vulnerability🦹🏻 It is one of the most destructive attacks in the #Solidity smart contracts 💸 The untrusted contract that exploits the vulnerability is able to drain all user's funds 🚰 #100DaysOfCode
How it works 🧵
1/ To make it happen, there should be 2 contracts: a vulnerable contract and an attacker’s contract 👺
2/ The attacker should deposit some funds into the vulnerable contract 💰
Day 68 of #100DaysOfDeFI 🚀 Today I worked on the Factory smart contract that is a part of the decentralized exchange architecture 💱 Factory creates and keeps track of all Pair contracts 👩🏻💻 #womenwhocode#100DaysOfCode
Summary 🧵
1/ The Factory will include:
🔷 createPair - create a Liquidity Pool;
🔷 adjustAmount - adjust a number of tokens using a formula;
🔷 getReserves - a getter function;
🔷 addLiquidity - add liquidity to the LP;
🔷 removeLiquidity - withdraw liquidity;
🔷 trade1for2 - swap tokens.
2/ First, initialize contract and define the state variables 👩🏻💻
Day 67 of #100DaysOfDeFI 🚀 Today I continued creating a basic DEX 👩🏻💻 and focused on developing a Pair smart contract 👾 Pair represents the Liquidity Pool 🪙 it is in charge of swapping 💱 managing the liquidity pool and burning 🔥 #womenwhocode#100DaysOfCode
Summary 🧵
1/ In this example of the Pair smart contract I’ll implement the following methods:
🔶 getReservers - get quantities of each token;
🔶 updateReserves - update the tokens’ quantities;
🔶 swap - exchange two tokens;
🔶 withdrawTokens - send the tokens back to the LP.
2/ First, initialize the Pair contract. We’ll need to import some contracts from OpenZeppelin and a Tokens contract from the day 66 of the challenge. Initialize state variables and constructor, too👩🏻💻
Day 66 of #100DaysOfDeFI 🚀 Today and the following days I'll dive into DEXs implementation in #Solidity ⭐️ I’ll review the Uniswap smart contracts and create a decentralized exchange protocol 👩🏻💻 #womenwhocode#100DaysOfCode
Summary 🧵
1/ Uniswap smart contract architecture consists of Core and Periphery:
🔹 Core is used for storing and swapping the tokens, adding funds, getting rewards, etc;
🔹 Periphery interacts with the Core.
2/ Core stores the following smart contracts:
🔹 Pair - swaps, mints and burns tokens;
🔹 Factory - creates pairs of tokens;
🔹 ERC20 - keeps track of ownership of pool.
Periphery has only 1 smart contract:
🔹 Router - interacts with the Core.
Day 63 of #100DaysOfDeFI 🚀 Today I learned how to deploy an NFT collection on a testnet 🤖 and uploaded a collection of watermelon houses generated with AI on OpenSea 🐳 special thanks to @javilop for creating these cute houses! 🍉 #womenwhocode#100DaysOfCode
Summary 🧵
1/ First, upload a collection of images on Pinata, I described it in detail on day 56 of the challenge 🔙
2/ Now create json files for each image and add CID to “image” 👇