diff --git a/Cargo.toml b/Cargo.toml index bf49d45b93..e327b8f26a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,9 +54,6 @@ syn-solidity = { version = "0.7.7", path = "crates/syn-solidity", default-featur serde = { version = "1.0", default-features = false, features = ["alloc"] } serde_json = { version = "1.0", default-features = false, features = ["alloc"] } -# ssz -ethereum_ssz = { version = "0.5.3", default-features = false } - # macros proc-macro-error = "1.0" proc-macro2 = "1.0" diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index bbafaa5900..7c391185e3 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -51,7 +51,6 @@ getrandom = ["alloy-primitives/getrandom"] rand = ["alloy-primitives/rand"] rlp = ["alloy-primitives/rlp", "dep:alloy-rlp"] serde = ["alloy-primitives/serde"] -ssz = ["std", "alloy-primitives/ssz"] arbitrary = [ "std", "alloy-primitives/arbitrary", diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index 3f4bd42d43..43819fbfec 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -39,9 +39,6 @@ alloy-rlp = { workspace = true, optional = true } # serde serde = { workspace = true, optional = true, features = ["derive"] } -# ssz -ethereum_ssz = { workspace = true, optional = true } - # getrandom getrandom = { workspace = true, optional = true } @@ -92,7 +89,6 @@ getrandom = ["dep:getrandom"] rand = ["dep:rand", "getrandom", "ruint/rand"] rlp = ["dep:alloy-rlp", "ruint/alloy-rlp"] serde = ["dep:serde", "bytes/serde", "hex/serde", "ruint/serde"] -ssz = ["std", "dep:ethereum_ssz", "ruint/ssz"] arbitrary = [ "std", "dep:arbitrary", @@ -101,7 +97,6 @@ arbitrary = [ "dep:proptest-derive", "ruint/arbitrary", "ruint/proptest", - "ethereum_ssz?/arbitrary", ] k256 = ["dep:k256"] allocative = ["dep:allocative"] diff --git a/crates/primitives/src/bits/macros.rs b/crates/primitives/src/bits/macros.rs index 1ba15b352e..4e93569c6c 100644 --- a/crates/primitives/src/bits/macros.rs +++ b/crates/primitives/src/bits/macros.rs @@ -179,7 +179,6 @@ macro_rules! wrap_fixed_bytes { $crate::impl_serde!($name); $crate::impl_allocative!($name); $crate::impl_arbitrary!($name, $n); - $crate::impl_ssz_fixed_len!($name, $n); $crate::impl_rand!($name); impl $name { @@ -665,65 +664,6 @@ macro_rules! impl_arbitrary { ($t:ty, $n:literal) => {}; } -#[doc(hidden)] -#[macro_export] -#[cfg(feature = "ssz")] -macro_rules! impl_ssz_fixed_len { - ($type:ty, $fixed_len:expr) => { - impl $crate::private::ssz::Encode for $type { - #[inline] - fn is_ssz_fixed_len() -> bool { - true - } - - #[inline] - fn ssz_fixed_len() -> usize { - $fixed_len - } - - #[inline] - fn ssz_bytes_len(&self) -> usize { - <$type as $crate::private::ssz::Encode>::ssz_fixed_len() - } - - #[inline] - fn ssz_append(&self, buf: &mut $crate::private::Vec) { - buf.extend_from_slice(self.as_slice()); - } - } - - impl $crate::private::ssz::Decode for $type { - #[inline] - fn is_ssz_fixed_len() -> bool { - true - } - - #[inline] - fn ssz_fixed_len() -> usize { - $fixed_len - } - - fn from_ssz_bytes(bytes: &[u8]) -> Result { - let len = bytes.len(); - let expected: usize = <$type as $crate::private::ssz::Decode>::ssz_fixed_len(); - - if len != expected { - Err($crate::private::ssz::DecodeError::InvalidByteLength { len, expected }) - } else { - Ok(<$type>::from_slice(bytes)) - } - } - } - }; -} - -#[doc(hidden)] -#[macro_export] -#[cfg(not(feature = "ssz"))] -macro_rules! impl_ssz_fixed_len { - ($t:ty, $n:literal) => {}; -} - macro_rules! fixed_bytes_macros { ($d:tt $($(#[$attr:meta])* macro $name:ident($ty:ident $($rest:tt)*);)*) => {$( /// Converts a sequence of string literals containing hex-encoded data diff --git a/crates/primitives/src/bits/mod.rs b/crates/primitives/src/bits/mod.rs index 55b03196f1..be65685742 100644 --- a/crates/primitives/src/bits/mod.rs +++ b/crates/primitives/src/bits/mod.rs @@ -18,6 +18,3 @@ mod rlp; #[cfg(feature = "serde")] mod serde; - -#[cfg(feature = "ssz")] -mod ssz; diff --git a/crates/primitives/src/bits/ssz.rs b/crates/primitives/src/bits/ssz.rs deleted file mode 100644 index 94dc1ce5aa..0000000000 --- a/crates/primitives/src/bits/ssz.rs +++ /dev/null @@ -1,136 +0,0 @@ -use crate::FixedBytes; -use alloc::vec::Vec; -use ssz::{Decode, DecodeError, Encode}; - -impl Encode for FixedBytes { - #[inline] - fn is_ssz_fixed_len() -> bool { - true - } - - #[inline] - fn ssz_bytes_len(&self) -> usize { - N - } - - #[inline] - fn ssz_fixed_len() -> usize { - N - } - - #[inline] - fn ssz_append(&self, buf: &mut Vec) { - buf.extend_from_slice(&self.0); - } - - #[inline] - fn as_ssz_bytes(&self) -> Vec { - self.0.to_vec() - } -} - -impl Decode for FixedBytes { - fn is_ssz_fixed_len() -> bool { - true - } - - fn ssz_fixed_len() -> usize { - N - } - - fn from_ssz_bytes(bytes: &[u8]) -> Result { - if bytes.len() != N { - return Err(DecodeError::InvalidByteLength { len: bytes.len(), expected: N }); - } - - let mut fixed_array = [0u8; N]; - fixed_array.copy_from_slice(bytes); - - Ok(Self(fixed_array)) - } -} - -#[cfg(test)] -mod tests { - use super::*; - use crate::{Address, Bloom}; - - macro_rules! test_encode_decode_ssz { - ($test_name:ident, $type:ty, [$( $value:expr ),*]) => { - #[test] - fn $test_name() { - $( - let expected: $type = $value; - let encoded = ssz::Encode::as_ssz_bytes(&expected); - let actual: $type = ssz::Decode::from_ssz_bytes(&encoded).unwrap(); - assert_eq!(expected, actual, "Failed for value: {:?}", $value); - )* - } - }; - } - - test_encode_decode_ssz!( - test_encode_decode_fixed_bytes32, - FixedBytes<32>, - [fixed_bytes!("a1de988600a42c4b4ab089b619297c17d53cffae5d5120d82d8a92d0bb3b78f2")] - ); - - test_encode_decode_ssz!( - test_encode_decode_fixed_bytes4, - FixedBytes<4>, - [fixed_bytes!("01234567")] - ); - - test_encode_decode_ssz!( - test_encode_decode_bloom, - Bloom, - [bloom!( - "00000000000000000000000000000000 - 00000000100000000000000000000000 - 00000000000000000000000000000000 - 00000000000000000000000000000000 - 00000000000000000000000000000000 - 00000000000000000000000000000000 - 00000002020000000000000000000000 - 00000000000000000000000800000000 - 10000000000000000000000000000000 - 00000000000000000000001000000000 - 00000000000000000000000000000000 - 00000000000000000000000000000000 - 00000000000000000000000000000000 - 00000000000000000000000000000000 - 00000000000000000000000000000000 - 00000000000000000000000000000000" - )] - ); - test_encode_decode_ssz!( - test_encode_decode_address, - Address, - [ - address!("2222222222222222222222222222222222222222"), - address!("0000000000000000000000000000000000012321"), - address!("0000000000000000000000000000000000000000") - ] - ); - - #[test] - fn test_ssz_fixed_lengths() { - assert_eq!(::ssz_fixed_len(), 8); - assert_eq!(::ssz_fixed_len(), 8); - - assert_eq!(<[u8; 32] as Encode>::ssz_fixed_len(), 32); - assert_eq!(<[u8; 32] as Decode>::ssz_fixed_len(), 32); - - assert_eq!(::ssz_fixed_len(), 256); - assert_eq!(::ssz_fixed_len(), 256); - - assert_eq!(
::ssz_fixed_len(), 20); - assert_eq!(
::ssz_fixed_len(), 20); - - assert_eq!( as Encode>::ssz_fixed_len(), 32); - assert_eq!( as Decode>::ssz_fixed_len(), 32); - - assert_eq!( as Encode>::ssz_fixed_len(), 4); - assert_eq!( as Decode>::ssz_fixed_len(), 4); - } -} diff --git a/crates/primitives/src/bytes/mod.rs b/crates/primitives/src/bytes/mod.rs index 6b13511127..0b5aee34b0 100644 --- a/crates/primitives/src/bytes/mod.rs +++ b/crates/primitives/src/bytes/mod.rs @@ -12,9 +12,6 @@ mod rlp; #[cfg(feature = "serde")] mod serde; -#[cfg(feature = "ssz")] -mod ssz; - /// Wrapper type around [`bytes::Bytes`] to support "0x" prefixed hex strings. #[derive(Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(transparent)] diff --git a/crates/primitives/src/bytes/ssz.rs b/crates/primitives/src/bytes/ssz.rs deleted file mode 100644 index c4ced1717e..0000000000 --- a/crates/primitives/src/bytes/ssz.rs +++ /dev/null @@ -1,62 +0,0 @@ -use crate::Bytes; -use alloc::vec::Vec; -use ssz::{Decode, DecodeError, Encode}; - -impl Encode for Bytes { - #[inline] - fn is_ssz_fixed_len() -> bool { - false - } - - #[inline] - fn ssz_bytes_len(&self) -> usize { - self.0.len() - } - - #[inline] - fn ssz_append(&self, buf: &mut Vec) { - buf.extend_from_slice(&self.0); - } - - #[inline] - fn as_ssz_bytes(&self) -> Vec { - self.0.to_vec() - } -} - -impl Decode for Bytes { - #[inline] - fn is_ssz_fixed_len() -> bool { - false - } - - #[inline] - fn from_ssz_bytes(bytes: &[u8]) -> Result { - Ok(bytes.to_vec().into()) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - macro_rules! test_encode_decode_ssz { - ($test_name:ident, $type:ty, [$( $value:expr ),*]) => { - #[test] - fn $test_name() { - $( - let expected: $type = $value; - let encoded = ssz::Encode::as_ssz_bytes(&expected); - let actual: $type = ssz::Decode::from_ssz_bytes(&encoded).unwrap(); - assert_eq!(expected, actual, "Failed for value: {:?}", $value); - )* - } - }; - } - - test_encode_decode_ssz!( - test_encode_decode_bytes, - Bytes, - [bytes!("01234567"), bytes!("6394198df16000526103ff60206004601c335afa6040516060f3")] - ); -} diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index 6e8c65f30f..2914862b6b 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -122,9 +122,6 @@ pub mod private { #[cfg(feature = "allocative")] pub use allocative; - #[cfg(feature = "ssz")] - pub use ssz; - #[cfg(feature = "serde")] pub use serde;