Home

Awesome

<br /> <p align="center"> <a href="https://arbitrum.io/"> <img src="https://arbitrum.io/assets/stylus/stylus_with_paint_bg.png" alt="Logo" width="100%"> </a> <h3 align="center">The Stylus SDK</h3> <p align="center"> <a href="https://docs.arbitrum.io/stylus/stylus-gentle-introduction"><strong>Bf contracts on Arbitrum »</strong></a> <br /> </p> </p>

Overview

Bf is a humorous, esoteric programming language lauded for its minimalism, difficulty, and ability to produce inscrutable code for even the simplest of programs. For example, here's the shortest known implementation of Hello World, by KSab.

+[>>>->-[>->----<<<]>>]>.---.>+..+++.>>.<.>>---.<<<.+++.------.<-.>>+.

The 8 symbols seen in the above constitute the entirety of the Bf programming language. Because their operations simulate a Turing Machine, Bf can be used to write any computable function. That is, anything you can do in C, Rust, etc, you can do in Bf — if you can figure out how to write it!

For better or worse, this repo includes a Bf-to-WebAssembly compiler, which allows Bf programs to run at near-native speeds on Arbitrum chains. The symbols are interpreted as follows.

OpEffect
>Move the machine's head 1 cell to the right.
<Move the machine's head 1 cell to the left.
+Increment the byte stored in the current cell.
-Decrement the byte stored in the current cell.
.Append the current cell's byte to the EVM return data.
,Read the next byte of calldata into the current cell.
[Jump to the matching ] if the current cell's byte is 0.
]Jump to the matching [ if the current cell's byte is not 0.

Usage

To invoke the compiler, run

cargo run <input.b> -o <output.wat>

To upload the .wat to a Stylus-enabled Arbitrum chain, see cargo stylus.

Why does this exist?

Though seemingly just for fun, we hope this repo will be of educational value to framework developers. Creating Stylus SDKs for new languages is surprisingly straightforward, and uses the same building blocks seen in the generated .wat files this Bf compiler produces. One can even deploy hand-written .wat files using the imports seen in prelude.wat;

(module
    (import "vm_hooks" "read_args"    (func $read_args   (param i32    )))
    (import "vm_hooks" "write_result" (func $return_data (param i32 i32)))

    (func $main (export "user_entrypoint") (param $args_len i32) (result i32)
        ;; your code here
    )
)

All it takes is a WebAssembly-enabled compiler and a few imports, the full list of which can be found here. The table below includes our official SDKs built on the same ideas.

RepoUse casesLicense
Rust SDKEverything!Apache 2.0 or MIT
C/C++ SDKCryptography and algorithmsApache 2.0 or MIT
Bf SDKEducationalApache 2.0 or MIT

Want to write your own? Join us in the #stylus channel on discord!

License

© 2022-2023 Offchain Labs, Inc.

This project is licensed under either of

at your option.

The SPDX license identifier for this project is MIT OR Apache-2.0.