#assembly #tvm #blockchain

tycho-asm

Rust implementation of TVM Assembler

4 releases

Uses new Rust 2024

new 0.2.1 Nov 6, 2025
0.2.0 Sep 30, 2025
0.1.1 Aug 5, 2025
0.1.0 Jun 26, 2025

#16 in #tvm

Download history 1/week @ 2025-07-10 2/week @ 2025-07-24 77/week @ 2025-07-31 39/week @ 2025-08-07 2/week @ 2025-08-14 9/week @ 2025-08-21 11/week @ 2025-08-28 21/week @ 2025-09-04 7/week @ 2025-09-11 5/week @ 2025-09-18 117/week @ 2025-09-25 69/week @ 2025-10-02 20/week @ 2025-10-09 32/week @ 2025-10-16 17/week @ 2025-10-23

181 downloads per month
Used in 5 crates (2 directly)

MIT/Apache

160KB
4.5K SLoC

tycho-asm   crates-io-batch docs-badge rust-version-badge workflow-badge

Status: WIP

About

Rust implementation of TVM Assembler.

LSP Server/Client

  • Install TVM Assembler VSCode extension
  • Install CLI
    cargo install --locked tvmasm
    

How to use

Building a contract using CLI

tvmasm build ./src/tests/walletv3.tvm -o walletv3.boc

Output:

Code path:      walletv3.boc
Code hash:      84dafa449f98a6987789ba232358072bc0f76dc4524002a5d0918b9a75d2d599
Unique cells:   1
Unique bits:    888

Building a contract from Rust

Runtime:

use tycho_asm::Code;
use tycho_types::prelude::Cell;

let code: Cell = Code::assemble(r#"
    PUSHINT 1
    SWAP DUP
    PUSHCONT {
        TUCK
        MUL
        SWAP
        DEC
    }
    REPEAT
    DROP
"#)?;

Compile time:

use tycho_asm_macros::tvmasm;
use tycho_types::prelude::{Boc, Cell};

const CODE: &[u8] = tvmasm!(
    "PUSHINT 1",
    "PUSHCONT { INC PUSHINT 10 LESS }",
    "PUSHCONT { DUMPSTK }",
    "WHILE",
);

let code: Cell = Boc::decode(CODE)?;

Syntax

// Single-line comments

// Opcodes must be in uppercase, can start with a digit or minus,
// and can contain '#' or '_'
NOP
2DROP
-ROT
STREF_L

// Opcodes with number as an argument
PUSHINT 12
PUSHINT -0xded
PUSHINT 0b10110101

// Opcodes with stack register as an argument
PUSH s1
XCHG s10, s100
PU2XC s1, s(-1), s(-2)

// Opcodes with control registers (c0, .., c5, c7)
PUSH c3
PUSHCTR c7

// Opcodes with slice or continuation
PUSHSLICE x{123123_}
PUSHSLICE b{10001001}
IFREFELSEREF {
  PUSHINT 1
}, {
  PUSHINT 2
}

// Insert raw slices into code
@inline x{a924}

Full opcodes list

Contributing

We welcome contributions to the project! If you notice any issues or errors, feel free to open an issue or submit a pull request.

License

Licensed under either of

at your option.

Dependencies

~6–17MB
~191K SLoC