From 83ef772154dbb378f18533b9dbca8df33938a8a0 Mon Sep 17 00:00:00 2001 From: ratankaliani Date: Thu, 5 Sep 2024 22:15:38 +0000 Subject: [PATCH] wip --- Cargo.lock | 1 + utils/host/Cargo.toml | 1 + utils/host/src/helpers.rs | 8 +++++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 13b33c30..ce4d0e4c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4131,6 +4131,7 @@ dependencies = [ "dotenv", "futures", "kona-host", + "kona-preimage", "num-format", "op-succinct-client-utils", "revm", diff --git a/utils/host/Cargo.toml b/utils/host/Cargo.toml index 4814cd72..67e62ae1 100644 --- a/utils/host/Cargo.toml +++ b/utils/host/Cargo.toml @@ -12,6 +12,7 @@ alloy-sol-types.workspace = true op-succinct-client-utils.workspace = true rkyv.workspace = true kona-host.workspace = true +kona-preimage.workspace = true sp1-sdk.workspace = true anyhow.workspace = true cargo_metadata.workspace = true diff --git a/utils/host/src/helpers.rs b/utils/host/src/helpers.rs index 6c56b5d2..45011e00 100644 --- a/utils/host/src/helpers.rs +++ b/utils/host/src/helpers.rs @@ -1,6 +1,7 @@ -use alloy_primitives::hex; +use alloy_primitives::{hex, keccak256}; use op_succinct_client_utils::BytesHasherBuilder; use std::{collections::HashMap, fs, io::Read, path::PathBuf}; +use kona_preimage::{HintWriterClient, PreimageKey, PreimageKeyType, PreimageOracleClient}; pub fn load_kv_store(data_dir: &PathBuf) -> HashMap<[u8; 32], Vec, BytesHasherBuilder> { let capacity = get_file_count(data_dir); @@ -13,15 +14,20 @@ pub fn load_kv_store(data_dir: &PathBuf) -> HashMap<[u8; 32], Vec, BytesHash if path.is_file() { // Extract the file name let file_name = path.file_stem().unwrap().to_str().unwrap(); + println!("File name: {:?}", file_name); // Convert the file name to PreimageKey if let Ok(key) = hex::decode(file_name) { + // Hash the key with SHA256. + let key = PreimageKey::new(keccak256(&key).into(), PreimageKeyType::Keccak256); + // Read the file contents let mut file = fs::File::open(path).expect("Failed to open file"); let mut contents = Vec::new(); file.read_to_end(&mut contents).expect("Failed to read file"); // Insert the key-value pair into the cache + println!("Inserting key: {:?}", key); cache.insert(key.try_into().unwrap(), contents); } }