Skip to content

Commit

Permalink
chore: undo import and iter changes
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI committed Feb 26, 2024
1 parent 92372a9 commit fb190ab
Show file tree
Hide file tree
Showing 35 changed files with 104 additions and 55 deletions.
1 change: 1 addition & 0 deletions starknet-accounts/src/account/declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use super::{
LegacyDeclaration, PreparedDeclaration, PreparedLegacyDeclaration, RawDeclaration,
RawLegacyDeclaration,
};

use starknet_core::{
crypto::compute_hash_on_elements,
types::{
Expand Down
1 change: 1 addition & 0 deletions starknet-accounts/src/account/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use super::{
RawExecution,
};
use crate::{Call, ExecutionEncoder};

use starknet_core::{
crypto::compute_hash_on_elements,
types::{
Expand Down
1 change: 1 addition & 0 deletions starknet-accounts/src/account/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::Call;

use async_trait::async_trait;
use auto_impl::auto_impl;
use starknet_core::types::{
Expand Down
1 change: 1 addition & 0 deletions starknet-accounts/src/factory/argent.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 1 addition & 0 deletions starknet-accounts/src/factory/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::NotPreparedError;

use async_trait::async_trait;
use starknet_core::{
crypto::compute_hash_on_elements,
Expand Down
1 change: 1 addition & 0 deletions starknet-accounts/src/factory/open_zeppelin.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 1 addition & 0 deletions starknet-accounts/src/single_owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion starknet-core/src/crypto.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
1 change: 1 addition & 0 deletions starknet-core/src/serde/byte_array.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod base64 {
use alloc::{fmt::Formatter, format, vec::Vec};

Check warning on line 2 in starknet-core/src/serde/byte_array.rs

View workflow job for this annotation

GitHub Actions / udeps

the item `Vec` is imported redundantly

use base64::{engine::general_purpose::STANDARD, Engine};
use serde::{de::Visitor, Deserializer, Serializer};

Expand Down
1 change: 1 addition & 0 deletions starknet-core/src/serde/num_hex.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod u64 {
use alloc::{fmt::Formatter, format};

use serde::{de::Visitor, Deserializer, Serializer};

struct NumHexVisitor;
Expand Down
4 changes: 3 additions & 1 deletion starknet-core/src/serde/unsigned_field_element.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
8 changes: 5 additions & 3 deletions starknet-core/src/types/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
// - `TXN`
// - `TXN_RECEIPT`

use alloc::{format, string::String, vec::Vec};

Check warning on line 25 in starknet-core/src/types/codegen.rs

View workflow job for this annotation

GitHub Actions / udeps

the item `String` is imported redundantly

Check warning on line 25 in starknet-core/src/types/codegen.rs

View workflow job for this annotation

GitHub Actions / udeps

the item `Vec` is imported redundantly

use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_with::serde_as;

use crate::{
serde::{byte_array::base64, unsigned_field_element::UfeHex},

Check warning on line 31 in starknet-core/src/types/codegen.rs

View workflow job for this annotation

GitHub Actions / udeps

the item `UfeHex` is imported redundantly
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, *};

Expand Down
1 change: 1 addition & 0 deletions starknet-core/src/types/eth_address.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use alloc::{fmt::Formatter, format};
use core::str::FromStr;

use serde::{de::Visitor, Deserialize, Serialize};
use starknet_ff::FieldElement;

Expand Down
4 changes: 3 additions & 1 deletion starknet-core/src/types/execution_result.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
1 change: 1 addition & 0 deletions starknet-core/src/types/hash_256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use alloc::{
format,
str::FromStr,
};

use serde::{de::Visitor, Deserialize, Serialize};
use starknet_ff::FieldElement;

Expand Down
4 changes: 3 additions & 1 deletion starknet-core/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::serde::unsigned_field_element::UfeHex;
use alloc::{string::String, vec::Vec};

Check warning on line 1 in starknet-core/src/types/mod.rs

View workflow job for this annotation

GitHub Actions / udeps

the item `String` is imported redundantly

Check warning on line 1 in starknet-core/src/types/mod.rs

View workflow job for this annotation

GitHub Actions / udeps

the item `Vec` is imported redundantly

use serde::{Deserialize, Serialize};
use serde_with::serde_as;

use crate::serde::unsigned_field_element::UfeHex;

pub use starknet_ff::*;

mod conversions;
Expand Down
4 changes: 3 additions & 1 deletion starknet-core/src/types/msg.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 3 additions & 1 deletion starknet-core/src/types/serde_impls.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 3 additions & 1 deletion starknet-core/src/utils.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
3 changes: 2 additions & 1 deletion starknet-crypto-codegen/src/pedersen.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion starknet-crypto-codegen/src/poseidon/mod.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
9 changes: 5 additions & 4 deletions starknet-crypto/src/ecdsa.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 3 additions & 1 deletion starknet-crypto/src/fe_utils.rs
Original file line number Diff line number Diff line change
@@ -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!!!
//
Expand Down
3 changes: 2 additions & 1 deletion starknet-crypto/src/pedersen_hash.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 2 additions & 1 deletion starknet-crypto/src/rfc6979.rs
Original file line number Diff line number Diff line change
@@ -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");

Expand Down
1 change: 1 addition & 0 deletions starknet-crypto/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg(test)]

use crate::FieldElement;

pub fn field_element_from_be_hex(hex: &str) -> FieldElement {
Expand Down
3 changes: 2 additions & 1 deletion starknet-curve/src/curve_params.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
42 changes: 23 additions & 19 deletions starknet-curve/src/ec_point.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
}
}
10 changes: 6 additions & 4 deletions starknet-ff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions starknet-providers/src/any.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use crate::{
jsonrpc::{HttpTransport, JsonRpcClient},
Provider, ProviderError, SequencerGatewayProvider,
};
use async_trait::async_trait;
use starknet_core::types::{
BlockHashAndNumber, BlockId, BroadcastedDeclareTransaction,
Expand All @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion starknet-providers/src/jsonrpc/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,7 +18,6 @@ use starknet_core::{
TransactionTraceWithHash,
},
};
use std::{any::Any, error::Error, fmt::Display};

use crate::{provider::ProviderImplError, Provider, ProviderError};

Expand Down
1 change: 1 addition & 0 deletions starknet-providers/src/sequencer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::provider::ProviderError;

use log::trace;
use reqwest::{Client, Error as ReqwestError, StatusCode};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
Expand Down
Loading

0 comments on commit fb190ab

Please sign in to comment.