GithubHelp home page GithubHelp logo

obol_labs's Introduction

# README for Gas Optimization Assignment: Distribute.sol

Description

This assignment focused on gas optimizing a smart contract named Distribute.sol. The key objective was to enhance the efficiency of the distribute() function within a tight timeframe of one hour, without altering the Solidity version or adding any extra functionalities to the contract.

Assignment Overview

The Objective

  • Task: Improve the gas cost of calling the distribute() function in the Distribute contract.
  • Constraints:
    • Do not change the Solidity version.
    • Do not add extra functionality or behavior to the contract.
  • Timeframe: 1 hour.

My Process

  1. Optimize distribute(): I decided to focus only on reducing the gas consumption of the distribute() function.
  2. Unit Testing for Gas Usage: To save time, I only wrote two unit-tests per contract, my goal was to have enough to just determine the gas usage.
  3. Documentation: I spent the last time I had left to write this README.

The changes in my Optimized Contract

Key Changes - Optimized distribute() function

  1. Immutable Variable: Changed createTime to an immutable variable distributeTime, added with 2 weeks set at contract deployment instead of inside distribute().
  2. Internal Visibility: Changed the state variables distributeTime and contributors to internal variables.
  3. Custom Error: Replaced the require statement with a custom error Code1.

Gas Usage Results

  • distribute() Function:

    • Original: 90656 gas
    • Optimized: 88321 gas
    • OtmimizedContract: 81851 gas (Last task)
  • Deployment Gas Usage:

    • Original: 602781 gas
    • Optimized: 445416 gas
    • OtmimizedContract: 254740 gas (Last task)

How to Run

  1. Clone the Repository: Clone the git repository to your local machine.
  2. Install Dependencies: Run yarn to install required dependencies.
  3. Testing: Execute unit tests with yarn test to verify functionality and gas usage.
  4. Gas Reporting: The gas usage can be seen using the Hardhat gas reporter. Make sure to have it configured in your Hardhat setup.

Screenshot

screenshot of Gas Reporter

Additional Information

  • License: MIT
  • Author: @dadogg80

obol_labs's People

Contributors

dadogg80 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.