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

feat: add block.timestamp asserter for AA #3031

Merged
merged 84 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
5a60e58
Add timestamp asserter
ischasny Oct 3, 2024
70ad274
Add timestamp asserter to tracer and tests
ischasny Oct 3, 2024
5223913
Capture validation traces as transaction gets executed
ischasny Oct 4, 2024
d167279
Add block.timestamp columns
ischasny Oct 8, 2024
0bc40d4
Merge from main
ischasny Oct 8, 2024
c65a2c0
Clean up custom accounts
ischasny Oct 8, 2024
28af0e3
fix test
ischasny Oct 8, 2024
46c11bf
Allow deprecated function
ischasny Oct 8, 2024
82628d3
Fix compilation errors
ischasny Oct 8, 2024
a1972f4
Change refcell to mutex
ischasny Oct 8, 2024
0892349
Switched to the latest contracts
ischasny Oct 8, 2024
547a9fe
latest contracts
ischasny Oct 8, 2024
5b28a9d
Update contracts
ischasny Oct 8, 2024
b29aaaf
Merge branch 'main' into ivan/add-timestamp-asserter
Deniallugo Oct 9, 2024
86cad9f
Fix building contracts
Deniallugo Oct 9, 2024
c724a3f
mkdir
Deniallugo Oct 9, 2024
8ba4a04
Fix building contracts
Deniallugo Oct 9, 2024
4a30b86
Create artifacts
Deniallugo Oct 9, 2024
173fb29
Add timestamp asserter ranges
ischasny Oct 10, 2024
d9b473e
Merge from main
ischasny Oct 10, 2024
9c0d5bb
Merge from main
ischasny Oct 10, 2024
a54e6eb
fix lint
ischasny Oct 10, 2024
c12aff8
Merge branch 'main' into ivan/add-timestamp-asserter
ischasny Oct 10, 2024
3a8234d
Update config
ischasny Oct 10, 2024
980d7a7
Update EN
ischasny Oct 10, 2024
4c78721
Merge branch 'main' into ivan/add-timestamp-asserter
ischasny Oct 11, 2024
ba0332d
Fix EN test
ischasny Oct 11, 2024
7453e00
Fix EN test
ischasny Oct 11, 2024
bafd5c0
config typo
ischasny Oct 11, 2024
1df73ac
Add mempool filtering
ischasny Oct 11, 2024
c0c504b
Merge branch 'main' into ivan/add-timestamp-asserter
ischasny Oct 14, 2024
7304422
Fix mempool tests
ischasny Oct 14, 2024
34c5a6c
Fix compilation errors
ischasny Oct 14, 2024
7721509
Updated mempool handling
ischasny Oct 15, 2024
d95f012
Merge branch 'main' into ivan/add-timestamp-asserter
ischasny Oct 15, 2024
f7fb4c2
Fix main
ischasny Oct 15, 2024
aa23ec1
Add mempool test
ischasny Oct 15, 2024
b099841
Add mempool test
ischasny Oct 15, 2024
9c935f7
Merge
ischasny Oct 15, 2024
4716cdd
Updated contracts
ischasny Oct 16, 2024
82841ac
Update to the latest contracts
ischasny Oct 16, 2024
10fff81
Update contracts
ischasny Oct 16, 2024
8051e0a
Update contracts
ischasny Oct 16, 2024
623a98e
Add tx_sender test
ischasny Oct 16, 2024
b2ea3cb
brush up
ischasny Oct 17, 2024
6105694
Fix integration test
ischasny Oct 18, 2024
3d090ef
Merge
ischasny Oct 18, 2024
ceb6e10
Fix lint
ischasny Oct 18, 2024
d93b52d
Fix tests
ischasny Oct 18, 2024
030cf95
Merge branch 'main' into ivan/add-timestamp-asserter
ischasny Oct 18, 2024
d8a3df8
Add missing sqlx file
ischasny Oct 18, 2024
a2373d0
Add more integration tests
ischasny Oct 21, 2024
30fc4a4
Merge
ischasny Oct 21, 2024
a7adae5
Fix unit test
ischasny Oct 21, 2024
fb31dd9
Review feedback
ischasny Oct 22, 2024
222dada
Add missing sqlx file
ischasny Oct 22, 2024
1867ab2
Fix lint
ischasny Oct 22, 2024
a0a5198
Fixed comments
ischasny Oct 22, 2024
a920f76
Merge main
ischasny Oct 28, 2024
6c90948
Review comments
ischasny Oct 29, 2024
c79976d
Merge branch 'main' into ivan/add-timestamp-asserter
ischasny Oct 29, 2024
f20a68b
lint
ischasny Oct 29, 2024
9dea6bd
lint
ischasny Oct 29, 2024
d4dcc4c
Fix integration tests
ischasny Oct 29, 2024
136187e
Fix integraiton test
ischasny Oct 29, 2024
4d3c079
Merge branch 'main' into ivan/add-timestamp-asserter
ischasny Oct 29, 2024
7fe6d7e
SWitch to protocol defence branch
ischasny Oct 29, 2024
433aa1e
Merge branch 'main' into ivan/add-timestamp-asserter
ischasny Oct 29, 2024
2d06dab
Fix integration test
ischasny Oct 29, 2024
cbe0bbb
Lint fix
ischasny Oct 29, 2024
8ec0c3e
Removed window range check
ischasny Oct 29, 2024
acd55a6
Review feedback
ischasny Oct 29, 2024
56ea915
lint fix
ischasny Oct 29, 2024
14b506d
add test for range overflow
ischasny Oct 29, 2024
5fa2f06
Update integration test
ischasny Oct 29, 2024
53e9ec8
Updated contracts
ischasny Oct 31, 2024
125ff97
Updated contracts
ischasny Oct 31, 2024
bd954a3
Update to the last contracts
ischasny Oct 31, 2024
fcaf160
Merge branch 'main' into ivan/add-timestamp-asserter
ischasny Oct 31, 2024
29d99d4
Review feedback
ischasny Oct 31, 2024
bd395d2
Review feedback
ischasny Oct 31, 2024
56e9375
Review feedback
ischasny Oct 31, 2024
42cc5f7
Remove unnecessary workflows change
ischasny Nov 1, 2024
4a7adb1
Remove unnecessary workflows change
ischasny Nov 1, 2024
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
11 changes: 11 additions & 0 deletions .github/workflows/new-build-core-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ jobs:
tar -C ./contracts -zxf l1-contracts.tar.gz
tar -C ./contracts -zxf l2-contracts.tar.gz
tar -C ./contracts -zxf system-contracts.tar.gz
# TODO Remove mkdir once we use foundry inside contracts repo
mkdir -p contracts/l1-contracts/out

