Skip to content

Commit

Permalink
Rely on precalculated class hash for argent predeclaring; minor impro…
Browse files Browse the repository at this point in the history
…vements
  • Loading branch information
FabijanC committed Dec 6, 2024
1 parent e8859aa commit 92e5112
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
18 changes: 10 additions & 8 deletions crates/starknet-devnet-core/src/starknet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)?;
}
}

Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions crates/starknet-devnet/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion website/docs/predeployed.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Alternatively, provide a path to the [Sierra artifact](https://github.com/starkw
--account-class-custom <SIERRA_PATH>
```

## 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.

Expand Down

0 comments on commit 92e5112

Please sign in to comment.