Skip to content

Commit

Permalink
fix: accounts + chain id (#1423)
Browse files Browse the repository at this point in the history
* add accounts + fix chain id

* fix mod

* fix mod

* remove safe unwrap comments
  • Loading branch information
greged93 authored Oct 3, 2024
1 parent 042525b commit 95c481b
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 103 deletions.
6 changes: 3 additions & 3 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml
version: 0.1
cli:
version: 1.22.5
version: 1.22.6
plugins:
sources:
- id: trunk
ref: v1.6.2
ref: v1.6.3
uri: https://github.com/trunk-io/plugins
runtimes:
enabled:
Expand Down Expand Up @@ -34,7 +34,7 @@ lint:
- git-diff-check
- [email protected]
- [email protected]
- osv-scanner@1.8.5
- osv-scanner@1.9.0
- [email protected]
- [email protected]
- [email protected]
Expand Down
2 changes: 1 addition & 1 deletion src/bin/hive_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async fn main() -> eyre::Result<()> {

// Set the chain id
let chain_id = starknet_provider.chain_id().await?;
let modulo = 1u64 << 53;
let modulo = (1u64 << 53) - 1;
let chain_id_mod: u64 = (Felt::from(modulo).to_bigint() & chain_id.to_bigint()).try_into()?;
let _ = CHAIN_ID.get_or_init(|| Felt::from(chain_id_mod));

Expand Down
8 changes: 4 additions & 4 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ where

/// Tries to start a [`EthClient`] by fetching the current chain id, initializing a [`EthDataProvider`] and a [`Pool`].
pub async fn try_new(starknet_provider: SP, pool_config: PoolConfig, database: Database) -> eyre::Result<Self> {
let chain = (starknet_provider.chain_id().await.map_err(KakarotError::from)?.to_bigint()
& Felt::from(u32::MAX).to_bigint())
.to_u64()
.unwrap();
// We take the chain id modulo 2**53 to keep compatibility with the tooling.
let modulo = (1u64 << 53) - 1;
let starknet_chain_id = starknet_provider.chain_id().await.map_err(KakarotError::from)?;
let chain = (starknet_chain_id.to_bigint() & Felt::from(modulo).to_bigint()).to_u64().unwrap();

// Create a new EthDataProvider instance with the initialized database and Starknet provider.
let eth_provider = EthDataProvider::try_new(database, StarknetProvider::new(starknet_provider)).await?;
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ async fn setup_hive(starknet_provider: &JsonRpcClient<HttpTransport>) -> Result<
use starknet::{accounts::ConnectedAccount, core::types::Felt, providers::Provider as _};

let chain_id = starknet_provider.chain_id().await?;
let modulo = 1u64 << 53;
let modulo = (1u64 << 53) - 1;
let chain_id: u64 = (Felt::from(modulo).to_bigint() & chain_id.to_bigint()).try_into()?;

CHAIN_ID.set(chain_id.into()).expect("Failed to set chain id");
Expand Down
1 change: 0 additions & 1 deletion src/models/felt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ impl From<Felt252Wrapper> for Felt {
#[allow(clippy::fallible_impl_from)]
impl From<Address> for Felt252Wrapper {
fn from(address: Address) -> Self {
// safe unwrap since H160 is 20 bytes
Self(Felt::from_bytes_be_slice(address.as_slice()))
}
}
Expand Down
32 changes: 32 additions & 0 deletions src/pool/sepolia_accounts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
"0xb89b13d4cd81e673590d5c5fe07b7a95c9bdae37e7da993bb55060c49dd21b",
"0x7e28affdd5dc3903fc11ddf667c313cad5f7593ec68c81c8936a8fc4cafce25",
"0xd740608de6e375938944c34aecb5d5f5469bbabe264cc28c672a946588adc5",
"0x7732f430974ab068c4989ebf4f4b8024b450a7663dba6064ef1f11f71ecbc60",
"0xc9b62b08a81e88fb7894967ce6c7257bec9c95faf308238f79fba669a3c913",
"0x1bb0355251fc030c90537908f5431d5dd77dd01d5ccdd6461b2e1bee759a632",
"0x2563a565f7b156c1ea814b8b6bc16a310c049c0fc5c1fd6c6edee2f4ec02d6a",
"0x19395269310dd7a2520d67fb7722796e03541eae8d83349b1361b30cecc775d",
"0x41b98540dfb3a3456abe2c0e6c206fb66d5c268fcf8b81cd5dc4d30abeef7d8",
"0x511d0f2ed36cbe939ae05f5dc9cc3141de7893723f5f152ae11917c6d3f7211",
"0x1b61866fe2e195aa10b859594066c9bbe39d43a3b90b65865f5cf666ee3ba79",
"0x6b94e632ae5ddbc6b54d58c72ce6339f2c6fed5a579243859ddc54f6dbeddf5",
"0xc0ae2d70922a941295d6a07fc1c6b84bcb063b83de2750f6abc9b024fe6b2c",
"0x75f628d8199c4e6f8b7cea4798241adbc14a291d4e0aa1b64302a7b78ed98fb",
"0xd77153735ed2fd33aa9e031df8fe416deb456e76585cee92e98f8fb1d7dbae",
"0x109d5fa7e4f228647c202e1922a81306b1c4efae0d7b2ded7c71521565f6af4",
"0x4f3f076a44f26dc0c8c1364652287f96ab45da2f9a93ccc54a0f2f64f1050f9",
"0x6cd3732a00849eaee57041aadac6d747a8823939da40870eeb0302b3f7affb8",
"0x394d012f18a366fa30ae21be6b2b1019d2c9e08b1fd9b469d5decddbd243109",
"0x22fb3426c949e74ea9eccc48932e6036454c369764e7a28df440c5c6eb47750",
"0x209d52fe2a4632ed2294f45faf94cb9a7ea16e950f1a38fe60294aa946eb745",
"0x1f8a93a3d83b99ec90b098eb93c9c90dafe57c0eb8dae4dab37beece56f078e",
"0x3c89ab21270f228f66aef83ab8ef74158a789dfef9ed9c08b6c1cfd23fda292",
"0x226a05817ddc19e329cdc64e047f0076a8d338bfe684f0883ba37f2aa171094",
"0x5e39291bc104f0cd82f66e368bdd972fd975eb154083458057c2f2738ad7521",
"0x17e012f88b87e6c44f6a93d755b93c5a5d5f082f9f97b100abf9f40452caa1a",
"0x79781f343ab264bbc26580694817cc117d628ddc262d85c5d1539a7cb793419",
"0x402f507f0d448d37728c6902b8efcd8edb3bda96d15fbd25215e58726836c9b",
"0x4cd4cf8ae23b251743c3ea56c6adcfd39ec4a066325bd28e73aa954786afc3f",
"0x64c147dbcc1fd952b7e5956136353f73a5dfc0ed29a0c343eabc7527462be90"
]
120 changes: 30 additions & 90 deletions src/pool/staging_accounts.json
Original file line number Diff line number Diff line change
@@ -1,92 +1,32 @@
[
{
"address": "0x6f644133991e779509cb319fd4c9416f949950f07a8bc3cb10916966ec1dca"
},
{
"address": "0xc6d61dd26ec6175554977f61198b28f58a7c5f46228b7fb7b44f6f619d800"
},
{
"address": "0x6faca0d5ce2437933257a91d95536c7cf3bfa12808f314741efd104e9a0c2d9"
},
{
"address": "0x2cced3d1628b867e1b69216df87d869e7f5c8dd066a9114d44e2d1af3fbf2c4"
},
{
"address": "0x30ee97c478d8a845d0d6ec0c447650ee6161817199f3d5c2a84f8a033b960b2"
},
{
"address": "0x13b09830d3bef686db99c570df79ddfd813502cfa1d7c640ed871a0de6637ba"
},
{
"address": "0x1e8f2ef3d53eb800432031fc3000b69b5132a2c4c0df821c20173ac8a91de6d"
},
{
"address": "0x2523ffb01dad3d8803a4bae7e2990d74d92b201f5425f921cec2ccb92ee6f18"
},
{
"address": "0xf6413b17b8ae645ce13e635df7dcb573086ff9558d8d9d7d2e343a250e4885"
},
{
"address": "0x765e5f1ae2f6d796f359ea7c47c88387046d371aef1f02337921fe326fbacc2"
},
{
"address": "0x21466caac9f9e2605100c76a0ab15e2cbc72942b876f4665fa490dd83f7a00f"
},
{
"address": "0x28d165b48e0b523044bd790bae4cc7096d8747565b1d58691683662e12b6402"
},
{
"address": "0x7297a3b129e3d3101bb9956338c9c64b7055556146c7ff2497caad4a831c11d"
},
{
"address": "0x8d9da3628af39d3bb9a2155b4eb63af7791da1fd3864f93bb57130fa2b59d2"
},
{
"address": "0x4dc2ebca0fa6de9e7f67e821e425a0f9a53cb300cc44cbd93d69c307ac536eb"
},
{
"address": "0x6ea69b53281261da1cfde205a5e8c02db26bfa51df77419fef71014c53e03f1"
},
{
"address": "0x3709159b0a92aefacba33401098c5b3c09240b67dd5c1d5ee9a778e6205028b"
},
{
"address": "0x3ea725fcff7ddaffbdc1134be5ae164bcbf8155135de1d8663c5efb106c9b08"
},
{
"address": "0x3135b4bb94b1b7c0d7a7074291d0f1d92ab57d1f61bddd0b7195f70207752ae"
},
{
"address": "0x1eb1e028ffa31652cecb7d18311aac1a281610a535f20e7a3a82c13db226b0c"
},
{
"address": "0x4f57bf04228bf2d2db2e0a8573c6594558a5f0b487c1229b5fe7723473afa58"
},
{
"address": "0x2f24013ebb0911d5f27a2a2c3d07b8c73b2f36239d8325187ed25db1ce794b5"
},
{
"address": "0x10e3a8574c22d19951d8e8715cc98a26b9ed9fe39f8e002cc82f49c189ea56c"
},
{
"address": "0x6f823719688a9c3e54f7528d4e2a464773170365c2e8b97d699aa2cc519875e"
},
{
"address": "0x669774f839f462c3267b1d28e9c31264e1436a48033ee0f71e77bef153cfb81"
},
{
"address": "0x6ad46e2c0b5f52412560bb12ad77e2958d53e5f30fc5bc995101dd700e22597"
},
{
"address": "0xe07332a9bf6f9d3ced6f3f1cb60607d01fba1f6be9da1b3650c58c8d683e06"
},
{
"address": "0x3c320f3726b90a8e21d200eeb956f863c59c9d3744e5f5d9280c648225c7775"
},
{
"address": "0xdc68dd15efb6b43a02a8679e4a21a9b8195cd44e6134d5034131520c55dbfa"
},
{
"address": "0x594aa6e8d8d5ea9ea4a86681222f65975ed38c4e0f20e8493c0ad9887b3c3f4"
}
"0x6f644133991e779509cb319fd4c9416f949950f07a8bc3cb10916966ec1dca",
"0xc6d61dd26ec6175554977f61198b28f58a7c5f46228b7fb7b44f6f619d800",
"0x6faca0d5ce2437933257a91d95536c7cf3bfa12808f314741efd104e9a0c2d9",
"0x2cced3d1628b867e1b69216df87d869e7f5c8dd066a9114d44e2d1af3fbf2c4",
"0x30ee97c478d8a845d0d6ec0c447650ee6161817199f3d5c2a84f8a033b960b2",
"0x13b09830d3bef686db99c570df79ddfd813502cfa1d7c640ed871a0de6637ba",
"0x1e8f2ef3d53eb800432031fc3000b69b5132a2c4c0df821c20173ac8a91de6d",
"0x2523ffb01dad3d8803a4bae7e2990d74d92b201f5425f921cec2ccb92ee6f18",
"0xf6413b17b8ae645ce13e635df7dcb573086ff9558d8d9d7d2e343a250e4885",
"0x765e5f1ae2f6d796f359ea7c47c88387046d371aef1f02337921fe326fbacc2",
"0x21466caac9f9e2605100c76a0ab15e2cbc72942b876f4665fa490dd83f7a00f",
"0x28d165b48e0b523044bd790bae4cc7096d8747565b1d58691683662e12b6402",
"0x7297a3b129e3d3101bb9956338c9c64b7055556146c7ff2497caad4a831c11d",
"0x8d9da3628af39d3bb9a2155b4eb63af7791da1fd3864f93bb57130fa2b59d2",
"0x4dc2ebca0fa6de9e7f67e821e425a0f9a53cb300cc44cbd93d69c307ac536eb",
"0x6ea69b53281261da1cfde205a5e8c02db26bfa51df77419fef71014c53e03f1",
"0x3709159b0a92aefacba33401098c5b3c09240b67dd5c1d5ee9a778e6205028b",
"0x3ea725fcff7ddaffbdc1134be5ae164bcbf8155135de1d8663c5efb106c9b08",
"0x3135b4bb94b1b7c0d7a7074291d0f1d92ab57d1f61bddd0b7195f70207752ae",
"0x1eb1e028ffa31652cecb7d18311aac1a281610a535f20e7a3a82c13db226b0c",
"0x4f57bf04228bf2d2db2e0a8573c6594558a5f0b487c1229b5fe7723473afa58",
"0x2f24013ebb0911d5f27a2a2c3d07b8c73b2f36239d8325187ed25db1ce794b5",
"0x10e3a8574c22d19951d8e8715cc98a26b9ed9fe39f8e002cc82f49c189ea56c",
"0x6f823719688a9c3e54f7528d4e2a464773170365c2e8b97d699aa2cc519875e",
"0x669774f839f462c3267b1d28e9c31264e1436a48033ee0f71e77bef153cfb81",
"0x6ad46e2c0b5f52412560bb12ad77e2958d53e5f30fc5bc995101dd700e22597",
"0xe07332a9bf6f9d3ced6f3f1cb60607d01fba1f6be9da1b3650c58c8d683e06",
"0x3c320f3726b90a8e21d200eeb956f863c59c9d3744e5f5d9280c648225c7775",
"0xdc68dd15efb6b43a02a8679e4a21a9b8195cd44e6134d5034131520c55dbfa",
"0x594aa6e8d8d5ea9ea4a86681222f65975ed38c4e0f20e8493c0ad9887b3c3f4"
]
5 changes: 3 additions & 2 deletions src/providers/eth_provider/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ where
SP: starknet::providers::Provider + Send + Sync,
{
pub async fn try_new(database: Database, starknet_provider: StarknetProvider<SP>) -> Result<Self> {
// We take the chain_id modulo u32::MAX to ensure compatibility with tooling
// We take the chain_id modulo 2**53 to ensure compatibility with tooling
// see: https://github.com/ethereum/EIPs/issues/2294
// Note: Metamask is breaking for a chain_id = u64::MAX - 1
let modulo = (1u64 << 53) - 1;
let chain_id =
(Felt::from(u32::MAX).to_biguint() & starknet_provider.chain_id().await?.to_biguint()).try_into().unwrap(); // safe unwrap
(Felt::from(modulo).to_biguint() & starknet_provider.chain_id().await?.to_biguint()).try_into()?;

Ok(Self { database, starknet_provider, chain_id })
}
Expand Down
2 changes: 1 addition & 1 deletion src/test_utils/eoa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl<P: Provider + Send + Sync + Clone> KakarotEOA<P> {
return Err(eyre::eyre!("Failed to deploy contract"));
};

let selector = get_selector_from_name("evm_contract_deployed").unwrap(); // safe unwrap
let selector = get_selector_from_name("evm_contract_deployed")?;

let event = receipt
.events
Expand Down

0 comments on commit 95c481b

Please sign in to comment.