Crates.io | stylus-sdk-bf |
lib.rs | stylus-sdk-bf |
version | 0.1.1 |
source | src |
created_at | 2023-08-06 04:17:19.818125 |
updated_at | 2023-08-31 12:13:45.369163 |
description | Brainfuck support for Arbitrum Stylus |
homepage | https://github.com/OffchainLabs/stylus-sdk-bf |
repository | https://github.com/OffchainLabs/stylus-sdk-bf |
max_upload_size | |
id | 936912 |
size | 63,629 |
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.
Op | Effect |
---|---|
> |
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 . |
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
.
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.
Repo | Use cases | License |
---|---|---|
Rust SDK | Everything! | Apache 2.0 or MIT |
C/C++ SDK | Cryptography and algorithms | Apache 2.0 or MIT |
Bf SDK | Educational | Apache 2.0 or MIT |
Want to write your own? Join us in the #stylus
channel on discord!
© 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
.