Skip to main content

clvm_tools_rs

GitHub Coverage Status Build Crate Build Wheels

PyPI Crates.io

Theory of operation of the modern compiler: ./HOW_CHIALISP_IS_COMPILED.md

This repo can be installed via cargo

cargo install clvm_tools_rs

or via pip

pip install clvm_tools_rs@git+https://github.com/Chia-Network/clvm_tools_rs.git@e17412032aa7d3b8b1d1f931893fb5802eee626a

Note: pip installs a subset of the tools installed by cargo, including brun, run, opc and opd.

The most current version of the language is in the nightly branch:

[nightly](https://github.com/Chia-Network/clvm_tools_rs/tree/nightly)

To install from a specific branch:

cargo install --no-default-features --git 'https://github.com/Chia-Network/clvm_tools_rs' --branch nightly

To install a git checkout into your current python environment (must be in some kind of venv or conda environment):

git clone https://github.com/Chia-Network/clvm_tools_rs
cd clvm_tools_rs
maturin develop

Install from PYPI:

pip install -i https://pypi.chia.net/nightlies/ clvm_tools_rs

Most people still compile chialisp via python. One way to set up compilation in that way is like this:

import json
from clvm_tools_rs import compile_clvm

def compile_module_with_symbols(include_paths,source):
    path_obj = Path(source)
    file_path = path_obj.parent
    file_stem = path_obj.stem
    target_file = file_path / (file_stem + ".clvm.hex")
    sym_file = file_path / (file_stem + ".sym")
    compile_result = compile_clvm(source, str(target_file.absolute()), include_paths, True)
    symbols = compile_result['symbols']
    if len(symbols) != 0:
        with open(str(sym_file.absolute()),'w') as symfile:
            symfile.write(json.dumps(symbols))

The command line tools provided:

- run -- Compiles CLVM code from chialisp

Most commonly, you'll compile chialisp like this:

  ./target/debug/run -O -i include_dir chialisp.clsp

'run' outputs the code resulting from compiling the program, or an error.

- repl -- Accepts chialisp forms and expressions and produces results
          interactively.
          
Run like:

  ./target/debug/repl
  
Example session:

>>> (defmacro assert items
   (if (r items)
       (list if (f items) (c assert (r items)) (q . (x)))
     (f items)
     )
   )
(q)
>>> (assert 1 1 "hello")
(q . hello)
>>> (assert 1 0 "bye")
failed: CompileErr(Srcloc { file: "*macros*", line: 2, col: 26, until: Some(Until { line: 2, col: 82 }) }, "clvm raise in (8) (())")
>>> 

- cldb -- Stepwise run chialisp programs with program readable yaml output.

  ./target/debug/cldb '(mod (X) (x X))' '(4)'
  ---
  - Arguments: (() (4))
    Operator: "4"
    Operator-Location: "*command*(1):11"
    Result-Location: "*command*(1):11"
    Row: "0"
    Value: (() 4)
  - Env: "4"
    Env-Args: ()
    Operator: "2"
    Operator-Location: "*command*(1):11"
    Result-Location: "*command*(1):13"
    Row: "1"
    Value: "4"
  - Arguments: (4)
    Failure: clvm raise in (8 5) (() 4)
    Failure-Location: "*command*(1):11"
    Operator: "8"
    Operator-Location: "*command*(1):13"

- brun -- Runs a "binary" program.  Instead of serving as a chialisp
  compiler, instead runs clvm programs.

As 'brun' from the python code:

$ ./target/debug/run '(mod (X) (defun fact (N X) (if (> 2 X) N (fact (* X N) (- X 1)))) (fact 1 X))'
(a (q 2 2 (c 2 (c (q . 1) (c 5 ())))) (c (q 2 (i (> (q . 2) 11) (q . 5) (q 2 2 (c 2 (c (* 11 5) (c (- 11 (q . 1)) ()))))) 1) 1))
$ ./target/debug/brun '(a (q 2 2 (c 2 (c (q . 1) (c 5 ())))) (c (q 2 (i (> (q . 2) 11) (q . 5) (q 2 2 (c 2 (c (* 11 5) (c (- 11 (q . 1)) ()))))) 1) 1))' '(5)'
120

- opc -- crush clvm s-expression form to hex.

As 'opc' from the python code.

opc '(a (q 2 2 (c 2 (c (q . 1) (c 5 ())))) (c (q 2 (i (> (q . 2) 11) (q . 5) (q 2 2 (c 2 (c (* 11 5) (c (- 11 (q . 1)) ()))))) 1) 1))'
ff02ffff01ff02ff02ffff04ff02ffff04ffff0101ffff04ff05ff8080808080ffff04ffff01ff02ffff03ffff15ffff0102ff0b80ffff0105ffff01ff02ff02ffff04ff02ffff04ffff12ff0bff0580ffff04ffff11ff0bffff010180ff808080808080ff0180ff018080

- opd -- disassemble hex to s-expression form.

As 'opd' from the python code.

opd 'ff02ffff01ff02ff02ffff04ff02ffff04ffff0101ffff04ff05ff8080808080ffff04ffff01ff02ffff03ffff15ffff0102ff0b80ffff0105ffff01ff02ff02ffff04ff02ffff04ffff12ff0bff0580ffff04ffff11ff0bffff010180ff808080808080ff0180ff018080'
(a (q 2 2 (c 2 (c (q . 1) (c 5 ())))) (c (q 2 (i (> (q . 2) 11) (q . 5) (q 2 2 (c 2 (c (* 11 5) (c (- 11 (q . 1)) ()))))) 1) 1))

History

This is a second-hand port of chia's clvm tools to rust via the work of ChiaMineJP porting to typescript. This would have been a lot harder to get to where it is without prior work mapping out the types of various semi-dynamic things (thanks, ChiaMineJP).

Some reasons for doing this are:

  • Chia switched the clvm implementation to rust: clvm_rs, and this code may both pick up speed and track clvm better being in the same language.

  • I wrote a new compiler with a simpler, less intricate structure that should be easier to improve and verify in the future in ocaml: ochialisp.

  • Also it's faster even in this unoptimized form.

All acceptance tests i've brought over so far work, and more are being added. As of now, I'm not aware of anything that shouldn't be authentic when running these command line tools from clvm_tools in their equivalents in this repository

  • opc

  • opd

  • run

  • brun

  • repl

argparse was ported to javascript and I believe I have faithfully reproduced it as it is used in cmds, so command line parsing should work similarly in all three versions.

The directory structure is expected to be:

src/classic  <-- any ported code with heritage pointing back to
                 the original chia repo.
                
src/compiler <-- a newer compiler (ochialisp) with a simpler
                 structure.  Select new style compilation by
                 including a `(include *standard-cl-21*)`
                 form in your toplevel `mod` form.

Mac M1

Use cargo build --no-default-features due to differences in how mac m1 and other platforms handle python extensions.

Use with chia-blockchain

# Activate your venv, then
$ maturin develop --release

Release files for clvm-tools-rs 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for clvm-tools-rs 0.4.0
File Size Uploaded
clvm_tools_rs-0.4.0.tar.gz 552.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for clvm-tools-rs 0.4.0
File
clvm_tools_rs-0.4.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
clvm_tools_rs-0.4.0-cp39-abi3-musllinux_1_1_x86_64.whl CPython 3.9 abi3 Linux musl 1.1+ x86-64 Details
clvm_tools_rs-0.4.0-cp39-abi3-manylinux_2_28_x86_64.whl CPython 3.9 abi3 Linux glibc 2.28+ x86-64 Details
clvm_tools_rs-0.4.0-cp39-abi3-manylinux_2_28_aarch64.whl CPython 3.9 abi3 Linux glibc 2.28+ ARM64 Details
clvm_tools_rs-0.4.0-cp39-abi3-macosx_13_0_x86_64.whl CPython 3.9 abi3 macOS 13.0+ x86-64 Details
clvm_tools_rs-0.4.0-cp39-abi3-macosx_13_0_arm64.whl CPython 3.9 abi3 macOS 13.0+ ARM64 Details

Total release size: 9.2 MB

Release files / clvm_tools_rs-0.4.0.tar.gz

Download URL clvm_tools_rs-0.4.0.tar.gz
Size 552.6 kB
Tags Source
SHA-256 checksum
How to use checksums
81860b64bb0a67ec8b471d45632a2809c462356eacfbe3c2ccd9a53d9c4798dd
BLAKE2b-256 checksum
How to use checksums
6e9c291e2a56057a2750581c1f8a2795ccbecfd8213a48879ebbbc71c81b5d0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 31, 2025.

Transparency log

Release files / clvm_tools_rs-0.4.0-cp39-abi3-win_amd64.whl

Download URL clvm_tools_rs-0.4.0-cp39-abi3-win_amd64.whl
Size 1.4 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
759fd851dfe95d23ef7192c4a4c306de66230db703873d50d5d32e3040cfdf53
BLAKE2b-256 checksum
How to use checksums
55a30449785c7fd099b82999c3bf697db42c573557b53111295f13cbc9be714a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 31, 2025.

Transparency log

Release files / clvm_tools_rs-0.4.0-cp39-abi3-musllinux_1_1_x86_64.whl

Download URL clvm_tools_rs-0.4.0-cp39-abi3-musllinux_1_1_x86_64.whl
Size 1.5 MB
Tags CPython 3.9 Linux musl 1.1+ x86-64 abi3
SHA-256 checksum
How to use checksums
5c469dfa29ae9936c53af575360025a1115d88bfc46f25b9ac1eabb2031dd1ce
BLAKE2b-256 checksum
How to use checksums
866ee631cbae5b77e206403339f74ad3eb88de0c3b33ea74fec3901a03ebe8bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 31, 2025.

Transparency log

Release files / clvm_tools_rs-0.4.0-cp39-abi3-manylinux_2_28_x86_64.whl

Download URL clvm_tools_rs-0.4.0-cp39-abi3-manylinux_2_28_x86_64.whl
Size 1.5 MB
Tags CPython 3.9 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
3e8ff1aa203a8aa876391d72d2527af0980114a99b9ddbf2230b3ca4ff17ded3
BLAKE2b-256 checksum
How to use checksums
2b66ad16ffa16a2274f015f3752ed1ab3a89c493e33b10c6d9677b372450be48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 31, 2025.

Transparency log

Release files / clvm_tools_rs-0.4.0-cp39-abi3-manylinux_2_28_aarch64.whl

Download URL clvm_tools_rs-0.4.0-cp39-abi3-manylinux_2_28_aarch64.whl
Size 1.5 MB
Tags CPython 3.9 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
82369052c2bb3a90df6120e8679d48fb2d9a546355be4acd73ebb0d3304b1726
BLAKE2b-256 checksum
How to use checksums
5ae06d4b9c9f6b317098aed246e6e9f1b5825f5c3fab72f852441bbdd11219c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 31, 2025.

Transparency log

Release files / clvm_tools_rs-0.4.0-cp39-abi3-macosx_13_0_x86_64.whl

Download URL clvm_tools_rs-0.4.0-cp39-abi3-macosx_13_0_x86_64.whl
Size 1.4 MB
Tags CPython 3.9 abi3 macOS 13.0+ x86-64
SHA-256 checksum
How to use checksums
78a39bd07c093e85c93924d67b5847155bf6c52fe8d1510a8a8cf11de3bbbd32
BLAKE2b-256 checksum
How to use checksums
6f2a25eefc4f8f12ad9f0864095ec52c9b475feae9ba79054c728c024001183f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 31, 2025.

Transparency log

Release files / clvm_tools_rs-0.4.0-cp39-abi3-macosx_13_0_arm64.whl

Download URL clvm_tools_rs-0.4.0-cp39-abi3-macosx_13_0_arm64.whl
Size 1.3 MB
Tags CPython 3.9 abi3 macOS 13.0+ ARM64
SHA-256 checksum
How to use checksums
4f2973b5e31c5844857757f9365881cbe698f578add5536a7bca325231df655c
BLAKE2b-256 checksum
How to use checksums
dc95de14a0b38c833c643868d48e27a870d85bc180b3de1568cdd69e980c3d2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 31, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.4.0 This release

7 release files

0.3.0

7 release files

0.2.0

7 release files

0.1.48

7 release files

0.1.45

7 release files

0.1.44

6 release files

0.1.43

6 release files

0.1.41

6 release files

0.1.39

6 release files

0.1.37

6 release files

0.1.36

4 release files

0.1.33

7 release files

0.1.31

8 release files

0.1.29

7 release files

0.1.28

7 release files

0.1.25

7 release files

0.1.21

7 release files

0.1.20

7 release files

0.1.17

7 release files

0.1.16

7 release files

0.1.14

7 release files

0.1.13

7 release files

0.1.9

5 release files

0.1.8

5 release files

0.1.7

5 release files

0.1.6

5 release files

0.1.5

3 release files

0.1.4

3 release files

0.1.3

3 release files

0.1.2

3 release files

0.1.1

3 release files

0.1.0

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page