Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/offchainlabs/stylus-sdk-bf
Bf Smart Contracts on Arbitrum ๐
https://github.com/offchainlabs/stylus-sdk-bf
Last synced: 7 days ago
JSON representation
Bf Smart Contracts on Arbitrum ๐
- Host: GitHub
- URL: https://github.com/offchainlabs/stylus-sdk-bf
- Owner: OffchainLabs
- Created: 2023-08-04T02:26:54.000Z (over 1 year ago)
- Default Branch: stylus
- Last Pushed: 2024-08-02T16:14:29.000Z (4 months ago)
- Last Synced: 2024-08-09T10:14:07.875Z (3 months ago)
- Language: WebAssembly
- Homepage:
- Size: 60.5 KB
- Stars: 7
- Watchers: 7
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: licenses/Apache-2.0
Awesome Lists containing this project
README
The Stylus SDK
## Overview
[Bf][wiki] 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][hello], by KSab.
```brainfuck
+[>>>->-[>->----<<<]>>]>.---.>+..+++.>>.<.>>---.<<<.+++.------.<-.>>+.
```The 8 symbols seen in the above constitute the entirety of the Bf programming language. Because their operations simulate a [Turing Machine][Turing], 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`. |[wiki]: https://esolangs.org/wiki/Brainfuck
[hello]: https://tio.run/##HYpBCoAwEAMftGxeEPKR0oMWCiJ4EHz/mnYOQ0hyvsf1zG/cVdEkpbItGZJd6oIzFEBEQAKtVXnfVW5An/yq@gE
[Turing]: https://en.wikipedia.org/wiki/Turing_machine## Usage
To invoke the compiler, run
```sh
cargo run -o
```To upload the `.wat` to a Stylus-enabled Arbitrum chain, see [`cargo stylus`][cargo].
[cargo]: https://github.com/OffchainLabs/stylus-sdk-bf
## 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`][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][hostios]. The table below includes our official SDKs built on the same ideas.
| Repo | Use cases | License |
|:-----------------|:----------------------------|:------------------|
| [Rust SDK][Rust] | Everything! | Apache 2.0 or MIT |
| [C/C++ SDK][C] | Cryptography and algorithms | Apache 2.0 or MIT |
| [Bf SDK][Bf] | Educational | Apache 2.0 or MIT |Want to write your own? Join us in the `#stylus` channel on [discord][discord]!
[prelude]: https://github.com/OffchainLabs/stylus-sdk-bf/blob/stylus/src/prelude.wat
[hostios]: https://github.com/OffchainLabs/stylus-sdk-rs/blob/stylus/stylus-sdk/src/hostio.rs[Rust]: https://github.com/OffchainLabs/stylus-sdk-rs
[C]: https://github.com/OffchainLabs/stylus-sdk-c
[Bf]: https://github.com/OffchainLabs/stylus-sdk-bf[discord]: https://discord.com/invite/5KE54JwyTs
## License
ยฉ 2022-2023 Offchain Labs, Inc.
This project is licensed under either of
- [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0) ([licenses/Apache-2.0](licenses/Apache-2.0))
- [MIT license](https://opensource.org/licenses/MIT) ([licenses/MIT](licenses/MIT))at your option.
The [SPDX](https://spdx.dev) license identifier for this project is `MIT OR Apache-2.0`.