Categorygithub.com/unpackdev/solgo
modulepackage
0.3.7
Repository: https://github.com/unpackdev/solgo.git
Documentation: pkg.go.dev

# README

Build Status Security Status Coverage Status Go Report Card License PkgGoDev Discord

Ethereum and Solidity Toolkit in Go: Parser and Analyzer

SolGo - a robust tool crafted in Go, designed to dissect and analyze Solidity's source code.

The parser is generated from a Solidity grammar file using Antlr, producing a lexer, parser, and listener using AntlrGo. This allows for the syntactic analysis of Solidity code, transforming it into a parse tree that offers a detailed syntactic representation of the code, allowing for intricate navigation and manipulation.

This project is ideal for those diving into data analysis, construction of robust APIs, developing advanced analysis tools, enhancing smart contract security, and anyone keen on harnessing Go for their Solidity endeavors.

Solidity Version Support

Currently, Solidity versions equal or higher to 0.6.0 are supported.

Older versions may or may not work due to changes in syntax that is not currently supported by the grammar file. In the future, we have plans to support all versions of Solidity.

Disclaimer

Please be aware that this project is still under active development. While it is approaching a state suitable for production use, there may still be undiscovered issues or limitations. Over the next few months, extensive testing will be conducted to evaluate its performance and stability. Additional tests and documentation will also be added during this phase. Additionally, most of the interfaces will stay as is, however, there could be architectural changes that may break your build in the future. I'll try to change as little as possible and notify everyone about the change in release notes.

Once I am confident that the project is fully ready for production, this disclaimer will be removed. Until then, please use the software with caution and report any potential issues or feedback to help improve its quality.

Documentation

The SolGo basic documentation is hosted on GitHub, ensuring it's always up-to-date with the latest changes and features. You can access the full documentation here.

Getting Started

Detailed examples of how to install and use this package can be found in the Usage section.

Need help?

Want to use this library but have issues, questions or just want to join the wagon and follow the ride?

You can join our Discord server.

Solidity Language Grammar

Latest Solidity language grammar higher overview and detailed description can be found here.

ANTLR Grammar

We are using grammar files that are maintained by the Solidity team. Link to the grammar files can be found here.

ANTLR Go

We are using the ANTLR4 Go runtime library to generate the parser. Repository can be found here.

Crytic Slither

We are using Slither to detect vulnerabilities in smart contracts. Repository can be found here.

Makes no sense to rewrite all of that hard work just to be written in Go. Therefore, a bit of python will not hurt. In the future we may change direction.

Features

  • Protocol Buffers: Utilizing Protocol Buffers, SolGo offers a structured data format, paving the way for enhanced analysis and facilitating a unified interface for diverse tools. Currently, it supports Go and Javascript, with plans to incorporate Rust and Python in upcoming versions.
  • Abstract Syntax Tree (AST) Generation: Package ast is equipped with a dedicated builder that crafts an Abstract Syntax Tree (AST) tailored for Solidity code.
  • Intermediate Representation (IR) Generation: From the AST, SolGo is adept at generating an Intermediate Representation (IR). ir package serves as a language-neutral depiction of the contract, encapsulating pivotal components like functions, state variables, and events, thus broadening the scope for intricate analysis and contract manipulation.
  • Control Flow Graph (CFG) Generation: Building upon the IR, SolGo provides tools for constructing and visualizing Control Flow Graphs (CFGs) of Solidity contracts, aiding in the analysis of contract execution paths and potential bottlenecks.
  • Application Binary Interface (ABI) Generation: SolGo's in-built abi package can interpret contract definitions, enabling the generation of ABI for a collective group of contracts or individual ones.
  • Opcode Tools: The opcode package in SolGo demystifies bytecode by decompiling it into opcodes. Additionally, it provides tools for the creation and visualization of opcode execution trees, granting a holistic perspective of opcode sequences in smart contracts.
  • Library Integration: SolGo is programmed to autonomously source and assimilate Solidity contracts from renowned libraries, notably OpenZeppelin. This feature enables users to seamlessly import and utilize contracts from these libraries without the need for manual integration.
  • EIP & ERC Registry: SolGo introduces a package standards exclusively for Ethereum Improvement Proposals (EIPs) and Ethereum Request for Comments (ERCs). This package streamlines interactions with diverse contract standards by encompassing functions, events, and a registry system optimized for proficient management.
  • Solidity Compiler Detection & Compilation: SolGo intelligently identifies the Solidity version employed for contract compilation. This not only streamlines the process of determining the compiler version but also equips users with the capability to seamlessly compile contracts.
  • Security Audit Package: Prioritizing security, SolGo has incorporated an audit package. This specialized package leverages Slither's sophisticated algorithms to scrutinize and pinpoint potential vulnerabilities in Solidity smart contracts, ensuring robust protection against adversarial threats.
  • Contract Bytecode Validation: Enhanced validation package ensures the integrity and authenticity of contract bytecode. By comparing the bytecode of a deployed contract with the expected bytecode generated from its source code, SolGo can detect any discrepancies or potential tampering. This feature is crucial for verifying that a deployed contract's bytecode corresponds accurately to its source code, providing an added layer of security and trust for developers and users alike.

