Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Fix #1451, option 3: Partial boundary control #1454

Closed
wants to merge 20 commits into from
Closed
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
1,698 changes: 900 additions & 798 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions bus-mapping/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ eth-types = { path = "../eth-types" }
gadgets = { path = "../gadgets" }
mock = { path = "../mock", optional = true }

ethers-core = "0.17.0"
ethers-providers = "0.17.0"
ethers-providers = "2.0.7"
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_04_20" }
itertools = "0.10"
lazy_static = "1.4"
Expand Down
8 changes: 4 additions & 4 deletions bus-mapping/src/circuit_input_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl<'a> CircuitInputBuilder {
/// Create a new Transaction from a [`eth_types::Transaction`].
pub fn new_tx(
&mut self,
eth_tx: &eth_types::Transaction,
eth_tx: &eth_types::eth_core::Transaction,
is_success: bool,
) -> Result<Transaction, Error> {
let call_id = self.block_ctx.rwc.0;
Expand Down Expand Up @@ -263,7 +263,7 @@ impl<'a> CircuitInputBuilder {
/// generated operations.
fn handle_tx(
&mut self,
eth_tx: &eth_types::Transaction,
eth_tx: &eth_types::eth_core::Transaction,
geth_trace: &GethExecTrace,
is_last_tx: bool,
) -> Result<(), Error> {
Expand Down Expand Up @@ -390,7 +390,7 @@ pub fn get_call_memory_offset_length(step: &GethExecStep, nth: usize) -> Result<
}
}

type EthBlock = eth_types::Block<eth_types::Transaction>;
type EthBlock = eth_types::Block<eth_types::eth_core::Transaction>;

