LeanAsm is a reusable Lean 4 foundation for typed RV64IM and scalar x86-64
assembly, executable machine semantics, encoding, and source emission.
The structured assembly layer, LeanAsm.Rv64.SAsm, is RISC-V-specific.
It is intended to be shared by:
ssz-asmcl-asmp2p-asm
The architecture follows the verified macro-assembly approach demonstrated by
Verified-zkEVM/evm-asm, while
remaining independent of EVM, zkVM execution, and riscv-zkvm.
| Module | Purpose |
|---|---|
LeanAsm.Rv64.Basic |
Registers and real, fixed-width RV64IM instructions |
LeanAsm.Rv64.Memory |
Finite disjoint byte regions and write permissions |
LeanAsm.Rv64.State |
Register state and placed executable images |
LeanAsm.Rv64.Program |
Flat instruction programs and composition |
LeanAsm.Rv64.Profile |
Stable opcode tags and consumer ISA allow-lists |
LeanAsm.Rv64.Execution |
Trap-aware execution and instruction fetch |
LeanAsm.Rv64.Encoding |
Little-endian 32-bit machine-code encoding |
LeanAsm.Rv64.Emit |
GNU-as output for real instructions |
LeanAsm.Rv64.SAsm.Ast |
RV64 structured control-flow syntax |
LeanAsm.Rv64.SAsm.Flatten |
Position-aware lowering and offset checks |
LeanAsm.Symbolic |
Labels, data, relocations, and GNU pseudo instructions |
LeanAsm.Frontend |
EmitAsm, LowerRv64, and LowerX64 capability APIs |
LeanAsm.ABI.LP64 |
RISC-V integer ABI register and stack-frame helpers |
LeanAsm.X64 |
Scalar x86-64 instructions, flags, memory, encoding, and execution |
LeanAsm.X64.Symbolic |
Labels, closed-code relocation, and GNU assembly/data output |
LeanAsm.ABI.SysVAMD64 |
System V AMD64 integer registers and aligned stack frames |
Rv64.Instrcontains only one-word real instructions.- Consumers restrict that shared instruction type with
IsaProfile; they do not introduce another instruction inductive merely to obtain a subset. - Source languages integrate through
EmitAsm,LowerRv64, andLowerX64. A source may provide assembly emission without instruction lowering. X64.Instrmodels real, variable-length instructions. Encoding determines instruction lengths; undefined flags remain explicit and trap when consumed.- RISC-V pseudo instructions such as
li,la,call symbol, andretare represented byLeanAsm.Symbolic, not by RV64 execution semantics. - Code and data memory are separate. Data memory is a finite list of disjoint regions with explicit write permission.
- No zkVM input/output, commit operation, custom ECALL, or accelerator is part of the portable core.
- The RV64 SAsm layer proves lowering size and checks offset ranges. Full Hoare/separation-logic extraction is a later milestone.
[[require]]
name = "LeanAsm"
git = "https://github.com/NyxFoundation/LeanAsm"
rev = "<commit>"import LeanAsm.Rv64.Execution
import LeanAsm.Rv64.SAsm.Flatten
open LeanAsm.Rv64When updating existing SAsm consumers, replace LeanAsm.SAsm.* imports and
LeanAsm.SAsm namespace references with LeanAsm.Rv64.SAsm.* and
LeanAsm.Rv64.SAsm. This includes the Source wrapper in LeanAsm.Frontend.
The old module paths and namespace are not retained.
On Linux x86-64, generate and run the C-callable example:
lake build
mkdir -p build
lake env lean --run Examples/X64.lean > build/x64.s
gcc -Wall -Wextra -Werror Examples/X64.c build/x64.s -o build/x64-example
./build/x64-example
python3 Tests/X64/check.pyThe example prints 5050. See x86-64 foundation for prerequisites,
supported operand forms, model boundaries, and the System V AMD64 ABI.
These consumers still target RISC-V. The x86-64 foundation does not migrate their routines or proofs automatically.
p2p-asmlowers structured code toRv64.Instrand states its accepted opcodes with anIsaProfile.cl-asmretainsriscv-zkvmas its proof frontend and provides a partialLowerRv64adapter for portable code generation.ssz-asmusesLeanAsm.Symbolicdirectly and provides assembly emission, without claiming fixed-width lowering for labels and pseudo instructions.
See docs/design.md and NOTICE.md.