- name: Install Apt dependencies
if: env.BUILD_CONTRACTS == 'true'
Expand Down Expand Up @@ -142,6 +144,7 @@ jobs:
cp etc/tokens/{test,localhost}.json
zkstack dev contracts


- name: Upload contracts
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
with:
Expand Down Expand Up @@ -208,6 +211,14 @@ jobs:
path: |
./contracts

# TODO Remove it when we migrate to foundry inside contracts repository
- name: Create necessary artefacts
shell: bash
run: |
mkdir -p contracts/l1-contracts/artifacts/
ischasny marked this conversation as resolved.
Show resolved Hide resolved
mkdir -p contracts/l1-contracts/out


- name: login to Docker registries
if: ${{ inputs.action == 'push' }}
shell: bash
Expand Down
41 changes: 40 additions & 1 deletion core/bin/external_node/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use zksync_core_leftovers::temp_config_store::read_yaml_repr;
use zksync_dal::{ConnectionPool, Core};
use zksync_metadata_calculator::MetadataCalculatorRecoveryConfig;
use zksync_node_api_server::{
tx_sender::TxSenderConfig,
tx_sender::{TimestampAsserterParams, TxSenderConfig},
web3::{state::InternalApiConfig, Namespace},
};
use zksync_protobuf_config::proto;
Expand Down Expand Up @@ -121,6 +121,7 @@ pub(crate) struct RemoteENConfig {
pub l1_weth_bridge_addr: Option<Address>,
pub l2_weth_bridge_addr: Option<Address>,
pub l2_testnet_paymaster_addr: Option<Address>,
pub l2_timestamp_asserter_addr: Option<Address>,
pub base_token_addr: Address,
pub l1_batch_commit_data_generator_mode: L1BatchCommitmentMode,
pub dummy_verifier: bool,
Expand All @@ -146,6 +147,10 @@ impl RemoteENConfig {
.get_main_contract()
.rpc_context("get_main_contract")
.await?;
let timestamp_asserter_address = client
ischasny marked this conversation as resolved.
Show resolved Hide resolved
.get_timestamp_asserter()
.rpc_context("get_timestamp_asserter")
.await?;
let base_token_addr = match client.get_base_token_l1_address().await {
Err(ClientError::Call(err))
if [
Expand Down Expand Up @@ -206,6 +211,7 @@ impl RemoteENConfig {
.as_ref()
.map(|a| a.dummy_verifier)
.unwrap_or_default(),
l2_timestamp_asserter_addr: timestamp_asserter_address,
})
}

Expand All @@ -227,6 +233,7 @@ impl RemoteENConfig {
l2_legacy_shared_bridge_addr: Some(Address::repeat_byte(7)),
l1_batch_commit_data_generator_mode: L1BatchCommitmentMode::Rollup,
dummy_verifier: true,
l2_timestamp_asserter_addr: None,
}
}
}
Expand Down Expand Up @@ -454,6 +461,12 @@ pub(crate) struct OptionalENConfig {
pub gateway_url: Option<SensitiveUrl>,
/// Interval for bridge addresses refreshing in seconds.
bridge_addresses_refresh_interval_sec: Option<NonZeroU64>,
/// Minimum difference in seconds between the range start and range end for TimestampAsserter
#[serde(default = "OptionalENConfig::default_timestamp_asserter_min_range_sec")]
pub timestamp_asserter_min_range_sec: u32,
/// Minimum time between current block.timestamp and the end of the asserted range for TimestampAsserter
#[serde(default = "OptionalENConfig::default_timestamp_asserter_min_time_till_end_sec")]
pub timestamp_asserter_min_time_till_end_sec: u32,
}

