From b13e594510f346fd9062dd56c4cbfd75cfb2c8e7 Mon Sep 17 00:00:00 2001 From: Lyova Potyomkin Date: Thu, 24 Oct 2024 13:04:32 +0300 Subject: [PATCH 1/5] fix: extend allowed storage slots for validation as per EIP-7562 --- core/lib/multivm/src/tracers/validator/mod.rs | 16 +++++++++++++--- etc/env/base/chain.toml | 4 ++-- etc/env/base/contracts.toml | 4 ++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/core/lib/multivm/src/tracers/validator/mod.rs b/core/lib/multivm/src/tracers/validator/mod.rs index a1573f24c668..7f9a91750ac3 100644 --- a/core/lib/multivm/src/tracers/validator/mod.rs +++ b/core/lib/multivm/src/tracers/validator/mod.rs @@ -1,4 +1,8 @@ -use std::{collections::HashSet, marker::PhantomData, sync::Arc}; +use std::{ + collections::{BTreeSet, HashSet}, + marker::PhantomData, + sync::Arc, +}; use once_cell::sync::OnceCell; use zksync_system_constants::{ @@ -32,7 +36,7 @@ mod vm_virtual_blocks; #[derive(Debug, Clone)] pub struct ValidationTracer { validation_mode: ValidationTracerMode, - auxilary_allowed_slots: HashSet, + auxilary_allowed_slots: BTreeSet, user_address: Address, #[allow(dead_code)] @@ -51,6 +55,8 @@ pub struct ValidationTracer { type ValidationRoundResult = Result; impl ValidationTracer { + const MAX_ALLOWED_SLOT_OFFSET: u32 = 127; + pub fn new( params: ValidationParams, vm_version: VmVersion, @@ -133,7 +139,11 @@ impl ValidationTracer { // The user is allowed to touch its own slots or slots semantically related to him. let valid_users_slot = address == self.user_address || u256_to_account_address(&key) == self.user_address - || self.auxilary_allowed_slots.contains(&u256_to_h256(key)); + || self + .auxilary_allowed_slots + .range(u256_to_h256(key - Self::MAX_ALLOWED_SLOT_OFFSET)..=u256_to_h256(key)) + .next() + .is_some(); if valid_users_slot { return true; } diff --git a/etc/env/base/chain.toml b/etc/env/base/chain.toml index 903696e3a819..6d1fdae53cee 100644 --- a/etc/env/base/chain.toml +++ b/etc/env/base/chain.toml @@ -90,8 +90,8 @@ fee_model_version = "V2" validation_computational_gas_limit = 300000 save_call_traces = true -bootloader_hash = "0x010008c37ecadea8b003884eb9d81fdfb7161b3b309504e5318f15da19c500d8" -default_aa_hash = "0x0100055da70d970f98ca4677a4b2fcecef5354f345cc5c6d13a78339e5fd87a9" +bootloader_hash = "0x010008c3be57ae5800e077b6c2056d9d75ad1a7b4f0ce583407961cc6fe0b678" +default_aa_hash = "0x0100055dba11508480be023137563caec69debc85f826cb3a4b68246a7cabe30" protective_reads_persistence_enabled = false diff --git a/etc/env/base/contracts.toml b/etc/env/base/contracts.toml index dbadbbc2c776..735da993058b 100644 --- a/etc/env/base/contracts.toml +++ b/etc/env/base/contracts.toml @@ -26,8 +26,8 @@ RECURSION_NODE_LEVEL_VK_HASH = "0x1186ec268d49f1905f8d9c1e9d39fc33e98c74f91d91a2 RECURSION_LEAF_LEVEL_VK_HASH = "0x101e08b00193e529145ee09823378ef51a3bc8966504064f1f6ba3f1ba863210" RECURSION_CIRCUITS_SET_VKS_HASH = "0x18c1639094f58177409186e8c48d9f577c9410901d2f1d486b3e7d6cf553ae4c" GENESIS_TX_HASH = "0xb99ebfea46cbe05a21cd80fe5597d97b204befc52a16303f579c607dc1ac2e2e" -GENESIS_ROOT = "0x28a7e67393021f957572495f8fdadc2c477ae3f4f413ae18c16cff6ee65680e2" -GENESIS_BATCH_COMMITMENT = "0xc57085380434970021d87774b377ce1bb12f5b6064af11595e70011965747def" +GENESIS_ROOT = "0x7275936e5a0063b159d5d22734931fea07871e8d57e564d61ef56e4a6ee23e5c" +GENESIS_BATCH_COMMITMENT = "0xf5f9a5abe62e8a6e0cb2d34d27435c3e5a8fbd7e2e54ca1d108fc58cb86c708a" PRIORITY_TX_MAX_GAS_LIMIT = 72000000 DEPLOY_L2_BRIDGE_COUNTERPART_GAS_LIMIT = 10000000 GENESIS_ROLLUP_LEAF_INDEX = "54" From f33de7d41a89ebc9a165c739a4265c05e002b8d9 Mon Sep 17 00:00:00 2001 From: Lyova Potyomkin Date: Thu, 24 Oct 2024 13:31:28 +0300 Subject: [PATCH 2/5] fmt --- prover/crates/bin/prover_autoscaler/src/global/watcher.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/prover/crates/bin/prover_autoscaler/src/global/watcher.rs b/prover/crates/bin/prover_autoscaler/src/global/watcher.rs index 1b54d332ebb1..6e02c0fe2fdc 100644 --- a/prover/crates/bin/prover_autoscaler/src/global/watcher.rs +++ b/prover/crates/bin/prover_autoscaler/src/global/watcher.rs @@ -6,7 +6,6 @@ use reqwest::{ header::{HeaderMap, HeaderValue, CONTENT_TYPE}, Method, }; - use tokio::sync::Mutex; use url::Url; use zksync_utils::http_with_retries::send_request_with_retries; From 7ed9349fbd3a2204d59863c9a8d16f438836319f Mon Sep 17 00:00:00 2001 From: Lyova Potyomkin Date: Thu, 24 Oct 2024 18:44:59 +0300 Subject: [PATCH 3/5] fixes --- core/lib/multivm/src/tracers/validator/mod.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/lib/multivm/src/tracers/validator/mod.rs b/core/lib/multivm/src/tracers/validator/mod.rs index 7f9a91750ac3..9e9cb819b293 100644 --- a/core/lib/multivm/src/tracers/validator/mod.rs +++ b/core/lib/multivm/src/tracers/validator/mod.rs @@ -137,11 +137,15 @@ impl ValidationTracer { } // The user is allowed to touch its own slots or slots semantically related to him. + let from = u256_to_h256(key.saturating_sub(Self::MAX_ALLOWED_SLOT_OFFSET.into())); + let to = u256_to_h256(key); let valid_users_slot = address == self.user_address - || u256_to_account_address(&key) == self.user_address + // we don't allow dirty bytes in front of the address + || key < U256::from(2).pow(160.into()) + && u256_to_account_address(&key) == self.user_address || self .auxilary_allowed_slots - .range(u256_to_h256(key - Self::MAX_ALLOWED_SLOT_OFFSET)..=u256_to_h256(key)) + .range(from..=to) .next() .is_some(); if valid_users_slot { From c70b3e17ab24f1a8173b5d36f541a621a683d583 Mon Sep 17 00:00:00 2001 From: Lyova Potyomkin Date: Thu, 24 Oct 2024 19:34:10 +0300 Subject: [PATCH 4/5] Update core/lib/multivm/src/tracers/validator/mod.rs Co-authored-by: Vlad Bochok <41153528+vladbochok@users.noreply.github.com> --- core/lib/multivm/src/tracers/validator/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/lib/multivm/src/tracers/validator/mod.rs b/core/lib/multivm/src/tracers/validator/mod.rs index 9e9cb819b293..09af817b56e8 100644 --- a/core/lib/multivm/src/tracers/validator/mod.rs +++ b/core/lib/multivm/src/tracers/validator/mod.rs @@ -141,8 +141,7 @@ impl ValidationTracer { let to = u256_to_h256(key); let valid_users_slot = address == self.user_address // we don't allow dirty bytes in front of the address - || key < U256::from(2).pow(160.into()) - && u256_to_account_address(&key) == self.user_address + || key == address_to_u256(self.user_address) || self .auxilary_allowed_slots .range(from..=to) From 75c7e5f63eb42f442f6be949947dacdd4a2a25b8 Mon Sep 17 00:00:00 2001 From: Lyova Potyomkin Date: Thu, 24 Oct 2024 19:47:36 +0300 Subject: [PATCH 5/5] fixes --- core/lib/multivm/src/tracers/validator/mod.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/lib/multivm/src/tracers/validator/mod.rs b/core/lib/multivm/src/tracers/validator/mod.rs index 09af817b56e8..057551a9efeb 100644 --- a/core/lib/multivm/src/tracers/validator/mod.rs +++ b/core/lib/multivm/src/tracers/validator/mod.rs @@ -12,7 +12,7 @@ use zksync_system_constants::{ use zksync_types::{ vm::VmVersion, web3::keccak256, AccountTreeId, Address, StorageKey, H256, U256, }; -use zksync_utils::{be_bytes_to_safe_address, u256_to_account_address, u256_to_h256}; +use zksync_utils::{address_to_u256, be_bytes_to_safe_address, u256_to_h256}; use self::types::{NewTrustedValidationItems, ValidationTracerMode}; use crate::{ @@ -140,8 +140,7 @@ impl ValidationTracer { let from = u256_to_h256(key.saturating_sub(Self::MAX_ALLOWED_SLOT_OFFSET.into())); let to = u256_to_h256(key); let valid_users_slot = address == self.user_address - // we don't allow dirty bytes in front of the address - || key == address_to_u256(self.user_address) + || key == address_to_u256(&self.user_address) || self .auxilary_allowed_slots .range(from..=to)