From ea57ae0f6913c4e099069c357d0f303d3322d8a3 Mon Sep 17 00:00:00 2001 From: malik Date: Wed, 11 Dec 2024 12:18:41 +0100 Subject: [PATCH] sync --- Cargo.lock | 20 -------------------- examples/log.rs | 30 ++++++------------------------ zink/codegen/Cargo.toml | 1 - zink/codegen/src/event.rs | 6 +++--- 4 files changed, 9 insertions(+), 48 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dcb8df2f2..e0569d53d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1134,15 +1134,6 @@ dependencies = [ "sha2", ] -[[package]] -name = "keccak" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" -dependencies = [ - "cpufeatures", -] - [[package]] name = "keccak-asm" version = "0.1.4" @@ -1886,16 +1877,6 @@ dependencies = [ "digest 0.10.7", ] -[[package]] -name = "sha3" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" -dependencies = [ - "digest 0.10.7", - "keccak", -] - [[package]] name = "sha3-asm" version = "0.1.4" @@ -2670,7 +2651,6 @@ dependencies = [ "hex", "proc-macro2", "quote", - "sha3", "syn 2.0.77", "zabi", ] diff --git a/examples/log.rs b/examples/log.rs index dffb1ca8f..b60c5d796 100644 --- a/examples/log.rs +++ b/examples/log.rs @@ -25,51 +25,33 @@ pub mod event_tests { /// Test log0 #[zink::external] + #[allow(path_statements)] pub fn test_log0() { - unsafe { zink::ffi::evm::log0(b"MyEvent") } + MyEvent::Topic0; } /// Test log1 #[zink::external] pub fn test_log1(value: U256) { - unsafe { - let topic = value.bytes32(); - zink::ffi::evm::log1(topic, b"MyEvent") - } + MyEvent::Topic1(value); } /// Test log2 #[zink::external] pub fn test_log2(value1: U256, value2: U256) { - unsafe { - let topic1 = value1.bytes32(); - let topic2 = value2.bytes32(); - zink::ffi::evm::log2(topic1, topic2, b"MyEvent") - } + MyEvent::Topic2(value1, value2); } /// Test log3 #[zink::external] pub fn test_log3(value1: U256, value2: U256, value3: U256) { - unsafe { - let topic1 = value1.bytes32(); - let topic2 = value2.bytes32(); - let topic3 = value3.bytes32(); - zink::ffi::evm::log3(topic1, topic2, topic3, b"MyEvent") - } + MyEvent::Topic3(value1, value2, value3); } /// Test log4 #[zink::external] pub fn test_log4(value1: U256, value2: U256, value3: U256, value4: U256) { - unsafe { - let topic1 = value1.bytes32(); - let topic2 = value2.bytes32(); - let topic3 = value3.bytes32(); - let topic4 = value4.bytes32(); - - zink::ffi::evm::log4(topic1, topic2, topic3, topic4, b"MyEvent") - } + MyEvent::Topic4(value1, value2, value3, value4); } } diff --git a/zink/codegen/Cargo.toml b/zink/codegen/Cargo.toml index 767338601..f925f27bb 100644 --- a/zink/codegen/Cargo.toml +++ b/zink/codegen/Cargo.toml @@ -17,6 +17,5 @@ heck.workspace = true hex.workspace = true proc-macro2.workspace = true quote.workspace = true -sha3 = "0.10.8" syn.workspace = true zabi = { workspace = true, features = [ "hex", "syn" ] } diff --git a/zink/codegen/src/event.rs b/zink/codegen/src/event.rs index 875b9847b..6f6d78a30 100644 --- a/zink/codegen/src/event.rs +++ b/zink/codegen/src/event.rs @@ -1,10 +1,10 @@ use proc_macro::{Span, TokenStream}; use quote::{quote, ToTokens}; -use sha3::{Digest, Keccak256}; use syn::{ parse::Parse, parse_quote, spanned::Spanned, Abi, Data, DeriveInput, Error, Fields, LitByteStr, Result, Type, Variant, }; +use zabi::keccak256; /// Custom error type for better error handling #[derive(Debug)] @@ -314,13 +314,13 @@ fn type_to_string(ty: &Type) -> String { /// Generate topic hash fn generate_topic_hash(input: &str) -> [u8; 32] { - Keccak256::digest(input.as_bytes()).into() + keccak256(input.as_bytes().to_vec().as_slice()) } /// Generate data hash fn generate_data_hash(data: &[Vec]) -> [u8; 32] { let flattened: Vec = data.concat(); - Keccak256::digest(&flattened).into() + keccak256(&flattened.as_slice()) } /// Helper function to flatten and pad data