Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/deps-2a1b482950
Browse files Browse the repository at this point in the history
  • Loading branch information
clearloop committed Oct 13, 2024
2 parents 4a3af74 + be2a0b5 commit ed52444
Show file tree
Hide file tree
Showing 80 changed files with 2,594 additions and 1,408 deletions.
File renamed without changes.
1,253 changes: 824 additions & 429 deletions Cargo.lock

Large diffs are not rendered by default.

33 changes: 20 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ members = [
resolver = "2"

[workspace.package]
version = "0.1.10"
version = "0.1.11"
authors = ["clearloop"]
edition = "2021"
license = "GPL-3.0-only"
Expand All @@ -30,20 +30,21 @@ cargo_metadata = "0.18.1"
ccli = "0.0.1"
colored = "2.1.0"
etc = "0.1.19"
heck = "0.5.0"
hex = "0.4.3"
indexmap = "2.2.2"
paste = "1.0.14"
postcard = { version = "1.0.8", default-features = false }
proc-macro2 = "1.0.78"
quote = "1.0.35"
revm = { version = "3.5.0", default-features = false }
revm = { version = "14", default-features = false }
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.48", features = [ "full" ] }
syn = { version = "2.0.77", features = [ "full" ] }
thiserror = "1.0.56"
tiny-keccak = "2.0.2"
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 @@ -52,18 +53,18 @@ wasmparser = "0.121.0"
wat = "1.0.85"

## EVM packages
opcodes = { package = "evm-opcodes", path = "evm/opcodes", version = "=0.0.3", 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.10" }
filetests = { package = "zinkc-filetests", path = "compiler/filetests", version = "0.1.10" }
zabi = { path = "abi", version = "0.1.10" }
zingen = { path = "codegen", version = "0.1.10" }
zink = { path = ".", version = "0.1.10" }
zink-codegen = { path = "zink/codegen", version = "0.1.10" }
zinkc = { path = "compiler", version = "0.1.10" }
zint = { path = "zint", version = "0.1.10" }
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" }
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" }

[workspace.metadata.conta]
packages = [
Expand Down Expand Up @@ -99,7 +100,13 @@ path = "zink/src/lib.rs"
paste.workspace = true
zink-codegen.workspace = true

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tiny-keccak.workspace = true

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
anyhow.workspace = true
filetests.workspace = true
opcodes = { workspace = true, features = ["data"] }
tracing.workspace = true
zint.workspace = true
hex.workspace = true
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<img align="right" width="150" height="150" top="100" src = "https://github.com/clearloop/zink/assets/26088946/2b13f312-ca96-44ae-aa04-b0db9471aadb"/>
<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

Expand Down Expand Up @@ -68,7 +68,18 @@ pub extern "C" fn recursion(n: usize) -> usize {
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 keep tuned for `v0.3.0`.
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 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 ^ ^

- ETH: `0xf0306047Fa598fe95502f466aeb49b68dd94365B`
- SOL: `AZGXAerErfwVzJkiSR8moVPZxe1nEhvjdkvxQ7qR6Yst`

## LICENSE

Expand Down
5 changes: 5 additions & 0 deletions _typos.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
[default]
extend-ignore-re = [
"\\w{44,52}",
]

[default.extend-words]
zink = "zink"
77 changes: 77 additions & 0 deletions abi/src/abi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//! Zink ABI implementation
//!
//! Currently just a wrapper of solidity ABI.

use core::ops::{Deref, DerefMut};

/// Function ABI.
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Abi(sol_abi::Abi);

impl Deref for Abi {
type Target = sol_abi::Abi;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl DerefMut for Abi {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

#[cfg(feature = "bytes")]
impl Abi {
/// Convert [`Abi`] to bytes.
pub fn to_bytes(&self) -> postcard::Result<Vec<u8>> {
postcard::to_stdvec(self).map_err(Into::into)
}

/// Convert bytes to [`Abi`].
pub fn from_bytes(bytes: impl AsRef<[u8]>) -> postcard::Result<Self> {
postcard::from_bytes(bytes.as_ref()).map_err(Into::into)
}
}

#[cfg(feature = "hex")]
mod hex_impl {
use crate::{result::Result, Abi};
use core::fmt;

impl Abi {
/// Convert [`Abi`] to hex string.
pub fn to_hex(&self) -> Result<String> {
Ok("0x".to_string() + &hex::encode(self.to_bytes()?))
}

/// Convert hex string to [`Abi`].
pub fn from_hex(hex: impl AsRef<str>) -> Result<Self> {
Self::from_bytes(hex::decode(hex.as_ref().trim_start_matches("0x"))?)
.map_err(Into::into)
}
}

impl fmt::Display for Abi {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.to_hex().unwrap_or_default())
}
}

impl core::str::FromStr for Abi {
type Err = crate::result::Error;

fn from_str(hex: &str) -> Result<Self> {
Self::from_hex(hex)
}
}
}

#[cfg(feature = "syn")]
impl From<&syn::Signature> for Abi {
fn from(sig: &syn::Signature) -> Self {
Self(sol_abi::Abi::from(sig))
}
}
75 changes: 4 additions & 71 deletions abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,11 @@
//!
//! Currently just a wrapper of solidity ABI.

mod abi;
pub mod result;
pub mod selector;

use core::ops::{Deref, DerefMut};
pub use abi::Abi;

/// Function ABI.
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Abi(sol_abi::Abi);

impl Deref for Abi {
type Target = sol_abi::Abi;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl DerefMut for Abi {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

#[cfg(feature = "bytes")]
impl Abi {
/// Convert [`Abi`] to bytes.
pub fn to_bytes(&self) -> postcard::Result<Vec<u8>> {
postcard::to_stdvec(self).map_err(Into::into)
}

/// Convert bytes to [`Abi`].
pub fn from_bytes(bytes: impl AsRef<[u8]>) -> postcard::Result<Self> {
postcard::from_bytes(bytes.as_ref()).map_err(Into::into)
}
}

#[cfg(feature = "hex")]
mod hex_impl {
use crate::{result::Result, Abi};

impl Abi {
/// Convert [`Abi`] to hex string.
pub fn to_hex(&self) -> Result<String> {
Ok("0x".to_string() + &hex::encode(self.to_bytes()?))
}

/// Convert hex string to [`Abi`].
pub fn from_hex(hex: impl AsRef<str>) -> Result<Self> {
Self::from_bytes(hex::decode(hex.as_ref().trim_start_matches("0x"))?)
.map_err(Into::into)
}
}

impl ToString for Abi {
fn to_string(&self) -> String {
self.to_hex().unwrap_or_default()
}
}

impl core::str::FromStr for Abi {
type Err = crate::result::Error;

fn from_str(hex: &str) -> Result<Self> {
Self::from_hex(hex)
}
}
}

#[cfg(feature = "syn")]
impl From<&syn::Signature> for Abi {
fn from(sig: &syn::Signature) -> Self {
Self(sol_abi::Abi::from(sig))
}
}
#[cfg(feature = "selector")]
pub use selector::keccak256;
4 changes: 2 additions & 2 deletions abi/src/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
#![cfg(feature = "selector")]

use crate::Abi;
use tiny_keccak::{Hasher, Sha3};
use tiny_keccak::{Hasher, Keccak};

/// Generate a keccak hash of the input (sha3)
pub fn keccak256(input: &[u8]) -> [u8; 32] {
let mut hasher = Sha3::v256();
let mut hasher = Keccak::v256();
let mut output = [0; 32];
hasher.update(input);
hasher.finalize(&mut output);
Expand Down
1 change: 1 addition & 0 deletions codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ thiserror.workspace = true
tracing.workspace = true
wasmparser.workspace = true
zabi = { workspace = true, features = [ "hex", "selector", "syn" ] }
hex.workspace = true
21 changes: 12 additions & 9 deletions codegen/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{Buffer, Error, Result};
use opcodes::{for_each_shanghai_operator, OpCode as _, ShangHai as OpCode};

/// Low level assembler implementation for EVM.
#[derive(Default, Clone)]
#[derive(Default, Clone, Debug)]
pub struct Assembler {
/// Buffer of the assembler.
buffer: Buffer,
Expand Down Expand Up @@ -46,8 +46,8 @@ impl Assembler {
return Ok(());
}

tracing::trace!(
"increment stack pointer {}({items}) -> {}",
tracing::debug!(
"increment stack pointer {}.add({items}) -> {}",
self.sp,
self.sp + items
);
Expand All @@ -67,15 +67,18 @@ impl Assembler {
return Ok(());
}

tracing::trace!(
"decrement stack pointer {}({items}) -> {}",
tracing::debug!(
"decrement stack pointer {}.sub({items}) -> {}",
self.sp,
self.sp - items
);
self.sp = self
.sp
.checked_sub(items)
.ok_or(Error::StackUnderflow(self.sp, items))?;
self.sp = if self.sp == items {
0
} else {
self.sp
.checked_sub(items)
.ok_or(Error::StackUnderflow(self.sp, items))?
};

Ok(())
}
Expand Down
5 changes: 5 additions & 0 deletions codegen/src/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ impl Backtrace {
self.instrs.pop_last().unwrap_or_default().1
}

/// Get the last byte
pub fn last(&self) -> Option<Vec<u8>> {
self.instrs.last_key_value().map(|(_, op)| op.clone())
}

/// Pop the last `n` operands from the backtrace.
pub fn popn(&mut self, n: usize) -> Vec<Vec<u8>> {
let mut r: Vec<Vec<u8>> = Default::default();
Expand Down
Loading

0 comments on commit ed52444

Please sign in to comment.