Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ rayon = { version = "1.5.3", optional = true }
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2", tag = "v2022_10_22", optional = true }

# loader_evm
ethereum_types = { package = "ethereum-types", version = "0.13", default-features = false, features = ["std"], optional = true }
sha3 = { version = "0.10", optional = true }
revm = { version = "2.1.0", optional = true }
bytes = { version = "1.2", optional = true }
rlp = { version = "0.5", default-features = false, features = ["std"], optional = true }
bytes = { version = "1.1.0", default-features = false, optional = true }
primitive-types = { version = "0.12.1", default-features = false, features = ["std"], optional = true }
rlp = { version = "0.5.2", default-features = false, features = ["std"], optional = true }
revm = { version = "= 2.3.1", optional = true }

# loader_halo2
halo2_wrong_ecc = { git = "https://github.com/privacy-scaling-explorations/halo2wrong", tag = "v2022_10_22", package = "ecc", optional = true }
Expand All @@ -46,7 +46,7 @@ default = ["loader_evm", "loader_halo2", "system_halo2"]

parallel = ["dep:rayon"]

loader_evm = ["dep:ethereum_types", "dep:sha3", "dep:revm", "dep:bytes", "dep:rlp"]
loader_evm = ["dep:bytes", "dep:sha3", "dep:primitive-types", "dep:rlp", "dep:revm"]
loader_halo2 = ["dep:halo2_proofs", "dep:halo2_wrong_ecc", "dep:poseidon"]

