From fb190abb9e80e0c12abb7a8a37407491b0c7c8b4 Mon Sep 17 00:00:00 2001 From: Jonathan LEI Date: Mon, 26 Feb 2024 07:25:18 +0000 Subject: [PATCH] chore: undo import and iter changes --- starknet-accounts/src/account/declaration.rs | 1 + starknet-accounts/src/account/execution.rs | 1 + starknet-accounts/src/account/mod.rs | 1 + starknet-accounts/src/factory/argent.rs | 1 + starknet-accounts/src/factory/mod.rs | 1 + .../src/factory/open_zeppelin.rs | 1 + starknet-accounts/src/single_owner.rs | 1 + starknet-core/src/crypto.rs | 2 +- starknet-core/src/serde/byte_array.rs | 1 + starknet-core/src/serde/num_hex.rs | 1 + .../src/serde/unsigned_field_element.rs | 4 +- starknet-core/src/types/codegen.rs | 8 ++-- starknet-core/src/types/eth_address.rs | 1 + starknet-core/src/types/execution_result.rs | 4 +- starknet-core/src/types/hash_256.rs | 1 + starknet-core/src/types/mod.rs | 4 +- starknet-core/src/types/msg.rs | 4 +- starknet-core/src/types/serde_impls.rs | 4 +- starknet-core/src/utils.rs | 4 +- starknet-crypto-codegen/src/pedersen.rs | 3 +- starknet-crypto-codegen/src/poseidon/mod.rs | 3 +- starknet-crypto/src/ecdsa.rs | 9 ++-- starknet-crypto/src/fe_utils.rs | 4 +- starknet-crypto/src/pedersen_hash.rs | 3 +- starknet-crypto/src/rfc6979.rs | 3 +- starknet-crypto/src/test_utils.rs | 1 + starknet-curve/src/curve_params.rs | 3 +- starknet-curve/src/ec_point.rs | 42 ++++++++++--------- starknet-ff/src/lib.rs | 10 +++-- starknet-providers/src/any.rs | 9 ++-- starknet-providers/src/jsonrpc/mod.rs | 3 +- starknet-providers/src/sequencer/mod.rs | 1 + starknet-providers/src/sequencer/provider.rs | 18 ++++---- starknet-signers/src/local_wallet.rs | 1 + starknet-signers/src/signer.rs | 1 + 35 files changed, 104 insertions(+), 55 deletions(-) diff --git a/starknet-accounts/src/account/declaration.rs b/starknet-accounts/src/account/declaration.rs index 926b9d83..ebd19820 100644 --- a/starknet-accounts/src/account/declaration.rs +++ b/starknet-accounts/src/account/declaration.rs @@ -3,6 +3,7 @@ use super::{ LegacyDeclaration, PreparedDeclaration, PreparedLegacyDeclaration, RawDeclaration, RawLegacyDeclaration, }; + use starknet_core::{ crypto::compute_hash_on_elements, types::{ diff --git a/starknet-accounts/src/account/execution.rs b/starknet-accounts/src/account/execution.rs index 4f61df9e..6c36700f 100644 --- a/starknet-accounts/src/account/execution.rs +++ b/starknet-accounts/src/account/execution.rs @@ -3,6 +3,7 @@ use super::{ RawExecution, }; use crate::{Call, ExecutionEncoder}; + use starknet_core::{ crypto::compute_hash_on_elements, types::{ diff --git a/starknet-accounts/src/account/mod.rs b/starknet-accounts/src/account/mod.rs index 18dffb82..3ac2b8a6 100644 --- a/starknet-accounts/src/account/mod.rs +++ b/starknet-accounts/src/account/mod.rs @@ -1,4 +1,5 @@ use crate::Call; + use async_trait::async_trait; use auto_impl::auto_impl; use starknet_core::types::{ diff --git a/starknet-accounts/src/factory/argent.rs b/starknet-accounts/src/factory/argent.rs index 04a31b0e..44cc142d 100644 --- a/starknet-accounts/src/factory/argent.rs +++ b/starknet-accounts/src/factory/argent.rs @@ -1,4 +1,5 @@ use crate::{AccountFactory, PreparedAccountDeployment, RawAccountDeployment}; + use async_trait::async_trait; use starknet_core::types::{BlockId, BlockTag, FieldElement}; use starknet_providers::Provider; diff --git a/starknet-accounts/src/factory/mod.rs b/starknet-accounts/src/factory/mod.rs index 32811ee7..cfe2398f 100644 --- a/starknet-accounts/src/factory/mod.rs +++ b/starknet-accounts/src/factory/mod.rs @@ -1,4 +1,5 @@ use super::NotPreparedError; + use async_trait::async_trait; use starknet_core::{ crypto::compute_hash_on_elements, diff --git a/starknet-accounts/src/factory/open_zeppelin.rs b/starknet-accounts/src/factory/open_zeppelin.rs index 56884e21..bb1b81b8 100644 --- a/starknet-accounts/src/factory/open_zeppelin.rs +++ b/starknet-accounts/src/factory/open_zeppelin.rs @@ -1,4 +1,5 @@ use crate::{AccountFactory, PreparedAccountDeployment, RawAccountDeployment}; + use async_trait::async_trait; use starknet_core::types::{BlockId, BlockTag, FieldElement}; use starknet_providers::Provider; diff --git a/starknet-accounts/src/single_owner.rs b/starknet-accounts/src/single_owner.rs index b84982c5..a2040f9a 100644 --- a/starknet-accounts/src/single_owner.rs +++ b/starknet-accounts/src/single_owner.rs @@ -2,6 +2,7 @@ use crate::{ Account, Call, ConnectedAccount, ExecutionEncoder, RawDeclaration, RawExecution, RawLegacyDeclaration, }; + use async_trait::async_trait; use starknet_core::types::{contract::ComputeClassHashError, BlockId, BlockTag, FieldElement}; use starknet_providers::Provider; diff --git a/starknet-core/src/crypto.rs b/starknet-core/src/crypto.rs index 324c533f..e703fc24 100644 --- a/starknet-core/src/crypto.rs +++ b/starknet-core/src/crypto.rs @@ -1,6 +1,6 @@ use crate::types::FieldElement; -pub use starknet_crypto::{pedersen_hash, ExtendedSignature, Signature}; +pub use starknet_crypto::{pedersen_hash, ExtendedSignature, Signature}; use starknet_crypto::{rfc6979_generate_k, sign, verify, SignError, VerifyError}; mod errors { diff --git a/starknet-core/src/serde/byte_array.rs b/starknet-core/src/serde/byte_array.rs index d11ac709..d5ddd470 100644 --- a/starknet-core/src/serde/byte_array.rs +++ b/starknet-core/src/serde/byte_array.rs @@ -1,5 +1,6 @@ pub mod base64 { use alloc::{fmt::Formatter, format, vec::Vec}; + use base64::{engine::general_purpose::STANDARD, Engine}; use serde::{de::Visitor, Deserializer, Serializer}; diff --git a/starknet-core/src/serde/num_hex.rs b/starknet-core/src/serde/num_hex.rs index 1ecf9d03..985b9053 100644 --- a/starknet-core/src/serde/num_hex.rs +++ b/starknet-core/src/serde/num_hex.rs @@ -1,5 +1,6 @@ pub mod u64 { use alloc::{fmt::Formatter, format}; + use serde::{de::Visitor, Deserializer, Serializer}; struct NumHexVisitor; diff --git a/starknet-core/src/serde/unsigned_field_element.rs b/starknet-core/src/serde/unsigned_field_element.rs index 85640b8a..1a4d8a53 100644 --- a/starknet-core/src/serde/unsigned_field_element.rs +++ b/starknet-core/src/serde/unsigned_field_element.rs @@ -1,11 +1,13 @@ -use crate::types::FieldElement; use alloc::{fmt::Formatter, format}; + use serde::{ de::{Error as DeError, Visitor}, Deserializer, Serializer, }; use serde_with::{DeserializeAs, SerializeAs}; +use crate::types::FieldElement; + pub struct UfeHex; pub struct UfeHexOption; diff --git a/starknet-core/src/types/codegen.rs b/starknet-core/src/types/codegen.rs index bca5c70f..dcbf5f3c 100644 --- a/starknet-core/src/types/codegen.rs +++ b/starknet-core/src/types/codegen.rs @@ -22,13 +22,15 @@ // - `TXN` // - `TXN_RECEIPT` +use alloc::{format, string::String, vec::Vec}; + +use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use serde_with::serde_as; + use crate::{ serde::{byte_array::base64, unsigned_field_element::UfeHex}, types::FieldElement, }; -use alloc::{format, string::String, vec::Vec}; -use serde::{Deserialize, Deserializer, Serialize, Serializer}; -use serde_with::serde_as; use super::{serde_impls::NumAsHex, *}; diff --git a/starknet-core/src/types/eth_address.rs b/starknet-core/src/types/eth_address.rs index 82a78e3f..f71c2542 100644 --- a/starknet-core/src/types/eth_address.rs +++ b/starknet-core/src/types/eth_address.rs @@ -1,5 +1,6 @@ use alloc::{fmt::Formatter, format}; use core::str::FromStr; + use serde::{de::Visitor, Deserialize, Serialize}; use starknet_ff::FieldElement; diff --git a/starknet-core/src/types/execution_result.rs b/starknet-core/src/types/execution_result.rs index 24427093..8de0b583 100644 --- a/starknet-core/src/types/execution_result.rs +++ b/starknet-core/src/types/execution_result.rs @@ -1,7 +1,9 @@ -use super::TransactionExecutionStatus; use alloc::string::String; + use serde::{Deserialize, Serialize}; +use super::TransactionExecutionStatus; + /// A more idiomatic way to access `execution_status` and `revert_reason`. #[derive(Debug, Clone, PartialEq, Eq)] pub enum ExecutionResult { diff --git a/starknet-core/src/types/hash_256.rs b/starknet-core/src/types/hash_256.rs index 1ae12464..a75c9896 100644 --- a/starknet-core/src/types/hash_256.rs +++ b/starknet-core/src/types/hash_256.rs @@ -3,6 +3,7 @@ use alloc::{ format, str::FromStr, }; + use serde::{de::Visitor, Deserialize, Serialize}; use starknet_ff::FieldElement; diff --git a/starknet-core/src/types/mod.rs b/starknet-core/src/types/mod.rs index e70e2355..0eac373d 100644 --- a/starknet-core/src/types/mod.rs +++ b/starknet-core/src/types/mod.rs @@ -1,8 +1,10 @@ -use crate::serde::unsigned_field_element::UfeHex; use alloc::{string::String, vec::Vec}; + use serde::{Deserialize, Serialize}; use serde_with::serde_as; +use crate::serde::unsigned_field_element::UfeHex; + pub use starknet_ff::*; mod conversions; diff --git a/starknet-core/src/types/msg.rs b/starknet-core/src/types/msg.rs index c1415c76..aa621fbe 100644 --- a/starknet-core/src/types/msg.rs +++ b/starknet-core/src/types/msg.rs @@ -1,8 +1,10 @@ -use super::{EthAddress, Hash256, MsgToL1}; use alloc::vec::Vec; + use sha3::{Digest, Keccak256}; use starknet_ff::FieldElement; +use super::{EthAddress, Hash256, MsgToL1}; + #[derive(Debug, Clone)] pub struct MsgToL2 { pub from_address: EthAddress, diff --git a/starknet-core/src/types/serde_impls.rs b/starknet-core/src/types/serde_impls.rs index 4546cf28..81d98889 100644 --- a/starknet-core/src/types/serde_impls.rs +++ b/starknet-core/src/types/serde_impls.rs @@ -1,8 +1,10 @@ -use super::{SyncStatus, SyncStatusType}; use alloc::{fmt::Formatter, format}; + use serde::{de::Visitor, Deserialize, Deserializer, Serialize}; use serde_with::{DeserializeAs, SerializeAs}; +use super::{SyncStatus, SyncStatusType}; + pub(crate) struct NumAsHex; struct NumAsHexVisitorU64; diff --git a/starknet-core/src/utils.rs b/starknet-core/src/utils.rs index 288e8f63..d5e9a377 100644 --- a/starknet-core/src/utils.rs +++ b/starknet-core/src/utils.rs @@ -1,5 +1,7 @@ -use crate::{crypto::compute_hash_on_elements, types::FieldElement}; use alloc::string::String; + +use crate::{crypto::compute_hash_on_elements, types::FieldElement}; + use sha3::{Digest, Keccak256}; use starknet_crypto::pedersen_hash; diff --git a/starknet-crypto-codegen/src/pedersen.rs b/starknet-crypto-codegen/src/pedersen.rs index 97dd9a4c..66e5a3bf 100644 --- a/starknet-crypto-codegen/src/pedersen.rs +++ b/starknet-crypto-codegen/src/pedersen.rs @@ -1,12 +1,13 @@ // Code ported from the build.rs script here: // https://github.com/eqlabs/pathfinder/blob/7f9a6bb0264943f93a633f61fc4e0bc9237f68a0/crates/stark_hash/build.rs +use std::fmt::Write; + use proc_macro::TokenStream; use starknet_curve::{ curve_params::{PEDERSEN_P0, PEDERSEN_P1, PEDERSEN_P2, PEDERSEN_P3}, AffinePoint, }; -use std::fmt::Write; use syn::{parse_macro_input, LitInt}; pub fn lookup_table(input: TokenStream) -> TokenStream { diff --git a/starknet-crypto-codegen/src/poseidon/mod.rs b/starknet-crypto-codegen/src/poseidon/mod.rs index 5b70e1cf..e1d2a4d6 100644 --- a/starknet-crypto-codegen/src/poseidon/mod.rs +++ b/starknet-crypto-codegen/src/poseidon/mod.rs @@ -1,9 +1,10 @@ // Code ported from the build.rs script here: // https://github.com/eqlabs/pathfinder/blob/00a1a74a90a7b8a7f1d07ac3e616be1cb39cf8f1/crates/stark_poseidon/build.rs +use std::fmt::Write; + use proc_macro::TokenStream; use starknet_ff::FieldElement; -use std::fmt::Write; mod params; diff --git a/starknet-crypto/src/ecdsa.rs b/starknet-crypto/src/ecdsa.rs index fa825ecc..e81e1d3e 100644 --- a/starknet-crypto/src/ecdsa.rs +++ b/starknet-crypto/src/ecdsa.rs @@ -1,12 +1,13 @@ -use crate::{ - fe_utils::{add_unbounded, bigint_mul_mod_floor, mod_inverse, mul_mod_floor}, - FieldElement, RecoverError, SignError, VerifyError, -}; use starknet_curve::{ curve_params::{EC_ORDER, GENERATOR}, AffinePoint, ProjectivePoint, }; +use crate::{ + fe_utils::{add_unbounded, bigint_mul_mod_floor, mod_inverse, mul_mod_floor}, + FieldElement, RecoverError, SignError, VerifyError, +}; + const ELEMENT_UPPER_BOUND: FieldElement = FieldElement::from_mont([ 18446743986131435553, 160989183, diff --git a/starknet-crypto/src/fe_utils.rs b/starknet-crypto/src/fe_utils.rs index b5b4307d..7fe285c6 100644 --- a/starknet-crypto/src/fe_utils.rs +++ b/starknet-crypto/src/fe_utils.rs @@ -1,9 +1,11 @@ -use crate::FieldElement; use core::ops::{Add, Mul}; + use num_bigint::BigInt; use num_integer::Integer; use num_traits::{One, Zero}; +use crate::FieldElement; + // These are inefficient and crappy implementations of crypto math operations because I have // absolutely no idea how to do them without using `num-bigint`. But hey it works!!! // diff --git a/starknet-crypto/src/pedersen_hash.rs b/starknet-crypto/src/pedersen_hash.rs index b61bc385..75913184 100644 --- a/starknet-crypto/src/pedersen_hash.rs +++ b/starknet-crypto/src/pedersen_hash.rs @@ -1,7 +1,8 @@ -use crate::pedersen_points::*; use starknet_curve::{curve_params, AffinePoint, ProjectivePoint}; use starknet_ff::FieldElement; +use crate::pedersen_points::*; + const SHIFT_POINT: ProjectivePoint = ProjectivePoint::from_affine_point(&curve_params::SHIFT_POINT); /// Computes the Starkware version of the Pedersen hash of x and y. All inputs are little-endian. diff --git a/starknet-crypto/src/rfc6979.rs b/starknet-crypto/src/rfc6979.rs index 7afb85ad..5b2f5f60 100644 --- a/starknet-crypto/src/rfc6979.rs +++ b/starknet-crypto/src/rfc6979.rs @@ -1,9 +1,10 @@ -use crate::FieldElement; use crypto_bigint::{ArrayEncoding, ByteArray, Integer, U256}; use hmac::digest::Digest; use sha2::digest::{crypto_common::BlockSizeUser, FixedOutputReset, HashMarker}; use zeroize::{Zeroize, Zeroizing}; +use crate::FieldElement; + const EC_ORDER: U256 = U256::from_be_hex("0800000000000010ffffffffffffffffb781126dcae7b2321e66a241adc64d2f"); diff --git a/starknet-crypto/src/test_utils.rs b/starknet-crypto/src/test_utils.rs index dcc4880a..83f587f7 100644 --- a/starknet-crypto/src/test_utils.rs +++ b/starknet-crypto/src/test_utils.rs @@ -1,4 +1,5 @@ #![cfg(test)] + use crate::FieldElement; pub fn field_element_from_be_hex(hex: &str) -> FieldElement { diff --git a/starknet-curve/src/curve_params.rs b/starknet-curve/src/curve_params.rs index ca6848e0..c9938f7f 100644 --- a/starknet-curve/src/curve_params.rs +++ b/starknet-curve/src/curve_params.rs @@ -1,6 +1,7 @@ -use crate::ec_point::AffinePoint; use starknet_ff::FieldElement; +use crate::ec_point::AffinePoint; + pub const EC_ORDER: FieldElement = FieldElement::from_mont([ 8939893405601011193, 1143265896874747514, diff --git a/starknet-curve/src/ec_point.rs b/starknet-curve/src/ec_point.rs index 04792318..2c191450 100644 --- a/starknet-curve/src/ec_point.rs +++ b/starknet-curve/src/ec_point.rs @@ -1,6 +1,8 @@ +use starknet_ff::FieldElement; + use crate::curve_params::{ALPHA, BETA}; + use core::ops; -use starknet_ff::FieldElement; /// A point on an elliptic curve over [FieldElement]. #[derive(Copy, Clone, Debug, Eq, PartialEq)] @@ -133,16 +135,17 @@ impl ops::SubAssign<&AffinePoint> for AffinePoint { impl ops::Mul<&[bool]> for &AffinePoint { type Output = AffinePoint; + #[allow(clippy::suspicious_arithmetic_impl)] fn mul(self, rhs: &[bool]) -> Self::Output { - rhs.iter() - .rev() - .fold(AffinePoint::identity(), |mut acc, &bit| { - acc.double_assign(); - if bit { - acc += self; - } - acc - }) + let mut product = AffinePoint::identity(); + for b in rhs.iter().rev() { + product.double_assign(); + if *b { + product += self; + } + } + + product } } @@ -278,15 +281,16 @@ impl ops::AddAssign<&ProjectivePoint> for ProjectivePoint { impl ops::Mul<&[bool]> for &ProjectivePoint { type Output = ProjectivePoint; + #[allow(clippy::suspicious_arithmetic_impl)] fn mul(self, rhs: &[bool]) -> Self::Output { - rhs.iter() - .rev() - .fold(ProjectivePoint::identity(), |mut acc, &bit| { - acc.double_assign(); - if bit { - acc += self; - } - acc - }) + let mut product = ProjectivePoint::identity(); + for b in rhs.iter().rev() { + product.double_assign(); + if *b { + product += self; + } + } + + product } } diff --git a/starknet-ff/src/lib.rs b/starknet-ff/src/lib.rs index b7687b7d..36a5cd1b 100644 --- a/starknet-ff/src/lib.rs +++ b/starknet-ff/src/lib.rs @@ -5,15 +5,17 @@ #[cfg_attr(test, macro_use)] extern crate alloc; +use core::{ + fmt, ops, + str::{self, FromStr}, +}; + use crate::fr::Fr; + use ark_ff::{ fields::{Field, Fp256, PrimeField}, BigInteger, BigInteger256, }; -use core::{ - fmt, ops, - str::{self, FromStr}, -}; use crypto_bigint::{CheckedAdd, CheckedMul, NonZero, Zero, U256}; mod fr; diff --git a/starknet-providers/src/any.rs b/starknet-providers/src/any.rs index adb447d8..0369dbab 100644 --- a/starknet-providers/src/any.rs +++ b/starknet-providers/src/any.rs @@ -1,7 +1,3 @@ -use crate::{ - jsonrpc::{HttpTransport, JsonRpcClient}, - Provider, ProviderError, SequencerGatewayProvider, -}; use async_trait::async_trait; use starknet_core::types::{ BlockHashAndNumber, BlockId, BroadcastedDeclareTransaction, @@ -14,6 +10,11 @@ use starknet_core::types::{ TransactionTraceWithHash, }; +use crate::{ + jsonrpc::{HttpTransport, JsonRpcClient}, + Provider, ProviderError, SequencerGatewayProvider, +}; + /// A convenient Box-able type that implements the [Provider] trait. This can be useful when you /// want to accept any built-in provider implementation from the library in your appliation, since /// the [Provider] trait itself cannot be Box-ed due to the use of associated type. diff --git a/starknet-providers/src/jsonrpc/mod.rs b/starknet-providers/src/jsonrpc/mod.rs index 953fa8a3..66232291 100644 --- a/starknet-providers/src/jsonrpc/mod.rs +++ b/starknet-providers/src/jsonrpc/mod.rs @@ -1,3 +1,5 @@ +use std::{any::Any, error::Error, fmt::Display}; + use async_trait::async_trait; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use serde_with::serde_as; @@ -16,7 +18,6 @@ use starknet_core::{ TransactionTraceWithHash, }, }; -use std::{any::Any, error::Error, fmt::Display}; use crate::{provider::ProviderImplError, Provider, ProviderError}; diff --git a/starknet-providers/src/sequencer/mod.rs b/starknet-providers/src/sequencer/mod.rs index fe45f8fd..1fdc97d8 100644 --- a/starknet-providers/src/sequencer/mod.rs +++ b/starknet-providers/src/sequencer/mod.rs @@ -1,4 +1,5 @@ use crate::provider::ProviderError; + use log::trace; use reqwest::{Client, Error as ReqwestError, StatusCode}; use serde::{de::DeserializeOwned, Deserialize, Serialize}; diff --git a/starknet-providers/src/sequencer/provider.rs b/starknet-providers/src/sequencer/provider.rs index 63c1200d..f7ac82d7 100644 --- a/starknet-providers/src/sequencer/provider.rs +++ b/starknet-providers/src/sequencer/provider.rs @@ -1,10 +1,7 @@ #![allow(deprecated)] -use super::models::TransactionFinalityStatus; -use crate::{ - provider::ProviderImplError, - sequencer::{models::conversions::ConversionError, GatewayClientError}, - Provider, ProviderError, SequencerGatewayProvider, -}; + +use std::any::Any; + use async_trait::async_trait; use starknet_core::types::{ BlockHashAndNumber, BlockId, BroadcastedDeclareTransaction, @@ -16,7 +13,14 @@ use starknet_core::types::{ SimulationFlagForEstimateFee, StarknetError, SyncStatusType, Transaction, TransactionStatus, TransactionTrace, TransactionTraceWithHash, }; -use std::any::Any; + +use crate::{ + provider::ProviderImplError, + sequencer::{models::conversions::ConversionError, GatewayClientError}, + Provider, ProviderError, SequencerGatewayProvider, +}; + +use super::models::TransactionFinalityStatus; #[allow(unused)] #[cfg_attr(not(target_arch = "wasm32"), async_trait)] diff --git a/starknet-signers/src/local_wallet.rs b/starknet-signers/src/local_wallet.rs index 8c77a602..c4ce3778 100644 --- a/starknet-signers/src/local_wallet.rs +++ b/starknet-signers/src/local_wallet.rs @@ -1,4 +1,5 @@ use crate::{Infallible, Signer, SigningKey, VerifyingKey}; + use async_trait::async_trait; use starknet_core::{ crypto::{EcdsaSignError, Signature}, diff --git a/starknet-signers/src/signer.rs b/starknet-signers/src/signer.rs index 61e15acc..777d3a3a 100644 --- a/starknet-signers/src/signer.rs +++ b/starknet-signers/src/signer.rs @@ -1,4 +1,5 @@ use crate::VerifyingKey; + use async_trait::async_trait; use auto_impl::auto_impl; use starknet_core::{crypto::Signature, types::FieldElement};