Skip to content

hummanta/sol-to-o1js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Solidity Compiler & Transpiler for Mina

This project aims to provide an efficient tool that can transpile smart contracts written in Solidity into Mina's contract language or directly compile them into Mina Virtual Machine bytecode/circuits, helping developers quickly deploy and verify smart contracts on the Mina blockchain.

Using solang-parser to analyze Solidity source code, we translate it into TypeScript based on the Solidity AST. Since o1js extends TypeScript, the plan is to first generate a general TypeScript AST using SWC, and then add specific o1js syntax support, such as @method, as needed. Inspired by charcoal.

Features

  • Converts Solidity code into Mina-compatible TypeScript smart contracts while preserving core logic.
  • Generates low-level bytecode or circuits executable by the Mina Virtual Machine (In Development).
  • High-performance command-line tool built with Rust, supporting custom input/output paths and target platforms.

Installation

Install via Cargo

Ensure Rust and Cargo are installed:

cargo install --path .

Or clone the repository and build manually:

git clone https://github.com/hummanta/sol-to-o1js.git
cd sol-to-o1js
cargo build --release

The executable will be located in the target/release/ directory.

Usage

1️⃣ Transpile Solidity Smart Contract to Mina Contract Language

Example Solidity Contract Square.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

contract Square {
    uint256 public num;

    constructor() {
        num = 3;
    }

    function update(uint256 square) public {
        require(square == num * num, "Square does not match current state squared");
        num = square;
    }
}

Transpilation Command

./target/release/transpiler \
    --input ./samples/Square.sol \
    --output ./target/Square.ts

Transpiled Mina Contract Square.ts

import { Field, SmartContract, state, State, method } from 'o1js';

export class Square extends SmartContract {
  @state(Field) num = State<Field>();

  init() {
    super.init();
    this.num.set(Field(3));
  }

  @method async update(square: Field) {
    const currentState = this.num.get();
    this.num.requireEquals(currentState);
    square.assertEquals(currentState.mul(currentState));
    this.num.set(square);
  }
}

2️⃣ TODO: Compile Solidity to Mina VM Bytecode / Circuits

This feature is under development. Stay tuned!

Expected Command

./target/release/compiler \
    --input ./samples/Square.sol \
    --output ./target/Square.bytecode

Expected Output

0xABEF0C10f...7F00DDE

Roadmap

  • Solidity to Mina contract language transpilation
  • Solidity to Mina VM bytecode/circuit compilation
  • Support for more complex data structures and functions
  • Integration with automated testing tools

Testing

Run tests using:

cargo test

License

This project is licensed under the Apache License 2.0.

About

Solidity Compiler & Transpiler for Mina

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published