Skip to content

Commit

Permalink
fix(devnet): devnet predeployed contracts stable address across syste…
Browse files Browse the repository at this point in the history
…ms (re) (#346)

Co-authored-by: antiyro <[email protected]>
  • Loading branch information
cchudant and antiyro authored Oct 15, 2024
1 parent a178d79 commit 57552e4
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next release

- fix(devnet): devnet predeployed contracts stable address across systems (re)
- chore: Fixed README table format
- fix(cli): fixed devnet cli arguments
- fix(db): max rocksdb LOG files count and size and add more memory metrics
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/client/devnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,5 @@ starknet_api.workspace = true
# Other
anyhow.workspace = true
log.workspace = true
rand = { workspace = true, features = ["small_rng"] }
serde_json.workspace = true
tokio.workspace = true
18 changes: 9 additions & 9 deletions crates/client/devnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use mp_convert::ToFelt;
use mp_state_update::{ContractStorageDiffItem, StateDiff, StorageEntry};
use starknet_api::{core::ContractAddress, state::StorageKey};
use starknet_signers::SigningKey;
use starknet_types_core::felt::Felt;
use starknet_types_core::{
felt::Felt,
hash::{Poseidon, StarkHash},
};
use std::{collections::HashMap, time::SystemTime};

mod balances;
Expand Down Expand Up @@ -99,20 +102,17 @@ impl ChainGenesisDescription {
get_storage_var_address("Account_public_key", &[])
}

pub fn from_seed(seed: u64) -> Felt {
use rand::{RngCore, SeedableRng};
// Use a fixed seed for deterministic RNG. Do not use StdRng but SmallRng so that it's stable across systems.
let mut rng = rand::rngs::SmallRng::seed_from_u64(seed);
let mut buffer = [0u8; 32];
rng.fill_bytes(&mut buffer);
// We may want to make this seed a cli argument in the future.
let seed = Felt::from_hex_unchecked("0x1278b36872363a1276387");

Felt::from_bytes_be_slice(&buffer)
fn rand_from_i(seed: Felt, i: u64) -> Felt {
Poseidon::hash(&seed, &(31 ^ !i).into())
}

Ok(DevnetKeys(
(0..n_addr)
.map(|addr_idx| {
let secret_scalar = from_seed(addr_idx);
let secret_scalar = rand_from_i(seed, addr_idx);
let key = SigningKey::from_secret_scalar(secret_scalar);
let pubkey = key.verifying_key();

Expand Down
4 changes: 2 additions & 2 deletions tests/js_tests/constant.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const RPC_URL = "http://127.0.0.1:9944";
export const SIGNER_PUBLIC =
"0x67e6d6a380e8b79aeb9d5164643174b3a9e4f381e5f28929441e17b81056f91";
"0x021ae26856dbb24032cac6bba14a776741331dc031f0dc43efb5f333e6a64da2";
export const SIGNER_PRIVATE =
"0x4189668c9e4825137bf31e02d7f6b70120e0d18a16ed9fa73632e8066975065";
"0x077e56c6dc32d40a67f6f7e6625c8dc5e570abe49c0a24e9202e4ae906abcc07";

0 comments on commit 57552e4

Please sign in to comment.