Rue is a programming language I’ve been working on designing for the Chia blockchain for the last couple years.
You can visit the Rue Docs and GitHub repository for more info, but keep in mind that the language is still very unfinished, as we’ll get into later. Keep reading to learn more!
CLVM
First, let’s start off with a bit of background. The Chia blockchain has an on-chain programming environment called CLVM (the Chialisp Virtual Machine), which provides a set of low level opcodes which control the conditions under which a coin can be spent. I won’t go too into the weeds here, but will give a summary.
For example, take this program in Chialisp:
You can think of a puzzle as a function that takes in some arguments (referred to as the solution) and returns a list of conditions. In this case, the AGG_SIG_ME condition (which roughly means aggregate signature for my coin) ensures that the public key has signed off on the conditions passed into the solution.
This compiles to the following CLVM bytecode, which is what is actually used on-chain:
It’s nearly impossible to figure out what’s going on without the original source code. So that’s why we have the higher level Chialisp language with a compiler to generate this. We sort of get the best of both worlds, it’s simple and efficient to execute when compiled, and readable by us humans before compilation.
The Problem
That was a pretty simple example of Chialisp, but it can get much more complicated.
For instance, this is the simplest example that illustrates my point that I could find, from the CAT puzzle:
Lists in CLVM are made up of cons-pairs. In this case, a lineage_proof is structured like this (where f means first and r means rest, the two halves of the pair):
(f lineage_proof) = parent_parent_coin_id
(f (r lineage_proof)) = parent_inner_puzzle_hash
(f (r (r lineage_proof))) = parent_amount
So to know what this code is doing you need to know what lineage_proof is first.
Imagine if you could write code like this instead:
Sure, it’s more verbose, but with this you have the following benefits:
The syntax is more familiar if you’re coming from a language like JavaScript or Rust.
Everything is strictly typed at compile time, so you can catch errors during development instead of at runtime.
Types like LineageProof are more clearly defined, so you can refer to the fields by name instead of having to manually index them.
Enter, Rue Lang
The code above is written in a new language called Rue, which compiles directly to CLVM, just like Chialisp does. My primary goal with the language is to lower the barrier to entry to create smart coins on the Chia blockchain. I believe Rue has the potential to greatly simplify the development process, and make it less difficult to write secure code.
Like Chialisp, the language is “purely functional”, which means:
Once you declare a variable, it cannot be modified. I like to think of it more as binding a value to a name rather than making a variable, since they can’t vary.
Functions themselves are values, so they can be passed around like any other. This is known as “higher order functions”.
There are “no side effects”. If you run a program multiple times with the same input, it will always produce the same output.
However, there are a few key differences:
As of writing, Rue has a more powerful type system (in fact, by default Chialisp is completely untyped).
It has a built-in standard library of common functionality you’ll need, like conditions and tree hashing.
You can export and import symbols from other modules. This could pave the way for making a package manager for Chia.
Generally, the syntax and scoping makes code simpler and reduces the number of surprises. That said, modern Chialisp has gotten a lot better in this regard.
There’s a proper language server that has type errors, compiler warnings, syntax highlighting, and in the future features like Go To Definition.
The code produced by Rue and Chialisp are different, and currently it is not a design goal to make the outputs completely compatible with each other. However, the same program written in both languages should behave the same.
So, where are we at?
I got pretty far with implementing the compiler, and you can view the current codebase in the GitHub repo.
However, I ran into some issues when testing more complicated programs that illuminated underlying problems with the compiler’s code. The type system also still needs to be improved a bit. I haven’t completely decided whether to rewrite the compiler from the ground up or just redesign certain parts of it incrementally. But I have learned so much since I started the project that it’s tempting to start over (especially since I can’t easily resolve the current problems).
As you may know, I work at Chia Network Inc. In addition to that I also maintain Sage Wallet and the Chia Wallet SDK in my spare time, which pretty much takes up most of the free time I have. Because of this, I haven’t been able to dedicate as much time as I would like to working on Rue Lang, and it’s been left in this sort of broken state of which I can’t really recommend anyone to use it in production.
What can you do to help?
If you’ve read this far and are thinking “what is he on about”, that pretty much sums up my concern. It’s going to be difficult to find someone with the knowledge about or interest to learn all of the following:
Chialisp
The low level CLVM runtime
Rust programming
Compiler design
If you do and would like to help with the compiler directly, please reach out.
That said, if I’m being realistic I need to just find more time to work on it so that it can get done. Currently, much of my time is spent on Sage Wallet and the Wallet SDK, both of which are more approachable projects for people to contribute to. The more others can help out with the development of those projects, the more free time I have to work on Rue (and I greatly appreciate those who have already contributed).
I’m open to other ideas on how we can make this new language happen, if you have them. Open source development can be time consuming, but I believe it’s all possible, eventually.
Thanks for reading!