diff --git a/Cargo.lock b/Cargo.lock index e6e3e48b..caa19134 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1590,9 +1590,7 @@ dependencies = [ "toml 0.8.13", "tracing", "tracing-subscriber", - "zkevm_opcode_defs 1.5.0", "zksync-web3-rs", - "zksync_basic_types", "zksync_contracts", "zksync_multivm", "zksync_types", @@ -7406,22 +7404,6 @@ dependencies = [ "sha3 0.10.8", ] -[[package]] -name = "zkevm_opcode_defs" -version = "1.5.0" -source = "git+https://github.com/matter-labs/era-zkevm_opcode_defs.git?branch=v1.5.0#109d9f734804a8b9dc0531c0b576e2a0f55a40de" -dependencies = [ - "bitflags 2.6.0", - "blake2", - "ethereum-types 0.14.1", - "k256 0.13.3", - "lazy_static", - "p256", - "serde", - "sha2 0.10.8", - "sha3 0.10.8", -] - [[package]] name = "zksync-web3-rs" version = "0.1.1" diff --git a/Cargo.toml b/Cargo.toml index 6815bf3d..7bed699f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,8 +11,6 @@ categories = ["cryptography"] publish = false # We don't want to publish our binaries. [dependencies] -zkevm_opcode_defs = { git = "https://github.com/matter-labs/era-zkevm_opcode_defs.git", branch = "v1.5.0" } -zksync_basic_types = { git = "https://github.com/matter-labs/zksync-era.git", rev = "cfbcc11be0826e8c55fafa84ae01b2aead25d127" } zksync_multivm = { git = "https://github.com/matter-labs/zksync-era.git", rev = "cfbcc11be0826e8c55fafa84ae01b2aead25d127" } zksync_contracts = { git = "https://github.com/matter-labs/zksync-era.git", rev = "cfbcc11be0826e8c55fafa84ae01b2aead25d127" } zksync_types = { git = "https://github.com/matter-labs/zksync-era.git", rev = "cfbcc11be0826e8c55fafa84ae01b2aead25d127" } diff --git a/e2e-tests/test/anvil-apis.test.ts b/e2e-tests/test/anvil-apis.test.ts index 8f97d088..d1817ed7 100644 --- a/e2e-tests/test/anvil-apis.test.ts +++ b/e2e-tests/test/anvil-apis.test.ts @@ -133,7 +133,7 @@ describe("anvil_setCode", function () { await provider.send("anvil_setCode", [address, shortCode]); }; - await expectThrowsAsync(action, "bytes must be divisible by 32"); + await expectThrowsAsync(action, "Invalid bytecode"); }); it("Should update code with a different smart contract", async function () { diff --git a/e2e-tests/test/hardhat-apis.test.ts b/e2e-tests/test/hardhat-apis.test.ts index 6bbcaa28..88415035 100644 --- a/e2e-tests/test/hardhat-apis.test.ts +++ b/e2e-tests/test/hardhat-apis.test.ts @@ -135,7 +135,7 @@ describe("hardhat_setCode", function () { await provider.send("hardhat_setCode", [address, shortCode]); }; - await expectThrowsAsync(action, "bytes must be divisible by 32"); + await expectThrowsAsync(action, "Invalid bytecode"); }); it("Should update code with a different smart contract", async function () { diff --git a/src/bootloader_debug.rs b/src/bootloader_debug.rs index 816147b6..afc2c31e 100644 --- a/src/bootloader_debug.rs +++ b/src/bootloader_debug.rs @@ -4,12 +4,12 @@ use zksync_multivm::{ }; use once_cell::sync::OnceCell; -use zksync_basic_types::U256; use zksync_multivm::interface::storage::WriteStorage; use zksync_multivm::vm_latest::{ constants::BOOTLOADER_HEAP_PAGE, BootloaderState, HistoryMode, SimpleMemory, VmTracer, ZkSyncVmState, }; +use zksync_types::U256; /// Magic value that we put in bootloader.yul at the beginning of the debug section - to detect that /// debugger was enabled. diff --git a/src/cache.rs b/src/cache.rs index 7846ca8c..6683d4ef 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -6,9 +6,9 @@ use std::io::{BufReader, BufWriter}; use std::path::Path; use std::result::Result; use std::str::FromStr; -use zksync_basic_types::H256; use zksync_types::api::{Block, BridgeAddresses, Transaction, TransactionVariant}; use zksync_types::Transaction as RawTransaction; +use zksync_types::H256; use crate::config::cache::CacheConfig; @@ -379,8 +379,8 @@ impl Cache { #[cfg(test)] mod tests { use tempdir::TempDir; - use zksync_basic_types::{H160, U64}; use zksync_types::{Execute, ExecuteTransactionCommon}; + use zksync_types::{H160, U64}; use crate::testing; diff --git a/src/deps/system_contracts.rs b/src/deps/system_contracts.rs index 0cf0a739..c4d0b430 100644 --- a/src/deps/system_contracts.rs +++ b/src/deps/system_contracts.rs @@ -1,6 +1,5 @@ use once_cell::sync::Lazy; use serde_json::Value; -use zksync_basic_types::{AccountTreeId, Address, H160}; use zksync_types::{ block::DeployedContract, ACCOUNT_CODE_STORAGE_ADDRESS, BOOTLOADER_ADDRESS, BOOTLOADER_UTILITIES_ADDRESS, CODE_ORACLE_ADDRESS, COMPRESSOR_ADDRESS, @@ -11,6 +10,7 @@ use zksync_types::{ P256VERIFY_PRECOMPILE_ADDRESS, PUBDATA_CHUNK_PUBLISHER_ADDRESS, SHA256_PRECOMPILE_ADDRESS, SYSTEM_CONTEXT_ADDRESS, }; +use zksync_types::{AccountTreeId, Address, H160}; /// The `ecAdd` system contract address. pub const ECADD_PRECOMPILE_ADDRESS: Address = H160([ diff --git a/src/filters.rs b/src/filters.rs index 8d4214dd..706d42ee 100644 --- a/src/filters.rs +++ b/src/filters.rs @@ -1,7 +1,7 @@ use std::collections::{HashMap, HashSet}; -use zksync_basic_types::{H160, H256, U256, U64}; use zksync_types::api::{BlockNumber, Log}; +use zksync_types::{H160, H256, U256, U64}; use zksync_web3_decl::types::FilterChanges; use crate::utils; diff --git a/src/fork.rs b/src/fork.rs index 1ed9d042..6c2036a4 100644 --- a/src/fork.rs +++ b/src/fork.rs @@ -15,7 +15,7 @@ use std::{ use eyre::eyre; use tokio::runtime::Builder; -use zksync_basic_types::{Address, L1BatchNumber, L2BlockNumber, L2ChainId, H256, U256, U64}; +use zksync_types::{Address, L1BatchNumber, L2BlockNumber, L2ChainId, H256, U256, U64}; use zksync_types::{ api::{ @@ -727,9 +727,9 @@ impl ForkDetails { #[cfg(test)] mod tests { - use zksync_basic_types::{AccountTreeId, L1BatchNumber, H256}; use zksync_multivm::interface::storage::ReadStorage; use zksync_types::{api::TransactionVariant, StorageKey}; + use zksync_types::{AccountTreeId, L1BatchNumber, H256}; use crate::config::cache::CacheConfig; use crate::config::gas::{ diff --git a/src/formatter.rs b/src/formatter.rs index b29a7757..ec9cf464 100644 --- a/src/formatter.rs +++ b/src/formatter.rs @@ -8,7 +8,7 @@ use std::collections::HashMap; use std::str; use crate::fork::block_on; -use zksync_basic_types::H160; +use zksync_types::H160; use zksync_multivm::interface::{Call, VmEvent, VmExecutionResultAndLogs}; use zksync_types::StorageLogWithPreviousValue; diff --git a/src/http_fork_source.rs b/src/http_fork_source.rs index 18ccfbce..2c1cf8b9 100644 --- a/src/http_fork_source.rs +++ b/src/http_fork_source.rs @@ -9,11 +9,11 @@ use crate::{ fork::{block_on, ForkSource}, }; use eyre::Context; -use zksync_basic_types::{H256, U256}; use zksync_types::{ api::{BridgeAddresses, Transaction}, url::SensitiveUrl, }; +use zksync_types::{H256, U256}; use zksync_web3_decl::{ client::Client, namespaces::{EthNamespaceClient, ZksNamespaceClient}, @@ -54,19 +54,16 @@ impl ForkSource for HttpForkSource { fn get_storage_at( &self, - address: zksync_basic_types::Address, - idx: zksync_basic_types::U256, + address: zksync_types::Address, + idx: zksync_types::U256, block: Option, - ) -> eyre::Result { + ) -> eyre::Result { let client = self.create_client(); block_on(async move { client.get_storage_at(address, idx, block).await }) .wrap_err("fork http client failed") } - fn get_bytecode_by_hash( - &self, - hash: zksync_basic_types::H256, - ) -> eyre::Result>> { + fn get_bytecode_by_hash(&self, hash: zksync_types::H256) -> eyre::Result>> { let client = self.create_client(); block_on(async move { client.get_bytecode_by_hash(hash).await }) .wrap_err("fork http client failed") @@ -74,7 +71,7 @@ impl ForkSource for HttpForkSource { fn get_transaction_by_hash( &self, - hash: zksync_basic_types::H256, + hash: zksync_types::H256, ) -> eyre::Result> { if let Ok(Some(transaction)) = self .cache @@ -117,7 +114,7 @@ impl ForkSource for HttpForkSource { fn get_raw_block_transactions( &self, - block_number: zksync_basic_types::L2BlockNumber, + block_number: zksync_types::L2BlockNumber, ) -> eyre::Result> { let number = block_number.0 as u64; if let Ok(Some(transaction)) = self @@ -151,7 +148,7 @@ impl ForkSource for HttpForkSource { fn get_block_by_hash( &self, - hash: zksync_basic_types::H256, + hash: zksync_types::H256, full_transactions: bool, ) -> eyre::Result>> { if let Ok(Some(block)) = self @@ -280,7 +277,7 @@ impl ForkSource for HttpForkSource { /// Returns details of a block, given miniblock number fn get_block_details( &self, - miniblock: zksync_basic_types::L2BlockNumber, + miniblock: zksync_types::L2BlockNumber, ) -> eyre::Result> { let client = self.create_client(); block_on(async move { client.get_block_details(miniblock).await }).wrap_err(format!( @@ -358,8 +355,8 @@ impl ForkSource for HttpForkSource { mod tests { use std::str::FromStr; - use zksync_basic_types::{Address, L2BlockNumber, H160, H256, U64}; use zksync_types::api::BlockNumber; + use zksync_types::{Address, L2BlockNumber, H160, H256, U64}; use crate::testing; diff --git a/src/main.rs b/src/main.rs index 6d5ef0bd..3d07089e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,7 +45,7 @@ use futures::{ FutureExt, }; use jsonrpc_core::MetaIoHandler; -use zksync_basic_types::H160; +use zksync_types::H160; use crate::constants::{LEGACY_RICH_WALLETS, RICH_WALLETS}; use crate::namespaces::{ diff --git a/src/namespaces/anvil.rs b/src/namespaces/anvil.rs index 4e332cfb..36c0ed66 100644 --- a/src/namespaces/anvil.rs +++ b/src/namespaces/anvil.rs @@ -1,5 +1,5 @@ use jsonrpc_derive::rpc; -use zksync_basic_types::{Address, U256, U64}; +use zksync_types::{Address, U256, U64}; use super::{ResetRequest, RpcResult}; diff --git a/src/namespaces/eth_test.rs b/src/namespaces/eth_test.rs index bbdebe1a..7d7b427f 100644 --- a/src/namespaces/eth_test.rs +++ b/src/namespaces/eth_test.rs @@ -1,7 +1,7 @@ use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_derive::rpc; -use zksync_basic_types::H256; use zksync_types::transaction_request::CallRequest; +use zksync_types::H256; /// /// ETH namespace extension for the test node. diff --git a/src/namespaces/evm.rs b/src/namespaces/evm.rs index ee6472f1..9cb7ff65 100644 --- a/src/namespaces/evm.rs +++ b/src/namespaces/evm.rs @@ -1,5 +1,5 @@ use jsonrpc_derive::rpc; -use zksync_basic_types::{Address, U256, U64}; +use zksync_types::{Address, U256, U64}; use crate::namespaces::RpcResult; diff --git a/src/namespaces/hardhat.rs b/src/namespaces/hardhat.rs index 68360ed6..b99b7a0f 100644 --- a/src/namespaces/hardhat.rs +++ b/src/namespaces/hardhat.rs @@ -1,6 +1,6 @@ use jsonrpc_derive::rpc; use serde::{Deserialize, Serialize}; -use zksync_basic_types::{Address, U256, U64}; +use zksync_types::{Address, U256, U64}; use super::RpcResult; diff --git a/src/namespaces/net.rs b/src/namespaces/net.rs index f18aa142..2fc6b3c8 100644 --- a/src/namespaces/net.rs +++ b/src/namespaces/net.rs @@ -1,5 +1,5 @@ use jsonrpc_derive::rpc; -use zksync_basic_types::U256; +use zksync_types::U256; use crate::namespaces::Result; diff --git a/src/node/anvil.rs b/src/node/anvil.rs index bed94535..5d3efd56 100644 --- a/src/node/anvil.rs +++ b/src/node/anvil.rs @@ -1,4 +1,4 @@ -use zksync_basic_types::{Address, U256, U64}; +use zksync_types::{Address, U256, U64}; use zksync_web3_decl::error::Web3Error; use crate::{ diff --git a/src/node/debug.rs b/src/node/debug.rs index 441b754f..ddd86c90 100644 --- a/src/node/debug.rs +++ b/src/node/debug.rs @@ -7,7 +7,7 @@ use zksync_multivm::tracers::CallTracer; use zksync_multivm::vm_latest::HistoryDisabled; use zksync_multivm::vm_latest::{constants::ETH_CALL_GAS_LIMIT, ToTracerPointer, Vm}; -use zksync_basic_types::H256; +use zksync_types::H256; use zksync_types::{ api::{BlockId, BlockNumber, DebugCall, ResultDebugCall, TracerConfig, TransactionVariant}, l2::L2Tx, @@ -242,13 +242,13 @@ mod tests { testing::{self, LogBuilder}, }; use ethers::abi::{short_signature, AbiEncode, HumanReadableParser, ParamType, Token}; - use zksync_basic_types::{Address, Nonce, H160, U256}; use zksync_types::{ api::{Block, CallTracerConfig, SupportedTracers, TransactionReceipt}, transaction_request::CallRequestBuilder, utils::deployed_address_create, K256PrivateKey, }; + use zksync_types::{Address, Nonce, H160, U256}; fn deploy_test_contracts(node: &InMemoryNode) -> (Address, Address) { let private_key = K256PrivateKey::from_bytes(H256::repeat_byte(0xee)).unwrap(); diff --git a/src/node/eth.rs b/src/node/eth.rs index c8ce50e5..251bb04b 100644 --- a/src/node/eth.rs +++ b/src/node/eth.rs @@ -4,10 +4,6 @@ use anyhow::Context as _; use colored::Colorize; use futures::FutureExt; use itertools::Itertools; -use zksync_basic_types::{ - web3::{self, Bytes}, - AccountTreeId, Address, H160, H256, U256, U64, -}; use zksync_multivm::interface::ExecutionResult; use zksync_multivm::vm_latest::constants::ETH_CALL_GAS_LIMIT; use zksync_types::{ @@ -19,6 +15,10 @@ use zksync_types::{ utils::storage_key_for_standard_token_balance, PackedEthSignature, StorageKey, L2_BASE_TOKEN_ADDRESS, MAX_L1_TRANSACTION_GAS_LIMIT, }; +use zksync_types::{ + web3::{self, Bytes}, + AccountTreeId, Address, H160, H256, U256, U64, +}; use zksync_utils::{h256_to_u256, u256_to_h256}; use zksync_web3_decl::{ error::Web3Error, @@ -202,7 +202,7 @@ impl EthNamespa for InMemoryNode { /// Returns the chain ID of the node. - fn chain_id(&self) -> RpcResult { + fn chain_id(&self) -> RpcResult { match self.get_inner().read() { Ok(inner) => Ok(U64::from(inner.fork_storage.chain_id.as_u64())).into_boxed_future(), Err(_) => Err(into_jsrpc_error(Web3Error::InternalError( @@ -367,7 +367,7 @@ impl EthNamespa /// the code as a `Bytes` object. fn get_code( &self, - address: zksync_basic_types::Address, + address: zksync_types::Address, _block: Option, ) -> RpcResult { let inner = self.get_inner().clone(); @@ -407,7 +407,7 @@ impl EthNamespa /// Returns a `BoxFuture` containing the transaction count as a `U256` wrapped in a `jsonrpc_core::Result`. fn get_transaction_count( &self, - address: zksync_basic_types::Address, + address: zksync_types::Address, _block: Option, ) -> RpcResult { let inner = self.get_inner().clone(); @@ -438,7 +438,7 @@ impl EthNamespa /// A `BoxFuture` that resolves to an `Option` of a `TransactionReceipt` or an error. fn get_transaction_receipt( &self, - hash: zksync_basic_types::H256, + hash: zksync_types::H256, ) -> RpcResult> { let inner = self.get_inner().clone(); @@ -489,7 +489,7 @@ impl EthNamespa /// A `BoxFuture` containing a `jsonrpc_core::Result` that resolves to an `Option` of `Block`. fn get_block_by_hash( &self, - hash: zksync_basic_types::H256, + hash: zksync_types::H256, full_transactions: bool, ) -> RpcResult>> { let inner = self.get_inner().clone(); @@ -565,7 +565,7 @@ impl EthNamespa /// A `jsonrpc_core::BoxFuture` that resolves to a `jsonrpc_core::Result` containing an optional `zksync_types::api::Transaction`. fn get_transaction_by_hash( &self, - hash: zksync_basic_types::H256, + hash: zksync_types::H256, ) -> RpcResult> { let inner = self.get_inner().clone(); @@ -639,7 +639,7 @@ impl EthNamespa } /// Returns the current block number as a `U64` wrapped in a `BoxFuture`. - fn get_block_number(&self) -> RpcResult { + fn get_block_number(&self) -> RpcResult { let inner = self.get_inner().clone(); Box::pin(async move { @@ -1038,7 +1038,7 @@ impl EthNamespa fn get_block_transaction_count_by_hash( &self, - block_hash: zksync_basic_types::H256, + block_hash: zksync_types::H256, ) -> RpcResult> { let inner = self.get_inner().clone(); @@ -1090,10 +1090,10 @@ impl EthNamespa /// A `BoxFuture` containing a `jsonrpc_core::Result` that resolves to a [H256] value in the storage. fn get_storage( &self, - address: zksync_basic_types::Address, + address: zksync_types::Address, idx: U256, block: Option, - ) -> RpcResult { + ) -> RpcResult { let inner = self.get_inner().clone(); Box::pin(async move { @@ -1192,8 +1192,8 @@ impl EthNamespa /// A `BoxFuture` containing a `jsonrpc_core::Result` that maybe resolves to a [zksync_types::api::Transaction], if found. fn get_transaction_by_block_hash_and_index( &self, - block_hash: zksync_basic_types::H256, - index: zksync_basic_types::web3::Index, + block_hash: zksync_types::H256, + index: zksync_types::web3::Index, ) -> RpcResult> { let inner = self.get_inner().clone(); @@ -1260,7 +1260,7 @@ impl EthNamespa fn get_transaction_by_block_number_and_index( &self, block_number: BlockNumber, - index: zksync_basic_types::web3::Index, + index: zksync_types::web3::Index, ) -> RpcResult> { let inner = self.get_inner().clone(); @@ -1358,7 +1358,7 @@ impl EthNamespa futures::future::ok(accounts).boxed() } - fn coinbase(&self) -> RpcResult { + fn coinbase(&self) -> RpcResult { not_implemented("eth_coinbase") } @@ -1370,10 +1370,7 @@ impl EthNamespa not_implemented("eth_hashrate") } - fn get_uncle_count_by_block_hash( - &self, - _hash: zksync_basic_types::H256, - ) -> RpcResult> { + fn get_uncle_count_by_block_hash(&self, _hash: zksync_types::H256) -> RpcResult> { not_implemented("eth_getUncleCountByBlockHash") } @@ -1484,16 +1481,16 @@ mod tests { }, }; use maplit::hashmap; - use zksync_basic_types::vm::VmVersion; - use zksync_basic_types::{web3, Nonce}; use zksync_multivm::utils::get_max_batch_gas_limit; use zksync_types::l2::TransactionType; + use zksync_types::vm::VmVersion; use zksync_types::{ api, api::{BlockHashObject, BlockNumber, BlockNumberObject, TransactionReceipt}, utils::deployed_address_create, Bloom, K256PrivateKey, EMPTY_UNCLES_HASH, }; + use zksync_types::{web3, Nonce}; use zksync_web3_decl::types::{SyncState, ValueOrArray}; #[tokio::test] diff --git a/src/node/evm.rs b/src/node/evm.rs index 16247484..e80b71da 100644 --- a/src/node/evm.rs +++ b/src/node/evm.rs @@ -1,4 +1,4 @@ -use zksync_basic_types::{Address, U256, U64}; +use zksync_types::{Address, U256, U64}; use zksync_web3_decl::error::Web3Error; use crate::{ diff --git a/src/node/hardhat.rs b/src/node/hardhat.rs index 48d84114..020de562 100644 --- a/src/node/hardhat.rs +++ b/src/node/hardhat.rs @@ -1,4 +1,4 @@ -use zksync_basic_types::{Address, U256, U64}; +use zksync_types::{Address, U256, U64}; use zksync_web3_decl::error::Web3Error; use crate::{ diff --git a/src/node/in_memory.rs b/src/node/in_memory.rs index acd0daea..9464b15f 100644 --- a/src/node/in_memory.rs +++ b/src/node/in_memory.rs @@ -10,10 +10,6 @@ use anyhow::Context as _; use colored::Colorize; use indexmap::IndexMap; use once_cell::sync::OnceCell; -use zksync_basic_types::{ - web3::{keccak256, Bytes, Index}, - AccountTreeId, Address, L1BatchNumber, L2BlockNumber, H160, H256, H64, U256, U64, -}; use zksync_contracts::BaseSystemContracts; use zksync_multivm::{ interface::{ @@ -45,6 +41,10 @@ use zksync_types::{ ACCOUNT_CODE_STORAGE_ADDRESS, EMPTY_UNCLES_HASH, MAX_L2_TX_GAS_LIMIT, SYSTEM_CONTEXT_ADDRESS, SYSTEM_CONTEXT_BLOCK_INFO_POSITION, }; +use zksync_types::{ + web3::{keccak256, Bytes, Index}, + AccountTreeId, Address, L1BatchNumber, L2BlockNumber, H160, H256, H64, U256, U64, +}; use zksync_utils::{bytecode::hash_bytecode, h256_to_account_address, h256_to_u256, u256_to_h256}; use zksync_web3_decl::error::Web3Error; @@ -1082,7 +1082,7 @@ impl InMemoryNode { match &tx_result.result { ExecutionResult::Success { output } => { tracing::info!("Call: {}", "SUCCESS".green()); - let output_bytes = zksync_basic_types::web3::Bytes::from(output.clone()); + let output_bytes = zksync_types::web3::Bytes::from(output.clone()); tracing::info!("Output: {}", serde_json::to_string(&output_bytes).unwrap()); } ExecutionResult::Revert { output } => { @@ -1815,7 +1815,7 @@ pub fn load_last_l1_batch(storage: StoragePtr) -> Option<(u64 mod tests { use ethabi::{Token, Uint}; use gas::DEFAULT_FAIR_PUBDATA_PRICE; - use zksync_basic_types::Nonce; + use zksync_types::Nonce; use zksync_types::{utils::deployed_address_create, K256PrivateKey}; use super::*; @@ -2000,7 +2000,7 @@ mod tests { gas_per_pubdata_limit: U256::from(50000), }, U256::from(0), - zksync_basic_types::L2ChainId::from(260), + zksync_types::L2ChainId::from(260), &private_key, vec![], Default::default(), diff --git a/src/node/in_memory_ext.rs b/src/node/in_memory_ext.rs index 3c552bc9..0cbf207c 100644 --- a/src/node/in_memory_ext.rs +++ b/src/node/in_memory_ext.rs @@ -1,10 +1,10 @@ use anyhow::anyhow; -use zksync_basic_types::{AccountTreeId, Address, U256, U64}; use zksync_types::{ get_code_key, get_nonce_key, utils::{decompose_full_nonce, nonces_to_full_nonce, storage_key_for_eth_balance}, StorageKey, }; +use zksync_types::{AccountTreeId, Address, U256, U64}; use zksync_utils::{h256_to_u256, u256_to_h256}; use crate::{ @@ -406,9 +406,9 @@ mod tests { use crate::{http_fork_source::HttpForkSource, node::InMemoryNode}; use std::str::FromStr; use std::sync::{Arc, RwLock}; - use zksync_basic_types::{Nonce, H256}; use zksync_multivm::interface::storage::ReadStorage; use zksync_types::{api::BlockNumber, fee::Fee, l2::L2Tx, PackedEthSignature}; + use zksync_types::{Nonce, H256}; #[tokio::test] async fn test_set_balance() { diff --git a/src/node/net.rs b/src/node/net.rs index bc73a6bd..7ddf0dfc 100644 --- a/src/node/net.rs +++ b/src/node/net.rs @@ -1,4 +1,4 @@ -use zksync_basic_types::U256; +use zksync_types::U256; use crate::{ fork::ForkSource, diff --git a/src/node/zks.rs b/src/node/zks.rs index ad66444b..2af5edd8 100644 --- a/src/node/zks.rs +++ b/src/node/zks.rs @@ -3,7 +3,6 @@ use std::collections::HashMap; use bigdecimal::BigDecimal; use colored::Colorize; use futures::FutureExt; -use zksync_basic_types::{AccountTreeId, Address, L1BatchNumber, L2BlockNumber, H256, U256}; use zksync_types::{ api::{ BlockDetails, BlockDetailsBase, BlockStatus, BridgeAddresses, Proof, ProtocolVersion, @@ -13,6 +12,7 @@ use zksync_types::{ utils::storage_key_for_standard_token_balance, ExecuteTransactionCommon, ProtocolVersionId, Transaction, H160, L2_BASE_TOKEN_ADDRESS, }; +use zksync_types::{AccountTreeId, Address, L1BatchNumber, L2BlockNumber, H256, U256}; use zksync_utils::h256_to_u256; use zksync_web3_decl::error::Web3Error; @@ -139,11 +139,11 @@ impl ZksNamespa not_implemented("zks_estimateGasL1ToL2") } - fn get_main_contract(&self) -> RpcResult { + fn get_main_contract(&self) -> RpcResult { not_implemented("zks_getMainContract") } - fn get_testnet_paymaster(&self) -> RpcResult> { + fn get_testnet_paymaster(&self) -> RpcResult> { not_implemented("zks_getTestnetPaymaster") } @@ -185,7 +185,7 @@ impl ZksNamespa }) } - fn l1_chain_id(&self) -> RpcResult { + fn l1_chain_id(&self) -> RpcResult { use crate::namespaces::EthNamespaceT; self.chain_id() } @@ -232,7 +232,7 @@ impl ZksNamespa }) } - fn get_token_price(&self, token_address: zksync_basic_types::Address) -> RpcResult { + fn get_token_price(&self, token_address: zksync_types::Address) -> RpcResult { match format!("{:?}", token_address).to_lowercase().as_str() { "0x0000000000000000000000000000000000000000" => { // ETH @@ -281,9 +281,9 @@ impl ZksNamespa /// A `BoxFuture` containing a `Result` with a (Token, Balance) map where account has non-zero value. fn get_all_account_balances( &self, - address: zksync_basic_types::Address, + address: zksync_types::Address, ) -> jsonrpc_core::BoxFuture< - jsonrpc_core::Result>, + jsonrpc_core::Result>, > { let inner = self.get_inner().clone(); Box::pin({ @@ -324,9 +324,9 @@ impl ZksNamespa fn get_l2_to_l1_msg_proof( &self, - _block: zksync_basic_types::L2BlockNumber, - _sender: zksync_basic_types::Address, - _msg: zksync_basic_types::H256, + _block: zksync_types::L2BlockNumber, + _sender: zksync_types::Address, + _msg: zksync_types::H256, _l2_log_position: Option, ) -> RpcResult> { not_implemented("zks_getL2ToL1MsgProof") @@ -334,13 +334,13 @@ impl ZksNamespa fn get_l2_to_l1_log_proof( &self, - _tx_hash: zksync_basic_types::H256, + _tx_hash: zksync_types::H256, _index: Option, ) -> RpcResult> { not_implemented("zks_getL2ToL1LogProof") } - fn get_l1_batch_number(&self) -> RpcResult { + fn get_l1_batch_number(&self) -> RpcResult { not_implemented("zks_L1BatchNumber") } @@ -355,7 +355,7 @@ impl ZksNamespa /// A `BoxFuture` containing a `Result` with an `Option` representing details of the block (if found). fn get_block_details( &self, - block_number: zksync_basic_types::L2BlockNumber, + block_number: zksync_types::L2BlockNumber, ) -> RpcResult> { let inner = self.get_inner().clone(); Box::pin(async move { @@ -418,10 +418,9 @@ impl ZksNamespa fn get_miniblock_range( &self, - _batch: zksync_basic_types::L1BatchNumber, - ) -> jsonrpc_core::BoxFuture< - jsonrpc_core::Result>, - > { + _batch: zksync_types::L1BatchNumber, + ) -> jsonrpc_core::BoxFuture>> + { not_implemented("zks_getL1BatchBlockRange") } @@ -436,7 +435,7 @@ impl ZksNamespa /// A `BoxFuture` containing a `Result` with an `Option` representing details of the transaction (if found). fn get_transaction_details( &self, - hash: zksync_basic_types::H256, + hash: zksync_types::H256, ) -> RpcResult> { let inner = self.get_inner().clone(); Box::pin(async move { @@ -493,7 +492,7 @@ impl ZksNamespa /// /// # Parameters /// - /// * `_batch`: The batch number of type `zksync_basic_types::L1BatchNumber` for which the details are to be fetched. + /// * `_batch`: The batch number of type `zksync_types::L1BatchNumber` for which the details are to be fetched. /// /// # Returns /// @@ -501,7 +500,7 @@ impl ZksNamespa /// Given the current implementation, this will always be `None`. fn get_l1_batch_details( &self, - _batch: zksync_basic_types::L1BatchNumber, + _batch: zksync_types::L1BatchNumber, ) -> RpcResult> { Box::pin(async { Ok(None) }) } @@ -515,7 +514,7 @@ impl ZksNamespa /// # Returns /// /// A boxed future resolving to a `jsonrpc_core::Result` containing an `Option` of bytes. - fn get_bytecode_by_hash(&self, hash: zksync_basic_types::H256) -> RpcResult>> { + fn get_bytecode_by_hash(&self, hash: zksync_types::H256) -> RpcResult>> { let inner = self.get_inner().clone(); Box::pin(async move { let writer = inner.write().map_err(|_e| { @@ -556,7 +555,7 @@ impl ZksNamespa }) } - fn get_l1_gas_price(&self) -> RpcResult { + fn get_l1_gas_price(&self) -> RpcResult { not_implemented("zks_getL1GasPrice") } @@ -569,7 +568,7 @@ impl ZksNamespa /// # Returns /// /// Hard-coded address of 0x1 to replicate mainnet/testnet - fn get_base_token_l1_address(&self) -> RpcResult { + fn get_base_token_l1_address(&self) -> RpcResult { Ok(H160::from_low_u64_be(1)).into_boxed_future() } } @@ -586,9 +585,9 @@ mod tests { use crate::{http_fork_source::HttpForkSource, node::InMemoryNode}; use super::*; - use zksync_basic_types::{Address, H160, H256}; use zksync_types::api::{self, Block, TransactionReceipt, TransactionVariant}; use zksync_types::transaction_request::CallRequest; + use zksync_types::{Address, H160, H256}; use zksync_utils::u256_to_h256; #[tokio::test] diff --git a/src/testing.rs b/src/testing.rs index bd078830..7c46ec8c 100644 --- a/src/testing.rs +++ b/src/testing.rs @@ -19,13 +19,13 @@ use httptest::{ }; use itertools::Itertools; use std::str::FromStr; -use zksync_basic_types::{AccountTreeId, L1BatchNumber, L2BlockNumber, H160, U64}; use zksync_multivm::interface::{ExecutionResult, VmExecutionResultAndLogs}; use zksync_types::api::{ BlockDetailsBase, BlockIdVariant, BlockStatus, BridgeAddresses, DebugCall, DebugCallType, Log, }; use zksync_types::block::pack_block_info; use zksync_types::{fee::Fee, l2::L2Tx, Address, L2ChainId, Nonce, ProtocolVersionId, H256, U256}; +use zksync_types::{AccountTreeId, L1BatchNumber, L2BlockNumber, H160, U64}; use zksync_types::{K256PrivateKey, StorageKey}; use zksync_utils::u256_to_h256; @@ -551,7 +551,7 @@ pub fn deploy_contract( gas_per_pubdata_limit: U256::from(50000), }, U256::from(0), - zksync_basic_types::L2ChainId::from(260), + zksync_types::L2ChainId::from(260), private_key, vec![bytecode], Default::default(), @@ -847,7 +847,7 @@ impl ForkSource for ExternalStorage { fn get_transaction_by_block_hash_and_index( &self, _block_hash: H256, - _index: zksync_basic_types::web3::Index, + _index: zksync_types::web3::Index, ) -> eyre::Result> { todo!() } @@ -855,7 +855,7 @@ impl ForkSource for ExternalStorage { fn get_transaction_by_block_number_and_index( &self, _block_number: zksync_types::api::BlockNumber, - _index: zksync_basic_types::web3::Index, + _index: zksync_types::web3::Index, ) -> eyre::Result> { todo!() } diff --git a/src/utils.rs b/src/utils.rs index 8a328dbb..a2c09d96 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -2,12 +2,10 @@ use std::convert::TryInto; use std::fmt; use std::pin::Pin; -use anyhow::anyhow; +use anyhow::Context; use chrono::{DateTime, Utc}; use futures::Future; use jsonrpc_core::{Error, ErrorCode}; -use zkevm_opcode_defs::utils::bytecode_to_code_hash; -use zksync_basic_types::{H256, U256, U64}; use zksync_multivm::interface::storage::WriteStorage; use zksync_multivm::interface::{ Call, CallType, ExecutionResult, VmExecutionResultAndLogs, VmFactory, VmInterfaceExt, @@ -18,6 +16,7 @@ use zksync_types::api::{BlockNumber, DebugCall, DebugCallType}; use zksync_types::l2::L2Tx; use zksync_types::web3::Bytes; use zksync_types::CONTRACT_DEPLOYER_ADDRESS; +use zksync_types::{H256, U256, U64}; use zksync_utils::bytes_to_be_words; use zksync_web3_decl::error::Web3Error; @@ -57,31 +56,9 @@ pub fn to_human_size(input: U256) -> String { tmp.iter().rev().collect() } -pub fn bytes_to_chunks(bytes: &[u8]) -> Vec<[u8; 32]> { - bytes - .chunks(32) - .map(|el| { - let mut chunk = [0u8; 32]; - chunk.copy_from_slice(el); - chunk - }) - .collect() -} - -pub fn hash_bytecode(code: &[u8]) -> Result { - if code.len() % 32 != 0 { - return Err(anyhow!("bytes must be divisible by 32")); - } - - let chunked_code = bytes_to_chunks(code); - match bytecode_to_code_hash(&chunked_code) { - Ok(hash) => Ok(H256(hash)), - Err(_) => Err(anyhow!("invalid bytecode")), - } -} - pub fn bytecode_to_factory_dep(bytecode: Vec) -> Result<(U256, Vec), anyhow::Error> { - let bytecode_hash = hash_bytecode(&bytecode)?; + zksync_utils::bytecode::validate_bytecode(&bytecode).context("Invalid bytecode")?; + let bytecode_hash = zksync_utils::bytecode::hash_bytecode(&bytecode); let bytecode_hash = U256::from_big_endian(bytecode_hash.as_bytes()); let bytecode_words = bytes_to_be_words(bytecode); @@ -355,7 +332,7 @@ pub fn h256_to_u64(value: H256) -> u64 { #[cfg(test)] mod tests { - use zksync_basic_types::{H256, U256}; + use zksync_types::{H256, U256}; use crate::{http_fork_source::HttpForkSource, node::InMemoryNode, testing};