mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-05-05 17:49:31 +00:00
Provide methods for serializing Kernel
This commit is contained in:
parent
6b2503f778
commit
df5a90cca4
@ -36,6 +36,7 @@ serde = { version = "1.0.144", features = ["derive"] }
|
|||||||
static_assertions = "1.1.0"
|
static_assertions = "1.1.0"
|
||||||
hashbrown = { version = "0.12.3" }
|
hashbrown = { version = "0.12.3" }
|
||||||
tiny-keccak = "2.0.2"
|
tiny-keccak = "2.0.2"
|
||||||
|
serde_json = "1.0"
|
||||||
|
|
||||||
[target.'cfg(not(target_env = "msvc"))'.dependencies]
|
[target.'cfg(not(target_env = "msvc"))'.dependencies]
|
||||||
jemallocator = "0.5.0"
|
jemallocator = "0.5.0"
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::fs;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use ethereum_types::U256;
|
use ethereum_types::U256;
|
||||||
use itertools::{izip, Itertools};
|
use itertools::{izip, Itertools};
|
||||||
use keccak_hash::keccak;
|
use keccak_hash::keccak;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::ast::PushTarget;
|
use super::ast::PushTarget;
|
||||||
use crate::cpu::kernel::ast::Item::LocalLabelDeclaration;
|
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.
|
/// nontrivial given the circular dependency between an offset and its size.
|
||||||
pub(crate) const BYTES_PER_OFFSET: u8 = 3;
|
pub(crate) const BYTES_PER_OFFSET: u8 = 3;
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug)]
|
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize)]
|
||||||
pub struct Kernel {
|
pub struct Kernel {
|
||||||
pub(crate) code: Vec<u8>,
|
pub(crate) code: Vec<u8>,
|
||||||
|
|
||||||
@ -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.
|
/// Get a string representation of the current offset for debugging purposes.
|
||||||
pub(crate) fn offset_name(&self, offset: usize) -> String {
|
pub(crate) fn offset_name(&self, offset: usize) -> String {
|
||||||
match self
|
match self
|
||||||
|
|||||||
@ -5,6 +5,7 @@ use anyhow::{bail, Error};
|
|||||||
use ethereum_types::{BigEndianHash, H256, U256, U512};
|
use ethereum_types::{BigEndianHash, H256, U256, U512};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use plonky2::field::types::Field;
|
use plonky2::field::types::Field;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::extension_tower::{FieldExt, Fp12, BLS381, BN254};
|
use crate::extension_tower::{FieldExt, Fp12, BLS381, BN254};
|
||||||
use crate::generation::prover_input::EvmField::{
|
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.
|
/// Prover input function represented as a scoped function name.
|
||||||
/// Example: `PROVER_INPUT(ff::bn254_base::inverse)` is represented as `ProverInputFn([ff, bn254_base, inverse])`.
|
/// 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<String>);
|
pub struct ProverInputFn(Vec<String>);
|
||||||
|
|
||||||
impl From<Vec<String>> for ProverInputFn {
|
impl From<Vec<String>> for ProverInputFn {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user