Skip to content

Commit

Permalink
Merge pull request #148 from HerodotusDev/dependency-fix
Browse files Browse the repository at this point in the history
chore: `FieldElement` to `Felt`, version bump
  • Loading branch information
rkdud007 authored Sep 17, 2024
2 parents 4ccd4f5 + 23f9c3e commit 6f02adb
Show file tree
Hide file tree
Showing 18 changed files with 784 additions and 793 deletions.
1,375 changes: 692 additions & 683 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ tracing = "0.1"
reqwest = { version = "0.11", features = ["json"] }
rand = "0.8.4"
regex = "1"
starknet = "0.10.0"
starknet-crypto = "0.6.1"
starknet-types-core = "0.1.0"
starknet = "0.11.0"
starknet-crypto = "0.7.1"
starknet-types-core = "0.1.5"
cairo-lang-starknet-classes = "2.7.0"
cairo-vm = "1.0.0-rc6"
futures = "0.3.30"
lazy_static = "1.4.0"
thiserror = "1.0"
eth-trie-proofs = "0.1.1"
eth-trie-proofs = { version = "0.1.1", git = "https://github.com/HerodotusDev/trie-proofs.git" }
sn-trie-proofs = { version = "0.1.0", git = "https://github.com/HerodotusDev/trie-proofs.git" }

itertools = "0.10"
1 change: 1 addition & 0 deletions hdp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ reqwest = { workspace = true }
lazy_static = { workspace = true }
eth-trie-proofs = { workspace = true }
itertools = { workspace = true }
sn-trie-proofs = { workspace = true }

