From 271287e6e4d429fbbc40a61d45ad9d334699776f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Delabrouille?= <34384633+tdelabro@users.noreply.github.com> Date: Thu, 6 Jun 2024 11:18:36 +0200 Subject: [PATCH] fix: remove unecessary checks before tx execution (#1627) --- CHANGELOG.md | 1 + crates/pallets/starknet/src/lib.rs | 25 ------------------- .../pallets/starknet/src/tests/declare_tx.rs | 4 +-- .../starknet/src/tests/deploy_account_tx.rs | 2 +- .../pallets/starknet/src/tests/invoke_tx.rs | 2 +- 5 files changed, 5 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 194890f5d4..22f97f514b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Next release +- feat(runtime): remove custom checks before tx execution - test: Adding txv3 tests - feat: L1 gas price/fix diff --git a/crates/pallets/starknet/src/lib.rs b/crates/pallets/starknet/src/lib.rs index 306723fc8a..615603e01a 100644 --- a/crates/pallets/starknet/src/lib.rs +++ b/crates/pallets/starknet/src/lib.rs @@ -509,14 +509,6 @@ pub mod pallet { // This ensures that the function can only be called via unsigned transaction. ensure_none(origin)?; - let sender_address = match &transaction.tx { - starknet_api::transaction::InvokeTransaction::V0(tx) => tx.contract_address, - starknet_api::transaction::InvokeTransaction::V1(tx) => tx.sender_address, - starknet_api::transaction::InvokeTransaction::V3(tx) => tx.sender_address, - }; - // Check if contract is deployed - ensure!(ContractClassHashes::::contains_key(sender_address), Error::::AccountNotDeployed); - // Init caches let mut state = BlockifierStateAdapter::::default(); let block_context = Self::get_block_context(); @@ -576,17 +568,6 @@ pub mod pallet { // This ensures that the function can only be called via unsigned transaction. ensure_none(origin)?; - // Check class hash is not already declared - ensure!( - !ContractClasses::::contains_key(transaction.tx().class_hash().0), - Error::::ClassHashAlreadyDeclared - ); - // Check if contract is deployed - ensure!( - ContractClassHashes::::contains_key(transaction.tx().sender_address()), - Error::::AccountNotDeployed - ); - let mut state = BlockifierStateAdapter::::default(); let charge_fee = !::DisableTransactionFee::get(); @@ -633,12 +614,6 @@ pub mod pallet { // This ensures that the function can only be called via unsigned transaction. ensure_none(origin)?; - // Check if contract is deployed - ensure!( - !ContractClassHashes::::contains_key(transaction.contract_address), - Error::::AccountAlreadyDeployed - ); - let mut state = BlockifierStateAdapter::::default(); let charge_fee = !::DisableTransactionFee::get(); diff --git a/crates/pallets/starknet/src/tests/declare_tx.rs b/crates/pallets/starknet/src/tests/declare_tx.rs index 538868b00b..7a23c69cb1 100644 --- a/crates/pallets/starknet/src/tests/declare_tx.rs +++ b/crates/pallets/starknet/src/tests/declare_tx.rs @@ -146,7 +146,7 @@ fn given_contract_declare_tx_works_once_not_twice() { assert_eq!(Starknet::contract_class_by_class_hash(class_hash.0).unwrap(), contract_class); // TODO: Uncomment once we have ABI support // assert_eq!(Starknet::contract_class_by_class_hash(erc20_class_hash), erc20_class); - assert_err!(Starknet::declare(none_origin, transaction), Error::::ClassHashAlreadyDeclared); + assert_err!(Starknet::declare(none_origin, transaction), Error::::TransactionExecutionFailed); }); } @@ -170,7 +170,7 @@ fn given_contract_declare_tx_fails_sender_not_deployed() { None, None, ); - assert_err!(Starknet::declare(none_origin, transaction), Error::::AccountNotDeployed); + assert_err!(Starknet::declare(none_origin, transaction), Error::::TransactionExecutionFailed); }) } diff --git a/crates/pallets/starknet/src/tests/deploy_account_tx.rs b/crates/pallets/starknet/src/tests/deploy_account_tx.rs index 3d00ef498a..c06b910ab1 100644 --- a/crates/pallets/starknet/src/tests/deploy_account_tx.rs +++ b/crates/pallets/starknet/src/tests/deploy_account_tx.rs @@ -159,7 +159,7 @@ fn given_contract_run_deploy_account_tx_twice_fails() { assert_eq!(Starknet::contract_class_hash_by_address(deploy_tx.contract_address), account_class_hash.0); assert_err!( Starknet::deploy_account(RuntimeOrigin::none(), deploy_tx), - Error::::AccountAlreadyDeployed + Error::::TransactionExecutionFailed ); }); } diff --git a/crates/pallets/starknet/src/tests/invoke_tx.rs b/crates/pallets/starknet/src/tests/invoke_tx.rs index 0e0a370e1e..e1140e7a58 100644 --- a/crates/pallets/starknet/src/tests/invoke_tx.rs +++ b/crates/pallets/starknet/src/tests/invoke_tx.rs @@ -59,7 +59,7 @@ fn given_hardcoded_contract_run_invoke_tx_fails_sender_not_deployed() { tx.sender_address = contract_address; }; - assert_err!(Starknet::invoke(none_origin, transaction), Error::::AccountNotDeployed); + assert_err!(Starknet::invoke(none_origin, transaction), Error::::TransactionExecutionFailed); }) }