Skip to content

Commit

Permalink
patch with starknet felt
Browse files Browse the repository at this point in the history
  • Loading branch information
rkdud007 committed Sep 23, 2024
1 parent 2cbf18b commit 7b8a405
Show file tree
Hide file tree
Showing 17 changed files with 754 additions and 766 deletions.
1,350 changes: 676 additions & 674 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 @@ -35,8 +35,9 @@ 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 = "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"
Expand Down
4 changes: 2 additions & 2 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
29 changes: 14 additions & 15 deletions hdp/src/preprocessor/module_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use cairo_lang_starknet_classes::casm_contract_class::{
CasmContractClass, StarknetSierraCompilationError,
};
use starknet_crypto::Felt;

use crate::{
constant::HERODOTUS_PROGRAM_REGISTRY_URL,
Expand All @@ -13,7 +14,7 @@ use crate::{
},
};
use reqwest::Client;
use starknet_crypto::FieldElement;

use std::{path::PathBuf, str::FromStr};
use thiserror::Error;
use tracing::info;
Expand Down Expand Up @@ -64,8 +65,7 @@ impl ModuleRegistry {
local_class_path: Option<PathBuf>,
module_inputs: Vec<String>,
) -> Result<ExtendedModule, ModuleRegistryError> {
let program_hash =
program_hash.map(|program_hash| FieldElement::from_hex_be(&program_hash).unwrap());
let program_hash = program_hash.map(|program_hash| Felt::from_hex(&program_hash).unwrap());
let module_inputs: Result<Vec<ModuleInput>, _> = module_inputs
.into_iter()
.map(|input| ModuleInput::from_str(&input))
Expand All @@ -80,7 +80,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 @@ -103,7 +103,7 @@ impl ModuleRegistry {
};

let program_hash = casm.compiled_class_hash();
let converted_hash = FieldElement::from_bytes_be(&program_hash.to_bytes_be()).unwrap();
let converted_hash = Felt::from_bytes_be(&program_hash.to_bytes_be());
info!("program Hash: {:#?}", converted_hash);

let module = Module {
Expand Down Expand Up @@ -138,7 +138,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 @@ -177,15 +177,16 @@ impl ModuleRegistry {
#[cfg(test)]
mod tests {

use starknet_crypto::Felt;

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 @@ -211,10 +212,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_crypto::Felt;

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

Expand Down Expand Up @@ -34,7 +34,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_crypto::Felt;

impl AsCairoFormat for BaseProcessedDatalakeCompute {
type Output = ProcessedDatalakeCompute;
Expand All @@ -29,10 +29,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
24 changes: 7 additions & 17 deletions hdp/src/primitives/processed_types/cairo_format/felt_vec_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use anyhow::Result;
use serde::Serialize;
use serde_with::serde_as;
use starknet::core::serde::unsigned_field_element::UfeHex;
use starknet_crypto::FieldElement;
use starknet_crypto::Felt;

#[serde_as]
#[derive(Serialize, Debug)]
pub struct FieldElementVectorUnit {
#[serde_as(as = "Vec<UfeHex>")]
pub felts: Vec<FieldElement>,
pub felts: Vec<Felt>,
pub bytes_len: u64,
}

Expand All @@ -25,8 +25,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 @@ -53,7 +52,7 @@ mod tests {
let result = FieldElementVectorUnit::from_bytes(&bytes).unwrap();
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 @@ -62,10 +61,7 @@ mod tests {
let result = FieldElementVectorUnit::from_bytes(&bytes).unwrap();
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 @@ -74,13 +70,7 @@ mod tests {
let result = FieldElementVectorUnit::from_bytes(&bytes).unwrap();
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_crypto::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_crypto::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_crypto::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_crypto::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_crypto::Felt;

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

Expand Down Expand Up @@ -37,10 +37,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_crypto::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 7b8a405

Please sign in to comment.