From f09f722636c3c089f7a4a4d5f88dcd72e3f9ca61 Mon Sep 17 00:00:00 2001 From: clearloop Date: Mon, 2 Dec 2024 14:51:17 +0700 Subject: [PATCH 1/5] chore(zink): rename tools to zink folder --- Cargo.toml | 26 +++++++++++++---------- {abi => zink/abi}/Cargo.toml | 0 {abi => zink/abi}/README.md | 0 {abi => zink/abi}/src/abi.rs | 0 {abi => zink/abi}/src/lib.rs | 0 {abi => zink/abi}/src/result.rs | 0 {abi => zink/abi}/src/selector.rs | 0 {elko => zink/elko}/Cargo.toml | 0 {elko => zink/elko}/README.md | 0 {elko => zink/elko}/src/bin/elko.rs | 0 {elko => zink/elko}/src/build.rs | 0 {elko => zink/elko}/src/lib.rs | 0 {elko => zink/elko}/src/new.rs | 0 {elko => zink/elko}/src/utils/manifest.rs | 0 {elko => zink/elko}/src/utils/mod.rs | 0 {elko => zink/elko}/src/utils/result.rs | 0 {elko => zink/elko}/src/utils/wasm.rs | 0 {zint => zink/zint}/Cargo.toml | 0 {zint => zink/zint}/README.md | 0 {zint => zink/zint}/src/bytes.rs | 0 {zint => zink/zint}/src/contract.rs | 0 {zint => zink/zint}/src/evm.rs | 0 {zint => zink/zint}/src/lib.rs | 0 {zint => zink/zint}/src/lookup.rs | 0 {zint => zink/zint}/tests/addition.rs | 0 25 files changed, 15 insertions(+), 11 deletions(-) rename {abi => zink/abi}/Cargo.toml (100%) rename {abi => zink/abi}/README.md (100%) rename {abi => zink/abi}/src/abi.rs (100%) rename {abi => zink/abi}/src/lib.rs (100%) rename {abi => zink/abi}/src/result.rs (100%) rename {abi => zink/abi}/src/selector.rs (100%) rename {elko => zink/elko}/Cargo.toml (100%) rename {elko => zink/elko}/README.md (100%) rename {elko => zink/elko}/src/bin/elko.rs (100%) rename {elko => zink/elko}/src/build.rs (100%) rename {elko => zink/elko}/src/lib.rs (100%) rename {elko => zink/elko}/src/new.rs (100%) rename {elko => zink/elko}/src/utils/manifest.rs (100%) rename {elko => zink/elko}/src/utils/mod.rs (100%) rename {elko => zink/elko}/src/utils/result.rs (100%) rename {elko => zink/elko}/src/utils/wasm.rs (100%) rename {zint => zink/zint}/Cargo.toml (100%) rename {zint => zink/zint}/README.md (100%) rename {zint => zink/zint}/src/bytes.rs (100%) rename {zint => zink/zint}/src/contract.rs (100%) rename {zint => zink/zint}/src/evm.rs (100%) rename {zint => zink/zint}/src/lib.rs (100%) rename {zint => zink/zint}/src/lookup.rs (100%) rename {zint => zink/zint}/tests/addition.rs (100%) 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/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 From 088964e9071f6556d3eea6f5a2e9dd7c6ad77410 Mon Sep 17 00:00:00 2001 From: clearloop Date: Mon, 2 Dec 2024 15:16:50 +0700 Subject: [PATCH 2/5] docs(README): make README compact --- README.md | 85 ++++++++++++++++++++----------------------------------- 1 file changed, 31 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index e876791da..24a3a167b 100644 --- a/README.md +++ b/README.md @@ -1,91 +1,68 @@ -# 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! +Rustic smart contract language that targets the EVM. ```mermaid flowchart LR - R{{Rust}} --> W(WebAssembly) - O[...] --> W + R{{Rust}} --> W(WASM) W --> Z{Zink Compiler} Z --> V[(EVM)] ``` -Here we highly recommend you to choose `rust` as the language of your smart contracts -which will unlock all of the following features: +- **Safe**: `rustc` monitors your code! After compiling to WASM, `zinkc` precomputes stack + and memory usage to ensure safety in EVM bytecode. -- **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! +- **High Performance**: Optimizations from `rustc`, `wasm-opt`, and `zinkc` yield small, + high-performance EVM bytecode. -- **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! +- **Modular**: Upload and download your contract components via `crates.io`. -- **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 :) - -- **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. +- **Easy Debugging**: Develop smart contracts just in rust! 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 | +## ERC20 Example (In Development) ```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) - } +#[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"] + } } -``` - -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`. -## Donation - -After completing the ERC20 implementation, Zink will focus on MEV logic since everything could -be even more compact and realistic from this dark forest. +#[zink::interface] +impl ERC20 for ERC20 { + fn name() -> zink::String { + "Zink Language".to_string() + } +} +``` -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) 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 From bb391043f02a48c12afe294ce7947bd3c65fde7b Mon Sep 17 00:00:00 2001 From: clearloop Date: Mon, 2 Dec 2024 15:37:13 +0700 Subject: [PATCH 3/5] docs(PR): update PR template --- .github/PULL_REQUEST_TEMPLATE.md | 26 +++++++++++++++++- README.md | 47 ++++++++++++++++---------------- 2 files changed, 48 insertions(+), 25 deletions(-) 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/README.md b/README.md index 24a3a167b..66bc06a21 100644 --- a/README.md +++ b/README.md @@ -10,30 +10,8 @@ [![ci][ci-badge]][ci-link] [![telegram][telegram-badge]][telegram-group] -Rustic smart contract language that targets the EVM. - -```mermaid -flowchart LR - R{{Rust}} --> W(WASM) - W --> Z{Zink Compiler} - Z --> V[(EVM)] -``` - -- **Safe**: `rustc` monitors your code! After compiling to WASM, `zinkc` precomputes stack - and memory usage to ensure safety in EVM bytecode. - -- **High Performance**: Optimizations from `rustc`, `wasm-opt`, and `zinkc` yield small, - high-performance EVM bytecode. - -- **Modular**: Upload and download your contract components via `crates.io`. - -- **Easy Debugging**: Develop smart contracts just in rust! All of the rust tools are available for your contracts! - -Run `cargo install zinkup` to install the toolchain! - -## ERC20 Example (In Development) - ```rust +//! ERC20 Example (In Development) #[zink::contract] pub struct ERC20; @@ -53,9 +31,30 @@ impl ERC20 for ERC20 { } ``` +- **Safe**: `rustc` monitors your code! + +- **Efficient**: Optimizations from `rustc`, `wasm-opt`, and `zinkc` yield efficient EVM bytecode. + +- **Modular**: Upload and download your contract components via `crates.io`. + +- **Easy Debugging**: All of the rust tools are available for your contracts! + +Run `cargo install zinkup` to install the toolchain! See [book](https://zink-lang.org/) for the handbook. + +## Testing & Development + +| Command | Description | +| ---------- | ---------------------- | +| `cargo cc` | Clippy all packages | +| `cargo tt` | Run all tests | +| `cargo be` | Build all examples | +| `cargo te` | Run tests for examples | + +We're using `cargo-nextest` for testing, the commands above are described in [.cargo/config.toml](.cargo/config.toml). + ## Special Thanks -- [MegaETH](https://github.com/MegaETH) for the funding and trust! +- [MegaETH](https://github.com/megaeth-labs) for the funding and trust! - [revm](https://github.com/bluealloy/revm) for the EVM in rust! ## LICENSE From f320c5c63b159c3ef04e4b7bb0c983877d22a539 Mon Sep 17 00:00:00 2001 From: clearloop Date: Mon, 2 Dec 2024 15:58:13 +0700 Subject: [PATCH 4/5] docs(book): update the README of the book --- README.md | 18 ++++++++-------- docs/README.md | 49 ++++++-------------------------------------- docs/book.toml | 10 ++++----- docs/introduction.md | 2 ++ 4 files changed, 22 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index 66bc06a21..f47f5f7c2 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,14 @@ [![ci][ci-badge]][ci-link] [![telegram][telegram-badge]][telegram-group] +- **Safe**: `rustc` monitors your code! + +- **Efficient**: Efficient EVM bytecode from `rustc`, `wasm-opt`, and `zinkc`. + +- **Modular**: Upload and download your contract components via `crates.io`. + +- **Rusty**: All of the rust tools are available for your contracts! + ```rust //! ERC20 Example (In Development) #[zink::contract] @@ -31,15 +39,7 @@ impl ERC20 for ERC20 { } ``` -- **Safe**: `rustc` monitors your code! - -- **Efficient**: Optimizations from `rustc`, `wasm-opt`, and `zinkc` yield efficient EVM bytecode. - -- **Modular**: Upload and download your contract components via `crates.io`. - -- **Easy Debugging**: All of the rust tools are available for your contracts! - -Run `cargo install zinkup` to install the toolchain! See [book](https://zink-lang.org/) for the handbook. +Run `cargo install zinkup` to install the toolchain! See [book](https://zink-lang.org/) for more details. ## Testing & Development 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 From 13efbdbb110ecf39f9d3d156e6b67e870a168a83 Mon Sep 17 00:00:00 2001 From: clearloop Date: Mon, 2 Dec 2024 16:02:08 +0700 Subject: [PATCH 5/5] docs(README): notice bounty issues in README --- README.md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index f47f5f7c2..be7b0b2d5 100644 --- a/README.md +++ b/README.md @@ -10,16 +10,10 @@ [![ci][ci-badge]][ci-link] [![telegram][telegram-badge]][telegram-group] -- **Safe**: `rustc` monitors your code! - -- **Efficient**: Efficient EVM bytecode from `rustc`, `wasm-opt`, and `zinkc`. - -- **Modular**: Upload and download your contract components via `crates.io`. - -- **Rusty**: All of the rust tools are available for your contracts! +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/). ```rust -//! ERC20 Example (In Development) +//! ERC20 Example (WIP) #[zink::contract] pub struct ERC20; @@ -39,7 +33,15 @@ impl ERC20 for ERC20 { } ``` -Run `cargo install zinkup` to install the toolchain! See [book](https://zink-lang.org/) for more details. +- **Safe**: `rustc` monitors your code! + +- **Efficient**: Efficient EVM bytecode from `rustc`, `wasm-opt`, and `zinkc`. + +- **Modular**: Upload and download your contract components via `crates.io`. + +- **Rusty**: All of the rust tools are available for your contracts! + +Run `cargo install zinkup` to install the toolchain! ## Testing & Development