Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(utils): Move bytecode hashing to basic_types #3258

Merged
merged 8 commits into from
Nov 14, 2024
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
21 changes: 3 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 12 additions & 13 deletions core/bin/system-constants-generator/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ use zksync_multivm::{
zk_evm_latest::aux_structures::Timestamp,
};
use zksync_types::{
block::L2BlockHasher, ethabi::Token, fee::Fee, fee_model::BatchFeeInput, l1::L1Tx, l2::L2Tx,
u256_to_h256, utils::storage_key_for_eth_balance, AccountTreeId, Address, Execute,
K256PrivateKey, L1BatchNumber, L1TxCommonData, L2BlockNumber, L2ChainId, Nonce,
ProtocolVersionId, StorageKey, Transaction, BOOTLOADER_ADDRESS, SYSTEM_CONTEXT_ADDRESS,
SYSTEM_CONTEXT_GAS_PRICE_POSITION, SYSTEM_CONTEXT_TX_ORIGIN_POSITION, U256,
ZKPORTER_IS_AVAILABLE,
block::L2BlockHasher, bytecode::BytecodeHash, ethabi::Token, fee::Fee,
fee_model::BatchFeeInput, l1::L1Tx, l2::L2Tx, u256_to_h256, utils::storage_key_for_eth_balance,
AccountTreeId, Address, Execute, K256PrivateKey, L1BatchNumber, L1TxCommonData, L2BlockNumber,
L2ChainId, Nonce, ProtocolVersionId, StorageKey, Transaction, BOOTLOADER_ADDRESS,
SYSTEM_CONTEXT_ADDRESS, SYSTEM_CONTEXT_GAS_PRICE_POSITION, SYSTEM_CONTEXT_TX_ORIGIN_POSITION,
U256, ZKPORTER_IS_AVAILABLE,
};
use zksync_utils::bytecode::hash_bytecode;

use crate::intrinsic_costs::VmSpentResourcesResult;

Expand Down Expand Up @@ -63,15 +62,15 @@ impl<S: WriteStorage, H: HistoryMode> VmTracer<S, H> for SpecialBootloaderTracer

pub static GAS_TEST_SYSTEM_CONTRACTS: Lazy<BaseSystemContracts> = Lazy::new(|| {
let bytecode = read_bootloader_code("gas_test");
let hash = hash_bytecode(&bytecode);
let hash = BytecodeHash::for_bytecode(&bytecode).value();

let bootloader = SystemContractCode {
code: bytecode,
hash,
};

let bytecode = read_sys_contract_bytecode("", "DefaultAccount", ContractLanguage::Sol);
let hash = hash_bytecode(&bytecode);
let hash = BytecodeHash::for_bytecode(&bytecode).value();

BaseSystemContracts {
default_aa: SystemContractCode {
Expand Down Expand Up @@ -208,12 +207,12 @@ fn default_l1_batch() -> L1BatchEnv {
/// returns the amount of gas needed to perform and internal transfer, assuming no gas price
/// per pubdata, i.e. under assumption that the refund will not touch any new slots.
pub(super) fn execute_internal_transfer_test() -> u32 {
let raw_storage = InMemoryStorage::with_system_contracts(hash_bytecode);
let raw_storage = InMemoryStorage::with_system_contracts();
let mut storage_view = StorageView::new(raw_storage);
let bootloader_balance_key = storage_key_for_eth_balance(&BOOTLOADER_ADDRESS);
storage_view.set_value(bootloader_balance_key, u256_to_h256(U256([0, 0, 1, 0])));
let bytecode = read_bootloader_test_code("transfer_test");
let hash = hash_bytecode(&bytecode);
let hash = BytecodeHash::for_bytecode(&bytecode).value();
let bootloader = SystemContractCode {
code: bytecode,
hash,
Expand All @@ -222,7 +221,7 @@ pub(super) fn execute_internal_transfer_test() -> u32 {
let l1_batch = default_l1_batch();

let bytecode = read_sys_contract_bytecode("", "DefaultAccount", ContractLanguage::Sol);
let hash = hash_bytecode(&bytecode);
let hash = BytecodeHash::for_bytecode(&bytecode).value();
let default_aa = SystemContractCode {
code: bytecode,
hash,
Expand Down Expand Up @@ -293,7 +292,7 @@ pub(super) fn execute_user_txs_in_test_gas_vm(
.iter()
.fold(U256::zero(), |sum, elem| sum + elem.gas_limit());

let raw_storage = InMemoryStorage::with_system_contracts(hash_bytecode);
let raw_storage = InMemoryStorage::with_system_contracts();
let mut storage_view = StorageView::new(raw_storage);

for tx in txs.iter() {
Expand Down
2 changes: 2 additions & 0 deletions core/lib/basic_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ keywords.workspace = true
categories.workspace = true

[dependencies]
const-decoder.workspace = true
ethabi.workspace = true
hex.workspace = true
sha2.workspace = true
tiny-keccak.workspace = true
thiserror.workspace = true
serde = { workspace = true, features = ["derive"] }
Expand Down
Loading
Loading