External Projects / Extensions / Plugins

List of the projects that use SolGo:

  • {Un}pack - Solidity (Ethereum) Smart Contracts Analysis Toolchain.
  • Solidity-Gas-Optimizoor - An high performance automated tool that optimizes gas usage in Solidity smart contracts, focusing on storage and function call efficiency.

If you wish to add your repository to the list, make sure to submit new PR :)

Contributing

Contributions to SolGo are always welcome! Please visit Contributing for more information on how to get started.

License

SolGo is licensed under the Apache 2.0. See LICENSE for the full license text.

# Packages

Package abi provides tools for building and parsing Ethereum ABI (Application Binary Interface) data.
The package is designed to be flexible and adaptable to various Ethereum-compatible networks like Ethereum mainnet, Binance Smart Chain (BSC), and Polygon.
Package ast defines data structures and methods for abstract syntax tree nodes used in a specific programming language.
Package audit provides a comprehensive suite of tools for auditing smart contracts.
Package bindings abstracts the complexity of interacting with smart contracts deployed on the Ethereum blockchain and potentially other compatible networks.
Package bytecode provides tools for decoding and analyzing Ethereum contract, transaction, events, and log bytecode.
Package cfg provides structures and functions for building and manipulating control flow graphs (CFGs) of Solidity contracts.
Package clients provides tools for managing and interacting with Ethereum clients.
Package integrates various Ethereum-related functionalities including interaction with blockchain clients, fetching contract metadata from external providers such as etherscan, token discovery, bytecode validation, auditing, etc...
Package detector provides helpers for accessing solgo packages.
Package ir provides an intermediate representation for the AST of a Solidity contract.
Package metadata provides functionality for interacting with IPFS/SWARM and retrieving contract metadata.
Package observers provides tools for managing and interacting with Ethereum onchain data such as blocks, transactions, events and logs.
Package opcode offers tools for constructing and visualizing opcode execution trees, representing sequences of instructions.
No description provided by the author
No description provided by the author
Package standards provides structures and functions to represent and manipulate Ethereum Improvement Proposals (EIPs) and Ethereum standards.
Package storage provides tools for interacting with smart contract storages on the Ethereum based networks.
Package syntaxerrors provides tools for detecting and handling syntax errors in Solidity contracts.
No description provided by the author
Package tokens provides a high-level abstraction for interacting with Ethereum tokens.
No description provided by the author
Package validation provides utilities for verifying Ethereum based smart contracts.

# Functions

GetLocalSourcesPath returns the global local sources path.
New creates a new instance of SolGo.
NewParserFromSources creates a new instance of parser from a reader.
NewSourcesFromEtherScan creates a Sources from an EtherScan response.
NewSourcesFromMetadata creates a Sources from a metadata package ContractMetadata.
No description provided by the author
No description provided by the author
NewUnsortedSourcesFromEtherScan creates a Sources from an EtherScan response.
No description provided by the author
SetLocalSourcesPath sets the global local sources path.

# Constants

Predefined listener names.
Predefined listener names.
Predefined listener names.
Predefined listener names.

# Variables

No description provided by the author

# Structs

Node represents a unit of source code in Solidity with its dependencies.
Parser is a struct that encapsulates the functionality for parsing and analyzing Solidity contracts.
Sources represent a collection of SourceUnit.
SourceUnit represents a unit of source code in Solidity.

# Type aliases

ListenerName represents the name of a listener.