sha3 && log
This commit is contained in:
parent
4d6c5762ff
commit
ee8c903b0b
@ -5,3 +5,4 @@ authors = ["debris <marek.kotewicz@gmail.com>"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libc = "0.2.2"
|
libc = "0.2.2"
|
||||||
|
tiny-keccak = "1.0"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
//! Bare rust wrapper around evmjit
|
//! Bare rust wrapper around evmjit.
|
||||||
//!
|
//!
|
||||||
//! Requires latest version of Ethereum EVM JIT. https://github.com/debris/evmjit
|
//! Requires latest version of Ethereum EVM JIT. https://github.com/debris/evmjit
|
||||||
//!
|
//!
|
||||||
@ -14,6 +14,8 @@
|
|||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
extern crate tiny_keccak;
|
||||||
|
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use self::ffi::*;
|
use self::ffi::*;
|
||||||
|
|
||||||
@ -102,6 +104,14 @@ pub trait Env {
|
|||||||
out_size: *mut u64,
|
out_size: *mut u64,
|
||||||
code_address: JitI256) -> bool;
|
code_address: JitI256) -> bool;
|
||||||
|
|
||||||
|
fn log(&mut self,
|
||||||
|
beg: *const u8,
|
||||||
|
size: *const u64,
|
||||||
|
topic1: *const JitI256,
|
||||||
|
topic2: *const JitI256,
|
||||||
|
topic3: *const JitI256,
|
||||||
|
topic4: *const JitI256);
|
||||||
|
|
||||||
fn extcode(&self, address: *const JitI256, size: *mut u64) -> *const u8;
|
fn extcode(&self, address: *const JitI256, size: *mut u64) -> *const u8;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,8 +155,10 @@ impl DerefMut for EnvHandle {
|
|||||||
|
|
||||||
/// ffi functions
|
/// ffi functions
|
||||||
pub mod ffi {
|
pub mod ffi {
|
||||||
use super::*;
|
use std::slice;
|
||||||
use libc;
|
use libc;
|
||||||
|
use tiny_keccak::Keccak;
|
||||||
|
use super::*;
|
||||||
|
|
||||||
/// Jit context struct declaration.
|
/// Jit context struct declaration.
|
||||||
pub enum JitContext {}
|
pub enum JitContext {}
|
||||||
@ -243,8 +255,14 @@ pub mod ffi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern fn env_sha3(_begin: *const u8, _size: *const u64, _out_hash: *const JitI256) {
|
pub unsafe extern fn env_sha3(begin: *const u8, size: *const u64, out_hash: *mut JitI256) {
|
||||||
unimplemented!()
|
let out_hash = &mut *out_hash;
|
||||||
|
let input = slice::from_raw_parts(begin, *size as usize);
|
||||||
|
let outlen = out_hash.words.len() * 8;
|
||||||
|
let output = slice::from_raw_parts_mut(out_hash.words.as_mut_ptr() as *mut u8, outlen);
|
||||||
|
let mut sha3 = Keccak::new_sha3_256();
|
||||||
|
sha3.update(input);
|
||||||
|
sha3.finalize(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
@ -254,14 +272,15 @@ pub mod ffi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern fn env_log(_env: *mut EnvHandle,
|
pub unsafe extern fn env_log(env: *mut EnvHandle,
|
||||||
_beg: *const u8,
|
beg: *const u8,
|
||||||
_size: *const u64,
|
size: *const u64,
|
||||||
_topic1: *const JitI256,
|
topic1: *const JitI256,
|
||||||
_topic2: *const JitI256,
|
topic2: *const JitI256,
|
||||||
_topic3: *const JitI256,
|
topic3: *const JitI256,
|
||||||
_topic4: *const JitI256) {
|
topic4: *const JitI256) {
|
||||||
unimplemented!()
|
let env = &mut *env;
|
||||||
|
env.log(beg, size, topic1, topic2, topic3, topic4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user