diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 25f382366..de6e0fc33 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -3,5 +3,29 @@ Resolves # ### Changes - [x] step 1 -- [ ] step 2 - [ ] ... + + + + diff --git a/Cargo.toml b/Cargo.toml index 70ec8a899..807a43dcc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,18 +1,18 @@ [profile] -dev = { panic = "abort"} +dev = { panic = "abort" } release = { panic = "unwind" } [workspace] members = [ - "abi", "codegen", "compiler", "compiler/filetests", - "elko", "evm/opcodes", "evm/abi", + "zink/abi", "zink/codegen", - "zint", + "zink/elko", + "zink/zint", ] resolver = "2" @@ -42,9 +42,11 @@ semver = "1.0.21" serde = { version = "1.0.196", default-features = false } serde_json = "1.0.113" smallvec = "1.13.1" -syn = { version = "2.0.77", features = [ "full" ] } +syn = { version = "2.0.77", features = ["full"] } thiserror = "1.0.56" -tiny-keccak = { version = "2.0.2", features = ["keccak"], default-features = false } +tiny-keccak = { version = "2.0.2", features = [ + "keccak", +], default-features = false } toml = "0.8.9" tracing = "0.1.40" tracing-subscriber = "0.3.18" @@ -53,18 +55,20 @@ wasmparser = "0.121.0" wat = "1.0.85" ## EVM packages -opcodes = { package = "evm-opcodes", path = "evm/opcodes", version = "=0.0.4", features = [ "data" ] } +opcodes = { package = "evm-opcodes", path = "evm/opcodes", version = "=0.0.4", features = [ + "data", +] } sol-abi = { path = "evm/abi", version = "=0.0.1" } ## Zink packages elko = { path = "elko", version = "0.1.11" } filetests = { package = "zinkc-filetests", path = "compiler/filetests", version = "0.1.11" } -zabi = { path = "abi", version = "0.1.11" } -zingen = { path = "codegen", version = "0.1.11" } +zabi = { path = "zink/abi", version = "0.1.11" } +zingen = { path = "codegen", version = "0.1.11" } zink = { path = ".", version = "0.1.11" } zink-codegen = { path = "zink/codegen", version = "0.1.11" } zinkc = { path = "compiler", version = "0.1.11" } -zint = { path = "zint", version = "0.1.11" } +zint = { path = "zink/zint", version = "0.1.11" } [workspace.metadata.conta] packages = [ @@ -75,7 +79,7 @@ packages = [ "zint", "zink-codegen", "zink", - "elko" + "elko", ] # Zink Programming Language diff --git a/README.md b/README.md index e876791da..be7b0b2d5 100644 --- a/README.md +++ b/README.md @@ -1,91 +1,69 @@ -# The Zink Project +# The Zink Language > [!CAUTION] > -> This project is still under active development, plz DO NOT use it in production. +> This project is still under active development, please DO NOT use it in production. [![zink][version-badge]][version-link] [![ci][ci-badge]][ci-link] [![telegram][telegram-badge]][telegram-group] -[The Zink project][book] mainly provides a singlepass compiler `zinkc` which compiles -WASM to EVM bytecode, the source code of your smart contracts could be any language you like! +Welcome to the Zink Language! [Bounty issues](https://zink-lang.org/budgets) are now available, join the development of Zink by reading the [book](https://zink-lang.org/). -```mermaid -flowchart LR - R{{Rust}} --> W(WebAssembly) - O[...] --> W - W --> Z{Zink Compiler} - Z --> V[(EVM)] -``` +```rust +//! ERC20 Example (WIP) +#[zink::contract] +pub struct ERC20; + +#[zink::calls] +impl ERC20 { + /// VMs that zink supports + pub fn support() -> [zink::String; 4] { + ["EVM", "WASM", "RISC-V", "...OTHER_VMS"] + } +} -Here we highly recommend you to choose `rust` as the language of your smart contracts -which will unlock all of the following features: +#[zink::interface] +impl ERC20 for ERC20 { + fn name() -> zink::String { + "Zink Language".to_string() + } +} +``` -- **Safe**: `rustc` is watching you! Furthermore, after compiling your rust code to WASM, - `zinkc` will precompute all of the stack and memory usage in your contracts to ensure they - are safe in EVM bytecode as well! +- **Safe**: `rustc` monitors your code! -- **High Performance**: The optimizations are provided by the three of `rustc`, `wasm-opt` - and `zinkc`, your contracts will have the smallest size with **strong performance** in EVM - bytecode at the end! +- **Efficient**: Efficient EVM bytecode from `rustc`, `wasm-opt`, and `zinkc`. -- **Compatible**: All of the `no_std` libraries in rust are your libraries, you can use your - solidity contracts as part of your zink contracts and your zink contracts as part of your - solidity contracts :) +- **Modular**: Upload and download your contract components via `crates.io`. -- **Easy Debugging**: Developing your smart contracts with only one programming language! - zink will provide everything you need for developing your contracts officially based on the - stable projects in rust like the `foundry` tools. +- **Rusty**: All of the rust tools are available for your contracts! Run `cargo install zinkup` to install the toolchain! -## Fibonacci Example - -| fib(n) | Zink | Solidity@0.8.21 | -| ------ | ---- | --------------- | -| 0 | 110 | 614 | -| 1 | 110 | 614 | -| 2 | 262 | 1322 | -| 3 | 414 | 2030 | -| 4 | 718 | 3446 | -| 5 | 1174 | 5570 | - -```rust -/// Calculates the nth fibonacci number using recursion. -#[no_mangle] -pub extern "C" fn recursion(n: usize) -> usize { - if n < 2 { - n - } else { - recursion(n - 1) + recursion(n - 2) - } -} -``` - -As an example for the benchmark, calculating fibonacci sequence with recursion, missed -vyper because it doesn't support recursion...Zink is 5x fast on this, but it is mainly -caused by our current implementation is not completed yet ( missing logic to adapt to more -situations ), let's stay tuned for `v0.3.0`. +## Testing & Development -## Donation +| Command | Description | +| ---------- | ---------------------- | +| `cargo cc` | Clippy all packages | +| `cargo tt` | Run all tests | +| `cargo be` | Build all examples | +| `cargo te` | Run tests for examples | -After completing the ERC20 implementation, Zink will focus on MEV logic since everything could -be even more compact and realistic from this dark forest. +We're using `cargo-nextest` for testing, the commands above are described in [.cargo/config.toml](.cargo/config.toml). -Zink is now moving forward without any grants or backups, if you like this dreaming project, -please feel free to reach out, would be appreciated for any opportunities ^ ^ +## Special Thanks -- ETH: `0xf0306047Fa598fe95502f466aeb49b68dd94365B` -- SOL: `AZGXAerErfwVzJkiSR8moVPZxe1nEhvjdkvxQ7qR6Yst` +- [MegaETH](https://github.com/megaeth-labs) for the funding and trust! +- [revm](https://github.com/bluealloy/revm) for the EVM in rust! ## LICENSE GPL-3.0-only -[book]: https://docs.zink-lang.org/ +[book]: https://zink-lang.org/ [telegram-badge]: https://img.shields.io/endpoint?label=chat&style=flat&url=https%3A%2F%2Fmogyo.ro%2Fquart-apis%2Ftgmembercount%3Fchat_id%3Dzinklang [telegram-group]: https://t.me/zinklang [version-badge]: https://img.shields.io/crates/v/zinkc diff --git a/docs/README.md b/docs/README.md index 0da08496d..d06d9d883 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,47 +1,10 @@ # The Zink Book +This is the book for the Zink Language, you can read it online at [docs.zink-lang.org](https://zink-lang.org/). -## Validation - -e.g. How Zink Compiler helps you writing your EVM smart contracts ;) - - -#### `0x35` - CALLDATALOAD - -1. validate the function signatures -2. validate the stack usages - - -## Optimizations - - -#### StackCompressor - -The max limit of the defined local variables is 16 due to there is a hard limit -of 16 slots for reaching down the expression stack of EVM. - - -## Function Calls - -### Calling Convention - -There we two ways to handle the calling convention, for storing PC - -1. Store the PC - -few arguments -> store the PC on stack. -lots of arguments -> store the PC in reserved memory. - - -2. Retrieve the PC - -stack -> swap the parameters and the PC -memory -> read from reserved memory - - -3. Jump back to the caller - -stack -> swap the results and the PC - -> dup the PC and pop in caller function -memory -> load PC from memory +## Contributing +``` +cargo install mdbook +mdbook serve +``` diff --git a/docs/book.toml b/docs/book.toml index d00cff8dc..a1080729b 100644 --- a/docs/book.toml +++ b/docs/book.toml @@ -1,5 +1,5 @@ [book] -title = "The Zink Project" +title = "The Zink Language" authors = ["clearloop"] multilingual = false src = "." @@ -9,7 +9,7 @@ edition = "2021" [output.html] cname = "docs.zink-lang.org" -git-repository-url = "https://github.com/clearloop/zink" +git-repository-url = "https://github.com/zink-lang/zink" git-repository-icon = "fa-github" default-theme = "dark" preferred-dark-theme = "navy" @@ -17,11 +17,11 @@ curly-quotes = true mathjax-support = false # If editable -# edit-url-template = "https://github.com/clearloop/zink/edit/main/docs/{path}" +edit-url-template = "https://github.com/zink-lang/zink/edit/main/docs/{path}" # If enable folding chapters -# [output.html.fold] -# enable = true +[output.html.fold] +enable = true # level = 1 [output.html.playground] diff --git a/docs/introduction.md b/docs/introduction.md index 383ea68da..45e7d24c0 100644 --- a/docs/introduction.md +++ b/docs/introduction.md @@ -11,6 +11,7 @@ contracts on Ethereum. This guide is intended to serve a number of purposes and within you'll find: +- [The Bounty issues][bounty] - [The rustdocs of the zink project][rustdocs] - [The design of the zink compiler][compiler] - [The rust guide of zink projects][styles] @@ -23,3 +24,4 @@ This guide is intended to serve a number of purposes and within you'll find: [zinkc]: https://github.com/clearloop/zink/tree/main/compiler [rustdocs]: https://docs.zink-lang.org/rustdocs [source]: https://github.com/clearloop/zink/tree/main/docs +[bounty]: https://zink-lang.org/budgets diff --git a/abi/Cargo.toml b/zink/abi/Cargo.toml similarity index 100% rename from abi/Cargo.toml rename to zink/abi/Cargo.toml diff --git a/abi/README.md b/zink/abi/README.md similarity index 100% rename from abi/README.md rename to zink/abi/README.md diff --git a/abi/src/abi.rs b/zink/abi/src/abi.rs similarity index 100% rename from abi/src/abi.rs rename to zink/abi/src/abi.rs diff --git a/abi/src/lib.rs b/zink/abi/src/lib.rs similarity index 100% rename from abi/src/lib.rs rename to zink/abi/src/lib.rs diff --git a/abi/src/result.rs b/zink/abi/src/result.rs similarity index 100% rename from abi/src/result.rs rename to zink/abi/src/result.rs diff --git a/abi/src/selector.rs b/zink/abi/src/selector.rs similarity index 100% rename from abi/src/selector.rs rename to zink/abi/src/selector.rs diff --git a/elko/Cargo.toml b/zink/elko/Cargo.toml similarity index 100% rename from elko/Cargo.toml rename to zink/elko/Cargo.toml diff --git a/elko/README.md b/zink/elko/README.md similarity index 100% rename from elko/README.md rename to zink/elko/README.md diff --git a/elko/src/bin/elko.rs b/zink/elko/src/bin/elko.rs similarity index 100% rename from elko/src/bin/elko.rs rename to zink/elko/src/bin/elko.rs diff --git a/elko/src/build.rs b/zink/elko/src/build.rs similarity index 100% rename from elko/src/build.rs rename to zink/elko/src/build.rs diff --git a/elko/src/lib.rs b/zink/elko/src/lib.rs similarity index 100% rename from elko/src/lib.rs rename to zink/elko/src/lib.rs diff --git a/elko/src/new.rs b/zink/elko/src/new.rs similarity index 100% rename from elko/src/new.rs rename to zink/elko/src/new.rs diff --git a/elko/src/utils/manifest.rs b/zink/elko/src/utils/manifest.rs similarity index 100% rename from elko/src/utils/manifest.rs rename to zink/elko/src/utils/manifest.rs diff --git a/elko/src/utils/mod.rs b/zink/elko/src/utils/mod.rs similarity index 100% rename from elko/src/utils/mod.rs rename to zink/elko/src/utils/mod.rs diff --git a/elko/src/utils/result.rs b/zink/elko/src/utils/result.rs similarity index 100% rename from elko/src/utils/result.rs rename to zink/elko/src/utils/result.rs diff --git a/elko/src/utils/wasm.rs b/zink/elko/src/utils/wasm.rs similarity index 100% rename from elko/src/utils/wasm.rs rename to zink/elko/src/utils/wasm.rs diff --git a/zint/Cargo.toml b/zink/zint/Cargo.toml similarity index 100% rename from zint/Cargo.toml rename to zink/zint/Cargo.toml diff --git a/zint/README.md b/zink/zint/README.md similarity index 100% rename from zint/README.md rename to zink/zint/README.md diff --git a/zint/src/bytes.rs b/zink/zint/src/bytes.rs similarity index 100% rename from zint/src/bytes.rs rename to zink/zint/src/bytes.rs diff --git a/zint/src/contract.rs b/zink/zint/src/contract.rs similarity index 100% rename from zint/src/contract.rs rename to zink/zint/src/contract.rs diff --git a/zint/src/evm.rs b/zink/zint/src/evm.rs similarity index 100% rename from zint/src/evm.rs rename to zink/zint/src/evm.rs diff --git a/zint/src/lib.rs b/zink/zint/src/lib.rs similarity index 100% rename from zint/src/lib.rs rename to zink/zint/src/lib.rs diff --git a/zint/src/lookup.rs b/zink/zint/src/lookup.rs similarity index 100% rename from zint/src/lookup.rs rename to zink/zint/src/lookup.rs diff --git a/zint/tests/addition.rs b/zink/zint/tests/addition.rs similarity index 100% rename from zint/tests/addition.rs rename to zink/zint/tests/addition.rs