Moxzi alpha — a Motoko compiler written in Motoko, and the runtimes to go with it

moxzi alpha — a Motoko compiler written in Motoko, and the runtimes to go with it

 ░░░▒▒▒▒▒░▒░░░▒░░░░░░░░░░░░▒▒▓   ░▒ ░  ▓ █▓▒  ░░ ▒▒▒░░░░░▒▒▒░░░▒▒▒░░░░░░░░░░░░▒ 
 ░░░░▒░▒░░▒▒▒░░▒░░░░░░░░░░░░▒  ░░   ▒▒▓▒    ▒▓░▒▒░▒▒░▒░░░░▒▒▒▒▒░▒▒░░▒░░░░░░░░▒▒ 
 ░░░░                    ▒░▒    ░░▒░▒▒▒▒▒▓▓▒▒▒▒ ▒  ▓▒▒░░░░▒▒▒▒▒▒▒▒▒▒▒░░░░░░░▒▒▒ 
 ▒▒▒░  We hear you like  ▒▒░ ░░░░░░░▒▒▒▒░▒▒▒▒▒▒ █░ ▒▒▒░░▒░▒▒▒▒░░▒▒▒▒▒▒▒▒▒░░░▒▒▒ 
 ▒░▒▒  motoko, so we put ░▒░ ░░░░░░░░░▒▒▒▒▒▒▒▒▒▒  ▓ ▓▒░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░▒▒▒ 
 ▒░▒░  a motoko compiler ░▒░  ░  ░░░░▒░░░▒▓▒▒▒▒▒▓█  ▓▒░░░▒▒▒▒▒░▒▒▒░▒▒▒▒▒▒▒▒░▒▒▒ 
 ▒░░░  in your motoko so ░▒░ ░░░▒░▒░▓▒ ▓░░  ░░▒▒▒▓░▒░▒▒▒░▒▒▒▒▒░▒▒▒░▒▒▒▒▒▒▒▒▒▒▒▒ 
 ▒▒░░  so you can motoko ▒▒▒ ░    ░░░░▒░░▒▓▓▓▒▒▒▒▒░░▒▒▒░░░░▒▒▒▒▒▒▒▒░▒▒▒▒▒▒▒▒▒▒▒ 
 ░░░░  while you motoko! ▒▒▓ ░░▒▒░░░  ▓▒    ░▒▒▒▒▒░▒▓▒▒▒▒▒░▒▒░░▒▒▒▒░░▒▒▒▒▒▒▒▒▒▒ 
 ▒░░▒                    ░░▒▓    ░░▒  ▒▒▓▒▒▓▒▒▒▒▒▒░░▒▒▒▒▒▒▒▒▒░░▒▒▒▒▒▒▒▒▒▒▒▒▒░░▒ 
 ▒░▒▒░░░▒▒▒▒░░▒▒▒░░░░▒▒▒░░░▒▓▒ ░▒▒▒░ ░▒▒▒▒▒░ ▒▒▓▒▒▒░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 
 ▒░░▒▒░░░▒▒▒ -xzibit (maybe)▒▓ ░▒▒░░▒▓▓█▓░▒▓▓░ ░░░▒░▓▒▒▒▒▒▒▒▒▒▒░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 
 ▒▒░░░░░░▒▒▒░░░▒▒▒▒░░▒▒▒▒▒░░░▓  ░░░      ░▒▒▒░░░░▒▒░ ▒▓█████▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▒ 
 ▒▒░░░▒░░▒▒▒░░░▒▒▒▒░░░░▒▒▒▒░░▒▓  ░ ░░░░░░░░█ ░ ░░░ ░▒         ▒▓████▓▓▒▒░░▒▒▒▒▒ 
 ░░░░░░░░░▒▒░░░▒▒▒▒▒░░░░░░▒▒░▒▒▓ ░░  ░▓█▓█▒░▓▓▓░ ░ ▒▓▓               ▒████▓▒▒▒▒ 
 ░░▒░░░▒░▒░▒░░░▒▒▒░░░░░░▒▒▒▓█▓▒█▓ ░░░░░░░░▒▒▒▒▒ ░░░▒░█                    ░▓█▓▓ 
 ░░░▒▒░░░░░▒░▒░▒▒▒▒▒░▒▒▓█▓▒          ░░   ░▒▒▓░ ░░▒▒░█               ░        ░ 
 ░░▒▒▒▒░░░░▒▒░░░▒▓████            ░░  ░░▒▓▒▒░  ░▒▒▒▓ █      ░       ░           
 ░░░▒░▒░░▒░░▒▒▒██▒                ▒ ░░       ░░░░▒░  █              ░           
 ▒▒░░░░▒▒░▒▒▒▓░                   █   ░░░░░░░░       █              ░           
 ▒░▒▒░░░░▒▓▓                      █                 ██              ░           
 ▒▒░░▒░░░▓                        █▒                ██              ░           
                                                    ░                           

