Skip to content

Commit

Permalink
refactor(utils): Move bytecode hashing to basic_types (#3258)
Browse files Browse the repository at this point in the history
## What ❔

Moves bytecode hashing logic to `zksync_basic_types`.

## Why ❔

It belongs there by domain and further simplifies the dependency graph.

## Checklist

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [x] Tests for the changes have been added / updated.
- [x] Documentation comments have been added / updated.
- [x] Code has been formatted via `zkstack dev fmt` and `zkstack dev
lint`.
  • Loading branch information
slowli authored Nov 14, 2024
1 parent 8620a8e commit 1edcabe
Show file tree
Hide file tree
Showing 109 changed files with 545 additions and 766 deletions.
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

0 comments on commit 1edcabe

Please sign in to comment.