Skip to content

Commit cd1bb5a

Browse files
authored
feat(zink): clean primitives and workspace (#329)
* chore(zint): move zint out of crates * feat(zink): rename zink-abi-macro to zabi-codegen * feat(zink): rename ffi to isa * feat(zink): goodbye unsafe * chore(zink): revert safe_impl * feat(zink): remove trait asm * feat(zink): use asm instead of ffi * feat(zink): move u256 ffi to ext * chore(clippy): make clippy happy * docs(README): correct the bounty link * chore(zink): remove outdated proc-macro for safe impl * chore(codegen): redirect the calls of u256 to namespace ext * chore(workspace): move the examples to zink folder * chore(codegen): fix missed tests * ci(foundry): update the path in founry tests
1 parent c3c674c commit cd1bb5a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+536
-833
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ jobs:
2828
- name: Build and Install zint-cli
2929
run: |
3030
cargo build --release -p zint-cli
31-
cargo install --path crates/zint/cli
31+
cargo install --path zint/cli
3232
3333
- name: Run Tests
3434
run: cargo nextest run --workspace --no-fail-fast --release
3535

3636
- name: Run Example Tests
3737
run: cargo nextest run --workspace --no-fail-fast --release --examples
38-
38+
3939
- name: Test Elko Addition Example
4040
run: |
4141
cargo run -p elko -- new addition
@@ -45,7 +45,7 @@ jobs:
4545
4646
- name: Test Foundry Integration
4747
run: |
48-
cd crates/zint/storage
48+
cd zint/storage
4949
forge build
5050
cargo zint new
5151
cargo zint run

Cargo.lock

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
[profile]
2-
dev = { panic = "abort" }
3-
release = { panic = "unwind" }
4-
51
[workspace]
62
members = [
73
"codegen",
84
"compiler",
95
"compiler/filetests",
10-
"crates/zint",
11-
"crates/zint/cli",
126
"evm/opcodes",
137
"evm/abi",
148
"zink/abi",
9+
"zink/abi/codegen",
1510
"zink/codegen",
1611
"zink/elko",
17-
"zink/abi-macro",
12+
"zint",
13+
"zint/cli",
1814
]
1915
resolver = "2"
2016

@@ -68,73 +64,23 @@ sol-abi = { path = "evm/abi", version = "=0.0.1" }
6864
elko = { path = "elko", version = "0.1.12" }
6965
filetests = { package = "zinkc-filetests", path = "compiler/filetests", version = "0.1.12" }
7066
zabi = { path = "zink/abi", version = "0.1.12" }
67+
zabi-codegen = { path = "zink/abi/codegen", version = "0.1.12" }
7168
zingen = { path = "codegen", version = "0.1.12" }
72-
zink = { path = ".", version = "0.1.12" }
73-
zink-abi-macro = { path = "zink/abi-macro", version = "0.1.12" }
69+
zink = { path = "zink", version = "0.1.12" }
7470
zink-codegen = { path = "zink/codegen", version = "0.1.12" }
7571
zinkc = { path = "compiler", version = "0.1.12" }
76-
zint = { path = "crates/zint", version = "0.1.12" }
72+
zint = { path = "zint", version = "0.1.12" }
7773

7874
[workspace.metadata.conta]
7975
packages = [
8076
"zabi",
77+
"zabi-codegen",
8178
"zingen",
8279
"zinkc",
8380
"filetests",
8481
"zint",
8582
"zink-codegen",
86-
"zink-abi-macro",
8783
"zink",
8884
"cargo-zint",
8985
"elko",
9086
]
91-
92-
# Zink Programming Language
93-
# -------------------------
94-
95-
[package]
96-
name = "zink"
97-
description = "Standard library for zink projects."
98-
documentation = "https://docs.rs/zink"
99-
version.workspace = true
100-
authors.workspace = true
101-
edition.workspace = true
102-
license.workspace = true
103-
homepage.workspace = true
104-
repository.workspace = true
105-
readme = "zink/README.md"
106-
107-
[lib]
108-
path = "zink/src/lib.rs"
109-
110-
[dependencies]
111-
fmt = "0.1.0"
112-
paste.workspace = true
113-
zink-codegen.workspace = true
114-
zink-abi-macro = { workspace = true, optional = true }
115-
zabi.workspace = true
116-
smallvec.workspace = true
117-
clap.workspace = true
118-
119-
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
120-
tiny-keccak.workspace = true
121-
122-
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
123-
anyhow.workspace = true
124-
filetests.workspace = true
125-
opcodes = { workspace = true, features = ["data"] }
126-
tracing.workspace = true
127-
zint.workspace = true
128-
hex.workspace = true
129-
serde_json.workspace = true
130-
tempfile.workspace = true
131-
132-
[target.'cfg(target_arch = "wasm32")'.dependencies]
133-
dlmalloc = { version = "0.2", optional = true, features = ["global"] }
134-
135-
[features]
136-
# default = [ "evm" ]
137-
# evm = [ ]
138-
abi-import = ["zink-abi-macro", "zabi/encoding"]
139-
wasm-alloc = ["dep:dlmalloc"]
140-
default = ["wasm-alloc"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[![ci][ci-badge]][ci-link]
1111
[![telegram][telegram-badge]][telegram-group]
1212

13-
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/).
13+
Welcome to the Zink Language! [Bounty issues](https://zink-lang.org/bounties) are now available, join the development of Zink by reading the [book](https://zink-lang.org/).
1414

1515
```rust
1616
//! ERC20 Example (WIP)

_typos.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[default]
2-
extend-ignore-re = [
3-
"\\w{44,52}",
4-
]
2+
extend-ignore-re = ["\\w{44,52}"]
53

64
[default.extend-words]
75
zink = "zink"
6+
7+
[files]
8+
extend-exclude = ["docs/theme/*"]

codegen/src/visitor/control.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl Function {
8585
}
8686

8787
/// The select instruction selects one of its first two operands based
88-
/// on whether its third oprand is zero or not.
88+
/// on whether its third operand is zero or not.
8989
///
9090
/// STACK: [cond, val2, val1] -> \[val1\] if cond is non-zero, \[val2\] otherwise.
9191
pub fn _select(&mut self) -> Result<()> {

codegen/src/wasm/func.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ impl<'f> Functions<'f> {
5757
/// Remove all selector functions
5858
pub fn drain_selectors(&mut self, exports: &Exports) -> Self {
5959
let mut functions = Self::default();
60-
61-
for index in exports.selectors() {
60+
let selectors = exports.selectors();
61+
for index in selectors {
6262
if let Some(function) = self.0.remove(&index) {
6363
functions.0.insert(index, function);
6464
}

codegen/src/wasm/host.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ impl TryFrom<(&str, &str)> for HostFunc {
5050
match import {
5151
("zinkc", name) => match name {
5252
"emit_abi" => Ok(Self::EmitABI),
53-
"u256_add" => Ok(Self::Evm(OpCode::ADD)),
54-
"u256_sub" => Ok(Self::Evm(OpCode::SUB)),
55-
"u256_lt" => Ok(Self::Evm(OpCode::LT)),
56-
"u256_max" => Ok(Self::U256MAX),
57-
"u256_addmod" => Ok(Self::Evm(OpCode::ADDMOD)),
58-
"u256_mulmod" => Ok(Self::Evm(OpCode::MULMOD)),
5953
"label_reserve_mem_32" => Ok(Self::Label(CompilerLabel::ReserveMemory32)),
6054
"label_reserve_mem_64" => Ok(Self::Label(CompilerLabel::ReserveMemory64)),
6155
_ => Err(Error::HostFuncNotFound(module.into(), name.into())),
@@ -64,7 +58,13 @@ impl TryFrom<(&str, &str)> for HostFunc {
6458
tracing::error!("Failed to load host function: {:?}", import);
6559
Error::HostFuncNotFound(module.into(), name.into())
6660
})?)),
67-
("asm", name) => match name {
61+
("ext", name) => match name {
62+
"u256_add" => Ok(Self::Evm(OpCode::ADD)),
63+
"u256_sub" => Ok(Self::Evm(OpCode::SUB)),
64+
"u256_lt" => Ok(Self::Evm(OpCode::LT)),
65+
"u256_max" => Ok(Self::U256MAX),
66+
"u256_addmod" => Ok(Self::Evm(OpCode::ADDMOD)),
67+
"u256_mulmod" => Ok(Self::Evm(OpCode::MULMOD)),
6868
n if n.starts_with("sload") => Ok(Self::Evm(OpCode::SLOAD)),
6969
n if n.starts_with("tload") => Ok(Self::Evm(OpCode::TLOAD)),
7070
n if n.starts_with("revert") => {
@@ -101,18 +101,15 @@ pub enum CompilerLabel {
101101

102102
#[cfg(test)]
103103
mod tests {
104-
use anyhow::Ok;
105-
106104
use super::*;
107105

108106
#[test]
109107
fn test_addmod_mulmod_host_functions() -> anyhow::Result<()> {
110-
let addmod_func = HostFunc::try_from(("zinkc", "u256_addmod"))?;
111-
108+
let addmod_func = HostFunc::try_from(("ext", "u256_addmod"))?;
112109
assert_eq!(addmod_func, HostFunc::Evm(OpCode::ADDMOD));
113110

114111
// Test MULMOD host function conversion
115-
let mulmod_func = HostFunc::try_from(("zinkc", "u256_mulmod"));
112+
let mulmod_func = HostFunc::try_from(("ext", "u256_mulmod"));
116113
assert!(mulmod_func.is_ok());
117114
Ok(())
118115
}

codegen/src/wasm/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ impl Env {
118118

119119
/// Check if the input function is external function
120120
pub fn is_external(&self, index: u32) -> bool {
121-
// self.exports.get(&index).is_some()
122121
let Some(name) = self.exports.get(&index) else {
123122
return false;
124123
};

compiler/src/compiler.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ impl Compiler {
9696

9797
tracing::debug!("compile function {func_index} {:?}, abi: {abi:#?}", sig);
9898
let is_main = !self.config.dispatcher && env.is_main(func_index);
99-
10099
let mut codegen = Function::new(env, sig, abi, is_main)?;
101100
let mut locals_reader = func.body.get_locals_reader()?;
102101
let mut ops_reader = func.body.get_operators_reader()?;

0 commit comments

Comments
 (0)