system_halo2 = ["dep:halo2_proofs"]
Expand Down
3 changes: 1 addition & 2 deletions examples/evm-verifier-with-accumulator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use ethereum_types::Address;
use halo2_curves::bn256::{Bn256, Fq, Fr, G1Affine};
use halo2_proofs::{
dev::MockProver,
Expand All @@ -17,7 +16,7 @@ use halo2_proofs::{
use itertools::Itertools;
use plonk_verifier::{
loader::{
evm::{self, encode_calldata, EvmLoader, ExecutorBuilder},
evm::{self, encode_calldata, Address, EvmLoader, ExecutorBuilder},
native::NativeLoader,
},
pcs::kzg::{Gwc19, Kzg, KzgAs, LimbsEncoding},
Expand Down
3 changes: 1 addition & 2 deletions examples/evm-verifier.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use ethereum_types::Address;
use halo2_curves::bn256::{Bn256, Fq, Fr, G1Affine};
use halo2_proofs::{
circuit::{Layouter, SimpleFloorPlanner, Value},
Expand All @@ -20,7 +19,7 @@ use halo2_proofs::{
};
use itertools::Itertools;
use plonk_verifier::{
loader::evm::{self, encode_calldata, EvmLoader, ExecutorBuilder},
loader::evm::{self, encode_calldata, Address, EvmLoader, ExecutorBuilder},
pcs::kzg::{Gwc19, Kzg},
system::halo2::{compile, transcript::evm::EvmTranscript, Config},
verifier::{self, PlonkVerifier},
Expand Down
6 changes: 2 additions & 4 deletions src/loader/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ mod test;

pub use loader::{EcPoint, EvmLoader, Scalar};
pub use util::{
compile_yul, encode_calldata, estimate_gas, fe_to_u256, modulus, u256_to_fe, ExecutorBuilder,
MemoryChunk,
compile_yul, encode_calldata, estimate_gas, fe_to_u256, modulus, u256_to_fe, Address,
ExecutorBuilder, MemoryChunk, H256, U256, U512,
};

pub use ethereum_types::U256;

#[cfg(test)]
pub use test::execute;
3 changes: 1 addition & 2 deletions src/loader/evm/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
loader::{
evm::{
code::{Precompiled, YulCode},
fe_to_u256, modulus, u256_to_fe,
fe_to_u256, modulus, u256_to_fe, U256, U512,
},
EcPointLoader, LoadedEcPoint, LoadedScalar, Loader, ScalarLoader,
},
Expand All @@ -12,7 +12,6 @@ use crate::{
},
Error,
};
use ethereum_types::{U256, U512};
use hex;
use std::{
cell::RefCell,
Expand Down
3 changes: 1 addition & 2 deletions src/loader/evm/test.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::{
loader::evm::{test::tui::Tui, util::ExecutorBuilder},
loader::evm::{test::tui::Tui, Address, ExecutorBuilder, U256},
util::Itertools,
};
use ethereum_types::{Address, U256};
use std::env::var_os;

mod tui;
Expand Down
6 changes: 4 additions & 2 deletions src/loader/evm/test/tui.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! Copied and modified from https://github.com/foundry-rs/foundry/blob/master/ui/src/lib.rs

use crate::loader::evm::util::executor::{CallKind, DebugStep};
use crate::loader::evm::{
util::executor::{CallKind, DebugStep},
Address,
};
use crossterm::{
event::{
self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEvent, KeyModifiers,
Expand All @@ -9,7 +12,6 @@ use crossterm::{
execute,
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
};
use ethereum_types::Address;
use revm::opcode;
use std::{
cmp::{max, min},
Expand Down
3 changes: 2 additions & 1 deletion src/loader/evm/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ use crate::{
cost::Cost,
util::{arithmetic::PrimeField, Itertools},
};
use ethereum_types::U256;
use std::{
io::Write,
iter,
process::{Command, Stdio},
};

pub use primitive_types::{H160 as Address, H256, U256, U512};

pub(crate) mod executor;

pub use executor::ExecutorBuilder;
Expand Down
11 changes: 1 addition & 10 deletions src/loader/evm/util/executor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Copied and modified from https://github.com/foundry-rs/foundry/blob/master/evm/src/executor/mod.rs

use crate::loader::evm::{Address, H256, U256};
use bytes::Bytes;
use ethereum_types::{Address, H256, U256, U64};
use revm::{
evm_inner, opcode, spec_opcode_gas, Account, BlockEnv, CallInputs, CallScheme, CreateInputs,
CreateScheme, Database, DatabaseCommit, EVMData, Env, ExecutionResult, Gas, GasInspector,
Expand Down Expand Up @@ -77,14 +77,6 @@ pub struct Log {
pub address: Address,
pub topics: Vec<H256>,
pub data: Bytes,
pub block_hash: Option<H256>,
pub block_number: Option<U64>,
pub transaction_hash: Option<H256>,
pub transaction_index: Option<U64>,
pub log_index: Option<U256>,
pub transaction_log_index: Option<U256>,
pub log_type: Option<String>,
pub removed: Option<bool>,
}

#[derive(Clone, Debug, Default)]
Expand All @@ -98,7 +90,6 @@ impl<DB: Database> Inspector<DB> for LogCollector {
address: *address,
topics: topics.to_vec(),
data: data.clone(),
..Default::default()
});
}

Expand Down
3 changes: 1 addition & 2 deletions src/pcs/kzg/decider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ mod native {
mod evm {
use crate::{
loader::{
evm::{loader::Value, EvmLoader},
evm::{loader::Value, EvmLoader, U256},
LoadedScalar,
},
pcs::{
Expand All @@ -81,7 +81,6 @@ mod evm {
msm::Msm,
},
};
use ethereum_types::U256;
use std::{fmt::Debug, rc::Rc};

impl<M, MOS> Decider<M::G1Affine, Rc<EvmLoader>> for Kzg<M, MOS>
Expand Down
3 changes: 1 addition & 2 deletions src/system/halo2/transcript/evm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
loader::{
evm::{loader::Value, u256_to_fe, EcPoint, EvmLoader, MemoryChunk, Scalar},
evm::{loader::Value, u256_to_fe, EcPoint, EvmLoader, MemoryChunk, Scalar, U256},
native::{self, NativeLoader},
Loader,
},
Expand All @@ -12,7 +12,6 @@ use crate::{
},
Error,
};
use ethereum_types::U256;
use halo2_proofs::transcript::EncodedChallenge;
use std::{
io::{self, Read, Write},
Expand Down
5 changes: 4 additions & 1 deletion src/util/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ pub struct QuotientPolynomial<F: Clone> {

impl<F: Clone> QuotientPolynomial<F> {
pub fn num_chunk(&self) -> usize {
Integer::div_ceil(&(self.numerator.degree() - 1), &self.chunk_degree)
Integer::div_ceil(
&(self.numerator.degree().checked_sub(1).unwrap_or_default()),
&self.chunk_degree,
)
}
}

Expand Down
13 changes: 7 additions & 6 deletions src/verifier/plonk.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
cost::{Cost, CostEstimation},
loader::{native::NativeLoader, LoadedScalar, Loader},
loader::{LoadedScalar, Loader},
pcs::{self, AccumulatorEncoding, MultiOpenScheme},
util::{
arithmetic::{CurveAffine, Field, Rotation},
Expand Down Expand Up @@ -394,14 +394,15 @@ where
}
}

impl<C, MOS> CostEstimation<(C, MOS)> for Plonk<MOS>
impl<C, L, MOS> CostEstimation<(C, L, MOS)> for Plonk<MOS>
where
C: CurveAffine,
MOS: MultiOpenScheme<C, NativeLoader> + CostEstimation<C, Input = Vec<pcs::Query<C::Scalar>>>,
L: Loader<C>,
MOS: MultiOpenScheme<C, L> + CostEstimation<C, Input = Vec<pcs::Query<C::Scalar>>>,
{
type Input = Protocol<C>;
type Input = Protocol<C, L>;

fn estimate_cost(protocol: &Protocol<C>) -> Cost {
fn estimate_cost(protocol: &Protocol<C, L>) -> Cost {
let plonk_cost = {
let num_accumulator = protocol.accumulator_indices.len();
let num_instance = protocol.num_instance.iter().sum();
Expand All @@ -412,7 +413,7 @@ where
Cost::new(num_instance, num_commitment, num_evaluation, num_msm)
};
let pcs_cost = {
let queries = PlonkProof::<C, NativeLoader, MOS>::empty_queries(protocol);
let queries = PlonkProof::<C, L, MOS>::empty_queries(protocol);
MOS::estimate_cost(&queries)
};
plonk_cost + pcs_cost
Expand Down