Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename all remaining FieldElements to Felt for consistency #2433

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions bin/saya/src/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl TryFrom<SayaArgs> for SayaConfig {

#[cfg(test)]
mod tests {
use katana_primitives::felt::FieldElement;
use katana_primitives::Felt;

use super::*;
use crate::args::data_availability::CelestiaOptions;
Expand Down Expand Up @@ -249,12 +249,12 @@ mod tests {

let expected = StarknetAccountData {
starknet_url: Url::parse("http://localhost:5030").unwrap(),
chain_id: FieldElement::from_hex("0x534e5f5345504f4c4941").unwrap(),
signer_address: FieldElement::from_hex(
chain_id: Felt::from_hex("0x534e5f5345504f4c4941").unwrap(),
signer_address: Felt::from_hex(
"0x3aa0a12c62a46a200b1a1211e8cd09b520164104e76d79648ca459cf05db94",
)
.unwrap(),
signer_key: FieldElement::from_hex(
signer_key: Felt::from_hex(
"0x6b41bfa82e791a8b4e6b3ee058cb25b89714e4a23bd9a1ad6e6ba0bbc0b145b",
)
.unwrap(),
Expand Down
6 changes: 3 additions & 3 deletions bin/saya/src/args/proof.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use clap::Args;
use dojo_utils::env::DOJO_WORLD_ADDRESS_ENV_VAR;
use katana_primitives::felt::FieldElement;
use katana_primitives::Felt;
use url::Url;

#[derive(Debug, Args, Clone)]
pub struct ProofOptions {
#[arg(help = "The address of the World contract.")]
#[arg(long = "world", env = DOJO_WORLD_ADDRESS_ENV_VAR)]
pub world_address: FieldElement,
pub world_address: Felt,

Check warning on line 10 in bin/saya/src/args/proof.rs

View check run for this annotation

Codecov / codecov/patch

bin/saya/src/args/proof.rs#L10

Added line #L10 was not covered by tests

#[arg(help = "The address of the Fact Registry contract.")]
#[arg(long = "registry")]
pub fact_registry_address: FieldElement,
pub fact_registry_address: Felt,

Check warning on line 14 in bin/saya/src/args/proof.rs

View check run for this annotation

Codecov / codecov/patch

bin/saya/src/args/proof.rs#L14

Added line #L14 was not covered by tests

#[arg(long)]
#[arg(value_name = "PROVER URL")]
Expand Down
6 changes: 3 additions & 3 deletions bin/saya/src/args/starknet_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
DOJO_ACCOUNT_ADDRESS_ENV_VAR, DOJO_KEYSTORE_PASSWORD_ENV_VAR, DOJO_KEYSTORE_PATH_ENV_VAR,
DOJO_PRIVATE_KEY_ENV_VAR, STARKNET_RPC_URL_ENV_VAR,
};
use katana_primitives::felt::FieldElement;
use katana_primitives::Felt;
use url::Url;

#[derive(Debug, Args, Clone)]
Expand All @@ -21,11 +21,11 @@

#[arg(long, env = DOJO_ACCOUNT_ADDRESS_ENV_VAR)]
#[arg(help = "The address of the starknet account.")]
pub signer_address: FieldElement,
pub signer_address: Felt,

Check warning on line 24 in bin/saya/src/args/starknet_account.rs

View check run for this annotation

Codecov / codecov/patch

bin/saya/src/args/starknet_account.rs#L24

Added line #L24 was not covered by tests

#[arg(long, env = DOJO_PRIVATE_KEY_ENV_VAR)]
#[arg(help = "The private key of the starknet account.")]
pub signer_key: Option<FieldElement>,
pub signer_key: Option<Felt>,

#[arg(long = "keystore", env = DOJO_KEYSTORE_PATH_ENV_VAR)]
#[arg(value_name = "PATH")]
Expand Down
4 changes: 2 additions & 2 deletions bin/scheduler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::sync::Arc;

use clap::Parser;
use katana_primitives::felt::FieldElement;
use katana_primitives::Felt;
use saya_core::prover::{HttpProverParams, ProgramInput, ProverIdentifier, Scheduler};
use saya_core::ProverAccessKey;
use serde::{Deserialize, Serialize};
Expand All @@ -14,7 +14,7 @@
#[clap(author, version, about, long_about = None)]
pub struct CliInput {
#[arg(short, long)]
pub world: FieldElement,
pub world: Felt,

Check warning on line 17 in bin/scheduler/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/scheduler/src/main.rs#L17

Added line #L17 was not covered by tests
#[arg(short, long)]
pub key: String,
pub files: Vec<std::path::PathBuf>,
Expand Down
17 changes: 8 additions & 9 deletions crates/katana/controller/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use katana_primitives::genesis::allocation::{GenesisAllocation, GenesisContractAlloc};
use katana_primitives::genesis::constant::CONTROLLER_ACCOUNT_CONTRACT_CLASS_HASH;
use katana_primitives::genesis::Genesis;
use katana_primitives::FieldElement;
use katana_primitives::Felt;
use slot::account_sdk::signers::webauthn::{CredentialID, WebauthnBackend, WebauthnSigner};
use slot::account_sdk::signers::{HashSigner, Signer, SignerTrait};
use slot::account_sdk::OriginProvider;
Expand Down Expand Up @@ -47,9 +47,8 @@
storage: Some(get_contract_storage(credential_id, public_key)?),
};

let address = ContractAddress::from(FieldElement::from_bytes_be(
&user.contract_address.to_bytes_be(),
));
let address =
ContractAddress::from(Felt::from_bytes_be(&user.contract_address.to_bytes_be()));

(address, GenesisAllocation::Contract(account))
};
Expand Down Expand Up @@ -98,7 +97,7 @@
storage: Some(get_contract_storage(credential_id, public_key)?),
};

let address = ContractAddress::from(FieldElement::from_bytes_be(
let address = ContractAddress::from(Felt::from_bytes_be(

Check warning on line 100 in crates/katana/controller/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/katana/controller/src/lib.rs#L100

Added line #L100 was not covered by tests
&user.account.contract_address.to_bytes_be(),
));

Expand Down Expand Up @@ -187,7 +186,7 @@
let storage = get_storage_var_address(MULTIPLE_OWNERS_COMPONENT_SUB_STORAGE, &[guid])?;

// 1 for boolean True in Cairo. Refer to the provided link above.
let storage_mapping = HashMap::from([(storage, FieldElement::ONE)]);
let storage_mapping = HashMap::from([(storage, Felt::ONE)]);

Ok(storage_mapping)
}
Expand All @@ -206,12 +205,12 @@
// Controller address: 0x00397333e993ae162b476690e1401548ae97a8819955506b8bc918e067bdafc3
// <https://sepolia.starkscan.co/contract/0x00397333e993ae162b476690e1401548ae97a8819955506b8bc918e067bdafc3#contract-storage>

const CONTROLLER_ADDRESS: FieldElement =
const CONTROLLER_ADDRESS: Felt =
felt!("0x00397333e993ae162b476690e1401548ae97a8819955506b8bc918e067bdafc3");

const STORAGE_KEY: FieldElement =
const STORAGE_KEY: Felt =
felt!("0x023d8ecd0d641047a8d21e3cd8016377ed5c9cd9009539cd92b73adb8c023f10");
const STORAGE_VALUE: FieldElement = felt!("0x1");
const STORAGE_VALUE: Felt = felt!("0x1");

const WEBAUTHN_CREDENTIAL_ID: &str = "ja0NkHny-dlfPnClYECdmce0xTCuGT0xFjeuStaVqCI";
const WEBAUTHN_PUBLIC_KEY: &str = "pQECAyYgASFYIBLHWNmpxCtO47cfOXw9nFCGftMq57xhvQC98aY_zQchIlggIgGHmWwQe1_FGi9GYqcYYpoPC9mkkf0f1rVD5UoGPEA";
Expand Down
4 changes: 2 additions & 2 deletions crates/katana/core/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use katana_primitives::chain::ChainId;
use katana_primitives::env::BlockEnv;
use katana_primitives::transaction::TxHash;
use katana_primitives::version::CURRENT_STARKNET_VERSION;
use katana_primitives::FieldElement;
use katana_primitives::Felt;
use katana_provider::providers::fork::ForkedProvider;
use katana_provider::providers::in_memory::InMemoryProvider;
use katana_provider::traits::block::{BlockHashProvider, BlockWriter};
Expand Down Expand Up @@ -157,7 +157,7 @@ impl<EF: ExecutorFactory> Backend<EF> {
};

let tx_hashes = txs.iter().map(|tx| tx.hash).collect::<Vec<TxHash>>();
let header = Header::new(partial_header, FieldElement::ZERO);
let header = Header::new(partial_header, Felt::ZERO);
let block = Block { header, body: txs }.seal();
let block = SealedBlockWithStatus { block, status: FinalityStatus::AcceptedOnL2 };

Expand Down
6 changes: 3 additions & 3 deletions crates/katana/core/src/backend/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ mod tests {
use katana_primitives::state::StateUpdatesWithDeclaredClasses;
use katana_primitives::trace::TxExecInfo;
use katana_primitives::transaction::{InvokeTx, Tx, TxWithHash};
use katana_primitives::FieldElement;
use katana_primitives::Felt;
use katana_provider::providers::in_memory::InMemoryProvider;
use katana_provider::traits::block::{
BlockHashProvider, BlockNumberProvider, BlockProvider, BlockStatusProvider, BlockWriter,
Expand Down Expand Up @@ -185,7 +185,7 @@ mod tests {

let genesis = Genesis {
number: 23,
parent_hash: FieldElement::ZERO,
parent_hash: Felt::ZERO,
state_root: felt!("1334"),
timestamp: 6868,
gas_prices: GasPrices { eth: 9090, strk: 8080 },
Expand Down Expand Up @@ -233,7 +233,7 @@ mod tests {
status: FinalityStatus::AcceptedOnL1,
block: Block {
header: Header {
parent_hash: FieldElement::ZERO,
parent_hash: Felt::ZERO,
number: 1,
gas_prices: GasPrices::default(),
timestamp: 123456,
Expand Down
18 changes: 9 additions & 9 deletions crates/katana/core/src/service/messaging/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use katana_primitives::transaction::L1HandlerTx;
use katana_primitives::utils::transaction::{
compute_l1_to_l2_message_hash, compute_l2_to_l1_message_hash,
};
use katana_primitives::FieldElement;
use katana_primitives::Felt;
use starknet::core::types::EthAddress;
use tracing::{debug, trace, warn};

Expand Down Expand Up @@ -208,7 +208,7 @@ fn l1_handler_tx_from_log(log: Log, chain_id: ChainId) -> MessengerResult<L1Hand

// In an l1_handler transaction, the first element of the calldata is always the Ethereum
// address of the sender (msg.sender). https://docs.starknet.io/documentation/architecture_and_concepts/Network_Architecture/messaging-mechanism/#l1-l2-messages
let mut calldata = vec![FieldElement::from(from_address)];
let mut calldata = vec![Felt::from(from_address)];
calldata.extend(payload.clone());

Ok(L1HandlerTx {
Expand All @@ -218,7 +218,7 @@ fn l1_handler_tx_from_log(log: Log, chain_id: ChainId) -> MessengerResult<L1Hand
paid_fee_on_l1,
nonce: nonce.into(),
entry_point_selector,
version: FieldElement::ZERO,
version: Felt::ZERO,
contract_address: contract_address.into(),
})
}
Expand All @@ -238,8 +238,8 @@ fn parse_messages(messages: &[MessageToL1]) -> Vec<U256> {
.collect()
}

fn felt_from_u256(v: U256) -> FieldElement {
FieldElement::from_str(format!("{:#064x}", v).as_str()).unwrap()
fn felt_from_u256(v: U256) -> Felt {
Felt::from_str(format!("{:#064x}", v).as_str()).unwrap()
}

#[cfg(test)]
Expand All @@ -257,7 +257,7 @@ mod tests {
let from_address = felt!("0xbe3C44c09bc1a3566F3e1CA12e5AbA0fA4Ca72Be");
let to_address = felt!("0x39dc79e64f4bb3289240f88e0bae7d21735bef0d1a51b2bf3c4730cb16983e1");
let selector = felt!("0x2f15cff7b0eed8b9beb162696cf4e3e0e35fa7032af69cd1b7d2ac67a13f40f");
let payload = vec![FieldElement::ONE, FieldElement::TWO];
let payload = vec![Felt::ONE, Felt::TWO];
let nonce = 783082_u64;
let fee = 30000_u128;

Expand Down Expand Up @@ -303,8 +303,8 @@ mod tests {
chain_id,
message_hash,
paid_fee_on_l1: fee,
version: FieldElement::ZERO,
nonce: FieldElement::from(nonce),
version: Felt::ZERO,
nonce: Felt::from(nonce),
contract_address: to_address.into(),
entry_point_selector: selector,
};
Expand All @@ -319,7 +319,7 @@ mod tests {
fn parse_msg_to_l1() {
let from_address = selector!("from_address");
let to_address = selector!("to_address");
let payload = vec![FieldElement::ONE, FieldElement::TWO];
let payload = vec![Felt::ONE, Felt::TWO];

let messages = vec![MessageToL1 { from_address: from_address.into(), to_address, payload }];

Expand Down
6 changes: 3 additions & 3 deletions crates/katana/core/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use futures::stream::{Fuse, Stream, StreamExt};
use katana_executor::ExecutorFactory;
use katana_pool::{TransactionPool, TxPool};
use katana_primitives::transaction::ExecutableTxWithHash;
use katana_primitives::FieldElement;
use katana_primitives::Felt;
use tracing::{error, info};

use self::block_producer::BlockProducer;
Expand Down Expand Up @@ -97,11 +97,11 @@ pub struct TransactionMiner {
/// stores whether there are pending transacions (if known)
has_pending_txs: Option<bool>,
/// Receives hashes of transactions that are ready from the pool
rx: Fuse<Receiver<FieldElement>>,
rx: Fuse<Receiver<Felt>>,
}

impl TransactionMiner {
pub fn new(rx: Receiver<FieldElement>) -> Self {
pub fn new(rx: Receiver<Felt>) -> Self {
Self { rx: rx.fuse(), has_pending_txs: None }
}

Expand Down
8 changes: 4 additions & 4 deletions crates/katana/executor/benches/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use katana_primitives::block::GasPrices;
use katana_primitives::env::{BlockEnv, CfgEnv, FeeTokenAddressses};
use katana_primitives::genesis::constant::DEFAULT_FEE_TOKEN_ADDRESS;
use katana_primitives::transaction::{ExecutableTxWithHash, InvokeTx, InvokeTxV1};
use katana_primitives::FieldElement;
use katana_primitives::Felt;
use starknet::macros::{felt, selector};

pub fn tx() -> ExecutableTxWithHash {
Expand All @@ -11,10 +11,10 @@ pub fn tx() -> ExecutableTxWithHash {
calldata: vec![
DEFAULT_FEE_TOKEN_ADDRESS.into(),
selector!("transfer"),
FieldElement::THREE,
Felt::THREE,
felt!("0x100"),
FieldElement::ONE,
FieldElement::ZERO,
Felt::ONE,
Felt::ZERO,
],
max_fee: 10_000,
..Default::default()
Expand Down
6 changes: 3 additions & 3 deletions crates/katana/executor/src/abstraction/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use katana_primitives::class::ClassHash;
use katana_primitives::contract::{ContractAddress, Nonce};
use katana_primitives::FieldElement;
use katana_primitives::Felt;

/// Errors that can be returned by the executor.
#[derive(Debug, thiserror::Error)]
Expand All @@ -16,7 +16,7 @@ pub enum ExecutionError {
ClassAlreadyDeclared(ClassHash),

#[error("Entry point {0:#x} not found in contract")]
EntryPointNotFound(FieldElement),
EntryPointNotFound(Felt),

#[error("Invalid input: {input_descriptor}; {info}")]
InvalidInput { input_descriptor: String, info: String },
Expand Down Expand Up @@ -46,7 +46,7 @@ pub enum ExecutionError {
"Insufficient balance: max fee {max_fee} exceeds account balance u256({balance_low}, \
{balance_high})"
)]
InsufficientBalance { max_fee: u128, balance_low: FieldElement, balance_high: FieldElement },
InsufficientBalance { max_fee: u128, balance_low: Felt, balance_high: Felt },

#[error("Actual fee ({actual_fee}) exceeded max fee ({max_fee})")]
ActualFeeExceedsMaxFee { max_fee: u128, actual_fee: u128 },
Expand Down
4 changes: 2 additions & 2 deletions crates/katana/executor/src/abstraction/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use katana_primitives::block::ExecutableBlock;
use katana_primitives::env::{BlockEnv, CfgEnv};
use katana_primitives::fee::TxFeeInfo;
use katana_primitives::transaction::{ExecutableTxWithHash, TxWithHash};
use katana_primitives::FieldElement;
use katana_primitives::Felt;
use katana_provider::traits::state::StateProvider;

use crate::{
Expand Down Expand Up @@ -72,5 +72,5 @@ pub trait ExecutorExt {
) -> Vec<Result<TxFeeInfo, ExecutionError>>;

/// Perform a contract entry point call and return the output.
fn call(&self, call: EntryPointCall) -> Result<Vec<FieldElement>, ExecutionError>;
fn call(&self, call: EntryPointCall) -> Result<Vec<Felt>, ExecutionError>;
}
6 changes: 3 additions & 3 deletions crates/katana/executor/src/abstraction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use katana_primitives::receipt::Receipt;
use katana_primitives::state::{StateUpdates, StateUpdatesWithDeclaredClasses};
use katana_primitives::trace::TxExecInfo;
use katana_primitives::transaction::TxWithHash;
use katana_primitives::FieldElement;
use katana_primitives::Felt;
use katana_provider::traits::contract::ContractClassProvider;
use katana_provider::traits::state::StateProvider;
use katana_provider::ProviderResult;
Expand Down Expand Up @@ -96,9 +96,9 @@ pub struct EntryPointCall {
/// The address of the contract whose function you're calling.
pub contract_address: ContractAddress,
/// The input to the function.
pub calldata: Vec<FieldElement>,
pub calldata: Vec<Felt>,
/// The contract function name.
pub entry_point_selector: FieldElement,
pub entry_point_selector: Felt,
}

#[allow(clippy::large_enum_variant)]
Expand Down
4 changes: 2 additions & 2 deletions crates/katana/executor/src/implementation/blockifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use katana_primitives::env::{BlockEnv, CfgEnv};
use katana_primitives::fee::TxFeeInfo;
use katana_primitives::transaction::{ExecutableTx, ExecutableTxWithHash, TxWithHash};
use katana_primitives::FieldElement;
use katana_primitives::Felt;
use katana_provider::traits::state::StateProvider;
use tracing::info;

Expand Down Expand Up @@ -278,7 +278,7 @@
})
}

fn call(&self, call: EntryPointCall) -> Result<Vec<FieldElement>, ExecutionError> {
fn call(&self, call: EntryPointCall) -> Result<Vec<Felt>, ExecutionError> {

Check warning on line 281 in crates/katana/executor/src/implementation/blockifier/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/katana/executor/src/implementation/blockifier/mod.rs#L281

Added line #L281 was not covered by tests
let block_context = &self.block_context;
let mut state = self.state.0.lock();
let state = MutRefState::new(&mut state.inner);
Expand Down
Loading
Loading