Today we’re releasing the first public alpha of moxzi (0.1.0-alpha.1): a self-hosted
Motoko toolchain. The compiler is written in Motoko and compiled to WebAssembly — by
itself — and the same wasm runs in four places:

  • moxzi — a local CLI. moxzi build hello.mo in about 0.69s, no OCaml toolchain,
    no Nix.
  • On-chain builder — the same compiler deployed as a canister. moxzi build --remote
    escrows ICP escrows 3× what the compile estimated cost is, and
    refunds the difference after compile.
  • moxzid — a server that hosts Motoko actors off-chain with IC compatible semantics: one
    message at a time, traps roll back, timers, upgrades that keep state, cycles as a real
    budget, inter-actor calls, HTTPS outcalls, crash durability.
  • moxzi-web — the same runtime in a browser tab. Install actors, call them through
    the idlFactory dfx generate already writes, persist to IndexedDB.

Why it exists

Two reasons.

Trustless builds. Today, “this canister is the code I published” is a claim you make
about your laptop. If the compiler is itself a canister, a build becomes on-chain,
reproducible, and auditable end to end — the bytes were produced by a compiler anyone can
inspect, from sources anyone can hash. Every artifact moxzi emits names the compiler that
made it, by hash.

Motoko off the IC. A Motoko actor is a good programming model on its own —
transactional turns, durable state, no ORM. moxzid and moxzi-web let you run one on a
server or in a page, then deploy the same bytes to mainnet when you need consensus.

…more details

The thing binding the four together is byte identity and behavioral identity, gated in CI:

  • The compiler self-compiles on-chain to a byte-identical fixed point under mainnet’s
    real limits (40B instructions/message, 6 GiB heap). Most recent run: 169 files,
    7,650,739 B of source in, 5,652,432 B of wasm out, 2,379 messages, ~1 hour of block
    time, identical to the local build.
  • 221 corpus programs compile byte-identically across independent compiler builds.
  • 149 programs behave identically in the browser runtime and the native one — and the
    native runtime was validated against a real replica, so browser == native == replica.
  • The compiler compiles inside a Chrome tab, byte-identical to a native build.
  • moxzid survives kill -9 by snapshot and by write-ahead-log replay, proven by a
    gate, not a design note.

make alpha-check runs all of it — 60+ gates.

Language compatibility

moxzi began as a port of moc 1.8.2 and now matches 1.14.1:

Some limits:

  • No certificates off-chain. A certificate is a subnet threshold signature; there is no
    subnet in a server process or a tab, and a forged one makes no sense. So
    @dfinity/agent’s Actor is unsupported (generated idlFactorys are), and
    certified-data patterns need the real IC.
  • Browser metering is opt-in. V8 has no fuel, so moxzi-web rewrites the module to
    count its own instructions — worth it for untrusted code, off by default.
  • moxzid is single-node, with one shared bearer token; TLS belongs in your reverse
    proxy.
  • On-chain builds serialize per canister, and canister operators can read uploaded source
    (mops-tag builds upload nothing).

License

Business Source License 1.1 — source-available, free for non-commercial use and for
commercial development, testing and evaluation. Commercial production use and competing
hosted offerings need a commercial license. Each released version converts to
Apache-2.0 four years after release. Not OSI open source yet. The goal is to accelerate this, but we need a funded supporting organization. ICDevs.org stands ready to take it on but needs a permanent endowment to provide long-term support. see: https://icdevs.org/donations.html

Try it

curl -fsSL https://moxzi.ai/install.sh | sh

echo 'persistent actor { public query func greet(n : Text) : async Text { "Hello, " # n # "!" } };' > hello.mo
moxzi build hello.mo -o hello.wasm

That wasm deploys to the IC as-is, runs under moxzid, and runs in a browser via
moxzi-web. Same bytes, same behavior.

In a browser

npm install moxzi-web @dfinity/candid @dfinity/principal
import * as glue from 'moxzi-web/runtime';
import { Moxzi } from 'moxzi-web';
import { indexedDbStore } from 'moxzi-web/storage';
import { idlFactory } from './declarations/greeter/greeter.did.js'; // what dfx generate wrote

const moxzi = await Moxzi.start({ glue, store: await indexedDbStore('my-app'), autosave: true });
const greeter = await moxzi.install({ name: 'greeter', wasm: '/greeter.wasm', idlFactory });

