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: keyed nonces [WIP] #3646

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion core/bin/system-constants-generator/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub(super) fn get_l2_tx(
L2Tx::new_signed(
Some(contract_address),
vec![],
Nonce(0),
Nonce(0.into()),
Fee {
gas_limit: U256::from(10000000u32),
max_fee_per_gas: U256::from(BIG_BASE_FEE),
Expand Down
52 changes: 49 additions & 3 deletions core/lib/basic_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,52 @@ impl From<u32> for L2ChainId {
}
}

#[derive(
Default, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
)]
pub struct Nonce(pub U256);

#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct NonceKey(pub U256);

impl Nonce {
pub fn split(self) -> (NonceKey, NonceValue) {
(self.key(), self.value())
}

pub fn combine(key: NonceKey, value: NonceValue) -> Self {
Self(key.0 << 64 | U256::from(value.0))
}

pub fn value(self) -> NonceValue {
NonceValue(self.0.low_u64())
}

pub fn key(self) -> NonceKey {
NonceKey(self.0 >> 64)
}
}

impl<T: Into<U256>> Add<T> for Nonce {
type Output = Self;

fn add(self, other: T) -> Self {
Self(self.0 + other.into())
}
}

impl<T: Into<U256>> std::ops::AddAssign<T> for Nonce {
fn add_assign(&mut self, other: T) {
self.0 += other.into();
}
}

impl<T: Into<U256>> From<T> for Nonce {
fn from(value: T) -> Self {
Self(value.into())
}
}

basic_type!(
/// ZKsync network block sequential index.
L2BlockNumber,
Expand All @@ -235,9 +281,9 @@ basic_type!(
);

basic_type!(
/// ZKsync account nonce.
Nonce,
u32
/// ZKsync nonce value (lower 64 bits)
NonceValue,
u64
);

basic_type!(
Expand Down

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.

This file was deleted.

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