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

fix(devnet): devnet predeployed contracts stable address across systems (re) #346

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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";
Loading