npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sslc

v0.1.12

Published

cli tool to check Solidity storage memory layout of structs for inefficiencies

Downloads

18

Readme

Solidity Storage Layout Checker

License Version Download

Given some Solidity smart contract(s), extract all structs and check if their members could be laid out more efficient (=occupy less storage slots).

Timeout

If the number of struct members is sufficiently high, the algorithm to find the most efficient layout will run "indefinitely". To guard against this, there is a default 10 second timeout to calculate the most efficient layout of any given struct. If the timeout is exceeded the calculation will exit and give the "current best slot count" as well as info that the timeout was reached. This timeout can be customized using the -t <secs> argument.

Dependencies

Makes use of solidity-parser-antlr to parse Solidity files.

Usage

usage: sslc [-h] [-v] -f path [path ...] [-oj path] [-ot path]

Solidity storage layout checker

Optional arguments:
  -h, --help          Show this help message and exit.
  -v, --version       Show program's version number and exit.
  -f path [path ...]  input solidity file(s), supports glob
  -oj path            write output to JSON file
  -ot path            write output to text file
  -t secs             brute force timeout, default 10s

without install

npx sslc -f ~/my-solidity-project/contracts/*.sol

with install

npm i -g sslc
sslc -f ~/my-solidity-project/contracts/*.sol

Output

The script will print text output using Solidity syntax to stdout. It is also possible to save the text output to a file and/or save JSON output to a file.

Text output

struct MyFirstStruct { // file: SomeContract.sol | contract: SomeContract

  uint8 myFirstVar; // bytes: 1
  //---------- end of slot | bytes taken: 1 | bytes free: 31
  
  bytes32[] mySecondVar; // bytes: 32
  //---------- end of slot | bytes taken: 32 | bytes free: 0
  
  bool myThirdVar; // bytes: 1
  //---------- end of slot | bytes taken: 1 | bytes free: 31
  
  uint256 myFourthVar; // bytes: 32
  //---------- end of slot | bytes taken: 32 | bytes free: 0
  
  bool myFourthVar; // bytes: 1
  //---------- end of slot | bytes taken: 1 | bytes free: 31
 
} // slots that can be saved = 2

struct MyParentStruct { // file: SomeOtherContract.sol | contract: ParentContract

  uint8 myFirstVar; // bytes: 1
  //---------- end of slot | bytes taken: 1 | bytes free: 31
  
  uint256 mySecondVar; // bytes: 32
  //---------- end of slot | bytes taken: 32 | bytes free: 0
  
  uint16 myThirdVar; // bytes: 2
  //---------- end of slot | bytes taken: 2 | bytes free: 30
  
} // slots that can be saved = 1

struct MyOtherStruct { // file: SomeOtherContract.sol | contract: SomeOtherContract

  uint256 myFirstVar; // bytes: 32
  //---------- end of slot | bytes taken: 32 | bytes free: 0
  
  address mySecondVar; // bytes: 20
  //---------- end of slot | bytes taken: 20 | bytes free: 12
 
} // slots that can be saved = 0

// STRUCTS THAT CAN BE OPTIMIZED
// =============================
// file: SomeContract.sol
// contract: SomeContract
// struct: MyFirstStruct
// slots saved: 2
// -----------------------------
// file: SomeOtherContract.sol
// contract: ParentContract
// struct: MyParentStruct
// slots saved: 1
// -----------------------------

JSON output

[
    {
        "file": "SomeContract.sol",
        "contract": "SomeContract",
        "struct": "MyFirstStruct",
        "slotsSaved": 2,
        "timedout": false
    },
    {
        "file": "SomeOtherContract.sol",
        "contract": "ParentContract",
        "struct": "MyParentStruct",
        "slotsSaved": 1,
        "timedout": false
    }
]

Test

npm test

TODO

  • do the same for the layout of variables of a given contract

License

MIT