Code Monkey home page Code Monkey logo

sstan's Introduction

sstan Github Actions

sstan is a Solidity static analyzer specifically designed for the Code4Arena Bot Races. With the constantly changing landscape of the bot races, this design prioritizes DevX, using an Extractor pattern and macros to enable extremely quick development times when implementing new patterns. sstan comes "out of the box" with patterns to identify 50+ optimizations, vulnerabilities and QA patterns.

Table of Contents

 

Installation

First, make sure that you have Rust installed. Then you can enter the following commands in your terminal.

git clone https://github.com/0xKitsune/sstan &&
cd sstan &&
cargo install --path .

 

Usage

Now that you have sstan installed, you can use the sstan command from anywhere in your terminal. By default, sstan looks for a ./src directory and analyzes every file within the folder. If you would like to specify the directory sstan should target, you can pass the --path flag (ex. sstan --path <path_to_dir>).

In the default configuration, sstan runs analysis for every currently included optimization, vulnerability and QA pattern, however if you would like to run analysis for select patterns, you can create a .toml file for your custom configuration. You can use the default sstan.toml configuration for reference. After creating a custom .toml file, make sure to pass the --toml flag when running sstan (ex. sstan --toml <path_to_toml_file>).

Usage: sstan [OPTIONS]

Options:
  -p, --path <PATH>      Path to the root directory to analyze. The default directory is `./src`
  -o, --output <OUTPUT>  Path to the directory where the report will be written. The default directory is `./`
  -g, --git <GIT>        Github repository link for the codebase being analyzed (e.g `https://github.com/repo/blob/main`). This will create hyperlinks to line numbers within the final report.
  -t, --toml <TOML>      Path to `.toml` file containing a custom sstan configuration.
  -h, --help             Print help

 

Contributing

Check out Contributing.md for adding new features.

sstan's People

Contributors

0xkitsune avatar 0xosiris avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sstan's Issues

Discussion: `transferFrom` in contract -> approval and opens up a lot of potential vulnerabilities

When there is a transferFrom in a contract we can infer the contract has token approval in some capacity. We should have specific analysis over a contract with approval to check for low hanging vulnerabilities that might arise due to this.

A couple examples I can think of off the top of my head. There should never be any exposed swap callbacks without authentication checks on the caller. Another one would be you should never execute arbitrary calls through an unauthenticated external function. Any admin function might be vulnerable for rugging if the right constituents are met. Probably more, we should brainstorm.

Discussion: Report Format

We need to decide on how to best present the report. We could take an approach that is similar to Solstat, where it generates an .md file with a description, an example and if applicable, gas savings for each item, then listing all of the line numbers that this pertains to.

We could consider injecting snippets of the codebase into the report, but we should also be mindful that the report should be clearly communicated, specific to the report and not too lengthy.

I have also seen some people generate PDF files for the report.

We should figure out the optimal way to present the report.

For Reference:

Feat: Update parsing to read in all contracts at the same time, with some internal type to represent a graph of contracts.

We should think through what we will want to use the graph for and how it will need to be constructed.

One example is reentrancy, where we would need to know all the external functions and map a path from each function to see if it is able to be reentered. Further, we need to account for any modifiers or protected calls (ex. OnlyAdmin).

We should also account for read only reentrancy.

Another example is unprotected calls. We need to know all of the external functions in a contract, as well as which functions mutate a variable that is important to the protocol (either the contract itself or other contracts that rely on the contract). For example, this could be a variable that another contract reads as a fee, or a beneficiary address, etc.

Vuln: Unchecked arithmetic without type size requirement

Arithmetic expressions within an unchecked block need to enforce that the size of the return data does not exceed the capacity of the return type. Specifically applicable for operations increasing the capacity of the data i.e. + * ^.

Bad:

function add64x64(uint128 x, uint128 y) internal pure returns (uint128) {
        unchecked {
            uint256 answer = uint256(x) + y;
            return uint128(answer);
        }
    }

Good:

function add64x64(uint128 x, uint128 y) internal pure returns (uint128) {
        unchecked {
            uint256 answer = uint256(x) + y;
            require(answer <= MAX_64x64);
            return uint128(answer);
        }
    }

Vuln: No stale price requirement on chainlink Oracle.

Many projects use a chainlink or other oracle for on chain gas price, and token prices. For the chainlink oracle interface a call to the oracle will have call to the interface latestRoundData().

Following a call to latestRoundData() there should always be requirements to make sure the data is not stale. For Example:
Bad:

( roundId, rawPrice, , updateTime, answeredInRound ) = priceFeed.latestRoundData();

//--continue logic

Good:

( roundId, rawPrice, , updateTime, answeredInRound ) = priceFeed.latestRoundData();
require(rawPrice > 0, "Chainlink price <= 0");
require(updateTime != 0, "Incomplete round");
require(answeredInRound >= roundId, "Stale price");

I'm sure there are probably other oracles providing realtime data other than chainlink, so any other popular oracle interfaces should be included when parsing for the vulnerability.

Extractor: Primitive Extractors

PragmaExtractor
ImportExtractor
VariableExtractor
StorageVariableExtractor
ImmutableExtractor
FunctionExtractor
StructExtractor
ConstructorExtractor
EventExtractor
ErrorExtractor

Discussion: upgrades from solstat when migrating to sstan

We should document all of the changes and advanced features that we want sstan to have so that we can update our architecture accordingly, leaving the wires out for when we are ready to integrate these features.

One feature that comes to mind immediately is reading in the entire project as a whole instead of parsing and analyzing each contract one by one. This way, we can create a graph representing the contract relationships which will allow us to conduct much more complicated analysis.

Another could be some approach to fuzzing or mutation testing if not already implemented in the test suite. For example, if the test suite is in foundry, and the tests are not robust, we could also inject code to fuzz the tests where applicable and see if the protocol breaks anywhere.

Lets talk through all of the features that we want sstan to have, and coordinate from there.

Checklist

Feat: Create a test analysis

Inject fuzzing, forge coverage, do static analysis, mutation testing on test suite to give coverage and test quality.

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.