Preface
We want to be able to run (parts of) Anoma programs in/on many base environments:
- on existing blockchain VMs, such as the EVM and SVM
- on zkVMs, such as RISC0
- in the browser environment (best application distribution vector)
- on regular desktop operating systems
- on mobile operating systems (in the future)
At the moment, we do not have a single standardized low-level ISA/API that is supported in all of these environments (which are themselves quite heterogeneous). Instead, we have:
- With Galileo/APv1: “backend” application code in Solidity and Rust → RISC0 (resource logics) (runs on EVM/RISC0), “frontend” application code in a mix of Javascript and Rust → WASM (runs in the browser), “service” application code in a mix of Rust and Elixir (runs on a Linux server).
- With the local domain + controller software: Elixir (runs on desktop only).
- Old work on Anockma (Nock) and Cairo (another zkVM).
If we had a single standardized ISA/API which could be supported in all of these environments, we could greatly reduce the variety of different components needed to write an end-to-end Anoma application. This is closely related to the project of a low-level API, although note that here I’m talking about an even lower-level API (i.e. the RM and other application abstractions would be built on top of this layer).
Of these environments, by far the most performance-constrained are existing blockchain VMs, zkVMs, and the browser. I do not think that we need the most performant option to start – we can get away with something that isn’t too awful and optimize particular applications if they turn out to be popular. If we can find an option that works for those three, making it work on desktop and mobile operating systems should not be a problem.
Proposal
I propose that we use rv32im + ecalls (RISC-V “syscall” interface) as a standardized “low-level ISA”, where, more specifically:
- The basic rv32im instruction set provides 32-bit integer computation, memory, and control flow
- We define a set of custom ecalls (syscalls), including:
- System calls which provide optimized cryptographic operations (e.g. BLS12-381 elliptic curve operations) (similar to what RISC0 does)
- System calls which provide local persistent storage operations (read/write/scan)
- System calls which provide network operations (send message to pub/sub topic or node)
- System calls which provide distributed storage operations (scry)
All environments would need to support the basic rv32im instruction set, but they could support different subsets of system calls (and implement them differently), and authors/users of programs (or the compilers / other software acting on their behalf) will need to keep this in mind.
For example, both the SVM and EVM support bn254 elliptic curve operations as “precompiles”, but only the EVM supports BLS12-381 operations, so our BLS12-381 syscalls would not be supported by the SVM “Anoma low-level runtime”.
Further abstractions such as the resource machine, object systems, Anoma-level ideas, AVM ideas, etc. would be built on top of this base level.
In general, it appears that (with sufficient usage of ecall for key operations) this is feasible:
- rv32im is supported by RISC0 and other zkVMs
- rv32im can be compiled to the EVM and SVM with moderate overhead
- rv32im can be run in the browser
- I’m sure that we can manage desktop and mobile (although I haven’t investigated in detail).
- We can (relatively) easily compile a simple Scheme to rv32im, and efforts are underway to compile a subset of BEAM.
The abstraction layers would then look roughly as follows:
I think that this proposal is concordant with the ideas in Thoughts on a low-level Anoma API and A Roadmap for AL, and welcome feedback.
