Skip to content

Commit aa0ee34

Browse files
central_systest_blobs: deploy operator account
1 parent 16b1ded commit aa0ee34

5 files changed

Lines changed: 117 additions & 24 deletions

File tree

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/central_systest_blobs/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ http.workspace = true
2121
mockall.workspace = true
2222
serde.workspace = true
2323
serde_json.workspace = true
24+
starknet-core.workspace = true
25+
starknet-crypto.workspace = true
26+
starknet-types-core.workspace = true
2427
starknet_api = { workspace = true, features = ["testing"] }
2528
starknet_committer = { workspace = true, features = ["testing"] }
2629
starknet_patricia_storage = { workspace = true, features = ["testing"] }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6
1+
7

crates/central_systest_blobs/resources/preconfirmed_block.json

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"block_number": 1,
2+
"block_number": 2,
33
"pre_confirmed_block": {
44
"l1_da_mode": "CALLDATA",
55
"l1_data_gas_price": {
@@ -17,53 +17,68 @@
1717
"sequencer_address": "0x1000",
1818
"starknet_version": "0.14.3",
1919
"status": "PRE_CONFIRMED",
20-
"timestamp": 1001,
20+
"timestamp": 1002,
2121
"transaction_receipts": [
2222
{
23-
"actual_fee": "0x0",
23+
"actual_fee": "0xf8a7b",
2424
"events": [],
2525
"execution_resources": {
26-
"builtin_instance_counter": {},
26+
"builtin_instance_counter": {
27+
"pedersen_builtin": 12,
28+
"poseidon_builtin": 12,
29+
"range_check_builtin": 93
30+
},
2731
"data_availability": {
2832
"l1_data_gas": 0,
29-
"l1_gas": 0,
33+
"l1_gas": 3305,
3034
"l2_gas": 0
3135
},
3236
"n_memory_holes": 0,
33-
"n_steps": 0,
37+
"n_steps": 4602,
3438
"total_gas_consumed": {
3539
"l1_data_gas": 0,
36-
"l1_gas": 0,
37-
"l2_gas": 0
40+
"l1_gas": 3856,
41+
"l2_gas": 1014635
3842
}
3943
},
4044
"execution_status": "SUCCEEDED",
4145
"l2_to_l1_messages": [],
42-
"transaction_hash": "0x2bd201c1de8711bc3748efdbba3b2e997d44792dee9b4a8c598cf8663f99824",
46+
"transaction_hash": "0x3eb7b9db643a241dbb7bb6fcef605d767e2cd3acd626284587afac4507e52de",
4347
"transaction_index": 0
4448
}
4549
],
4650
"transaction_state_diffs": [
4751
{
48-
"declared_classes": [
52+
"declared_classes": [],
53+
"deployed_contracts": [
4954
{
50-
"class_hash": "0x77fcf11f339d18db724aa522729b4c0e4e04aa85a6f104c10b469c020207dc1",
51-
"compiled_class_hash": "0x1738a9f4a4bb3f014041cdb569087473d4ee4428328dc507cdac7da2df39b12"
55+
"address": "0xf99e7cdfbcce0bf14ce17e4c57fd2d12ad1bca5fc8e46a9fbafc36b59a9955",
56+
"class_hash": "0x77fcf11f339d18db724aa522729b4c0e4e04aa85a6f104c10b469c020207dc1"
5257
}
5358
],
54-
"deployed_contracts": [],
5559
"migrated_compiled_classes": [],
56-
"nonces": {},
60+
"nonces": {
61+
"0xf99e7cdfbcce0bf14ce17e4c57fd2d12ad1bca5fc8e46a9fbafc36b59a9955": "0x1"
62+
},
5763
"old_declared_contracts": [],
5864
"replaced_classes": [],
59-
"storage_diffs": {}
65+
"storage_diffs": {
66+
"0xf99e7cdfbcce0bf14ce17e4c57fd2d12ad1bca5fc8e46a9fbafc36b59a9955": [
67+
{
68+
"key": "0x3b28019ccfdbd30ffc65951d94bb85c9e2b8434111a000b5afd533ce65f57a4",
69+
"value": "0x411494b501a98abd8262b0da1351e17899a0c4ef23dd2f96fec5ba847310b20"
70+
}
71+
]
72+
}
6073
}
6174
],
6275
"transactions": [
6376
{
64-
"account_deployment_data": [],
6577
"class_hash": "0x77fcf11f339d18db724aa522729b4c0e4e04aa85a6f104c10b469c020207dc1",
66-
"compiled_class_hash": "0x1738a9f4a4bb3f014041cdb569087473d4ee4428328dc507cdac7da2df39b12",
78+
"constructor_calldata": [
79+
"0x411494b501a98abd8262b0da1351e17899a0c4ef23dd2f96fec5ba847310b20"
80+
],
81+
"contract_address_salt": "0x0",
6782
"fee_data_availability_mode": 0,
6883
"nonce": "0x0",
6984
"nonce_data_availability_mode": 0,
@@ -82,11 +97,14 @@
8297
"max_price_per_unit": "0x0"
8398
}
8499
},
85-
"sender_address": "0x424f4f545354524150",
86-
"signature": [],
100+
"sender_address": "0xf99e7cdfbcce0bf14ce17e4c57fd2d12ad1bca5fc8e46a9fbafc36b59a9955",
101+
"signature": [
102+
"0x4bf92970c40634da1a0452af752326723ae810809c676aa06fa5ef76e77cc26",
103+
"0x715137c17ff9a873f7d05def6648c93ee7fe0715ad3f21fbb1b59ed76bb1193"
104+
],
87105
"tip": "0x0",
88-
"transaction_hash": "0x2bd201c1de8711bc3748efdbba3b2e997d44792dee9b4a8c598cf8663f99824",
89-
"type": "DECLARE",
106+
"transaction_hash": "0x3eb7b9db643a241dbb7bb6fcef605d767e2cd3acd626284587afac4507e52de",
107+
"type": "DEPLOY_ACCOUNT",
90108
"version": "0x3"
91109
}
92110
]

crates/central_systest_blobs/src/cende_blob_regression_test.rs

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,41 +52,52 @@ use starknet_api::block_hash::block_hash_calculator::{
5252
TransactionHashingData,
5353
};
5454
use starknet_api::consensus_transaction::InternalConsensusTransaction;
55-
use starknet_api::contract_address;
5655
use starknet_api::contract_class::compiled_class_hash::HashVersion;
5756
use starknet_api::core::{ChainId, Nonce, OsChainInfo};
5857
use starknet_api::data_availability::{DataAvailabilityMode, L1DataAvailabilityMode};
5958
use starknet_api::executable_transaction::{
6059
AccountTransaction as ExecutableAccountTx,
6160
DeclareTransaction as ExecutableDeclareTx,
61+
DeployAccountTransaction as ExecutableDeployAccountTx,
6262
Transaction as ExecutableTx,
6363
};
6464
use starknet_api::hash::StateRoots;
6565
use starknet_api::rpc_transaction::{
6666
InternalRpcDeclareTransactionV3,
67+
InternalRpcDeployAccountTransaction,
6768
InternalRpcTransaction,
6869
InternalRpcTransactionWithoutTxHash,
70+
RpcDeployAccountTransaction,
71+
RpcDeployAccountTransactionV3,
6972
};
7073
use starknet_api::state::ThinStateDiff;
7174
use starknet_api::test_utils::TEST_SEQUENCER_ADDRESS;
7275
use starknet_api::transaction::fields::{
7376
AccountDeploymentData,
7477
AllResourceBounds,
78+
ContractAddressSalt,
7579
PaymasterData,
7680
Tip,
7781
TransactionSignature,
7882
};
7983
use starknet_api::transaction::{
84+
CalculateContractAddress,
8085
DeclareTransaction,
86+
DeployAccountTransaction,
87+
TransactionHash,
8188
TransactionHasher,
8289
TransactionOffsetInBlock,
8390
TransactionVersion,
8491
};
92+
use starknet_api::{calldata, contract_address};
8593
use starknet_committer::block_committer::input::StateDiff;
8694
use starknet_committer::db::facts_db::FactsDb;
8795
use starknet_committer::db::forest_trait::StorageInitializer;
96+
use starknet_core::crypto::ecdsa_sign;
97+
use starknet_crypto::get_public_key;
8898
use starknet_patricia_storage::map_storage::MapStorage;
8999
use starknet_transaction_prover::running::committer_utils::commit_state_diff;
100+
use starknet_types_core::felt::Felt;
90101

91102
const GCS_ERROR_CODE_NOT_FOUND: u16 = 404;
92103

@@ -201,6 +212,8 @@ struct BlobFactory {
201212
}
202213

203214
impl BlobFactory {
215+
const OPERATOR_PRIVATE_KEY: Felt = Felt::THREE;
216+
204217
pub fn new() -> Self {
205218
let chain_info =
206219
ChainInfo { chain_id: CHAIN_ID.clone(), ..ChainInfo::create_for_testing() };
@@ -362,6 +375,11 @@ impl BlobFactory {
362375
// Tx generation
363376
// =====================
364377

378+
fn sign_tx(tx_hash: TransactionHash) -> TransactionSignature {
379+
let sig = ecdsa_sign(&Self::OPERATOR_PRIVATE_KEY, &tx_hash.0).unwrap();
380+
TransactionSignature(Arc::new(vec![sig.r, sig.s]))
381+
}
382+
365383
fn boostrap_declare_tx(&mut self, contract: FeatureContract) {
366384
let sender_address = ExecutableDeclareTx::bootstrap_address();
367385
let sierra = contract.get_sierra();
@@ -417,6 +435,55 @@ impl BlobFactory {
417435
self.next_txs.push((executable.into(), internal_tx));
418436
}
419437

438+
fn make_free_deploy_account_tx(&mut self, account: FeatureContract) {
439+
let class_hash = account.get_sierra().calculate_class_hash();
440+
let public_key = get_public_key(&Self::OPERATOR_PRIVATE_KEY);
441+
let constructor_calldata = calldata![public_key];
442+
let contract_address_salt = ContractAddressSalt::default();
443+
// Build with placeholder signature to compute the hash (signature excluded from hash).
444+
let rpc_tx_unsigned = RpcDeployAccountTransactionV3 {
445+
signature: TransactionSignature::default(),
446+
resource_bounds: AllResourceBounds::new_unlimited_gas_no_fee_enforcement(),
447+
tip: Tip::default(),
448+
contract_address_salt,
449+
class_hash,
450+
constructor_calldata: constructor_calldata.clone(),
451+
nonce: Nonce::default(),
452+
nonce_data_availability_mode: DataAvailabilityMode::L1,
453+
fee_data_availability_mode: DataAvailabilityMode::L1,
454+
paymaster_data: PaymasterData::default(),
455+
};
456+
let contract_address = rpc_tx_unsigned.calculate_contract_address().unwrap();
457+
let without_hash_unsigned = InternalRpcTransactionWithoutTxHash::DeployAccount(
458+
InternalRpcDeployAccountTransaction {
459+
tx: RpcDeployAccountTransaction::V3(rpc_tx_unsigned.clone()),
460+
contract_address,
461+
},
462+
);
463+
let tx_hash = without_hash_unsigned.calculate_transaction_hash(&CHAIN_ID).unwrap();
464+
let signature = Self::sign_tx(tx_hash);
465+
466+
let mut rpc_tx_signed = rpc_tx_unsigned;
467+
rpc_tx_signed.signature = signature;
468+
let without_hash = InternalRpcTransactionWithoutTxHash::DeployAccount(
469+
InternalRpcDeployAccountTransaction {
470+
tx: RpcDeployAccountTransaction::V3(rpc_tx_signed.clone()),
471+
contract_address,
472+
},
473+
);
474+
475+
let executable = ExecutableDeployAccountTx::create(
476+
DeployAccountTransaction::V3(rpc_tx_signed.into()),
477+
&CHAIN_ID,
478+
)
479+
.unwrap();
480+
let internal = InternalConsensusTransaction::RpcTransaction(InternalRpcTransaction {
481+
tx: without_hash,
482+
tx_hash,
483+
});
484+
self.next_txs.push((executable.into(), internal));
485+
}
486+
420487
// =====================
421488
// Data generation
422489
// =====================
@@ -606,8 +673,8 @@ async fn test_make_data() {
606673
// Create the list of transactions to be included in the blobs:
607674
// 1. bootstrap declare of an ERC20 contract.
608675
// 2. bootstrap declare of an account with real validate.
609-
// TODO(Dori): the rest of the txs.
610676
// 3. deploy account (with zero fees).
677+
// TODO(Dori): the rest of the txs.
611678
// 4. deploy ERC20 contract from the account (with zero fees), while minting some tokens to the
612679
// sender account.
613680
// (from this point - all txs include non-zero fees, and no more bootstrap declares)
@@ -621,6 +688,8 @@ async fn test_make_data() {
621688
blob_factory.boostrap_declare_tx(erc20_contract);
622689
blob_factory.close_block().await;
623690
blob_factory.boostrap_declare_tx(account_with_real_validate);
691+
blob_factory.close_block().await;
692+
blob_factory.make_free_deploy_account_tx(account_with_real_validate);
624693

625694
let (blobs, preconfirmed_block) = blob_factory.finalize().await;
626695
expect_file![CHAIN_INFO_PATH].assert_eq(&serde_json::to_string_pretty(&chain_info).unwrap());

0 commit comments

Comments
 (0)