/Smart-Intermediate-Representation

A brand-new multi-scenarios smart contract compiler framework

Primary LanguageRustApache License 2.0Apache-2.0

The Smart Intermediate Representation

Release Issues Apache License

The Smart Intermediate Representation(short for IR) project is a new compiler framework intended for smart contract development, which is mainly inspired by LLVM, MLIR and Solidity/Yul. The compiler's goals are:

  • Trust and Security
  • Rollup Friendly
  • AI Friendly
  • High Performance and Low Gas Cost

Table of Contents

Background

Since the circulation of Blockchain and Smart Contracts, there have been many incidents of exploitation. These incidents are mainly caused by attacks on unsafe smart contracts such as reentrancy issues, and compiler bugs. In the existing cases, it is difficult to investigate or locate once the attack occurs. Most safe/secure cases also require 3rd-party auditing which is very costly.

Meanwhile, to wring the most performance out of a regular gas allowance, or something else. It's important to optimize both on-chain and off-chain scenarios.

Currently, we propose a universal technical solution to be adapted to any programming language to help blockchain platform/developer make their smart contract safer, high performance and multi-scenario compatibility.

Installation

Instructions about how to build and install the Smart Intermediate Representation compiler can be found in the Development Guide

Quick Start

Example

Here is a "Hello World" hand-written program with debug information in the IR:

module_name = "HelloWorld"
contract HelloWorld {
    state {
    }
    pub fn HelloWorld.HelloWorld.init()  {
        0:
            ret()
    }

    pub fn HelloWorld.HelloWorld.greeting() -> str {
        1:
            call(@ir.builtin.print("hello": str, ) -> void, )
            ret("Hello world!": str, )
    }

}

For more examples of IR textual format programs, you can see IR Example

Fetch the Docker Image and Build a Test IR Program

docker run smartir/cli:latest ir_cli build sir/example/hello_world.ir

Documentation

The IR Specification document is here

Roadmap

📢 NOTE: This roadmap is tentative, it will be adjusted at any time

The IR has a high level of compatibility with many blockchains. Here is a brief description of what we envision for the next versions.

V0.1

Feature Status Show Case
Support Solidity/Yul for Ethereum-Compatible In progress Yul to IR
Support IR-AI-based Intent Consistent Analysis In progress AI Intent
Provide a default high-level frontend language In progress -
Enhance Runtime Performance and Lowering Gas Cost In progress -
Support Formal Verification via Static Prover In progress -
Support ZKP by Abstract Circuit IR Not started -
Provide User-Defined Frontend guide Not started -
Provide Solidity -> WASM-based Layer 2 porting guide Not started -
Provide a default optimized VM based on wasmtime Not started -

Contribution

The IR is still under development. Contributions are always welcome. Please follow the Contributing Guide if you want to make a new feature for IR.

Community

wechat group

dingtalk group

License

Apache 2.0