Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Rename Declare to DeclareDeprecated & DeclareV2 to Declare #1220

Merged
merged 59 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
d0b2590
Add GasPricess & FeeTokenAddresses structs
fmoletta Jan 19, 2024
6327d7a
Update code
fmoletta Jan 19, 2024
3ea4172
Merge branch 'main' of github.com:lambdaclass/starknet_in_rust into u…
fmoletta Jan 19, 2024
e24dacd
RpcStateReader::get_gas_price fetch both
fmoletta Jan 19, 2024
5a4d984
Update code
fmoletta Jan 19, 2024
c1d4bd0
Clippy
fmoletta Jan 19, 2024
81a61f2
Fix comment
fmoletta Jan 19, 2024
8d6168d
Add VersionSpecificAccountTxFields struct
fmoletta Jan 22, 2024
badc6a5
Integrate into TransactionExecutionContext
fmoletta Jan 22, 2024
2bb0091
Replace max_fee field with account_tx_fields for InvokeFunction tx
fmoletta Jan 22, 2024
93d0d61
Check tx account fields version when creating Invoke tx
fmoletta Jan 22, 2024
bcaab19
Replace max_fee field with account_tx_fields for DeclareV3 tx
fmoletta Jan 22, 2024
7f44d13
Replace max_fee field with account_tx_fields for DeployAccount tx
fmoletta Jan 22, 2024
e7de24d
Update get_transaction_context for Txs not affected by this change
fmoletta Jan 22, 2024
444e288
Fixes
fmoletta Jan 22, 2024
a832b62
Fixes
fmoletta Jan 22, 2024
d08c64a
Fixes
fmoletta Jan 22, 2024
9815fa1
Fix handling of ignore_max_fee
fmoletta Jan 22, 2024
5bb3c5f
Improve placeholder method
fmoletta Jan 22, 2024
127da88
Handle TODOs
fmoletta Jan 22, 2024
0099b22
Implement get_onchain_data_cost
fmoletta Jan 23, 2024
a6940c4
Refactor
fmoletta Jan 23, 2024
8ae7451
Generalize fn
fmoletta Jan 23, 2024
791d45e
Start implementing check_fee_bounds
fmoletta Jan 23, 2024
d2aa130
Finish implementing check_fee_bounds
fmoletta Jan 23, 2024
f217d86
Replace old code
fmoletta Jan 23, 2024
c16c449
Fixes
fmoletta Jan 23, 2024
49c0830
Implement FeeType for VersionSpecificAccountTxFields
fmoletta Jan 23, 2024
f7b7400
Update other txs
fmoletta Jan 23, 2024
5c265b1
Clippy
fmoletta Jan 23, 2024
ccdfac2
Add test
fmoletta Jan 23, 2024
8070874
Simplify
fmoletta Jan 23, 2024
03f9487
Move test
fmoletta Jan 23, 2024
87c27a2
Merge branch 'main' of github.com:lambdaclass/starknet_in_rust into u…
fmoletta Jan 26, 2024
405579f
Return the appropiate error whe converting to deprecated declare
fmoletta Jan 26, 2024
73a6cd1
Fix conversion between sn api Invoke and sir InvokeFunction tx
fmoletta Jan 26, 2024
3b28a1d
Fix conversion between sn api and sir DeployAccount tx
fmoletta Jan 29, 2024
134e955
Implement declare_tx_from_sn_api_transaction
fmoletta Jan 29, 2024
2ffd1ed
Remove error
fmoletta Jan 29, 2024
9097246
Clippy
fmoletta Jan 29, 2024
d788483
Add V3 deser
fmoletta Jan 31, 2024
813d43a
Merge branch 'main' into map-sn-api-ro-sir-structs
fmoletta Jan 31, 2024
0810310
Merge branch 'main' of github.com:lambdaclass/starknet_in_rust into m…
fmoletta Feb 2, 2024
1060fea
Rename Declare to DeclareDeprecated
fmoletta Feb 2, 2024
f89067c
Rename module
fmoletta Feb 2, 2024
21ab314
Rename DeclareV2 to Declare
fmoletta Feb 2, 2024
19a0950
Rename module
fmoletta Feb 2, 2024
e1d7fe6
Push
fmoletta Feb 2, 2024
43b00b6
Rename tx hash calculation fns
fmoletta Feb 2, 2024
2d7fa5a
Fixes
fmoletta Feb 2, 2024
37994e8
Merge branch 'main' of github.com:lambdaclass/starknet_in_rust into r…
fmoletta Feb 5, 2024
70fa0d8
Fix merge
fmoletta Feb 5, 2024
79626de
Remove internal from variable names in tests
fmoletta Feb 5, 2024
3fb91e9
Fmt + fix typo
fmoletta Feb 5, 2024
a735a5e
Merge branch 'main' into rename-declare
fmoletta Feb 7, 2024
d18c636
Merge branch 'main' into rename-declare
fmoletta Feb 7, 2024
1f6b6d6
Merge branch 'main' of github.com:lambdaclass/starknet_in_rust into r…
fmoletta Feb 7, 2024
62b19c2
fmt
fmoletta Feb 7, 2024
09794d9
Merge branch 'main' of github.com:lambdaclass/starknet_in_rust into r…
fmoletta Feb 8, 2024
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
4 changes: 2 additions & 2 deletions bench/internals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use starknet_in_rust::{
contract_class_cache::PermanentContractClassCache,
in_memory_state_reader::InMemoryStateReader,
},
transaction::{declare::Declare, Deploy, DeployAccount, InvokeFunction},
transaction::{DeclareDeprecated, Deploy, DeployAccount, InvokeFunction},
utils::{Address, ClassHash},
};
use std::{hint::black_box, sync::Arc};
Expand Down Expand Up @@ -142,7 +142,7 @@ pub fn declare(
let address = CONTRACT_ADDRESS.clone();
scope(|| {
// new consumes more execution time than raw struct instantiation
let declare_tx = Declare::new(
let declare_tx = DeclareDeprecated::new(
class,
StarknetChainId::TestNet.to_felt(),
address,
Expand Down
10 changes: 5 additions & 5 deletions bench/yas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use starknet_in_rust::{
state::{
cached_state::CachedState, contract_class_cache::ContractClassCache, state_api::StateReader,
},
transaction::{DeclareV2, InvokeFunction},
transaction::{Declare, InvokeFunction},
utils::Address,
};
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -369,7 +369,7 @@ where
let sender_address = Address(*ACCOUNT_ADDRESS);
let nonce = state.get_nonce_at(&sender_address).unwrap();

let tx_execution_info = DeclareV2::new(
let tx_execution_info = Declare::new(
&sierra_contract_class,
Some(casm_contract_class),
casm_class_hash,
Expand Down Expand Up @@ -410,7 +410,7 @@ where
let sender_address = Address(*ACCOUNT_ADDRESS);
let nonce = state.get_nonce_at(&sender_address).unwrap();

let tx_execution_info = DeclareV2::new(
let tx_execution_info = Declare::new(
&sierra_contract_class,
Some(casm_contract_class),
casm_class_hash,
Expand Down Expand Up @@ -451,7 +451,7 @@ where
let sender_address = Address(*ACCOUNT_ADDRESS);
let nonce = state.get_nonce_at(&sender_address).unwrap();

let tx_execution_info = DeclareV2::new(
let tx_execution_info = Declare::new(
&sierra_contract_class,
Some(casm_contract_class),
casm_class_hash,
Expand Down Expand Up @@ -492,7 +492,7 @@ where
let sender_address = Address(*ACCOUNT_ADDRESS);
let nonce = state.get_nonce_at(&sender_address).unwrap();

let tx_execution_info = DeclareV2::new(
let tx_execution_info = Declare::new(
&sierra_contract_class,
Some(casm_contract_class),
casm_class_hash,
Expand Down
4 changes: 2 additions & 2 deletions examples/contract_execution/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use starknet_in_rust::{
cached_state::CachedState, contract_class_cache::PermanentContractClassCache,
in_memory_state_reader::InMemoryStateReader, state_api::State,
},
transaction::{DeclareV2, DeployAccount, InvokeFunction},
transaction::{Declare, DeployAccount, InvokeFunction},
utils::{calculate_sn_keccak, felt_to_hash, Address},
CasmContractClass, SierraContractClass,
};
Expand Down Expand Up @@ -159,7 +159,7 @@ fn test_contract(
//* --------------------------------------------
//* Declare new contract class
//* --------------------------------------------
let declare_tx = DeclareV2::new_with_tx_hash(
let declare_tx = Declare::new_with_tx_hash(
&sierra_contract_class,
Some(casm_class),
compiled_class_hash,
Expand Down
4 changes: 2 additions & 2 deletions examples/lru_cache/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use starknet_in_rust::{
contract_class_cache::{ContractClassCache, PermanentContractClassCache},
in_memory_state_reader::InMemoryStateReader,
},
transaction::{Declare, Deploy, InvokeFunction},
transaction::{DeclareDeprecated, Deploy, InvokeFunction},
utils::{calculate_sn_keccak, Address, ClassHash},
};
use std::{
Expand Down Expand Up @@ -53,7 +53,7 @@ fn run_contract(

let contract_class = ContractClass::from_path(contract_path.as_ref()).unwrap();

let declare_tx = Declare::new(
let declare_tx = DeclareDeprecated::new(
contract_class.clone(),
chain_id,
sender_address,
Expand Down
2 changes: 1 addition & 1 deletion src/core/transaction_hash/current.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pub(super) fn calculate_deploy_account_transaction_hash(
}

#[allow(clippy::too_many_arguments)]
pub(super) fn calculate_declare_v2_transaction_hash(
pub(super) fn calculate_declare_transaction_hash(
sierra_class_hash: Felt252,
compiled_class_hash: Felt252,
chain_id: Felt252,
Expand Down
13 changes: 5 additions & 8 deletions src/core/transaction_hash/deprecated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ pub(super) fn deprecated_calculate_deploy_account_transaction_hash(
)
}

/// Calculate the hash for a declared transaction.
pub fn deprecated_calculate_declare_transaction_hash(
/// Calculate the hash for a deprecated declare transaction.
pub fn calculate_declare_deprecated_transaction_hash(
contract_class: &ContractClass,
chain_id: Felt252,
sender_address: &Address,
Expand Down Expand Up @@ -185,11 +185,8 @@ fn preprocess_invoke_function_fields(
}
}

// ----------------------------
// V2 Hash Functions
// ----------------------------

pub(super) fn deprecated_calculate_declare_v2_transaction_hash(
/// Calculate the hash for a declare transaction.
pub(super) fn deprecated_calculate_declare_transaction_hash(
sierra_class_hash: Felt252,
compiled_class_hash: Felt252,
chain_id: Felt252,
Expand Down Expand Up @@ -255,7 +252,7 @@ mod tests {
}

#[test]
fn calculate_declare_hash_test() {
fn calculate_declare_deprecated_hash_test() {
let chain_id = StarknetChainId::MainNet;
let sender_address = Address(
Felt252::from_dec_str(
Expand Down
6 changes: 3 additions & 3 deletions src/core/transaction_hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn calculate_deploy_account_transaction_hash(

/// Calculate the hash for a Declare transaction of version 2+.
/// Uses the older pedersen version for deprecated account tx fields and the newer poseidon version for current account tx fields
pub fn calculate_declare_v2_transaction_hash(
pub fn calculate_declare_transaction_hash(
sierra_class_hash: Felt252,
compiled_class_hash: Felt252,
version: Felt252,
Expand All @@ -103,7 +103,7 @@ pub fn calculate_declare_v2_transaction_hash(
) -> Result<Felt252, HashError> {
match account_tx_fields {
VersionSpecificAccountTxFields::Deprecated(max_fee) => {
deprecated::deprecated_calculate_declare_v2_transaction_hash(
deprecated::deprecated_calculate_declare_transaction_hash(
sierra_class_hash,
compiled_class_hash,
chain_id,
Expand All @@ -114,7 +114,7 @@ pub fn calculate_declare_v2_transaction_hash(
)
}
VersionSpecificAccountTxFields::Current(fields) => {
Ok(current::calculate_declare_v2_transaction_hash(
Ok(current::calculate_declare_transaction_hash(
sierra_class_hash,
compiled_class_hash,
chain_id,
Expand Down
20 changes: 10 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ mod test {
ExecutionResourcesManager,
},
transaction::{
Declare, DeclareV2, Deploy, DeployAccount, InvokeFunction, L1Handler, Transaction,
VersionSpecificAccountTxFields,
Declare, DeclareDeprecated, Deploy, DeployAccount, InvokeFunction, L1Handler,
Transaction, VersionSpecificAccountTxFields,
},
utils::{
felt_to_hash,
Expand Down Expand Up @@ -824,8 +824,8 @@ mod test {
let class = CONTRACT_CLASS.clone();
let address = CONTRACT_ADDRESS.clone();
// new consumes more execution time than raw struct instantiation
let declare_tx = Transaction::Declare(
Declare::new(
let declare_tx = Transaction::DeclareDeprecated(
DeclareDeprecated::new(
class,
StarknetChainId::TestNet.to_felt(),
address,
Expand Down Expand Up @@ -977,14 +977,14 @@ mod test {
.unwrap();
}

fn declarev2_tx() -> DeclareV2 {
fn declarev2_tx() -> Declare {
let program_data = include_bytes!("../starknet_programs/cairo1/fibonacci.sierra");
let sierra_contract_class: SierraContractClass =
serde_json::from_slice(program_data).unwrap();

let sierra_class_hash = compute_sierra_class_hash(&sierra_contract_class).unwrap();

DeclareV2 {
Declare {
sender_address: TEST_ACCOUNT_CONTRACT_ADDRESS.clone(),
validate_entry_point_selector: *VALIDATE_DECLARE_ENTRY_POINT_SELECTOR,
version: 2.into(),
Expand All @@ -1006,7 +1006,7 @@ mod test {
#[test]
fn test_simulate_declare_v2() {
let (block_context, state) = create_account_tx_test_state().unwrap();
let declare_tx = Transaction::DeclareV2(Box::new(declarev2_tx()));
let declare_tx = Transaction::Declare(Box::new(declarev2_tx()));

simulate_transaction(
&[&declare_tx],
Expand Down Expand Up @@ -1173,7 +1173,7 @@ mod test {
let real_casm_class_hash = declare_v2.compiled_class_hash;
let wrong_casm_class_hash = Felt252::from(1);
declare_v2.compiled_class_hash = wrong_casm_class_hash;
let declare_tx = Transaction::DeclareV2(Box::new(declare_v2));
let declare_tx = Transaction::Declare(Box::new(declare_v2));

let err = declare_tx
.execute(
Expand Down Expand Up @@ -1255,7 +1255,7 @@ mod test {
// declare tx
// Signature & tx hash values are hand-picked for account validations to pass
let mut declare =
Declare::new(
DeclareDeprecated::new(
fib_contract_class,
chain_id,
Address(Felt252::ONE),
Expand All @@ -1277,7 +1277,7 @@ mod test {
let mut block_context = BlockContext::default();
block_context.starknet_os_config_mut().gas_price = GasPrices::new(12, 0);

let declare_tx = Transaction::Declare(declare);
let declare_tx = Transaction::DeclareDeprecated(declare);

let without_validate_fee = simulate_transaction(
&[&declare_tx],
Expand Down
Loading
Loading