Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(zink): gather development tools to zink folder #294

Merged
merged 5 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,29 @@ Resolves #
### Changes

- [x] step 1
- [ ] step 2
- [ ] ...

<!--
If you are solving a budget issue, please add your wallet address here.
We will use it to send you the bounty once the PR is merged.

Polygon Address: `0x0000000000000000000000000000000000000000`
-->

<!--
NOTES for testing your changes:

```
# Clippy all packages
cargo cc

# Run all tests
cargo tt

# Build all examples
cargo be

# Run tests for examples
cargo te
```
-->
26 changes: 15 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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"
Expand All @@ -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 = [
Expand All @@ -75,7 +79,7 @@ packages = [
"zint",
"zink-codegen",
"zink",
"elko"
"elko",
]

# Zink Programming Language
Expand Down
98 changes: 38 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,91 +1,69 @@
<img align="right" width="150" height="150" top="100" src = "https://avatars.githubusercontent.com/u/138247979?s=400&u=cbf4b9e9da048899a947f08d92e030806d5bd50b&v=4"/>

# 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 | [email protected] |
| ------ | ---- | --------------- |
| 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
Expand Down
49 changes: 6 additions & 43 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -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
```
10 changes: 5 additions & 5 deletions docs/book.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[book]
title = "The Zink Project"
title = "The Zink Language"
authors = ["clearloop"]
multilingual = false
src = "."
Expand All @@ -9,19 +9,19 @@ 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"
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]
Expand Down
2 changes: 2 additions & 0 deletions docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.