await greeter.greet('world');   // "Hello, world!"
await greeter.visitors();       // 2n — a candid nat is a BigInt, as agent-js users expect

install means make sure this actor exists: first visit installs, a return visit
restores from IndexedDB — including actors your actors spawned. Upgrades keep state.
Moxzi.start({ worker: true, deadlineMs: 5000, http: true }) adds a killable message
deadline and HTTPS outcalls.

If you code with an agent

The whole platform ships as agent-readable skills — one per product, in the standard
SKILL.md layout. Point your agent at the router skill and it fetches the rest as needed:

curl --create-dirs -o .claude/skills/moxzi/SKILL.md https://moxzi.ai/skills/moxzi.md

Browse them at moxzi.ai/skillsmoxzi-cli,
moxzid-server, moxzi-web, moxzi-onchain-builds, each with real commands, real
output shapes, and an error → cause → fix table. They’re versioned in the same repo as
the code they describe, so an agent building against moxzi isn’t working from whatever
it happened to be trained on.

Docs at moxzi.ai. Bug reports and disagreements very welcome.

and this works, reliably? If so this is quite possibly the best thing I’ve seen for the IC, ever.

My understanding was that this was far away from being plausible.

If a single onchain compiler canister has a conventional reproducible build and becomes widely ‘known’, verified and therefore highly trusted, then it can sign canisters that itself compiles, coupling their build hash and source code with a verification certificate. This avoids the need for people to have to build canisters before they can confidently review the source code (that’s a lot of effort and in my opinion a huge blocker).

Are you able to share more details about this on-chain compiler? Did you run into any challenges with it? What’s the cycles burn rate like? What do you think about blackholing it at some point?

I’d love to help support a blackholed on-chain Motoko compiler with an immutable perpetual cycles endowment. I would heavily use such a canister.

Looking forward to hearing more about this :folded_hands:

As a side note, and why I’m very excited about this - I was planning to start work soon on an on-chain scripting language runtime, so that the code that’s running can be reviewed without ever needing to perform a reproducible build - and also so that ‘chain of thought consensus’ LLMs mediated on the IC could actually start building and modifying their own canisters all onchain, autonomously.

If this can instead by done with Motoko it will get rid of a whole lot of work that I will no longer have to do :heart_eyes:

Please help us promote and get the word out: https://x.com/afat/status/2094393509994205489

And none of this would have been possible without the amazing motoko team giving us this language and the motoko community building in the shadows over all these years: https://moxzi.ai/docs/reference/acknowledgements/

(6) Jupiter-Faucet on X: “The importance of Moxzi for the IC cannot be understated! Why? 1. Canisters that you no longer need to perform build verification on before reading the source code (the Moxzi certificate proves source authenticity) 2. On-chain LLMs (or frontier LLMs mediated on-chain) can now” / X

Done!

I have some more thoughts - @icpp, how much effort do you think it would take to put together an ONICAI demonstration where the onchain LLM creates a simple Hello World Motoko canister, writing, building and deploying it all fully on-chain?

The compiler on chain has compiled the compiler itself(a massive project) and the ethegent evm(an even more massive project). Can I promise it is bullet proof. Nope. It is 100% alpha…but it mostly work and works from some massive motoko projects.

Well…let’s put it this way. I thought I was finished in late June and then the motoko team mentioned something about ‘byte parity’ and here we are on August 31st. :laughing:

…yes…the plan is to integrate into AstroFlora with ICRC-118/120 support so that you have on-chain compiled, verified wasms ready to deploy and manage…interest pending(interest means financial support). See: https://forum.dfinity.org/t/icrc-105-and-its-seven-cousins/42596. Will probably start off with ICRC-137 governance and them move to whatever makes sense: https://forum.dfinity.org/t/anti-dao-pre-dao-daoless-icrc-137-veto-based-governance/58696

There are a ton of docs at https://moxzi.ai/docs/ and the canister is live at xcn6l-iqaaa-aaaai-raq6q-cai. The cli will take care of most things for you so you don’t have to mess with it directly.

Beautiful, thank you :folded_hands: I’ll start digging into this soon once I’m finished with what I’m currently building (perhaps the last project I build in Rust)

Did you get written consent from CaffeineLabs for RIVVIR Tech LLC ?

So is the plan to open source?

If I understand correctly, moxzi lets you verify motoko canister builds but you can’t verify moxzi itself? Maybe I am misunderstanding something, I like the concept though.

Everything it uses is Apache 2.0 and should be properly attributed in the source/release. I need to double check the release.

Yes, that is the plan. I just need to arrange/raise long term support.

So essentially the shortcoming with pocket IC is that you need to have an off-chain CI/CD for build hash verification.

