Skip to content

Commit

Permalink
Merge branch 'rkhalil/op-compose' into rkhalil/stark2snark
Browse files Browse the repository at this point in the history
  • Loading branch information
Wollac authored Feb 12, 2024
2 parents 035b582 + 9e3d5bf commit c14ef25
Show file tree
Hide file tree
Showing 35 changed files with 77 additions and 82 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ cache_zkp/
log.txt
*.pb
*.zkp
cache_rpc.json
.idea
2 changes: 1 addition & 1 deletion guests/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion guests/eth-block/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion guests/op-block/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
4 changes: 3 additions & 1 deletion guests/op-compose/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ pub fn main() {
// read composition input
let compose_input: ComposeInput = env::read();
// process input
let compose_output = compose_input.process().expect("Failed to process composition.");
let compose_output = compose_input
.process()
.expect("Failed to process composition.");
// output statement about larger segment
env::commit(&compose_output);
}
2 changes: 1 addition & 1 deletion guests/op-derive/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions host/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ pub struct BuildArgs {
/// URL of the Optimism RPC node
pub op_rpc_url: Option<String>,

#[clap(short, long, require_equals = true, num_args = 0..=1, default_missing_value = "host/testdata")]
#[clap(short, long, require_equals = true, num_args = 0..=1, default_missing_value = "cache_rpc")]
/// Cache RPC calls locally; the value specifies the cache directory
///
/// [default when the flag is present: host/testdata]
/// [default when the flag is present: cache_rpc]
pub cache: Option<PathBuf>,

#[clap(short, long, require_equals = true)]
Expand Down
2 changes: 1 addition & 1 deletion host/tests/cmd.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/builder/initialize.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/builder/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/builder/prepare.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/host/preflight.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
11 changes: 4 additions & 7 deletions lib/src/host/provider/cached_rpc_provider.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@

use std::path::PathBuf;

use anyhow::Result;
use anyhow::{Context, Result};
use ethers_core::types::{
Block, Bytes, EIP1186ProofResponse, Transaction, TransactionReceipt, H256, U256,
};
Expand All @@ -31,11 +31,8 @@ pub struct CachedRpcProvider {

impl CachedRpcProvider {
pub fn new(cache_path: PathBuf, rpc_url: String) -> Result<Self> {
let cache = match FileProvider::from_file(&cache_path) {
Ok(provider) => provider,
Err(_) => FileProvider::empty(cache_path),
};
let rpc = RpcProvider::new(rpc_url)?;
let cache = FileProvider::new(cache_path).context("failed to init cache")?;
let rpc = RpcProvider::new(rpc_url).context("failed to init RPC")?;

Ok(CachedRpcProvider { cache, rpc })
}
Expand Down
74 changes: 36 additions & 38 deletions lib/src/host/provider/file_provider.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -14,22 +14,23 @@

use std::{
collections::HashMap,
fs::File,
io::{Read, Write},
path::{Path, PathBuf},
fs::{self, File},
io,
path::PathBuf,
};

use anyhow::{anyhow, Context, Result};
use ethers_core::types::{
Block, Bytes, EIP1186ProofResponse, Transaction, TransactionReceipt, H256, U256,
};
use flate2::{read::GzDecoder, write::GzEncoder, Compression};
use serde::{Deserialize, Serialize};
use serde_with::serde_as;

use super::{AccountQuery, BlockQuery, MutProvider, ProofQuery, Provider, StorageQuery};

#[serde_as]
#[derive(Clone, Deserialize, Serialize)]
#[derive(Clone, Default, Deserialize, Serialize)]
pub struct FileProvider {
#[serde(skip)]
file_path: PathBuf,
Expand All @@ -55,52 +56,49 @@ pub struct FileProvider {
}

impl FileProvider {
pub fn empty(file_path: PathBuf) -> Self {
FileProvider {
file_path,
dirty: false,
full_blocks: HashMap::new(),
partial_blocks: HashMap::new(),
receipts: HashMap::new(),
proofs: HashMap::new(),
transaction_count: HashMap::new(),
balance: HashMap::new(),
code: HashMap::new(),
storage: HashMap::new(),
/// Creates a new [FileProvider]. If the file exists, it will be read and
/// deserialized. Otherwise, a new file will be created when saved.
pub fn new(file_path: PathBuf) -> Result<Self> {
match FileProvider::read(file_path.clone()) {
Ok(provider) => Ok(provider),
Err(err) => match err.downcast_ref::<io::Error>() {
Some(io_err) if io_err.kind() == io::ErrorKind::NotFound => {
// create the file and directory if it doesn't exist
if let Some(parent) = file_path.parent() {
fs::create_dir_all(parent)?;
}
Ok(FileProvider {
file_path,
..Default::default()
})
}
_ => Err(err),
},
}
}

pub fn from_file(file_path: &PathBuf) -> Result<Self> {
let mut buf = vec![];
let mut decoder = flate2::read::GzDecoder::new(File::open(file_path)?);
decoder.read_to_end(&mut buf)?;

let mut out: Self = serde_json::from_slice(&buf[..])?;

out.file_path = file_path.clone();
fn read(file_path: PathBuf) -> Result<Self> {
let f = File::open(&file_path)?;
let mut out: Self = serde_json::from_reader(GzDecoder::new(f))?;
out.file_path = file_path;
out.dirty = false;

Ok(out)
}
}

pub fn save_to_file(&self, file_path: &Path) -> Result<()> {
impl Provider for FileProvider {
fn save(&self) -> Result<()> {
if self.dirty {
let mut encoder = flate2::write::GzEncoder::new(
File::create(file_path)
.with_context(|| format!("Failed to create '{}'", file_path.display()))?,
flate2::Compression::best(),
);
encoder.write_all(&serde_json::to_vec(self)?)?;
let f = File::create(&self.file_path)
.with_context(|| format!("Failed to create '{}'", self.file_path.display()))?;
let mut encoder = GzEncoder::new(f, Compression::best());
serde_json::to_writer(&mut encoder, &self)?;
encoder.finish()?;
}

Ok(())
}
}

impl Provider for FileProvider {
fn save(&self) -> Result<()> {
self.save_to_file(&self.file_path)
}

fn get_full_block(&mut self, query: &BlockQuery) -> Result<Block<Transaction>> {
match self.full_blocks.get(query) {
Expand Down
7 changes: 3 additions & 4 deletions lib/src/host/provider/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@

use std::{collections::BTreeSet, path::PathBuf};

use anyhow::{anyhow, Context, Result};
use anyhow::{anyhow, Result};
use ethers_core::types::{
Block, Bytes, EIP1186ProofResponse, Transaction, TransactionReceipt, H160, H256, U256,
};
Expand Down Expand Up @@ -74,8 +74,7 @@ pub trait MutProvider: Provider {
}

pub fn new_file_provider(file_path: PathBuf) -> Result<Box<dyn Provider>> {
let provider = file_provider::FileProvider::from_file(&file_path)
.with_context(|| format!("invalid cache file: {}", file_path.display()))?;
let provider = file_provider::FileProvider::new(file_path)?;

Ok(Box::new(provider))
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/host/provider/rpc_provider.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/host/provider_db.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/host/rpc_db.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/host/verify.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/input.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/optimism/batcher_db.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion primitives/src/access_list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion primitives/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion primitives/src/transactions/ethereum.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion primitives/src/transactions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion primitives/src/transactions/optimism.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion primitives/src/transactions/signature.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion primitives/src/trie/mpt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion testing/ef-tests/src/ethtests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion testing/ef-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion testing/ef-tests/testguest/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion testing/ef-tests/tests/evm.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion testing/ef-tests/tests/executor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 RISC Zero, Inc.
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down

0 comments on commit c14ef25

Please sign in to comment.