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

Passkey miscellaneous checks part 1 #2060

Merged
merged 57 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
9628adb
check account signature on passkey
saraswatpuneet Jun 18, 2024
521919e
reference
saraswatpuneet Jun 18, 2024
5e035f6
setup mock and account types
saraswatpuneet Jun 18, 2024
2a5edbb
set unused flag for now
saraswatpuneet Jun 18, 2024
079f764
fix build
saraswatpuneet Jun 18, 2024
e387a2d
address feedback
saraswatpuneet Jun 20, 2024
7195c75
set correct AccountId in mock
saraswatpuneet Jun 20, 2024
b0f4699
set spec version in future
saraswatpuneet Jun 20, 2024
913b619
update spec version
saraswatpuneet Jun 20, 2024
3535034
sync with types PR
saraswatpuneet Jun 21, 2024
2fbec5a
cleanup
saraswatpuneet Jun 21, 2024
e6ceee2
set pallet balances as dependency
saraswatpuneet Jun 22, 2024
3730996
refactor common types from payment
saraswatpuneet Jun 24, 2024
a395a83
withdraw tx fee
saraswatpuneet Jun 24, 2024
a3454dc
lint
saraswatpuneet Jun 24, 2024
b69ca9b
Merge branch 'main' into passkey_tx_charge
saraswatpuneet Jun 24, 2024
04eeb69
Merge branch 'main' into passkey_tx_charge
saraswatpuneet Jun 25, 2024
4acf6bf
set functions to charge tx fees
saraswatpuneet Jun 26, 2024
d952208
add negative test without funds fails
saraswatpuneet Jun 26, 2024
04329f1
charge tx and add tests
saraswatpuneet Jun 26, 2024
339642a
cleanup
saraswatpuneet Jun 26, 2024
c130441
Merge branch 'main' into passkey_tx_charge
saraswatpuneet Jun 26, 2024
40eed8b
cleanup
saraswatpuneet Jun 26, 2024
88ae756
charge fee post validation
saraswatpuneet Jun 26, 2024
ab7488a
add more tests
saraswatpuneet Jun 26, 2024
5b91e44
improve logic
saraswatpuneet Jun 27, 2024
df1de03
docs
saraswatpuneet Jun 27, 2024
d3fbc5e
Merge branch 'main' into passkey_tx_charge
saraswatpuneet Jun 28, 2024
c4445c0
Merge branch 'main' into passkey_tx_charge
saraswatpuneet Jun 28, 2024
c4a8da3
improve pattern inline with signed ext
saraswatpuneet Jun 28, 2024
9a0e534
fix tests
saraswatpuneet Jun 28, 2024
066428f
address feedback, undo refactor
saraswatpuneet Jun 28, 2024
5cf9ae9
cleanup
saraswatpuneet Jun 28, 2024
44f191f
Merge branch 'main' into passkey_tx_charge
saraswatpuneet Jun 28, 2024
6859481
fund accounts for benchamrking, add helper
saraswatpuneet Jul 1, 2024
d20d2ff
add more tests
saraswatpuneet Jul 1, 2024
42fcca4
add test suggested by aramik
saraswatpuneet Jul 1, 2024
e2378f9
add condition
saraswatpuneet Jul 1, 2024
32ba98e
use fungible trait/remove Curreny trait
saraswatpuneet Jul 1, 2024
6df024b
fix redundant calls and fix order of calls
saraswatpuneet Jul 1, 2024
a3874b4
fix
saraswatpuneet Jul 1, 2024
45aef19
combine tx validaity
saraswatpuneet Jul 1, 2024
36bc6db
cleanups
saraswatpuneet Jul 1, 2024
fb7b463
fix build
saraswatpuneet Jul 1, 2024
d0d9598
address feedback: check for error type
saraswatpuneet Jul 2, 2024
9669093
update spec version
saraswatpuneet Jul 2, 2024
6f88951
Merge branch 'main' into passkey_tx_charge
saraswatpuneet Jul 2, 2024
cc30f5c
call internal methods
saraswatpuneet Jul 2, 2024
7503e51
Merge branch 'main' into pass_tx_2051
saraswatpuneet Jul 2, 2024
55eef9a
update benchmarks
saraswatpuneet Jul 3, 2024
9461d8f
Merge branch 'main' into pass_tx_2051
saraswatpuneet Jul 3, 2024
89172b5
update spec version
saraswatpuneet Jul 6, 2024
f63e93d
Merge branch 'main' into passkey_miscellaneous_1
saraswatpuneet Jul 8, 2024
88642b3
address feedback
saraswatpuneet Jul 8, 2024
daa345c
address feedback
saraswatpuneet Jul 8, 2024
5c01c1c
update spec version
saraswatpuneet Jul 9, 2024
6c18eef
Merge branch 'main' into passkey_miscellaneous_1
saraswatpuneet Jul 10, 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
78 changes: 75 additions & 3 deletions pallets/passkey/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use frame_support::{
use frame_system::pallet_prelude::*;
use pallet_transaction_payment::OnChargeTransaction;
use sp_runtime::{
generic::Era,
traits::{Convert, Dispatchable, SignedExtension, Verify, Zero},
transaction_validity::{TransactionValidity, TransactionValidityError},
AccountId32, MultiSignature,
Expand Down Expand Up @@ -71,7 +72,9 @@ pub mod module {
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(0);

#[pallet::config]
pub trait Config: frame_system::Config + pallet_transaction_payment::Config {
pub trait Config:
frame_system::Config + pallet_transaction_payment::Config + Send + Sync
{
/// The overarching event type.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;

Expand Down Expand Up @@ -158,6 +161,10 @@ pub mod module {
let valid_tx = ValidTransaction::default();
let payload = Self::filter_valid_calls(&call)?;

let frame_system_checks =
FrameSystemChecks(payload.passkey_call.account_id.clone(), call.clone());
let frame_system_validity = frame_system_checks.validate()?;

let signatures_check = PasskeySignatureCheck::new(payload.clone());
let signature_validity = signatures_check.validate()?;

Expand All @@ -171,6 +178,7 @@ pub mod module {
let tx_payment_validity = tx_charge.validate()?;

let valid_tx = valid_tx
.combine_with(frame_system_validity)
.combine_with(signature_validity)
.combine_with(nonce_validity)
.combine_with(tx_payment_validity);
Expand All @@ -180,6 +188,10 @@ pub mod module {
fn pre_dispatch(call: &Self::Call) -> Result<(), TransactionValidityError> {
let payload = Self::filter_valid_calls(&call)?;

let frame_system_checks =
FrameSystemChecks(payload.passkey_call.account_id.clone(), call.clone());
frame_system_checks.pre_dispatch()?;

let signatures_check = PasskeySignatureCheck::new(payload.clone());
signatures_check.pre_dispatch()?;

Expand Down Expand Up @@ -325,7 +337,7 @@ where
/// Validates the transaction fee paid with tokens.
pub fn pre_dispatch(&self) -> Result<(), TransactionValidityError> {
let info = &self.1.get_dispatch_info();
let len = self.0.using_encoded(|c| c.len());
let len = self.1.using_encoded(|c| c.len());
let runtime_call: <T as frame_system::Config>::RuntimeCall =
<T as frame_system::Config>::RuntimeCall::from(self.1.clone());
let who = self.0.clone();
Expand All @@ -337,7 +349,7 @@ where
/// Validates the transaction fee paid with tokens.
pub fn validate(&self) -> TransactionValidity {
let info = &self.1.get_dispatch_info();
let len = self.0.using_encoded(|c| c.len());
let len = self.1.using_encoded(|c| c.len());
let runtime_call: <T as frame_system::Config>::RuntimeCall =
<T as frame_system::Config>::RuntimeCall::from(self.1.clone());
let who = self.0.clone();
Expand All @@ -350,3 +362,63 @@ where
)
}
}

/// Frame system related checks
#[derive(Encode, Decode, Clone, TypeInfo)]
#[scale_info(skip_type_params(T))]
pub struct FrameSystemChecks<T: Config + Send + Sync>(pub T::AccountId, pub Call<T>);

impl<T: Config + Send + Sync> FrameSystemChecks<T>
where
<T as frame_system::Config>::RuntimeCall:
From<Call<T>> + Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>,
{
/// Validates the transaction fee paid with tokens.
pub fn pre_dispatch(&self) -> Result<(), TransactionValidityError> {
let info = &self.1.get_dispatch_info();
let len = self.1.using_encoded(|c| c.len());
let runtime_call: <T as frame_system::Config>::RuntimeCall =
<T as frame_system::Config>::RuntimeCall::from(self.1.clone());
let who = self.0.clone();

let non_zero_sender_check = frame_system::CheckNonZeroSender::<T>::new();
let spec_version_check = frame_system::CheckSpecVersion::<T>::new();
let tx_version_check = frame_system::CheckTxVersion::<T>::new();
let genesis_hash_check = frame_system::CheckGenesis::<T>::new();
let era_check = frame_system::CheckEra::<T>::from(Era::immortal());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Order of check is kept same as in SignedExtras


non_zero_sender_check.pre_dispatch(&who, &runtime_call, info, len)?;
spec_version_check.pre_dispatch(&who, &runtime_call, info, len)?;
tx_version_check.pre_dispatch(&who, &runtime_call, info, len)?;
genesis_hash_check.pre_dispatch(&who, &runtime_call, info, len)?;
era_check.pre_dispatch(&who, &runtime_call, info, len)
saraswatpuneet marked this conversation as resolved.
Show resolved Hide resolved
}

/// Validates the transaction fee paid with tokens.
pub fn validate(&self) -> TransactionValidity {
let info = &self.1.get_dispatch_info();
let len = self.1.using_encoded(|c| c.len());
let runtime_call: <T as frame_system::Config>::RuntimeCall =
<T as frame_system::Config>::RuntimeCall::from(self.1.clone());
let who = self.0.clone();

let non_zero_sender_check = frame_system::CheckNonZeroSender::<T>::new();
let spec_version_check = frame_system::CheckSpecVersion::<T>::new();
let tx_version_check = frame_system::CheckTxVersion::<T>::new();
let genesis_hash_check = frame_system::CheckGenesis::<T>::new();
let era_check = frame_system::CheckEra::<T>::from(Era::immortal());

let non_zero_sender_validity =
non_zero_sender_check.validate(&who, &runtime_call, info, len)?;
let spec_version_validity = spec_version_check.validate(&who, &runtime_call, info, len)?;
let tx_version_validity = tx_version_check.validate(&who, &runtime_call, info, len)?;
let genesis_hash_validity = genesis_hash_check.validate(&who, &runtime_call, info, len)?;
let era_validity = era_check.validate(&who, &runtime_call, info, len)?;

Ok(non_zero_sender_validity
.combine_with(spec_version_validity)
.combine_with(tx_version_validity)
.combine_with(genesis_hash_validity)
.combine_with(era_validity))
}
}
4 changes: 2 additions & 2 deletions runtime/frequency/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("frequency"),
impl_name: create_runtime_str!("frequency"),
authoring_version: 1,
spec_version: 91,
spec_version: 92,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand All @@ -371,7 +371,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("frequency-testnet"),
impl_name: create_runtime_str!("frequency"),
authoring_version: 1,
spec_version: 91,
spec_version: 92,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down