implement calldatacopy

Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
xermicus
2024-03-19 10:49:47 +01:00
parent 6d058a42ed
commit 2b9e40225d
12 changed files with 210 additions and 43 deletions
+22 -1
View File
@@ -2,7 +2,7 @@
//! TODO: Switch to drink! once RISCV is ready in polkadot-sdk
use std::collections::HashMap;
use alloy_primitives::U256;
use alloy_primitives::{Keccak256, U256};
use parity_scale_codec::Encode;
use polkavm::{
Caller, Config, Engine, ExportIndex, GasMeteringKind, InstancePre, Linker, Module,
@@ -168,6 +168,27 @@ fn link_host_functions(engine: &Engine) -> Linker<State> {
)
.unwrap();
linker
.func_wrap(
"hash_keccak_256",
|caller: Caller<State>,
input_ptr: u32,
input_len: u32,
out_ptr: u32|
-> Result<(), Trap> {
let (mut caller, _) = caller.split();
let pre = caller.read_memory_into_vec(input_ptr, input_len)?;
let mut hasher = Keccak256::new();
hasher.update(&pre);
caller.write_memory(out_ptr, &hasher.finalize()[..])?;
Ok(())
},
)
.unwrap();
linker
}