/// Struct that wraps a GethClient and contains methods to perform all the steps
/// necessary to generate the circuit inputs for a block by querying geth for
Expand Down Expand Up @@ -594,7 +594,7 @@ impl<P: JsonRpcClient> BuilderClient<P> {
) -> Result<
(
CircuitInputBuilder,
eth_types::Block<eth_types::Transaction>,
eth_types::Block<eth_types::eth_core::Transaction>,
),
Error,
> {
Expand Down
8 changes: 5 additions & 3 deletions bus-mapping/src/circuit_input_builder/access.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::{operation::RW, Error};
use eth_types::{evm_types::OpcodeId, Address, GethExecStep, GethExecTrace, ToAddress, Word};
use ethers_core::utils::get_contract_address;
use eth_types::{
eth_core::get_contract_address, evm_types::OpcodeId, Address, GethExecStep, GethExecTrace,
ToAddress, Word,
};
use std::collections::{hash_map::Entry, HashMap, HashSet};

use AccessValue::{Account, Code, Storage};
Expand Down Expand Up @@ -116,7 +118,7 @@ impl Default for CodeSource {
/// sections.
pub fn gen_state_access_trace<TX>(
_block: &eth_types::Block<TX>,
tx: &eth_types::Transaction,
tx: &eth_types::eth_core::Transaction,
geth_trace: &GethExecTrace,
) -> Result<Vec<Access>, Error> {
let mut call_stack: Vec<(Address, CodeSource)> = Vec::new();
Expand Down
4 changes: 2 additions & 2 deletions bus-mapping/src/circuit_input_builder/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub struct Block {
/// Circuits Setup Paramteres
pub circuits_params: CircuitsParams,
/// Original block from geth
pub eth_block: eth_types::Block<eth_types::Transaction>,
pub eth_block: eth_types::Block<eth_types::eth_core::Transaction>,
}

impl Block {
Expand All @@ -98,7 +98,7 @@ impl Block {
chain_id: Word,
history_hashes: Vec<Word>,
prev_state_root: Word,
eth_block: &eth_types::Block<eth_types::Transaction>,
eth_block: &eth_types::Block<eth_types::eth_core::Transaction>,
circuits_params: CircuitsParams,
) -> Result<Self, Error> {
if eth_block.base_fee_per_gas.is_none() {
Expand Down
4 changes: 2 additions & 2 deletions bus-mapping/src/circuit_input_builder/input_state_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ use crate::{
Error,
};
use eth_types::{
eth_core::{get_contract_address, get_create2_address},
evm_types::{
gas_utils::memory_expansion_gas_cost, GasCost, MemoryAddress, OpcodeId, StackAddress,
},
Address, Bytecode, GethExecStep, ToAddress, ToBigEndian, ToWord, Word, H256, U256,
};
use ethers_core::utils::{get_contract_address, get_create2_address};
use std::cmp::max;

/// Reference to the internal state of the CircuitInputBuilder in a particular
Expand Down Expand Up @@ -686,7 +686,7 @@ impl<'a> CircuitInputStateRef<'a> {
let init_code = get_create_init_code(call_ctx, step)?.to_vec();
Ok(get_create2_address(
self.call()?.address,
salt.to_be_bytes().to_vec(),
salt.to_be_bytes(),
init_code,
))
}
Expand Down
7 changes: 3 additions & 4 deletions bus-mapping/src/circuit_input_builder/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

use std::collections::BTreeMap;

use eth_types::{evm_types::Memory, geth_types, GethExecTrace};
use ethers_core::utils::get_contract_address;
use eth_types::{eth_core::get_contract_address, evm_types::Memory, geth_types, GethExecTrace};

use crate::{
state_db::{CodeDB, StateDB},
Expand Down Expand Up @@ -36,7 +35,7 @@ pub struct TransactionContext {
impl TransactionContext {
/// Create a new Self.
pub fn new(
eth_tx: &eth_types::Transaction,
eth_tx: &eth_types::eth_core::Transaction,
geth_trace: &GethExecTrace,
is_last_tx: bool,
) -> Result<Self, Error> {
Expand Down Expand Up @@ -193,7 +192,7 @@ impl Transaction {
call_id: usize,
sdb: &StateDB,
code_db: &mut CodeDB,
eth_tx: &eth_types::Transaction,
eth_tx: &eth_types::eth_core::Transaction,
is_success: bool,
) -> Result<Self, Error> {
let (found, _) = sdb.get_account(&eth_tx.from);
Expand Down
4 changes: 2 additions & 2 deletions bus-mapping/src/evm/opcodes/begin_end_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use crate::{
Error,
};
use eth_types::{
eth_core::{get_contract_address, RlpStream},
evm_types::{GasCost, MAX_REFUND_QUOTIENT_OF_GAS_USED},
evm_unimplemented, ToWord, Word,
};
use ethers_core::utils::get_contract_address;

#[derive(Clone, Copy, Debug)]
pub(crate) struct BeginEndTx;
Expand Down Expand Up @@ -127,7 +127,7 @@ fn gen_begin_tx_steps(state: &mut CircuitInputStateRef) -> Result<ExecStep, Erro
// Keccak table and verify the contract address.
if state.tx.is_create() {
state.block.sha3_inputs.push({
let mut stream = ethers_core::utils::rlp::RlpStream::new();
let mut stream = RlpStream::new();
stream.begin_list(2);
stream.append(&caller_address);
stream.append(&nonce_prev);
Expand Down
6 changes: 2 additions & 4 deletions bus-mapping/src/evm/opcodes/sha3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use crate::{
},
Error,
};
use eth_types::{bytecode, Bytecode, GethExecStep, Word, U256};
use ethers_core::utils::keccak256;
use eth_types::{bytecode, keccak256, Bytecode, GethExecStep, Word, U256};
use rand::{rngs::ThreadRng, Rng};

#[derive(Clone, Copy, Debug)]
Expand Down Expand Up @@ -189,8 +188,7 @@ impl Sha3CodeGen {
#[cfg(test)]
pub(crate) mod sha3_tests {
use super::Sha3CodeGen;
use eth_types::{evm_types::OpcodeId, geth_types::GethData, Word};
use ethers_core::utils::keccak256;
use eth_types::{evm_types::OpcodeId, geth_types::GethData, keccak256, Word};
use mock::{
test_ctx::helpers::{account_0_code_account_1_no_code, tx_from_1_to_0},
TestContext,
Expand Down
2 changes: 1 addition & 1 deletion bus-mapping/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct BlockData {
/// the lastest one is at history_hashes[history_hashes.len() - 1].
pub history_hashes: Vec<Word>,
/// Block from geth
pub eth_block: eth_types::Block<eth_types::Transaction>,
pub eth_block: eth_types::Block<eth_types::eth_core::Transaction>,
/// Execution Trace from geth
pub geth_traces: Vec<eth_types::GethExecTrace>,
/// Circuits setup parameters
Expand Down
6 changes: 3 additions & 3 deletions bus-mapping/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

use crate::Error;
use eth_types::{
Address, Block, Bytes, EIP1186ProofResponse, GethExecTrace, Hash, ResultGethExecTraces,
Transaction, Word, U64,
eth_core::{BlockNumber, Transaction},
Address, Block, Bytes, EIP1186ProofResponse, GethExecTrace, Hash, ResultGethExecTraces, Word,
U64,
};
pub use ethers_core::types::BlockNumber;
use ethers_providers::JsonRpcClient;
use serde::Serialize;

Expand Down
5 changes: 2 additions & 3 deletions bus-mapping/src/state_db.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! Implementation of an in-memory key-value database to represent the
//! Ethereum State Trie.

use eth_types::{geth_types, Address, Hash, Word, H256, U256};
use ethers_core::utils::keccak256;
use eth_types::{geth_types, keccak256, Address, Hash, Word, H256, U256};
use lazy_static::lazy_static;
use std::collections::{HashMap, HashSet};

Expand Down Expand Up @@ -73,7 +72,7 @@ impl From<geth_types::Account> for Account {
nonce: account.nonce.as_u64(),
balance: account.balance,
storage: account.storage.clone(),
code_hash: CodeDB::hash(&account.code.to_vec()),
code_hash: CodeDB::hash(&account.code),
}
}
}
Expand Down
1 change: 0 additions & 1 deletion circuit-benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ rand = "0.8"
itertools = "0.10"
eth-types = { path = "../eth-types" }
env_logger = "0.9"
ethers-signers = "0.17.0"
mock = { path="../mock" }
rand_chacha = "0.3"

Expand Down
2 changes: 1 addition & 1 deletion circuit-benchmarks/src/pi_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ mod tests {

let n_tx = max_txs;
for _ in 0..n_tx {
let eth_tx = eth_types::Transaction::from(mock::CORRECT_MOCK_TXS[0].clone());
let eth_tx = eth_types::eth_core::Transaction::from(mock::CORRECT_MOCK_TXS[0].clone());
public_data.transactions.push(eth_tx);
}
public_data
Expand Down
8 changes: 6 additions & 2 deletions circuit-benchmarks/src/super_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
mod tests {
use ark_std::{end_timer, start_timer};
use bus_mapping::circuit_input_builder::CircuitsParams;
use eth_types::{address, bytecode, geth_types::GethData, Word};
use ethers_signers::{LocalWallet, Signer};
use eth_types::{
address, bytecode,
eth_signer::{LocalWallet, Signer},
geth_types::GethData,
Word,
};
use halo2_proofs::{
halo2curves::bn256::{Bn256, Fr, G1Affine},
plonk::{create_proof, keygen_pk, keygen_vk, verify_proof},
Expand Down
5 changes: 3 additions & 2 deletions eth-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ authors = ["The appliedzkp team"]
license = "MIT OR Apache-2.0"

[dependencies]
ethers-core = "0.17.0"
ethers-signers = "0.17.0"
ethers-core = "2.0.7"
ethers-signers = "2.0.7"
hex = "0.4"
lazy_static = "1.4"
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_04_20" }
Expand All @@ -26,3 +26,4 @@ strum = "0.24"

[features]
warn-unimplemented = []
ethers-core = []
27 changes: 13 additions & 14 deletions eth-types/src/geth_types.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
//! Types needed for generating Ethereum traces

use crate::{
eth_core::{get_contract_address, response, AccessList, NameOrAddress, TransactionRequest},
eth_signer::{LocalWallet, Signer},
keccak256,
sign_types::{biguint_to_32bytes_le, ct_option_ok_or, recover_pk, SignData, SECP256K1_Q},
AccessList, Address, Block, Bytes, Error, GethExecTrace, Hash, ToBigEndian, ToLittleEndian,
ToWord, Word, U64,
Address, Block, Bytes, Error, GethExecTrace, Hash, ToBigEndian, ToLittleEndian, ToWord, Word,
U64,
};
use ethers_core::{
types::{transaction::response, NameOrAddress, TransactionRequest},
utils::get_contract_address,
};
use ethers_signers::{LocalWallet, Signer};
use halo2_proofs::halo2curves::{group::ff::PrimeField, secp256k1};
use num::Integer;
use num_bigint::BigUint;
Expand Down Expand Up @@ -149,9 +146,9 @@ pub struct Transaction {
pub s: Word,
}

impl From<&Transaction> for crate::Transaction {
fn from(tx: &Transaction) -> crate::Transaction {
crate::Transaction {
impl From<&Transaction> for crate::eth_core::Transaction {
fn from(tx: &Transaction) -> crate::eth_core::Transaction {
crate::eth_core::Transaction {
from: tx.from,
to: tx.to,
nonce: tx.nonce.to_word(),
Expand All @@ -170,8 +167,8 @@ impl From<&Transaction> for crate::Transaction {
}
}

impl From<&crate::Transaction> for Transaction {
fn from(tx: &crate::Transaction) -> Transaction {
impl From<&crate::eth_core::Transaction> for Transaction {
fn from(tx: &crate::eth_core::Transaction) -> Transaction {
Transaction {
from: tx.from,
to: tx.to,
Expand Down Expand Up @@ -299,7 +296,7 @@ pub struct GethData {
/// the lastest one is at history_hashes[history_hashes.len() - 1].
pub history_hashes: Vec<Word>,
/// Block from geth
pub eth_block: Block<crate::Transaction>,
pub eth_block: Block<crate::eth_core::Transaction>,
/// Execution Trace from geth
pub geth_traces: Vec<GethExecTrace>,
/// Accounts
Expand All @@ -314,7 +311,9 @@ impl GethData {
assert_eq!(Word::from(wallet.chain_id()), self.chain_id);
let geth_tx: Transaction = (&*tx).into();
let req: TransactionRequest = (&geth_tx).into();
let sig = wallet.sign_transaction_sync(&req.chain_id(self.chain_id.as_u64()).into());
let sig = wallet
.sign_transaction_sync(&req.chain_id(self.chain_id.as_u64()).into())
.unwrap();
tx.v = U64::from(sig.v);
tx.r = sig.r;
tx.s = sig.s;
Expand Down
16 changes: 7 additions & 9 deletions eth-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ pub mod keccak;
pub mod sign_types;
pub use keccak::{keccak256, Keccak};

mod third_party;

pub use third_party::{eth_core, eth_signer};

pub use eth_core::{Address, Block, Bytes, H256, H64, U256, U64};

pub use bytecode::Bytecode;
pub use error::Error;
use halo2_proofs::halo2curves::{
Expand All @@ -30,14 +36,6 @@ use halo2_proofs::halo2curves::{
};

use crate::evm_types::{memory::Memory, stack::Stack, storage::Storage, OpcodeId};
use ethers_core::types;
pub use ethers_core::{
abi::ethereum_types::{BigEndianHash, U512},
types::{
transaction::{eip2930::AccessList, response::Transaction},
Address, Block, Bytes, Signature, H160, H256, H64, U256, U64,
},
};

use serde::{de, Deserialize, Serialize};
use std::{collections::HashMap, fmt, str::FromStr};
Expand Down Expand Up @@ -184,7 +182,7 @@ impl ToAddress for U256 {
}

/// Ethereum Hash (256 bits).
pub type Hash = types::H256;
pub type Hash = H256;

impl ToWord for Hash {
fn to_word(&self) -> Word {
Expand Down
2 changes: 2 additions & 0 deletions eth-types/src/third_party.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod eth_core;
pub mod eth_signer;
21 changes: 21 additions & 0 deletions eth-types/src/third_party/eth_core.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! We reexport ethers_core functions here for finer boundary control.
pub use ethers_core::{
abi::{
self,
ethereum_types::{BigEndianHash, U512},
Contract, Function, Param, ParamType, StateMutability, Token, Tokenize,
},
k256::ecdsa::SigningKey,
rand::{CryptoRng, RngCore},
types::{
transaction::{
eip2718::TypedTransaction, eip2930::AccessList, response, response::Transaction,
},
Address, Block, BlockNumber, Bloom, Bytes, NameOrAddress, OtherFields, Signature,
TransactionReceipt, TransactionRequest, H160, H256, H64, I256, U256, U64,
},
utils::{
get_contract_address, get_create2_address, rlp::RlpStream, secret_key_to_address,
WEI_IN_ETHER,
},
};
3 changes: 3 additions & 0 deletions eth-types/src/third_party/eth_signer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! Use exteral crate ethers_signers

pub use ethers_signers::{coins_bip39::English, LocalWallet, MnemonicBuilder, Signer, Wallet};
Loading