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 1 commit
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
24 changes: 15 additions & 9 deletions core/bin/zksync_server/src/node_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,20 @@ 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 timestamp_asserter_params = match self.contracts_config.l2_timestamp_asserter_addr {
Some(address) => {
let timestamp_asserter_config =
try_load_config!(self.configs.timestamp_asserter_config);
Some(TimestampAsserterParams {
address,
min_time_till_end: Duration::from_secs(
timestamp_asserter_config.min_time_till_end_sec as u64,
ischasny marked this conversation as resolved.
Show resolved Hide resolved
),
})
}
None => None,
};
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 @@ -325,14 +338,7 @@ impl MainNodeBuilder {
.fee_account
.address(),
self.genesis_config.l2_chain_id,
self.contracts_config
.l2_timestamp_asserter_addr
.map(|address| TimestampAsserterParams {
address,
min_time_till_end: Duration::from_secs(
timestamp_asserter_config.min_time_till_end_sec as u64,
),
}),
timestamp_asserter_params,
),
postgres_storage_caches_config,
rpc_config.vm_concurrency_limit(),
Expand Down
17 changes: 9 additions & 8 deletions core/lib/dal/src/transactions_dal.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, fmt, time::Duration};
use std::{cmp::min, collections::HashMap, fmt, time::Duration};

use bigdecimal::BigDecimal;
use itertools::Itertools;
Expand Down Expand Up @@ -316,15 +316,16 @@ impl TransactionsDal<'_, '_> {
let nanosecs = ((tx.received_timestamp_ms % 1000) * 1_000_000) as u32;
#[allow(deprecated)]
let received_at = NaiveDateTime::from_timestamp_opt(secs, nanosecs).unwrap();
let max_timestamp = NaiveDateTime::MAX.and_utc().timestamp() as u64;
#[allow(deprecated)]
let timestamp_asserter_range_start = validation_traces
.timestamp_asserter_range
.clone()
.map(|x| NaiveDateTime::from_timestamp_opt(x.start as i64, 0).unwrap());
let timestamp_asserter_range_start =
validation_traces.timestamp_asserter_range.clone().map(|x| {
NaiveDateTime::from_timestamp_opt(min(x.start, max_timestamp) as i64, 0).unwrap()
});
#[allow(deprecated)]
let timestamp_asserter_range_end = validation_traces
.timestamp_asserter_range
.map(|x| NaiveDateTime::from_timestamp_opt(x.end as i64, 0).unwrap());
let timestamp_asserter_range_end = validation_traces.timestamp_asserter_range.map(|x| {
NaiveDateTime::from_timestamp_opt(min(x.end, max_timestamp) as i64, 0).unwrap()
});
// Besides just adding or updating(on conflict) the record, we want to extract some info
// from the query below, to indicate what actually happened:
// 1) transaction is added
Expand Down
27 changes: 22 additions & 5 deletions core/node/api_server/src/tx_sender/tests/send_tx.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! Tests for sending raw transactions.

use std::ops::Range;

use assert_matches::assert_matches;
use chrono::NaiveDateTime;
use test_casing::test_casing;
use zksync_multivm::interface::{tracer::ValidationTraces, ExecutionResult};
use zksync_node_fee_model::MockBatchFeeParamsProvider;
Expand Down Expand Up @@ -309,8 +312,7 @@ async fn sending_transaction_out_of_gas() {
assert_matches!(vm_result.result, ExecutionResult::Revert { .. });
}

#[tokio::test]
async fn submitting_tx_with_validation_traces() {
async fn submit_tx_with_validation_traces(actual_range: Range<u64>, expected_range: Range<i64>) {
// This test verifies that when a transaction produces ValidationTraces,
// range_start and range_end get persisted in the database
let pool = ConnectionPool::<Core>::constrained_test_pool(1).await;
Expand Down Expand Up @@ -344,7 +346,7 @@ async fn submitting_tx_with_validation_traces() {
tx_executor.set_tx_validation_traces_responses(move |tx, _| {
assert_eq!(tx.hash(), tx_hash);
ValidationTraces {
timestamp_asserter_range: Some(10..20),
timestamp_asserter_range: Some(actual_range.clone()),
}
});

Expand All @@ -363,19 +365,34 @@ async fn submitting_tx_with_validation_traces() {
.unwrap()
.expect("transaction is not persisted");
assert_eq!(
10,
expected_range.start,
storage_tx
.timestamp_asserter_range_start
.unwrap()
.and_utc()
.timestamp()
);
assert_eq!(
20,
expected_range.end,
storage_tx
.timestamp_asserter_range_end
.unwrap()
.and_utc()
.timestamp()
);
}

#[tokio::test]
async fn submitting_tx_with_validation_traces() {
// This test verifies that when a transaction produces ValidationTraces,
// range_start and range_end get persisted in the database
submit_tx_with_validation_traces(10..20, 10..20).await;
}

#[tokio::test]
async fn submitting_tx_with_validation_traces_resulting_into_overflow() {
// This test verifies that the timestamp in ValidationTraces is capped at
// the maximum value supported by the NaiveDateTime type
submit_tx_with_validation_traces(10..u64::MAX, 10..NaiveDateTime::MAX.and_utc().timestamp())
.await;
}
34 changes: 28 additions & 6 deletions core/tests/ts-integration/tests/custom-account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,41 @@ describe('Tests for the custom account behavior', () => {

const tx = await erc20.transfer.populateTransaction(alice.address, TRANSFER_AMOUNT);

await expect(
sendCustomAccountTransaction(
try {
await sendCustomAccountTransaction(
tx as zksync.types.Transaction,
alice.provider,
customAccountAddress,
testMaster.environment().l2ChainId,
undefined,
undefined,
false
)
).toBeRejected(
'failed to validate the transaction. reason: Validation revert: Account validation error: Timestamp is out of range'
);
);
expect(null).fail('The transaction was expected to fail');
} catch (e) {
const err = e as Error;
expect(err.message).toContain(
'failed to validate the transaction. reason: Validation revert: Account validation error'
);
const functionSelectorMatch = err.message.match(/function_selector\s=\s(0x[0-9a-fA-F]{8})/);
const calldataMatch = err.message.match(/data\s=\s(0x[0-9a-fA-F]+)/);
ischasny marked this conversation as resolved.
Show resolved Hide resolved

if (!functionSelectorMatch || !calldataMatch) {
expect(null).fail('Function selector or calldata not found in the error message');
ischasny marked this conversation as resolved.
Show resolved Hide resolved
}

const functionSelector = functionSelectorMatch![1];
const calldata = calldataMatch![1];

const startHex = calldata.slice(74, 138);
const endHex = calldata.slice(138);
const start = BigInt(`0x${startHex}`);
const end = BigInt(`0x${endHex}`);

expect(functionSelector).toBe('0x3d5740d9');
ischasny marked this conversation as resolved.
Show resolved Hide resolved
expect(start).toBe(BigInt(rangeStart));
expect(end).toBe(BigInt(rangeEnd));
}
});

test('Should fail the validation with incorrect signature', async () => {
Expand Down
Loading