[features]
default = []
Expand Down
7 changes: 4 additions & 3 deletions hdp/src/cairo_runner/dry_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::provider::key::{
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use starknet::core::serde::unsigned_field_element::UfeHex;
use starknet_crypto::FieldElement;
use starknet_crypto::Felt;
use std::fs;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
Expand All @@ -25,7 +25,7 @@ pub struct DryRunnedModule {
pub fetch_keys: Vec<FetchKeyEnvelope>,
pub result: Uint256,
#[serde_as(as = "UfeHex")]
pub program_hash: FieldElement,
pub program_hash: Felt,
}

fn deserialize_fetch_keys<'de, D>(deserializer: D) -> Result<Vec<FetchKeyEnvelope>, D::Error>
Expand Down Expand Up @@ -173,7 +173,8 @@ mod tests {
assert_eq!(result[0].result, Uint256::ZERO);
assert_eq!(
result[0].program_hash,
felt!("0x04df21eb479ae4416fbdc00abab6fab43bff0b8083be4d1fd8602c8fbfbd2274")
Felt::from_hex("0x04df21eb479ae4416fbdc00abab6fab43bff0b8083be4d1fd8602c8fbfbd2274")
.unwrap()
);
}

Expand Down
27 changes: 11 additions & 16 deletions hdp/src/preprocessor/module_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
},
};
use reqwest::Client;
use starknet_crypto::FieldElement;
use starknet_types_core::felt::Felt;
use std::{path::PathBuf, str::FromStr};
use thiserror::Error;
use tracing::info;
Expand Down Expand Up @@ -65,8 +65,7 @@ impl ModuleRegistry {
module_inputs: Vec<String>,
) -> Result<ExtendedModule, ModuleRegistryError> {
let program_hash = program_hash.map(|program_hash| {
FieldElement::from_hex_be(&program_hash)
.expect("program hash cannot be converted to FieldElement")
Felt::from_hex(&program_hash).expect("program hash cannot be converted to FieldElement")
});
let module_inputs: Result<Vec<ModuleInput>, _> = module_inputs
.into_iter()
Expand All @@ -82,7 +81,7 @@ impl ModuleRegistry {

pub async fn get_extended_module_from_class_source(
&self,
program_hash: Option<FieldElement>,
program_hash: Option<Felt>,
local_class_path: Option<PathBuf>,
module_inputs: Vec<ModuleInput>,
) -> Result<ExtendedModule, ModuleRegistryError> {
Expand All @@ -105,8 +104,7 @@ impl ModuleRegistry {
};

let program_hash = casm.compiled_class_hash();
let converted_hash = FieldElement::from_bytes_be(&program_hash.to_bytes_be())
.expect("program hash cannot be converted to FieldElement");
let converted_hash = Felt::from_bytes_be(&program_hash.to_bytes_be());
info!("program Hash: {:#?}", converted_hash);

let module = Module {
Expand Down Expand Up @@ -141,7 +139,7 @@ impl ModuleRegistry {

async fn get_module_class_from_program_hash(
&self,
program_hash: FieldElement,
program_hash: Felt,
) -> Result<CasmContractClass, ModuleRegistryError> {
let program_hash_hex = format!("{:#x}", program_hash);

Expand Down Expand Up @@ -182,13 +180,12 @@ mod tests {

use super::*;

fn init() -> (ModuleRegistry, FieldElement) {
fn init() -> (ModuleRegistry, Felt) {
let module_registry = ModuleRegistry::new();
// This is test contract class hash
let program_hash = FieldElement::from_hex_be(
"0x64041a339b1edd10de83cf031cfa938645450f971d2527c90d4c2ce68d7d412",
)
.unwrap();
let program_hash =
Felt::from_hex("0x64041a339b1edd10de83cf031cfa938645450f971d2527c90d4c2ce68d7d412")
.unwrap();

(module_registry, program_hash)
}
Expand All @@ -214,10 +211,8 @@ mod tests {

assert_eq!(
extended_modules.task.program_hash,
FieldElement::from_hex_be(
"0x64041a339b1edd10de83cf031cfa938645450f971d2527c90d4c2ce68d7d412"
)
.unwrap()
Felt::from_hex("0x64041a339b1edd10de83cf031cfa938645450f971d2527c90d4c2ce68d7d412")
.unwrap()
);
assert_eq!(extended_modules.task.inputs, vec![]);
}
Expand Down
4 changes: 2 additions & 2 deletions hdp/src/primitives/processed_types/cairo_format/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use starknet::core::serde::unsigned_field_element::UfeHex;
use starknet_crypto::FieldElement;
use starknet_types_core::felt::Felt;

use crate::primitives::processed_types::account::ProcessedAccount as BaseProcessedAccount;

Expand Down Expand Up @@ -33,7 +33,7 @@ impl AsCairoFormat for BaseProcessedAccount {
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Eq, Hash)]
pub struct ProcessedAccount {
#[serde_as(as = "Vec<UfeHex>")]
pub address: Vec<FieldElement>,
pub address: Vec<Felt>,
pub account_key: String,
pub proofs: Vec<ProcessedMPTProof>,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::{felt_vec_unit::FieldElementVectorUnit, traits::AsCairoFormat};
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use starknet::core::serde::unsigned_field_element::UfeHex;
use starknet_crypto::FieldElement;
use starknet_types_core::felt::Felt;

impl AsCairoFormat for BaseProcessedDatalakeCompute {
type Output = ProcessedDatalakeCompute;
Expand All @@ -28,10 +28,10 @@ impl AsCairoFormat for BaseProcessedDatalakeCompute {
pub struct ProcessedDatalakeCompute {
pub task_bytes_len: u64,
#[serde_as(as = "Vec<UfeHex>")]
pub encoded_task: Vec<FieldElement>,
pub encoded_task: Vec<Felt>,
pub datalake_bytes_len: u64,
#[serde_as(as = "Vec<UfeHex>")]
pub encoded_datalake: Vec<FieldElement>,
pub encoded_datalake: Vec<Felt>,
pub datalake_type: u8,
pub property_type: u8,
}
Expand Down
26 changes: 8 additions & 18 deletions hdp/src/primitives/processed_types/cairo_format/felt_vec_unit.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use serde::Serialize;
use serde_with::serde_as;
use starknet::core::serde::unsigned_field_element::UfeHex;
use starknet_crypto::FieldElement;
use starknet_types_core::felt::Felt;

#[serde_as]
#[derive(Serialize, Debug)]
pub struct FieldElementVectorUnit {
/// Chunked vector of field elements
#[serde_as(as = "Vec<UfeHex>")]
pub felts: Vec<FieldElement>,
pub felts: Vec<Felt>,
/// Length of the original byte array before chunking into field elements
pub bytes_len: u64,
}
Expand All @@ -17,7 +17,7 @@ impl FieldElementVectorUnit {
/// Converts a byte slice into a `FieldElementVectorUnit`.
///
/// This function takes a slice of bytes and converts it into a `FieldElementVectorUnit`,
/// which consists of a vector of `FieldElement`s and the length of the original byte slice.
/// which consists of a vector of [`Felt`]s and the length of the original byte slice.
///
/// # Panics
///
Expand All @@ -34,8 +34,7 @@ impl FieldElementVectorUnit {
let len = chunk.len();
arr[..len].copy_from_slice(chunk);
let le_int = u64::from_le_bytes(arr);
FieldElement::from_dec_str(&le_int.to_string())
.expect("Invalid to convert FieldElement")
Felt::from_dec_str(&le_int.to_string()).expect("Invalid to convert FieldElement")
})
.collect();

Expand All @@ -62,7 +61,7 @@ mod tests {
let result = FieldElementVectorUnit::from_bytes(&bytes);
assert_eq!(result.bytes_len, 1);
assert_eq!(result.felts.len(), 1);
assert_eq!(result.felts[0], FieldElement::from_hex_be("0x1").unwrap());
assert_eq!(result.felts[0], Felt::from_hex("0x1").unwrap());
}

#[test]
Expand All @@ -71,10 +70,7 @@ mod tests {
let result = FieldElementVectorUnit::from_bytes(&bytes);
assert_eq!(result.bytes_len, 8);
assert_eq!(result.felts.len(), 1);
assert_eq!(
result.felts[0],
FieldElement::from_hex_be("efcdab9078563412").unwrap()
);
assert_eq!(result.felts[0], Felt::from_hex("efcdab9078563412").unwrap());
}

#[test]
Expand All @@ -83,13 +79,7 @@ mod tests {
let result = FieldElementVectorUnit::from_bytes(&bytes);
assert_eq!(result.bytes_len, 16);
assert_eq!(result.felts.len(), 2);
assert_eq!(
result.felts[0],
FieldElement::from_hex_be("efcdab9078563412").unwrap()
);
assert_eq!(
result.felts[1],
FieldElement::from_hex_be("8877665544332211").unwrap()
);
assert_eq!(result.felts[0], Felt::from_hex("efcdab9078563412").unwrap());
assert_eq!(result.felts[1], Felt::from_hex("8877665544332211").unwrap());
}
}
4 changes: 2 additions & 2 deletions hdp/src/primitives/processed_types/cairo_format/header.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use starknet::core::serde::unsigned_field_element::UfeHex;
use starknet_crypto::FieldElement;
use starknet_types_core::felt::Felt;

use crate::primitives::processed_types::header::{
ProcessedHeader as BaseProcessedHeader, ProcessedHeaderProof as BasedProcessedHeaderProof,
Expand Down Expand Up @@ -31,7 +31,7 @@ impl AsCairoFormat for BaseProcessedHeader {
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Eq, Hash)]
pub struct ProcessedHeader {
#[serde_as(as = "Vec<UfeHex>")]
pub rlp: Vec<FieldElement>,
pub rlp: Vec<Felt>,
/// rlp_bytes_len is the byte( 8 bit ) length from rlp string
pub rlp_bytes_len: u64,
pub proof: BasedProcessedHeaderProof,
Expand Down
6 changes: 3 additions & 3 deletions hdp/src/primitives/processed_types/cairo_format/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use starknet::core::serde::unsigned_field_element::UfeHex;
use starknet_crypto::FieldElement;
use starknet_types_core::felt::Felt;

use super::{AsCairoFormat, FieldElementVectorUnit};

Expand Down Expand Up @@ -53,7 +53,7 @@ impl DryRunProcessedModule {
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ProcessedModule {
#[serde_as(as = "Vec<UfeHex>")]
pub encoded_task: Vec<FieldElement>,
pub encoded_task: Vec<Felt>,
pub task_bytes_len: u64,
pub inputs: Vec<ModuleInput>,
/// Detail class code of the module.
Expand All @@ -63,7 +63,7 @@ pub struct ProcessedModule {

impl ProcessedModule {
pub fn new(
encoded_task: Vec<FieldElement>,
encoded_task: Vec<Felt>,
task_bytes_len: u64,
inputs: Vec<ModuleInput>,
module_class: CasmContractClass,
Expand Down
7 changes: 3 additions & 4 deletions hdp/src/primitives/processed_types/cairo_format/mpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::{felt_vec_unit::FieldElementVectorUnit, traits::AsCairoFormat};
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use starknet::core::serde::unsigned_field_element::UfeHex;
use starknet_crypto::FieldElement;
use starknet_types_core::felt::Felt;

impl AsCairoFormat for BaseProcessedMPTProof {
type Output = ProcessedMPTProof;
Expand All @@ -17,8 +17,7 @@ impl AsCairoFormat for BaseProcessedMPTProof {
.collect();

let proof_bytes_len = proof_felts.iter().map(|f| f.bytes_len).collect();
let proof_result: Vec<Vec<FieldElement>> =
proof_felts.iter().map(|f| f.felts.clone()).collect();
let proof_result: Vec<Vec<Felt>> = proof_felts.iter().map(|f| f.felts.clone()).collect();
ProcessedMPTProof {
block_number: self.block_number,
proof_bytes_len,
Expand All @@ -34,5 +33,5 @@ pub struct ProcessedMPTProof {
/// proof_bytes_len is the byte( 8 bit ) length from each proof string
pub proof_bytes_len: Vec<u64>,
#[serde_as(as = "Vec<Vec<UfeHex>>")]
pub proof: Vec<Vec<FieldElement>>,
pub proof: Vec<Vec<Felt>>,
}
7 changes: 3 additions & 4 deletions hdp/src/primitives/processed_types/cairo_format/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::primitives::processed_types::receipt::ProcessedReceipt as BaseProcess
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use starknet::core::serde::unsigned_field_element::UfeHex;
use starknet_crypto::FieldElement;
use starknet_types_core::felt::Felt;

impl AsCairoFormat for BaseProcessedReceipt {
type Output = ProcessedReceipt;
Expand All @@ -19,8 +19,7 @@ impl AsCairoFormat for BaseProcessedReceipt {
.collect();

let proof_bytes_len = proof_felts.iter().map(|f| f.bytes_len).collect();
let proof_result: Vec<Vec<FieldElement>> =
proof_felts.iter().map(|f| f.felts.clone()).collect();
let proof_result: Vec<Vec<Felt>> = proof_felts.iter().map(|f| f.felts.clone()).collect();
ProcessedReceipt {
key,
block_number: self.block_number,
Expand All @@ -39,7 +38,7 @@ pub struct ProcessedReceipt {
/// proof_bytes_len is the byte( 8 bit ) length from each proof string
pub proof_bytes_len: Vec<u64>,
#[serde_as(as = "Vec<Vec<UfeHex>>")]
pub proof: Vec<Vec<FieldElement>>,
pub proof: Vec<Vec<Felt>>,
}

#[cfg(test)]
Expand Down
6 changes: 3 additions & 3 deletions hdp/src/primitives/processed_types/cairo_format/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use alloy::primitives::StorageKey;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use starknet::core::serde::unsigned_field_element::UfeHex;
use starknet_crypto::FieldElement;
use starknet_types_core::felt::Felt;

use crate::primitives::processed_types::storage::ProcessedStorage as BaseProcessedStorage;

Expand Down Expand Up @@ -36,10 +36,10 @@ impl AsCairoFormat for BaseProcessedStorage {
pub struct ProcessedStorage {
// chunked address
#[serde_as(as = "Vec<UfeHex>")]
pub address: Vec<FieldElement>,
pub address: Vec<Felt>,
// chunked storage slot
#[serde_as(as = "Vec<UfeHex>")]
pub slot: Vec<FieldElement>,
pub slot: Vec<Felt>,
pub storage_key: StorageKey,
pub proofs: Vec<ProcessedMPTProof>,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::primitives::processed_types::transaction::ProcessedTransaction as Bas
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use starknet::core::serde::unsigned_field_element::UfeHex;
use starknet_crypto::FieldElement;
use starknet_types_core::felt::Felt;

impl AsCairoFormat for BaseProcessedTransaction {
type Output = ProcessedTransaction;
Expand All @@ -19,8 +19,7 @@ impl AsCairoFormat for BaseProcessedTransaction {
.collect();

let proof_bytes_len = proof_felts.iter().map(|f| f.bytes_len).collect();
let proof_result: Vec<Vec<FieldElement>> =
proof_felts.iter().map(|f| f.felts.clone()).collect();
let proof_result: Vec<Vec<Felt>> = proof_felts.iter().map(|f| f.felts.clone()).collect();
ProcessedTransaction {
key,
block_number: self.block_number,
Expand All @@ -38,7 +37,7 @@ pub struct ProcessedTransaction {
/// proof_bytes_len is the byte( 8 bit ) length from each proof string
pub proof_bytes_len: Vec<u64>,
#[serde_as(as = "Vec<Vec<UfeHex>>")]
pub proof: Vec<Vec<FieldElement>>,
pub proof: Vec<Vec<Felt>>,
}

#[cfg(test)]
Expand Down
Loading

0 comments on commit 6f02adb

Please sign in to comment.