Skip to main content

fluentbase_runtime/syscall_handler/hashing/
keccak256.rs

1/// This function will be removed in the future.
2/// We keep it only for backward compatibility with testnet.
3use crate::RuntimeContext;
4use fluentbase_types::{keccak256, B256};
5use rwasm::{StoreTr, TrapCode, Value};
6
7pub fn syscall_hashing_keccak256_handler(
8    caller: &mut impl StoreTr<RuntimeContext>,
9    params: &[Value],
10    _result: &mut [Value],
11) -> Result<(), TrapCode> {
12    let (data_offset, data_len, output_offset) = (
13        params[0].i32().unwrap() as usize,
14        params[1].i32().unwrap() as usize,
15        params[2].i32().unwrap() as usize,
16    );
17    let data = caller.memory_read_into_vec(data_offset, data_len)?;
18    let hash = syscall_hashing_keccak256_impl(&data);
19    caller.memory_write(output_offset, hash.as_slice())?;
20    Ok(())
21}
22
23pub fn syscall_hashing_keccak256_impl(data: &[u8]) -> B256 {
24    keccak256(data)
25}