Skip to content

Commit

Permalink
add is_system_address
Browse files Browse the repository at this point in the history
  • Loading branch information
nbaztec committed Apr 5, 2024
1 parent 8ec9e75 commit 88e233b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions crates/zksync/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,9 @@ pub async fn estimate_gas<M: Middleware>(

Ok(EstimatedGas { price: gas_price.to_ru256(), limit: fee.gas_limit.to_ru256() })
}

/// Returns true if the provided address is a reserved zkSync system address
/// All addresses less than 2^16 are considered reserved addresses.
pub fn is_system_address(address: Address) -> bool {
address.to_h256().to_ru256().lt(&rU256::from(2u128.pow(16)))
}
6 changes: 3 additions & 3 deletions crates/zksync/core/src/vm/runner.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{
convert::{ConvertAddress, ConvertH160, ConvertH256, ConvertRU256, ConvertU256},
is_system_address,
vm::tracer::CheatcodeTracer,
};
use alloy_primitives::Log;
Expand Down Expand Up @@ -371,15 +372,14 @@ where
codes.insert(k.key().to_h160().to_address(), (hash, bytecode));
} else {
// We populate bytecodes for all non-system addresses
let contract_address = k.key().to_ru256();
if !contract_address.lt(&rU256::from(2u128.pow(16))) {
if !is_system_address(k.key().to_h160().to_address()) {
if let Some(bytecode) = (&mut era_db).load_factory_dep(*v) {
let hash = B256::from_slice(v.as_bytes());
let bytecode = Bytecode::new_raw(Bytes::from(bytecode));
codes.insert(k.key().to_h160().to_address(), (hash, bytecode));
} else {
tracing::warn!(
"no bytecode was found for {:?} requested by account {:?}",
"no bytecode was found for {:?}, requested by account {:?}",
*v,
k.key().to_h160()
);
Expand Down

0 comments on commit 88e233b

Please sign in to comment.