From 092ccd491369e16095f0bf1c85df4a89e4048a90 Mon Sep 17 00:00:00 2001 From: cchudant Date: Tue, 15 Oct 2024 16:04:03 +0000 Subject: [PATCH 1/2] fix(devnet): devnet predeployed contracts stable address across systems (re) --- CHANGELOG.md | 1 + Cargo.lock | 1 - crates/client/devnet/Cargo.toml | 1 - crates/client/devnet/src/lib.rs | 18 +++++++++--------- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7da63016e..3d4f05c69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Next release +- fix(devnet): devnet predeployed contracts stable address across systems (re) - fix(cli): fixed devnet cli arguments - fix(db): max rocksdb LOG files count and size and add more memory metrics - fix(devnet): devnet predeployed contracts stable address across systems diff --git a/Cargo.lock b/Cargo.lock index b98c08ac6..d4ea1b25b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5287,7 +5287,6 @@ dependencies = [ "mp-transactions", "proptest", "proptest-derive", - "rand", "rstest 0.18.2", "serde_json", "starknet-core 0.11.0", diff --git a/crates/client/devnet/Cargo.toml b/crates/client/devnet/Cargo.toml index 6b5085a7a..373dd3814 100644 --- a/crates/client/devnet/Cargo.toml +++ b/crates/client/devnet/Cargo.toml @@ -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 diff --git a/crates/client/devnet/src/lib.rs b/crates/client/devnet/src/lib.rs index 8fd8cbc11..d7d212059 100644 --- a/crates/client/devnet/src/lib.rs +++ b/crates/client/devnet/src/lib.rs @@ -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; @@ -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(); From f3a17c654f6eb6aa39cb399eec4a6bfaac09c43c Mon Sep 17 00:00:00 2001 From: cchudant Date: Tue, 15 Oct 2024 16:14:59 +0000 Subject: [PATCH 2/2] fix(js-tests): devnet predeployed contract address --- tests/js_tests/constant.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/js_tests/constant.ts b/tests/js_tests/constant.ts index a51684dc6..38587b651 100644 --- a/tests/js_tests/constant.ts +++ b/tests/js_tests/constant.ts @@ -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";