Are there other blockers with pocket IC worth knowing that moxzi would solve?

I wouldn’t say that there are shortcomings with pocket-ic. It is the go to test platform for IC projects. If you want to test your IC hotness, you need pocket-ic. T-ecdsa/vetkeys/subnet simulation - moxzi does none of that. It just compiles the code into bytes that can use those things provided by the IC…so you’d inject your actor into pocket-ic to test just like you would with moc. For the IC, the thing that moxzi would get you would be the ability to upload your code and have it compile onchain. This gives two superpowers:

1 . You don’t have to download your component’s source and compile it yourself to trust that the actor you are deploying is the same as the trusted source. This isn’t necessarily a superpower because you can compare hashes, but it gets rid of the annoyances of having to have the same mops, same moc, same platform, etc.
2. Your canisters/sns can/could upgrade their own code. Traditionally, when you want to roll out new code you need folks to confirm your wasm hash via a build and then give a thumbs up. With moxzi you can just read the code and know tht it is going to get compiled properly.

Moxzi uses pocket-ic extensively to prove our on-chain compiles function the same as the same programs compiled with moc.

To rephrase your question “Are there other blockers with moc worth knowing that moxzi would solve?” The straightforward answer to that question is that “it allows you to do a verified compile on-chain”. Moc is great and actually a bit faster because it doesn’t need a wasm runtime and need a bunch of multi-round hoop jumping. The second answer would be the extra sauce added to run motoko actors(They aren’t really canisters without the IC magic, but they’re close) either on a server instance or in a web tab. This is interesting for applications where running on-chain just isn’t interesting, or might be interesting but not until you’ve proven product/market fit and economic viability. Or when you want common code running on-chain and off-chain to keep code breadth less complex(ie run reports off-chain using the same components that run on-chain).

Our Knights & Dragons demo already kind of does this: https://moxzi.ai/demos/knights.html. The knights ask an LLM to make them smarter so they can learn how to kill the dragons. You can plug in a anthropic code and it will use anthropic to do that, but you could try with onicai…and move the demo on chain(right now it does it all in a web tab).

Awesome stuff. It looks like it’s not open source yet. What’s holding this back? Why not open source it even as a work in progress?

I think there is a product fit, so much so that probably DFINITY should have made an on-chain compiler a long time ago, but it is understandably complex and not near as profitable and marketable as a DEX (if it is even profitable at all).

Another upside of this is that it might be more portable than moc. I’ve been waiting for someone to make a browser extension where if there is a standard for canisters to expose their source code files, then one could verify frontend/backend from inside a browser extension with the files that were provided which would generate green checks. When build hash changes, green check would disappear. I wonder if Moxzi being more WASM adjacent would be better suited for a job like this than moc which is more cli adjacent. Also would be a great way to test a lot of different scenarios and promote Motoko over Rust.

But ngl, unfortunately I feel like licensing is going to be difficult, since the nature of this tool is in spirit very open source to start with.

  1. Been busy with the release so I need to do some cleaning.
  2. I need to figure out how to support development long-term. I’ve built a lot of stuff for the IC “for free” and I really need to figure out a method to provide long-term support. The motoko team is on fire and releasing cool stuff almost every week. If I have any hope of keeping up I need some enumeration. The goal is to hand it to ICDevs.org and accelerate the open-source license but that requires a more substantial commitment from someone. People can just give ICP, use the ICDV miner where you keep your principal but donate maturity to the non-profit, or subscribe and cancel if you don’t think it is worth it. There are a bunch of avenues available, but not much activity.

The current license I have set up is the BUSL, which opens up the code for non-commercial use and sets a 4-year clock on switching to Apache. Would love to accelerate that if I know I can maintain support(much cheaper to do these days, but still not free).

Why not just buy and stake more ICP and make the code open source so that you don’t need to be responsible for maintaining it, and so that progress can be made much faster, and so that the ICP network benefits, and you benefit because you bought and staked more ICP.

:nerd_face:


In terms of maintenance, my suggestion would be to open source and deploy an immutable compiler canister that is for a specific version of Motoko. Every time there’s a new language version that’s incompatible with the compiler, you or someone else can improve the compiler and deploy a new version.

If instead the compiler canister keeps getting upgraded by someone then the trust burden starts entering into the picture again.


As mentioned I was going to work on a project very soon with similar goals - but now that I know that an on-chain Motoko compiler is possible it’s something I would work on myself and open source (unless someone else open sources their version first).

You sound super delulu rn. Icp psychosis. Ai psychosis.

Do they take the tears of children who get nothing for Christmas in exchange for these ICPs?