Skip to content

Commit

Permalink
[fix] move from_json_file back to prover crate (scroll-tech#1350)
Browse files Browse the repository at this point in the history
* move from_json_file back to prover crate

* fix test
  • Loading branch information
lightsing authored Jun 26, 2024
1 parent 5b58085 commit b1d78bf
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 35 deletions.
5 changes: 2 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions eth-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ halo2curves.workspace = true
log.workspace = true
regex.workspace = true
serde.workspace = true
serde_json = { workspace = true, features = ["unbounded_depth"] }
serde_stacker.workspace = true
serde_json.workspace = true
serde_with = "1.12"
uint = "0.9.1"
itertools.workspace = true
Expand Down
12 changes: 0 additions & 12 deletions eth-types/src/l2_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,15 +536,3 @@ pub struct AccountTrace {
#[serde(rename = "codeSize")]
pub code_size: u64,
}

#[ignore]
#[test]
fn test_block_trace_convert() {
let trace_v1: BlockTrace =
crate::utils::from_json_file("src/testdata/trace_v1_5224657.json").expect("should load");
let trace_v2: BlockTraceV2 = trace_v1.into();
let mut fd = std::fs::File::create("src/testdata/trace_v2_5224657.json").unwrap();
serde_json::to_writer_pretty(&mut fd, &trace_v2).unwrap();
// then we can use this command to compare the traces:
// vimdiff <(jq -S "del(.executionResults)|del(.txStorageTraces)" src/testdata/trace_v1_5224657.json) <(jq -S . src/testdata/trace_v2_5224657.json)
}
2 changes: 0 additions & 2 deletions eth-types/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
use crate::Address;
use revm_precompile::Precompiles;

mod io;
pub use io::*;
mod codehash;
pub use codehash::*;

Expand Down
15 changes: 0 additions & 15 deletions eth-types/src/utils/io.rs

This file was deleted.

25 changes: 25 additions & 0 deletions prover/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ use std::{
path::{Path, PathBuf},
};

pub fn from_json_file<'de, P: serde::Deserialize<'de>>(file_path: &str) -> anyhow::Result<P> {
if !Path::new(&file_path).exists() {
anyhow::bail!("File {file_path} doesn't exist");
}

let fd = File::open(file_path)?;
let mut deserializer = serde_json::Deserializer::from_reader(fd);
deserializer.disable_recursion_limit();
let deserializer = serde_stacker::Deserializer::new(&mut deserializer);

Ok(serde::Deserialize::deserialize(deserializer)?)
}

pub fn serialize_fr(f: &Fr) -> Vec<u8> {
f.to_bytes().to_vec()
}
Expand Down Expand Up @@ -127,3 +140,15 @@ pub fn load_instances(buf: &[u8]) -> Vec<Vec<Vec<Fr>>> {
})
.collect()
}

#[ignore]
#[test]
fn test_block_trace_convert() {
let trace_v1: eth_types::l2_types::BlockTrace =
from_json_file("src/testdata/trace_v1_5224657.json").expect("should load");
let trace_v2: eth_types::l2_types::BlockTraceV2 = trace_v1.into();
let mut fd = std::fs::File::create("src/testdata/trace_v2_5224657.json").unwrap();
serde_json::to_writer_pretty(&mut fd, &trace_v2).unwrap();
// then we can use this command to compare the traces:
// vimdiff <(jq -S "del(.executionResults)|del(.txStorageTraces)" src/testdata/trace_v1_5224657.json) <(jq -S . src/testdata/trace_v2_5224657.json)
}
2 changes: 1 addition & 1 deletion prover/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub fn dump_vk(dir: &str, filename: &str, raw_vk: &[u8]) {

pub fn from_json_file<'de, P: serde::Deserialize<'de>>(dir: &str, filename: &str) -> Result<P> {
let file_path = dump_proof_path(dir, filename);
Ok(eth_types::utils::from_json_file(&file_path)?)
crate::io::from_json_file(&file_path)
}

fn dump_proof_path(dir: &str, filename: &str) -> String {
Expand Down

0 comments on commit b1d78bf

Please sign in to comment.