impl OptionalENConfig {
Expand Down Expand Up @@ -685,6 +698,16 @@ impl OptionalENConfig {
contracts_diamond_proxy_addr: None,
gateway_url: enconfig.gateway_url.clone(),
bridge_addresses_refresh_interval_sec: enconfig.bridge_addresses_refresh_interval_sec,
timestamp_asserter_min_range_sec: general_config
.timestamp_asserter_config
.as_ref()
.map(|x| x.min_range_sec)
.unwrap_or(0),
ischasny marked this conversation as resolved.
Show resolved Hide resolved
timestamp_asserter_min_time_till_end_sec: general_config
.timestamp_asserter_config
.as_ref()
.map(|x| x.min_time_till_end_sec)
.unwrap_or(0),
})
}

Expand Down Expand Up @@ -819,6 +842,14 @@ impl OptionalENConfig {
3_600 * 24 * 7 // 7 days
}

const fn default_timestamp_asserter_min_range_sec() -> u32 {
10 * 60
}

const fn default_timestamp_asserter_min_time_till_end_sec() -> u32 {
2 * 60
}

fn from_env() -> anyhow::Result<Self> {
let mut result: OptionalENConfig = envy::prefixed("EN_")
.from_env()
Expand Down Expand Up @@ -1425,6 +1456,7 @@ impl From<&ExternalNodeConfig> for InternalApiConfig {
filters_disabled: config.optional.filters_disabled,
dummy_verifier: config.remote.dummy_verifier,
l1_batch_commit_data_generator_mode: config.remote.l1_batch_commit_data_generator_mode,
timestamp_asserter_address: config.remote.l2_timestamp_asserter_addr,
}
}
}
Expand All @@ -1447,6 +1479,13 @@ impl From<&ExternalNodeConfig> for TxSenderConfig {
chain_id: config.required.l2_chain_id,
// Does not matter for EN.
whitelisted_tokens_for_aa: Default::default(),
timestamp_asserter_params: config.remote.l2_timestamp_asserter_addr.map(|address| {
TimestampAsserterParams {
address,
min_range_sec: config.optional.timestamp_asserter_min_range_sec,
min_time_till_end_sec: config.optional.timestamp_asserter_min_time_till_end_sec,
}
}),
}
}
}
2 changes: 2 additions & 0 deletions core/bin/external_node/src/config/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ fn parsing_optional_config_from_env() {
"zks_getProof=100,eth_call=2",
),
("EN_L1_BATCH_COMMIT_DATA_GENERATOR_MODE", "Validium"),
("EN_TIMESTAMP_ASSERTER_MIN_RANGE_SEC", "1"),
("EN_TIMESTAMP_ASSERTER_MIN_TIME_TILL_END_SEC", "2"),
];
let env_vars = env_vars
.into_iter()
Expand Down
3 changes: 2 additions & 1 deletion core/bin/zksync_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use zksync_config::{
api::{HealthCheckConfig, MerkleTreeApiConfig, Web3JsonRpcConfig},
chain::{
CircuitBreakerConfig, MempoolConfig, NetworkConfig, OperationsManagerConfig,
StateKeeperConfig,
StateKeeperConfig, TimestampAsserterConfig,
},
fri_prover_group::FriProverGroupConfig,
house_keeper::HouseKeeperConfig,
Expand Down Expand Up @@ -195,5 +195,6 @@ fn load_env_config() -> anyhow::Result<TempConfigStore> {
external_proof_integration_api_config: ExternalProofIntegrationApiConfig::from_env().ok(),
experimental_vm_config: ExperimentalVmConfig::from_env().ok(),
prover_job_monitor_config: None,
timestamp_asserter_config: TimestampAsserterConfig::from_env().ok(),
})
}
10 changes: 9 additions & 1 deletion core/bin/zksync_server/src/node_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use zksync_config::{
use zksync_core_leftovers::Component;
use zksync_metadata_calculator::MetadataCalculatorConfig;
use zksync_node_api_server::{
tx_sender::TxSenderConfig,
tx_sender::{TimestampAsserterParams, TxSenderConfig},
web3::{state::InternalApiConfig, Namespace},
};
use zksync_node_framework::{
Expand Down Expand Up @@ -303,6 +303,7 @@ impl MainNodeBuilder {
fn add_tx_sender_layer(mut self) -> anyhow::Result<Self> {
let sk_config = try_load_config!(self.configs.state_keeper_config);
let rpc_config = try_load_config!(self.configs.api_config).web3_json_rpc;
let timestamp_asserter_config = try_load_config!(self.configs.timestamp_asserter_config);
let postgres_storage_caches_config = PostgresStorageCachesConfig {
factory_deps_cache_size: rpc_config.factory_deps_cache_size() as u64,
initial_writes_cache_size: rpc_config.initial_writes_cache_size() as u64,
Expand All @@ -322,6 +323,13 @@ impl MainNodeBuilder {
.fee_account
.address(),
self.genesis_config.l2_chain_id,
self.contracts_config
.l2_timestamp_asserter_addr
.map(|address| TimestampAsserterParams {
address,
min_range_sec: timestamp_asserter_config.min_range_sec,
min_time_till_end_sec: timestamp_asserter_config.min_time_till_end_sec,
ischasny marked this conversation as resolved.
Show resolved Hide resolved
}),
),
postgres_storage_caches_config,
rpc_config.vm_concurrency_limit(),
Expand Down
10 changes: 9 additions & 1 deletion core/lib/config/src/configs/chain.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{str::FromStr, time::Duration};

use serde::Deserialize;
use serde::{Deserialize, Serialize};
use zksync_basic_types::{
commitment::L1BatchCommitmentMode, network::Network, Address, L2ChainId, H256,
};
Expand Down Expand Up @@ -244,3 +244,11 @@ impl MempoolConfig {
Duration::from_millis(self.delay_interval)
}
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct TimestampAsserterConfig {
ischasny marked this conversation as resolved.
Show resolved Hide resolved
/// Minimum difference in seconds between the range start and range end
pub min_range_sec: u32,
/// Minimum time between current block.timestamp and the end of the asserted range
pub min_time_till_end_sec: u32,
}
2 changes: 2 additions & 0 deletions core/lib/config/src/configs/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub struct ContractsConfig {
pub l1_weth_bridge_proxy_addr: Option<Address>,
pub l2_weth_bridge_addr: Option<Address>,
pub l2_testnet_paymaster_addr: Option<Address>,
pub l2_timestamp_asserter_addr: Option<Address>,
pub l1_multicall3_addr: Address,
pub ecosystem_contracts: Option<EcosystemContracts>,
// Used by the RPC API and by the node builder in wiring the BaseTokenRatioProvider layer.
Expand All @@ -65,6 +66,7 @@ impl ContractsConfig {
l2_weth_bridge_addr: Some(Address::repeat_byte(0x0c)),
l2_testnet_paymaster_addr: Some(Address::repeat_byte(0x11)),
l1_multicall3_addr: Address::repeat_byte(0x12),
l2_timestamp_asserter_addr: Some(Address::repeat_byte(0x19)),
governance_addr: Address::repeat_byte(0x13),
base_token_addr: Some(Address::repeat_byte(0x14)),
ecosystem_contracts: Some(EcosystemContracts::for_tests()),
Expand Down
6 changes: 5 additions & 1 deletion core/lib/config/src/configs/general.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::{
configs::{
base_token_adjuster::BaseTokenAdjusterConfig,
chain::{CircuitBreakerConfig, MempoolConfig, OperationsManagerConfig, StateKeeperConfig},
chain::{
CircuitBreakerConfig, MempoolConfig, OperationsManagerConfig, StateKeeperConfig,
TimestampAsserterConfig,
},
consensus::ConsensusConfig,
da_client::DAClientConfig,
da_dispatcher::DADispatcherConfig,
Expand Down Expand Up @@ -56,4 +59,5 @@ pub struct GeneralConfig {
pub external_proof_integration_api_config: Option<ExternalProofIntegrationApiConfig>,
pub experimental_vm_config: Option<ExperimentalVmConfig>,
pub prover_job_monitor_config: Option<ProverJobMonitorConfig>,
pub timestamp_asserter_config: Option<TimestampAsserterConfig>,
}
12 changes: 12 additions & 0 deletions core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use zksync_crypto_primitives::K256PrivateKey;
use crate::{
configs::{
self,
chain::TimestampAsserterConfig,
da_client::{
avail::{AvailClientConfig, AvailDefaultConfig},
DAClientConfig::Avail,
Expand Down Expand Up @@ -265,6 +266,7 @@ impl Distribution<configs::ContractsConfig> for EncodeDist {
l1_weth_bridge_proxy_addr: self.sample_opt(|| rng.gen()),
l2_weth_bridge_addr: self.sample_opt(|| rng.gen()),
l2_testnet_paymaster_addr: self.sample_opt(|| rng.gen()),
l2_timestamp_asserter_addr: self.sample_opt(|| rng.gen()),
l1_multicall3_addr: rng.gen(),
ecosystem_contracts: self.sample(rng),
base_token_addr: self.sample_opt(|| rng.gen()),
Expand Down Expand Up @@ -1180,6 +1182,16 @@ impl Distribution<configs::GeneralConfig> for EncodeDist {
external_proof_integration_api_config: self.sample(rng),
experimental_vm_config: self.sample(rng),
prover_job_monitor_config: self.sample(rng),
timestamp_asserter_config: self.sample(rng),
}
}
}

impl Distribution<TimestampAsserterConfig> for EncodeDist {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> TimestampAsserterConfig {
TimestampAsserterConfig {
min_range_sec: self.sample(rng),
min_time_till_end_sec: self.sample(rng),
}
}
}

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

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

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

Loading
Loading