From 92e5112b1310573e282988158b981e82dfd27c7d Mon Sep 17 00:00:00 2001 From: FabijanC Date: Thu, 5 Dec 2024 16:34:48 +0100 Subject: [PATCH] Rely on precalculated class hash for argent predeclaring; minor improvements --- .../starknet-devnet-core/src/starknet/mod.rs | 18 ++++++++++-------- crates/starknet-devnet/src/cli.rs | 3 +-- website/docs/predeployed.md | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/crates/starknet-devnet-core/src/starknet/mod.rs b/crates/starknet-devnet-core/src/starknet/mod.rs index 2b1b95dcf..e5a8ee995 100644 --- a/crates/starknet-devnet-core/src/starknet/mod.rs +++ b/crates/starknet-devnet-core/src/starknet/mod.rs @@ -61,11 +61,11 @@ use self::transaction_trace::create_trace; use crate::account::Account; use crate::blocks::{StarknetBlock, StarknetBlocks}; use crate::constants::{ - ARGENT_CONTRACT_SIERRA, ARGENT_MULTISIG_CONTRACT_SIERRA, CHARGEABLE_ACCOUNT_ADDRESS, - CHARGEABLE_ACCOUNT_PRIVATE_KEY, DEVNET_DEFAULT_CHAIN_ID, DEVNET_DEFAULT_DATA_GAS_PRICE, - DEVNET_DEFAULT_GAS_PRICE, DEVNET_DEFAULT_STARTING_BLOCK_NUMBER, ETH_ERC20_CONTRACT_ADDRESS, - ETH_ERC20_NAME, ETH_ERC20_SYMBOL, STRK_ERC20_CONTRACT_ADDRESS, STRK_ERC20_NAME, - STRK_ERC20_SYMBOL, USE_KZG_DA, + ARGENT_CONTRACT_CLASS_HASH, ARGENT_CONTRACT_SIERRA, ARGENT_MULTISIG_CONTRACT_CLASS_HASH, + ARGENT_MULTISIG_CONTRACT_SIERRA, CHARGEABLE_ACCOUNT_ADDRESS, CHARGEABLE_ACCOUNT_PRIVATE_KEY, + DEVNET_DEFAULT_CHAIN_ID, DEVNET_DEFAULT_DATA_GAS_PRICE, DEVNET_DEFAULT_GAS_PRICE, + DEVNET_DEFAULT_STARTING_BLOCK_NUMBER, ETH_ERC20_CONTRACT_ADDRESS, ETH_ERC20_NAME, + ETH_ERC20_SYMBOL, STRK_ERC20_CONTRACT_ADDRESS, STRK_ERC20_NAME, STRK_ERC20_SYMBOL, USE_KZG_DA, }; use crate::contract_class_choice::AccountContractClassChoice; use crate::error::{DevnetResult, Error, TransactionValidationError}; @@ -167,10 +167,13 @@ impl Starknet { // predeclare argent account classes (not predeployable) if config.predeclare_argent { - for raw_sierra in [ARGENT_CONTRACT_SIERRA, ARGENT_MULTISIG_CONTRACT_SIERRA] { + for (class_hash, raw_sierra) in [ + (ARGENT_CONTRACT_CLASS_HASH, ARGENT_CONTRACT_SIERRA), + (ARGENT_MULTISIG_CONTRACT_CLASS_HASH, ARGENT_MULTISIG_CONTRACT_SIERRA), + ] { let contract_class = ContractClass::Cairo1(ContractClass::cairo_1_from_sierra_json_str(raw_sierra)?); - state.predeclare_contract_class(contract_class.generate_hash()?, contract_class)?; + state.predeclare_contract_class(class_hash, contract_class)?; } } @@ -1697,7 +1700,6 @@ mod tests { let config = StarknetConfig { predeclare_argent: true, ..Default::default() }; let starknet = Starknet::new(&config).unwrap(); for class_hash in [ARGENT_CONTRACT_CLASS_HASH, ARGENT_MULTISIG_CONTRACT_CLASS_HASH] { - // existence asserted by unwrapping let contract = starknet.get_class(&BlockId::Tag(BlockTag::Latest), class_hash).unwrap(); assert_eq!(contract.generate_hash().unwrap(), class_hash); } diff --git a/crates/starknet-devnet/src/cli.rs b/crates/starknet-devnet/src/cli.rs index da92cdd9f..88e4c83c2 100644 --- a/crates/starknet-devnet/src/cli.rs +++ b/crates/starknet-devnet/src/cli.rs @@ -57,8 +57,7 @@ pub(crate) struct Args { #[arg(long = "predeclare-argent")] #[arg(env = "PREDECLARE_ARGENT")] - #[arg(help = "If set, predeclares the latest Argent contract classes (regular and \ - multisig); increases startup time several times;")] + #[arg(help = "If set, predeclares the latest Argent contract classes (regular and multisig)")] predeclare_argent: bool, /// Initial balance of predeployed accounts diff --git a/website/docs/predeployed.md b/website/docs/predeployed.md index ff22927b8..c0920f878 100644 --- a/website/docs/predeployed.md +++ b/website/docs/predeployed.md @@ -29,7 +29,7 @@ Alternatively, provide a path to the [Sierra artifact](https://github.com/starkw --account-class-custom ``` -## Other predeclared account classes +## Predeclared account classes Both Cairo 0 and Cairo 1 versions of OpenZeppelin account are always predeclared, regardless of the chosen predeployment variant. If you specify the `--predeclare-argent` flag on startup, the latest regular and multistig variants of Argent accounts will also be predeclared.