Udemy
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
Advanced Solidity: Understanding and Optimizing Gas Costs
Rating: 4.9 out of 5(632 ratings)
3,280 students

Advanced Solidity: Understanding and Optimizing Gas Costs

Mastering the Ethereum Virtual Machine and the Solidity Compiler
Created byJeffrey Scholz
Last updated 10/2022
English
English [Auto],Korean [Auto],

What you'll learn

  • Learn how the Ethereum Virtual Machine sets the gas price
  • Learn how to improve the gas price of existing code
  • Learn how to debug execution costs for smart contracts
  • Learn what designs to avoid that lead to high execution costs

Course content

5 sections46 lectures2h 48m total length
  • Introduction2:37

    I will give you an overview of the course and make sure it is right for you.

  • Lecture 2: Calculating The Cost of an Ethereum Transfer3:04

    In this video we learn how to predict the cost of an Ethereum transfer in dollars.

  • Example Smart Contract Interactions Part 13:59

    An overview of example transaction fees for various smart contracts part 1

  • Example Smart Contract Interactions Part 21:09
  • Example Smart Contract Interactions Part 23:37

    An overview of example transaction fees for various smart contracts part 2

  • Heavy and Light Functions1:52

    We create our own example smart contract to further develop our intuition about smart contract transaction fees

  • Block Limit4:40
  • Gas Efficient Chains2:38

    Learn why gas optimization matters even on ethereum-compatible chains. Analyze gas block limits, transaction sizing, and how adoption and decentralization influence gas costs, with avalanche as an example.

  • Prerequisite: Storage Slots2:31
  • What are Opcodes5:06

    Delve into how opcodes power the Etherium computer by compiling Solidity into stack-based operations, loads, stores, and arithmetic that affect gas costs.

  • Opcode Gas Cost2:54
  • Opcode Debugging Gas Cost3:00
  • Function Selectors1:47

    Learn how function selectors in bytecode are four-byte hashes of function names, computed from exact signatures with event types, not variable names (as shown with blue, gray, green, yellow).

  • Cost of Doing Nothing: Op Codes6:08
  • Cost of Doing Nothing: Sum of Op Codes2:29
  • Cost of Doing Nothing: Transaction Data2:21

    Analyze how the data portion of a transaction drives gas costs. Zero bytes incur small increases; non-zero bytes cost 16 gas per byte, four bytes total 64 gas.

  • Cost of Doing Nothing: Memory Costs5:37
  • Non-payable Functions3:13
  • Unchecked Arithmetic Part 13:00

    Explains the unchecked block in Solidity, why it exists, and how pre-0.8 overflow and underflow could misbehave; shows how 0.8 adds checks and reverts on invalid arithmetic.

  • Unchecked Arithmetic Part 24:47

    Explore unchecked blocks, their gas savings, and the security risks of overflow and underflow; see practical use in OpenZeppelin counters and ERC-20 transfers, with gas analysis via opcodes.

  • Gas Limit and More on 21,000 Gas5:01
  • EIP 1559 Part 16:15

    Learn how EIP-1559 changes gas costs by burning the base fee, splitting fees into max priority fee per gas and max fee per gas, and adjusting base fees per block.

  • EIP 1559 Part 25:00

    Explore how EIP-1559 pricing works, clarifying max base fee, max fee per gas, and max priority fee, and show how base fees are burned and refunds or miner tips arise.

  • Solidity Optimizer6:18

Requirements

  • Basic understanding of solidity
  • Ideally, created an ERC-20 or ERC-721 token before

Description

Ever been surprised by the gas costs in a smart contract? The Ethereum Virtual Machine calculates these costs deterministically, but understanding how is a bit obscure unless you want to comb through the dense yellowpaper! This course helps you understand where every last bit of gas is coming from and the gotchas that can make transactions surprisingly expensive.

This course is for solidity developers looking to progress from beginner to advanced intermediate. Knowledge about Solidity, OpenZeppelin, and Remix is assumed. You should know how to deploy and test a smart contract, and ideally, you've created a token on the mainnet before (and experienced how expensive it can be!).

I’m the author of ERC1155D, arguably the most efficient NFT contract created. I’m here to share my learnings with you!

Some of the most enjoyable years of my life was teaching computer science at Columbia University, so I’m happy to relive those years virtually!


Topics covered include:

  • A deep dive into the solidity compiler

  • A deep dive into the Ethereum Virtual Machine

  • How to understand the output from the solidity compiler

  • How to track down wasteful computation

  • Understanding gas cost specifications

  • Techniques for improving gas costs

  • How memory, transaction data, state changes, and computational cost affect transaction cost

  • Bad designs to avoid

  • Where the Yellowpaper is wrong!

Follow me on Twitter: @jeyffre

Who this course is for:

  • Smart contract developers looking to make their smart contracts more gas efficient