MCPcopy Index your code
hub / github.com/RareSkills/gas-puzzles

github.com/RareSkills/gas-puzzles @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
10 symbols 20 edges 11 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

RareSkills Gas Puzzles

If you want to learn about gas optimization, take the Udemy gas optimization course!

Puzzles that are ready for you

  • [x] Distribute (hard)
  • [x] Array Sum (easy)
  • [x] Mint150 (hard)
  • [x] ERC165 (low level programming required)
  • [x] Array Sort (medium)
  • [x] Security101 (easy/medium)
  • [ ] Escrow
  • [ ] EscrowV2
  • [ ] Mint
  • [ ] Presale
  • [x] Vote (easy)
  • [x] Require (easy)
  • [ ] Staking

Contributors

DO NOT COMMIT SOLUTIONS, BE SURE TO PUT ANSWERS IN contracts/contracts_optimized to ensure they fall into the .gitignore

Players

Your goal is to optimize the contracts such that they reach the target efficiency.

Rules

  • you may not change the optimizer level
  • you may not change the solidity version
  • you may refactor functionality as long as you don't break the business logic
  • you may make reasonable assumptions about what variable sizes are necessary to get things done
  • you may remove unnecessary or redundant logic (some have been intentionally added)
  • because making functions payable is a controversial optimization, you do not need to make functions payable to reach the gas target unless the function needs to be payable to fulfill its business logic

Testing

As mentioned above, optimized contracts should be created in their own sub-folder to prevent committing them publicly.

The file structure should look similar to this:

- GasPuzzles
  |_
    contracts
    |_
      contracts_optimized
    | |_
    |   ArraySum.sol
    |   Distribute.sol
    |   ..
    |   ...
    |
    ArraySum.sol
    Distribute.sol
    ..
    ...

Within the contracts that are optimized be sure to follow the following naming convention to ensure tests run smoothly:

contract OptimizedArraySum {

...

contract OptimizedDistribute {

...
npx hardhat test
npx hardhat test test/ArraySum
npx prettier --write *

Core symbols most depended-on inside this repo

convertStringToBytes32
called by 4
test/Vote.js
logGasUsage
called by 1
test/ArraySort.js
shuffleArray
called by 1
test/ERC165.js
logGasUsage
called by 1
test/Vote.js
logGasUsage
called by 1
test/Require.js
logGasUsage
called by 1
test/ArraySum.js
logGasUsage
called by 1
test/Security101.js
logGasUsage
called by 1
test/Distribute.js

Shape

Function 10

Languages

TypeScript100%

Modules by API surface

test/Vote.js2 symbols
test/Security101.js1 symbols
test/Require.js1 symbols
test/Mint150.js1 symbols
test/ERC165.js1 symbols
test/Distribute.js1 symbols
test/ArraySum.js1 symbols
test/ArraySort.js1 symbols
scripts/deploy.js1 symbols

For agents

$ claude mcp add gas-puzzles \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact