From 5929a4fb39c88fe5f5d0e812821c98d00f175d26 Mon Sep 17 00:00:00 2001 From: clearloop <26088946+clearloop@users.noreply.github.com> Date: Sat, 21 Oct 2023 01:17:51 +0800 Subject: [PATCH] chore(zabi): not using default features of postcard --- Cargo.lock | 76 +-------------------- Cargo.toml | 2 +- codegen/abi/Cargo.toml | 2 +- codegen/src/func.rs | 152 ----------------------------------------- examples/Cargo.lock | 8 +-- 5 files changed, 9 insertions(+), 231 deletions(-) delete mode 100644 codegen/src/func.rs diff --git a/Cargo.lock b/Cargo.lock index 817dd2f79..a40007073 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -143,15 +143,6 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" -[[package]] -name = "atomic-polyfill" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3ff7eb3f316534d83a8a2c3d1674ace8a5a71198eba31e2e2b597833f699b28" -dependencies = [ - "critical-section", -] - [[package]] name = "auto_impl" version = "1.1.0" @@ -500,9 +491,9 @@ checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" [[package]] name = "cpufeatures" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" +checksum = "3fbc60abd742b35f2492f808e1abbb83d45f72db402e14c55057edc9c7b1e9e4" dependencies = [ "libc", ] @@ -521,12 +512,6 @@ dependencies = [ "url", ] -[[package]] -name = "critical-section" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216" - [[package]] name = "crunchy" version = "0.2.2" @@ -835,15 +820,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "hash32" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" -dependencies = [ - "byteorder", -] - [[package]] name = "hashbrown" version = "0.12.3" @@ -860,20 +836,6 @@ dependencies = [ "allocator-api2", ] -[[package]] -name = "heapless" -version = "0.7.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db04bc24a18b9ea980628ecf00e6c0264f3c1426dac36c00cb49b6fbad8b0743" -dependencies = [ - "atomic-polyfill", - "hash32", - "rustc_version", - "serde", - "spin 0.9.8", - "stable_deref_trait", -] - [[package]] name = "heck" version = "0.4.1" @@ -1006,7 +968,7 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" dependencies = [ - "spin 0.5.2", + "spin", ] [[package]] @@ -1070,16 +1032,6 @@ version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" -[[package]] -name = "lock_api" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "log" version = "0.4.20" @@ -1316,7 +1268,6 @@ checksum = "a55c51ee6c0db07e68448e336cf8ea4131a620edefebf9893e759b2d793420f8" dependencies = [ "cobs", "embedded-io", - "heapless", "serde", ] @@ -1644,12 +1595,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "scratch" version = "1.0.7" @@ -1814,15 +1759,6 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" -dependencies = [ - "lock_api", -] - [[package]] name = "spki" version = "0.7.2" @@ -1833,12 +1769,6 @@ dependencies = [ "der", ] -[[package]] -name = "stable_deref_trait" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" - [[package]] name = "strsim" version = "0.10.0" diff --git a/Cargo.toml b/Cargo.toml index ad707b89f..f7f8654c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ indexmap = "2.0.0" once_cell = "1.18.0" parking_lot = "0.12.1" paste = "1.0.13" -postcard = "1.0.8" +postcard = { version = "1.0.8", default-features = false } proc-macro2 = "1.0.69" quote = "1.0.33" revm = "3.5.0" diff --git a/codegen/abi/Cargo.toml b/codegen/abi/Cargo.toml index 5cac6781a..e058668ea 100644 --- a/codegen/abi/Cargo.toml +++ b/codegen/abi/Cargo.toml @@ -11,7 +11,7 @@ repository.workspace = true [dependencies] hex.workspace = true -postcard = { workspace = true, default-features = true, features = [ "use-std" ] } +postcard = { workspace = true, default-features = false, features = [ "use-std" ] } serde = { workspace = true, features = [ "derive" ] } sha3.workspace = true thiserror.workspace = true diff --git a/codegen/src/func.rs b/codegen/src/func.rs deleted file mode 100644 index 0e5206657..000000000 --- a/codegen/src/func.rs +++ /dev/null @@ -1,152 +0,0 @@ -//! Built-in functions for EVM -use crate::{Error, MacroAssembler, Result}; -use opcodes::ShangHai as OpCode; - -/// Selects one of its first two operands based on whether -/// its third operand is zero or not. -const SELECT: [OpCode; 6] = [ - OpCode::JUMPDEST, - OpCode::POP, - OpCode::PUSH1, - OpCode::Data(0x06), - OpCode::ADD, - OpCode::JUMP, -]; - -/// Function `sload` from EVM which is not available in WASM. -const SLOAD: [OpCode; 7] = [ - OpCode::JUMPDEST, - OpCode::SLOAD, - OpCode::SWAP1, - OpCode::PUSH1, - OpCode::Data(0x05), - OpCode::ADD, - OpCode::JUMP, -]; - -/// Function `sstore` from EVM which is not available in WASM. -const SSTORE: [OpCode; 6] = [ - OpCode::JUMPDEST, - OpCode::SSTORE, - OpCode::PUSH1, - OpCode::Data(0x05), - OpCode::ADD, - OpCode::JUMP, -]; - -/// EVM built-in function. -#[derive(Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq, Hash)] -pub enum Func { - /// Run function select. - Select, - /// Run function sload. - Sload, - /// Run function sstore. - Sstore, - /// Run function log0. - Log0, - /// Run function log1. - Log1, - /// Run function log2. - Log2, - /// Run function log3. - Log3, - /// Run function log4. - Log4, - - // zinkc helper functions - EmitABI, -} - -impl Func { - /// Stack input size. - pub fn stack_in(&self) -> u8 { - match self { - Self::Select => 3, - Self::Sload => 1, - Self::Sstore => 2, - Self::Log0 => 2, - Self::Log1 => 4, - Self::Log2 => 6, - Self::Log3 => 8, - Self::Log4 => 10, - _ => 0, - } - } - - /// Stack output size. - pub fn stack_out(&self) -> u8 { - match self { - Self::Select => 1, - Self::Sload => 1, - Self::Sstore => 0, - Self::Log0 => 0, - Self::Log1 => 0, - Self::Log2 => 0, - Self::Log3 => 0, - Self::Log4 => 0, - _ => 0, - } - } - - /// Pre-processing for the function. - pub fn prelude(&self, masm: &mut MacroAssembler) -> Result<()> { - match self { - Self::Select => { - masm._pc()?; - masm._swap2()?; - masm._swap1() - } - Self::Sstore => masm._swap1(), - _ => Ok(()), - } - } - - /// Get the bytecode of the function. - pub fn bytecode(&self) -> Vec { - match self { - Self::Select => SELECT.to_vec(), - Self::Sload => SLOAD.to_vec(), - Self::Sstore => SSTORE.to_vec(), - _ => unimplemented!("not implemented for {:?}", self), - } - .into_iter() - .map(|op| op.into()) - .collect() - } - - /// If this function should be embedded in - /// the main code. - /// - /// TODO: return `false` for functions that - /// are necessary to just stay in the code - /// section #109 - pub fn is_embedded(&self) -> bool { - true - } -} - -impl TryFrom<(&str, &str)> for Func { - type Error = Error; - - fn try_from(import: (&str, &str)) -> Result { - let (module, name) = import; - // NOTE: `select` is not external call - // so we don't need to check process it - // here - match import { - ("evm", "sload") => Ok(Self::Sload), - ("evm", "sstore") => Ok(Self::Sstore), - ("evm", "log0") => Ok(Self::Log0), - ("evm", "log1") => Ok(Self::Log1), - ("evm", "log2") => Ok(Self::Log2), - ("evm", "log3") => Ok(Self::Log3), - ("evm", "log4") => Ok(Self::Log4), - ("zinkc", "emit_abi") => Ok(Self::EmitABI), - _ => { - tracing::error!("Failed to load host function: {:?}", import); - Err(Error::HostFuncNotFound(module.into(), name.into())) - } - } - } -} diff --git a/examples/Cargo.lock b/examples/Cargo.lock index f67fc63ba..4e75d5bba 100644 --- a/examples/Cargo.lock +++ b/examples/Cargo.lock @@ -47,9 +47,9 @@ checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" [[package]] name = "cpufeatures" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" +checksum = "3fbc60abd742b35f2492f808e1abbb83d45f72db402e14c55057edc9c7b1e9e4" dependencies = [ "libc", ] @@ -156,9 +156,9 @@ checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" [[package]] name = "lock_api" -version = "0.4.10" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" dependencies = [ "autocfg", "scopeguard",