Skip to content

Commit

Permalink
sync
Browse files Browse the repository at this point in the history
  • Loading branch information
malik672 committed Dec 11, 2024
1 parent 583dbe2 commit ea57ae0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 48 deletions.
20 changes: 0 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 6 additions & 24 deletions examples/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
1 change: 0 additions & 1 deletion zink/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ] }
6 changes: 3 additions & 3 deletions zink/codegen/src/event.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -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>]) -> [u8; 32] {
let flattened: Vec<u8> = data.concat();
Keccak256::digest(&flattened).into()
keccak256(&flattened.as_slice())
}

/// Helper function to flatten and pad data
Expand Down

0 comments on commit ea57ae0

Please sign in to comment.