diff --git a/evm/Cargo.toml b/evm/Cargo.toml index 45849283..3e5f3482 100644 --- a/evm/Cargo.toml +++ b/evm/Cargo.toml @@ -36,6 +36,7 @@ serde = { version = "1.0.144", features = ["derive"] } static_assertions = "1.1.0" hashbrown = { version = "0.12.3" } tiny-keccak = "2.0.2" +serde_json = "1.0" [target.'cfg(not(target_env = "msvc"))'.dependencies] jemallocator = "0.5.0" diff --git a/evm/src/cpu/kernel/assembler.rs b/evm/src/cpu/kernel/assembler.rs index 2afd328f..ffa3caca 100644 --- a/evm/src/cpu/kernel/assembler.rs +++ b/evm/src/cpu/kernel/assembler.rs @@ -1,10 +1,12 @@ use std::collections::HashMap; +use std::fs; use std::time::Instant; use ethereum_types::U256; use itertools::{izip, Itertools}; use keccak_hash::keccak; use log::debug; +use serde::{Deserialize, Serialize}; use super::ast::PushTarget; use crate::cpu::kernel::ast::Item::LocalLabelDeclaration; @@ -20,7 +22,7 @@ use crate::generation::prover_input::ProverInputFn; /// nontrivial given the circular dependency between an offset and its size. pub(crate) const BYTES_PER_OFFSET: u8 = 3; -#[derive(PartialEq, Eq, Debug)] +#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)] pub struct Kernel { pub(crate) code: Vec, @@ -60,6 +62,16 @@ impl Kernel { } } + pub fn to_file(&self, path: &str) { + let kernel_serialized = serde_json::to_string(self).unwrap(); + fs::write(path, kernel_serialized).expect("Unable to write kernel to file"); + } + + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).expect("Unable to read kernel file"); + serde_json::from_slice(&bytes).unwrap() + } + /// Get a string representation of the current offset for debugging purposes. pub(crate) fn offset_name(&self, offset: usize) -> String { match self diff --git a/evm/src/generation/prover_input.rs b/evm/src/generation/prover_input.rs index 28380f7e..712c51fe 100644 --- a/evm/src/generation/prover_input.rs +++ b/evm/src/generation/prover_input.rs @@ -5,6 +5,7 @@ use anyhow::{bail, Error}; use ethereum_types::{BigEndianHash, H256, U256, U512}; use itertools::Itertools; use plonky2::field::types::Field; +use serde::{Deserialize, Serialize}; use crate::extension_tower::{FieldExt, Fp12, BLS381, BN254}; use crate::generation::prover_input::EvmField::{ @@ -19,7 +20,7 @@ use crate::witness::util::{kernel_peek, stack_peek}; /// Prover input function represented as a scoped function name. /// Example: `PROVER_INPUT(ff::bn254_base::inverse)` is represented as `ProverInputFn([ff, bn254_base, inverse])`. -#[derive(PartialEq, Eq, Debug, Clone)] +#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] pub struct ProverInputFn(Vec); impl From> for ProverInputFn {