Skip to content

Commit

Permalink
upgrade ethers-* packages to 0.17.0 (privacy-scaling-explorations#758)
Browse files Browse the repository at this point in the history
* upgrade ethers-* packages to 0.17.0

fixes privacy-scaling-explorations#757

* fix

* fix: use vector of static size

* confused naming scheme

* mock: change type signature of Block.nonce to H64
  • Loading branch information
pinkiebell authored Sep 9, 2022
1 parent 6abc33e commit d67e83d
Show file tree
Hide file tree
Showing 16 changed files with 586 additions and 657 deletions.
1,156 changes: 541 additions & 615 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions bus-mapping/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ gadgets = { path = "../gadgets" }
keccak256 = { path = "../keccak256" }
mock = { path = "../mock", optional = true }

ethers-core = "0.6"
ethers-providers = "0.6"
ethers-core = "0.17.0"
ethers-providers = "0.17.0"
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2022_08_19" }
itertools = "0.10"
lazy_static = "1.4"
Expand Down
4 changes: 3 additions & 1 deletion bus-mapping/src/circuit_input_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,9 @@ impl<P: JsonRpcClient> BuilderClient<P> {
None,
RW::WRITE,
AccessValue::Account {
address: eth_block.author,
address: eth_block
.author
.ok_or(Error::EthTypeError(eth_types::Error::IncompleteBlock))?,
},
)];
for (tx_index, tx) in eth_block.transactions.iter().enumerate() {
Expand Down
4 changes: 3 additions & 1 deletion bus-mapping/src/circuit_input_builder/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ impl Block {
Ok(Self {
chain_id,
history_hashes,
coinbase: eth_block.author,
coinbase: eth_block
.author
.ok_or(Error::EthTypeError(eth_types::Error::IncompleteBlock))?,
gas_limit: eth_block.gas_limit.low_u64(),
number: eth_block
.number
Expand Down
5 changes: 4 additions & 1 deletion bus-mapping/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ impl BlockData {
let mut sdb = StateDB::new();
let mut code_db = CodeDB::new();

sdb.set_account(&geth_data.eth_block.author, state_db::Account::zero());
sdb.set_account(
&geth_data.eth_block.author.expect("Block.author"),
state_db::Account::zero(),
);
for tx in geth_data.eth_block.transactions.iter() {
sdb.set_account(&tx.from, state_db::Account::zero());
if let Some(to) = tx.to.as_ref() {
Expand Down
2 changes: 1 addition & 1 deletion circuit-benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rand = "0.8"
itertools = "0.10"
eth-types = { path = "../eth-types" }
env_logger = "0.9"
ethers-signers = "0.6"
ethers-signers = "0.17.0"
mock = { path="../mock" }
rand_chacha = "0.3"

Expand Down
4 changes: 2 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.6"
ethers-signers = "0.6"
ethers-core = "0.17.0"
ethers-signers = "0.17.0"
hex = "0.4"
lazy_static = "1.4"
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2022_08_19" }
Expand Down
9 changes: 3 additions & 6 deletions eth-types/src/geth_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::{
Word, U64,
};
use ethers_core::types::TransactionRequest;
use ethers_core::utils::keccak256;
use ethers_signers::{LocalWallet, Signer};
use halo2_proofs::halo2curves::{group::ff::PrimeField, secp256k1};
use num::Integer;
Expand Down Expand Up @@ -65,7 +64,7 @@ impl<TX> TryFrom<&Block<TX>> for BlockConstants {

fn try_from(block: &Block<TX>) -> Result<Self, Self::Error> {
Ok(Self {
coinbase: block.author,
coinbase: block.author.ok_or(Error::IncompleteBlock)?,
timestamp: block.timestamp,
number: block.number.ok_or(Error::IncompleteBlock)?,
difficulty: block.difficulty,
Expand Down Expand Up @@ -199,7 +198,7 @@ impl Transaction {
)?;
// msg = rlp([nonce, gasPrice, gas, to, value, data, sig_v, r, s])
let req: TransactionRequest = self.into();
let msg = req.rlp(chain_id);
let msg = req.chain_id(chain_id).rlp();
let msg_hash: [u8; 32] = Keccak256::digest(&msg)
.as_slice()
.to_vec()
Expand Down Expand Up @@ -247,9 +246,7 @@ 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 tx_rlp = req.rlp(self.chain_id.as_u64());
let sighash = keccak256(tx_rlp.as_ref()).into();
let sig = wallet.sign_hash(sighash, true);
let sig = wallet.sign_transaction_sync(&req.chain_id(self.chain_id.as_u64()).into());
tx.v = U64::from(sig.v);
tx.r = sig.r;
tx.s = sig.s;
Expand Down
2 changes: 1 addition & 1 deletion eth-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub use ethers_core::abi::ethereum_types::U512;
use ethers_core::types;
pub use ethers_core::types::{
transaction::{eip2930::AccessList, response::Transaction},
Address, Block, Bytes, Signature, H160, H256, U256, U64,
Address, Block, Bytes, Signature, H160, H256, H64, U256, U64,
};

use serde::{de, Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0"

[dependencies]
lazy_static = "1.4"
ethers = "0.6"
ethers = { version = "0.17.0", features = ["ethers-solc"] }
serde_json = "1.0.66"
serde = {version = "1.0.130", features = ["derive"] }
bus-mapping = { path = "../bus-mapping"}
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/src/bin/gen_blockchain_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ async fn main() {
path: path_sol.to_str().expect("path is not str").to_string(),
name: name.to_string(),
abi,
bin,
bin_runtime,
bin: bin.into_bytes().expect("bin"),
bin_runtime: bin_runtime.into_bytes().expect("bin_runtime"),
};

let mut path_json = path_sol.clone();
Expand Down
7 changes: 3 additions & 4 deletions mock/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ license = "MIT OR Apache-2.0"
eth-types = { path = "../eth-types" }
external-tracer = { path = "../external-tracer" }
lazy_static = "1.4"
ethbloom = "0.11.1"
itertools = "0.10.3"
ethers-signers = "0.6"
ethers-core = "0.6"
ethers-signers = "0.17.0"
ethers-core = "0.17.0"
rand_chacha = "0.3"
rand = "0.8"
rand = "0.8"
19 changes: 11 additions & 8 deletions mock/src/block.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Mock Block definition and builder related methods.
use crate::{MockTransaction, MOCK_CHAIN_ID};
use eth_types::{Address, Block, Bytes, Hash, Transaction, Word, U64};
use ethbloom::Bloom;
use eth_types::{Address, Block, Bytes, Hash, Transaction, Word, H64, U64};
use ethers_core::types::Bloom;
use ethers_core::types::OtherFields;

#[derive(Clone, Debug)]
/// Mock structure which represents an Ethereum Block and can be used for tests.
Expand Down Expand Up @@ -30,7 +31,7 @@ pub struct MockBlock {
pub(crate) transactions: Vec<MockTransaction>,
size: Word,
mix_hash: Hash,
nonce: U64,
nonce: H64,
// This field is handled here as we assume that all block txs have the same ChainId.
// Also, the field is stored in the block_table since we don't have a chain_config
// structure/table.
Expand Down Expand Up @@ -61,7 +62,7 @@ impl Default for MockBlock {
transactions: Vec::new(),
size: Word::zero(),
mix_hash: Hash::zero(),
nonce: U64::zero(),
nonce: H64::zero(),
chain_id: *MOCK_CHAIN_ID,
}
}
Expand All @@ -73,7 +74,7 @@ impl From<MockBlock> for Block<Transaction> {
hash: mock.hash.or_else(|| Some(Hash::default())),
parent_hash: mock.parent_hash,
uncles_hash: mock.uncles_hash,
author: mock.author,
author: Some(mock.author),
state_root: mock.state_root,
transactions_root: mock.transactions_root,
receipts_root: mock.receipts_root,
Expand All @@ -96,6 +97,7 @@ impl From<MockBlock> for Block<Transaction> {
mix_hash: Some(mock.mix_hash),
nonce: Some(mock.nonce),
base_fee_per_gas: Some(mock.base_fee_per_gas),
other: OtherFields::default(),
}
}
}
Expand All @@ -106,7 +108,7 @@ impl From<MockBlock> for Block<()> {
hash: mock.hash.or_else(|| Some(Hash::default())),
parent_hash: mock.parent_hash,
uncles_hash: mock.uncles_hash,
author: mock.author,
author: Some(mock.author),
state_root: mock.state_root,
transactions_root: mock.transactions_root,
receipts_root: mock.receipts_root,
Expand All @@ -125,6 +127,7 @@ impl From<MockBlock> for Block<()> {
mix_hash: Some(mock.mix_hash),
nonce: Some(mock.nonce),
base_fee_per_gas: Some(mock.base_fee_per_gas),
other: OtherFields::default(),
}
}
}
Expand Down Expand Up @@ -261,8 +264,8 @@ impl MockBlock {
}

/// Set nonce field for the MockBlock.
pub fn nonce(&mut self, nonce: u64) -> &mut Self {
self.nonce = U64::from(nonce);
pub fn nonce(&mut self, nonce: H64) -> &mut Self {
self.nonce = nonce;
self
}

Expand Down
11 changes: 5 additions & 6 deletions mock/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use eth_types::{
geth_types::Transaction as GethTransaction, AccessList, Address, Bytes, Hash, Transaction,
Word, U64,
};
use ethers_core::types::OtherFields;
use ethers_core::{
rand::{CryptoRng, RngCore},
types::TransactionRequest,
utils::keccak256,
};
use ethers_signers::{LocalWallet, Signer};
use lazy_static::lazy_static;
Expand Down Expand Up @@ -181,6 +181,7 @@ impl From<MockTransaction> for Transaction {
max_priority_fee_per_gas: Some(mock.max_priority_fee_per_gas),
max_fee_per_gas: Some(mock.max_fee_per_gas),
chain_id: Some(mock.chain_id),
other: OtherFields::default(),
}
}
}
Expand Down Expand Up @@ -307,10 +308,8 @@ impl MockTransaction {
.value(self.value)
.data(self.input.clone())
.gas(self.gas)
.gas_price(self.gas_price);

let tx_rlp = tx.rlp(self.chain_id.low_u64());
let sighash = keccak256(tx_rlp.as_ref()).into();
.gas_price(self.gas_price)
.chain_id(self.chain_id.low_u64());

match (self.v, self.r, self.s) {
(None, None, None) => {
Expand All @@ -320,7 +319,7 @@ impl MockTransaction {
.from
.as_wallet()
.with_chain_id(self.chain_id.low_u64())
.sign_hash(sighash, true);
.sign_transaction_sync(&tx.into());
// Set sig parameters
self.sig_data((sig.v, sig.r, sig.s));
}
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ array-init = "2.0.0"
bus-mapping = { path = "../bus-mapping" }
eth-types = { path = "../eth-types" }
gadgets = { path = "../gadgets" }
ethers-core = "0.6"
ethers-core = "0.17.0"
strum = "0.24"
strum_macros = "0.24"
rand_xorshift = "0.3"
Expand All @@ -41,7 +41,7 @@ hex = "0.4.3"
mock = { path = "../mock" }
itertools = "0.10.1"
pretty_assertions = "1.0.0"
ethers-signers = "0.6"
ethers-signers = "0.17.0"
rand_chacha = "0.3"

[features]
Expand Down
6 changes: 2 additions & 4 deletions zkevm-circuits/src/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::{state_circuit::StateCircuit, witness::Block};
use bus_mapping::mock::BlockData;
use eth_types::geth_types::{GethData, Transaction};
use ethers_core::types::{NameOrAddress, TransactionRequest};
use ethers_core::utils::keccak256;
use ethers_signers::{LocalWallet, Signer};
use halo2_proofs::dev::{MockProver, VerifyFailure};
use halo2_proofs::halo2curves::bn256::Fr;
Expand Down Expand Up @@ -83,16 +82,15 @@ pub fn rand_tx<R: Rng + CryptoRng>(mut rng: R, chain_id: u64) -> Transaction {
let to = wallet1.address();
let data = b"hello";
let tx = TransactionRequest::new()
.chain_id(chain_id)
.from(from)
.to(to)
.nonce(3)
.value(1000)
.data(data)
.gas(500_000)
.gas_price(1234);
let tx_rlp = tx.rlp(chain_id);
let sighash = keccak256(tx_rlp.as_ref()).into();
let sig = wallet0.sign_hash(sighash, true);
let sig = wallet0.sign_transaction_sync(&tx.clone().into());
let to = tx.to.map(|to| match to {
NameOrAddress::Address(a) => a,
_ => unreachable!(),
Expand Down

0 comments on commit d67e83d

Please sign in to comment.