Skip to content

Commit

Permalink
chore: use latest starknet-rs rev
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI committed Jun 29, 2024
1 parent c676e4b commit c83b648
Show file tree
Hide file tree
Showing 35 changed files with 520 additions and 455 deletions.
287 changes: 150 additions & 137 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ indexmap = "2.1.0"
log = "0.4.19"
num-bigint = "0.4.3"
num-integer = "0.1.45"
num-traits = "0.2.19"
rand = "0.8.5"
rayon = "1.7.0"
regex = "1.8.4"
Expand All @@ -36,8 +37,8 @@ serde = { version = "1.0.164", features = ["derive"] }
serde_json = { version = "1.0.99", features = ["preserve_order"] }
serde_with = "2.3.3"
shellexpand = "3.1.0"
starknet = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "82bac8b196a59c340519249b92db410d0084d74d" }
starknet-crypto = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "82bac8b196a59c340519249b92db410d0084d74d" }
starknet = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "838c612e445ae22af07beceaba862c708da2ab2d" }
starknet-crypto = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "838c612e445ae22af07beceaba862c708da2ab2d" }
tempfile = "3.8.0"
thiserror = "1.0.40"
tokio = { version = "1.28.2", default-features = false, features = ["macros", "rt-multi-thread"] }
Expand Down
46 changes: 23 additions & 23 deletions src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use starknet::{
accounts::{ExecutionEncoding, SingleOwnerAccount},
core::{
serde::unsigned_field_element::UfeHex,
types::{BlockId, BlockTag, FieldElement},
types::{BlockId, BlockTag, Felt},
utils::get_contract_address,
},
macros::{felt, selector},
Expand All @@ -18,7 +18,7 @@ use starknet::{

use crate::signer::{AnySigner, SignerArgs, SignerResolutionTask};

const BRAAVOS_SIGNER_TYPE_STARK: FieldElement = FieldElement::ONE;
const BRAAVOS_SIGNER_TYPE_STARK: Felt = Felt::ONE;

pub const KNOWN_ACCOUNT_CLASSES: [KnownAccountClass; 16] = [
KnownAccountClass {
Expand Down Expand Up @@ -201,7 +201,7 @@ pub enum DeploymentStatus {
}

pub struct KnownAccountClass {
pub class_hash: FieldElement,
pub class_hash: Felt,
pub variant: AccountVariantType,
pub description: &'static str,
}
Expand All @@ -210,8 +210,8 @@ pub struct KnownAccountClass {
pub struct BuiltinAccount {
pub id: &'static str,
pub aliases: &'static [&'static str],
pub address: FieldElement,
pub private_key: FieldElement,
pub address: Felt,
pub private_key: Felt,
}

pub enum AccountVariantType {
Expand All @@ -228,7 +228,7 @@ pub enum AccountVariantType {
pub struct OzAccountConfig {
pub version: u64,
#[serde_as(as = "UfeHex")]
pub public_key: FieldElement,
pub public_key: Felt,
#[serde(default = "true_as_default")]
pub legacy: bool,
}
Expand All @@ -239,13 +239,13 @@ pub struct ArgentAccountConfig {
pub version: u64,
#[serde_as(as = "Option<UfeHex>")]
#[serde(default, skip_serializing_if = "Option::is_none")]
pub implementation: Option<FieldElement>,
pub implementation: Option<Felt>,
#[serde_as(as = "UfeHex")]
// Old account files use `signer`
#[serde(alias = "signer")]
pub owner: FieldElement,
pub owner: Felt,
#[serde_as(as = "UfeHex")]
pub guardian: FieldElement,
pub guardian: Felt,
}

#[serde_as]
Expand All @@ -254,7 +254,7 @@ pub struct BraavosAccountConfig {
pub version: u64,
#[serde_as(as = "Option<UfeHex>")]
#[serde(default, skip_serializing_if = "Option::is_none")]
pub implementation: Option<FieldElement>,
pub implementation: Option<Felt>,
pub multisig: BraavosMultisigConfig,
pub signers: Vec<BraavosSigner>,
}
Expand All @@ -277,16 +277,16 @@ pub enum BraavosSigner {
#[derive(Serialize, Deserialize)]
pub struct BraavosStarkSigner {
#[serde_as(as = "UfeHex")]
pub public_key: FieldElement,
pub public_key: Felt,
}

#[serde_as]
#[derive(Serialize, Deserialize)]
pub struct UndeployedStatus {
#[serde_as(as = "UfeHex")]
pub class_hash: FieldElement,
pub class_hash: Felt,
#[serde_as(as = "UfeHex")]
pub salt: FieldElement,
pub salt: Felt,
#[serde(skip_serializing_if = "Option::is_none")]
pub context: Option<DeploymentContext>,
}
Expand All @@ -295,9 +295,9 @@ pub struct UndeployedStatus {
#[derive(Serialize, Deserialize)]
pub struct DeployedStatus {
#[serde_as(as = "UfeHex")]
pub class_hash: FieldElement,
pub class_hash: Felt,
#[serde_as(as = "UfeHex")]
pub address: FieldElement,
pub address: Felt,
}

#[derive(Serialize, Deserialize)]
Expand All @@ -312,7 +312,7 @@ pub struct BraavosDeploymentContext {
// Old account files use `mock_implementation`
#[serde(alias = "mock_implementation")]
#[serde_as(as = "UfeHex")]
pub base_account_class_hash: FieldElement,
pub base_account_class_hash: Felt,
}

impl AccountArgs {
Expand Down Expand Up @@ -380,7 +380,7 @@ impl AccountArgs {
}

impl AccountConfig {
pub fn deploy_account_address(&self) -> Result<FieldElement> {
pub fn deploy_account_address(&self) -> Result<Felt> {
let undeployed_status = match &self.deployment {
DeploymentStatus::Undeployed(value) => value,
DeploymentStatus::Deployed(_) => {
Expand All @@ -393,7 +393,7 @@ impl AccountConfig {
undeployed_status.salt,
undeployed_status.class_hash,
&[oz.public_key],
FieldElement::ZERO,
Felt::ZERO,
)),
AccountVariant::Argent(argent) => match argent.implementation {
Some(implementation) => {
Expand All @@ -404,11 +404,11 @@ impl AccountConfig {
&[
implementation, // implementation
selector!("initialize"), // selector
FieldElement::TWO, // calldata_len
Felt::TWO, // calldata_len
argent.owner, // calldata[0]: signer
argent.guardian, // calldata[1]: guardian
],
FieldElement::ZERO,
Felt::ZERO,
))
}
None => {
Expand All @@ -417,7 +417,7 @@ impl AccountConfig {
undeployed_status.salt,
undeployed_status.class_hash,
&[argent.owner, argent.guardian],
FieldElement::ZERO,
Felt::ZERO,
))
}
},
Expand All @@ -441,7 +441,7 @@ impl AccountConfig {
&[
stark_signer.public_key, // calldata[0]: public_key
],
FieldElement::ZERO,
Felt::ZERO,
))
} // Reject other variants as we add more types
}
Expand Down Expand Up @@ -482,7 +482,7 @@ impl AccountVariant {
}

impl BraavosSigner {
pub fn decode(raw_signer_model: &[FieldElement]) -> Result<Self> {
pub fn decode(raw_signer_model: &[Felt]) -> Result<Self> {
let raw_signer_type = raw_signer_model
.get(4)
.ok_or_else(|| anyhow::anyhow!("unable to read `type` field"))?;
Expand Down
76 changes: 41 additions & 35 deletions src/account_factory/braavos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ use starknet::{
AccountFactory, PreparedAccountDeploymentV1, PreparedAccountDeploymentV3,
RawAccountDeploymentV1, RawAccountDeploymentV3,
},
core::types::{BlockId, BlockTag, FieldElement},
core::types::{BlockId, BlockTag, Felt},
providers::Provider,
signers::Signer,
};
use starknet_crypto::poseidon_hash_many;

pub struct BraavosAccountFactory<S, P> {
class_hash: FieldElement,
base_class_hash: FieldElement,
chain_id: FieldElement,
signer_public_key: FieldElement,
class_hash: Felt,
base_class_hash: Felt,
chain_id: Felt,
signer_public_key: Felt,
signer: S,
provider: P,
block_id: BlockId,
Expand All @@ -25,9 +25,9 @@ where
S: Signer,
{
pub async fn new(
class_hash: FieldElement,
base_class_hash: FieldElement,
chain_id: FieldElement,
class_hash: Felt,
base_class_hash: Felt,
chain_id: Felt,
signer: S,
provider: P,
) -> Result<Self, S::GetPublicKeyError> {
Expand Down Expand Up @@ -60,56 +60,61 @@ where
type SignError = S::SignError;

#[allow(clippy::misnamed_getters)]
fn class_hash(&self) -> FieldElement {
fn class_hash(&self) -> Felt {
self.base_class_hash
}

fn calldata(&self) -> Vec<FieldElement> {
fn calldata(&self) -> Vec<Felt> {
vec![self.signer_public_key]
}

fn chain_id(&self) -> FieldElement {
fn chain_id(&self) -> Felt {
self.chain_id
}

fn provider(&self) -> &Self::Provider {
&self.provider
}

fn is_signer_interactive(&self) -> bool {
self.signer.is_interactive()
}

fn block_id(&self) -> BlockId {
self.block_id
}

async fn sign_deployment_v1(
&self,
deployment: &RawAccountDeploymentV1,
) -> Result<Vec<FieldElement>, Self::SignError> {
let tx_hash =
PreparedAccountDeploymentV1::from_raw(deployment.clone(), self).transaction_hash();
query_only: bool,
) -> Result<Vec<Felt>, Self::SignError> {
let tx_hash = PreparedAccountDeploymentV1::from_raw(deployment.clone(), self)
.transaction_hash(query_only);

let signature = self.signer.sign_hash(&tx_hash).await?;

let mut aux_data = vec![
// account_implementation
self.class_hash,
// signer_type
FieldElement::ZERO,
Felt::ZERO,
// secp256r1_signer.x.low
FieldElement::ZERO,
Felt::ZERO,
// secp256r1_signer.x.high
FieldElement::ZERO,
Felt::ZERO,
// secp256r1_signer.y.low
FieldElement::ZERO,
Felt::ZERO,
// secp256r1_signer.y.high
FieldElement::ZERO,
Felt::ZERO,
// multisig_threshold
FieldElement::ZERO,
Felt::ZERO,
// withdrawal_limit_low
FieldElement::ZERO,
Felt::ZERO,
// fee_rate
FieldElement::ZERO,
Felt::ZERO,
// stark_fee_rate
FieldElement::ZERO,
Felt::ZERO,
// chain_id
self.chain_id,
];
Expand All @@ -129,33 +134,34 @@ where
async fn sign_deployment_v3(
&self,
deployment: &RawAccountDeploymentV3,
) -> Result<Vec<FieldElement>, Self::SignError> {
let tx_hash =
PreparedAccountDeploymentV3::from_raw(deployment.clone(), self).transaction_hash();
query_only: bool,
) -> Result<Vec<Felt>, Self::SignError> {
let tx_hash = PreparedAccountDeploymentV3::from_raw(deployment.clone(), self)
.transaction_hash(query_only);

let signature = self.signer.sign_hash(&tx_hash).await?;

let mut aux_data = vec![
// account_implementation
self.class_hash,
// signer_type
FieldElement::ZERO,
Felt::ZERO,
// secp256r1_signer.x.low
FieldElement::ZERO,
Felt::ZERO,
// secp256r1_signer.x.high
FieldElement::ZERO,
Felt::ZERO,
// secp256r1_signer.y.low
FieldElement::ZERO,
Felt::ZERO,
// secp256r1_signer.y.high
FieldElement::ZERO,
Felt::ZERO,
// multisig_threshold
FieldElement::ZERO,
Felt::ZERO,
// withdrawal_limit_low
FieldElement::ZERO,
Felt::ZERO,
// fee_rate
FieldElement::ZERO,
Felt::ZERO,
// stark_fee_rate
FieldElement::ZERO,
Felt::ZERO,
// chain_id
self.chain_id,
];
Expand Down
Loading

0 comments on commit c83b648

Please sign in to comment.