Skip to content

Commit 69e30f0

Browse files
central_systest_blobs: add proof tx to test privacy feature
1 parent 80f2783 commit 69e30f0

4 files changed

Lines changed: 102 additions & 14 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
12
1+
13

crates/central_systest_blobs/resources/preconfirmed_block.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"block_number": 13,
2+
"block_number": 14,
33
"pre_confirmed_block": {
44
"l1_da_mode": "CALLDATA",
55
"l1_data_gas_price": {
@@ -17,7 +17,7 @@
1717
"sequencer_address": "0x1000",
1818
"starknet_version": "0.14.3",
1919
"status": "PRE_CONFIRMED",
20-
"timestamp": 1013,
20+
"timestamp": 1014,
2121
"transaction_receipts": [
2222
{
2323
"actual_fee": "0xff313",
@@ -56,7 +56,7 @@
5656
},
5757
"execution_status": "SUCCEEDED",
5858
"l2_to_l1_messages": [],
59-
"transaction_hash": "0x4acc6e7cb93683ae3a42ed499788f2d0143e8c3357315e1ecaad4e65f6dd479",
59+
"transaction_hash": "0x1fa0c5398afa836eb5dff4cf1ddd3cc6d57d1eb8af9b93c74bd23fe67d32c5a",
6060
"transaction_index": 0
6161
}
6262
],
@@ -66,19 +66,19 @@
6666
"deployed_contracts": [],
6767
"migrated_compiled_classes": [],
6868
"nonces": {
69-
"0xf99e7cdfbcce0bf14ce17e4c57fd2d12ad1bca5fc8e46a9fbafc36b59a9955": "0xc"
69+
"0xf99e7cdfbcce0bf14ce17e4c57fd2d12ad1bca5fc8e46a9fbafc36b59a9955": "0xd"
7070
},
7171
"old_declared_contracts": [],
7272
"replaced_classes": [],
7373
"storage_diffs": {
7474
"0x6bd1d71a2fb67a567618584ca31da288dbc2e1a8421e4045e05f52c19bfab83": [
7575
{
7676
"key": "0x6fba6554adab51d0272b896b6f41768bd0491e5ad59c39fab38e65767974793",
77-
"value": "0xffffffffffffffffffffffff924412b1"
77+
"value": "0xffffffffffffffffffffffff8db86b6b"
7878
},
7979
{
8080
"key": "0x723973208639b7839ce298f7ffea61e3f9533872defd7abdb91023db4658812",
81-
"value": "0x6dbbed4e"
81+
"value": "0x72479494"
8282
}
8383
]
8484
}
@@ -96,7 +96,7 @@
9696
"0x2000"
9797
],
9898
"fee_data_availability_mode": 0,
99-
"nonce": "0xb",
99+
"nonce": "0xc",
100100
"nonce_data_availability_mode": 0,
101101
"paymaster_data": [],
102102
"proof_facts": [],
@@ -116,11 +116,11 @@
116116
},
117117
"sender_address": "0xf99e7cdfbcce0bf14ce17e4c57fd2d12ad1bca5fc8e46a9fbafc36b59a9955",
118118
"signature": [
119-
"0x47fc4402ccfebfe5e1a8af95ee4de99932534b43d9161e7024847382c022926",
120-
"0x71c9ccc594f6d54d88b649a51dc167c3df0423d4a3f95a0e1b85f2560e78588"
119+
"0x7635250c4e3d567295d7a2812dacc8f528d838dc1931c0988f7fe0f98fbc356",
120+
"0x4ece213c76134174981d469d96dc69e58890e6bcd5461b817669ed67b927ab5"
121121
],
122122
"tip": "0x0",
123-
"transaction_hash": "0x4acc6e7cb93683ae3a42ed499788f2d0143e8c3357315e1ecaad4e65f6dd479",
123+
"transaction_hash": "0x1fa0c5398afa836eb5dff4cf1ddd3cc6d57d1eb8af9b93c74bd23fe67d32c5a",
124124
"type": "INVOKE_FUNCTION",
125125
"version": "0x3"
126126
}

crates/central_systest_blobs/src/cende_blob_regression_test.rs

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ use starknet_api::transaction::fields::{
9999
ResourceBounds,
100100
Tip,
101101
TransactionSignature,
102+
PROOF_VERSION,
103+
VIRTUAL_OS_OUTPUT_VERSION,
104+
VIRTUAL_SNOS,
102105
};
103106
use starknet_api::transaction::{
104107
CalculateContractAddress,
@@ -110,7 +113,7 @@ use starknet_api::transaction::{
110113
TransactionOffsetInBlock,
111114
TransactionVersion,
112115
};
113-
use starknet_api::{calldata, contract_address};
116+
use starknet_api::{calldata, contract_address, proof_facts};
114117
use starknet_committer::block_committer::input::StateDiff;
115118
use starknet_committer::db::facts_db::FactsDb;
116119
use starknet_committer::db::forest_trait::StorageInitializer;
@@ -594,6 +597,46 @@ impl BlobFactory {
594597
calldata: &[Felt],
595598
with_fee_charge: bool,
596599
should_revert: bool,
600+
) {
601+
self.make_operator_invoke_tx_with_proof(
602+
address,
603+
function_name,
604+
calldata,
605+
with_fee_charge,
606+
should_revert,
607+
ProofFacts::default(),
608+
)
609+
}
610+
611+
/// Same as [Self::make_operator_invoke_tx], but with virtual SNOS proof facts.
612+
fn make_operator_proof_tx(
613+
&mut self,
614+
address: ContractAddress,
615+
function_name: &str,
616+
calldata: &[Felt],
617+
with_fee_charge: bool,
618+
should_revert: bool,
619+
) {
620+
self.make_operator_invoke_tx_with_proof(
621+
address,
622+
function_name,
623+
calldata,
624+
with_fee_charge,
625+
should_revert,
626+
self.make_snos_proof_facts(),
627+
);
628+
}
629+
630+
/// Utility method to share code between invokes with and without proofs. Should not be called
631+
/// directly, use [Self::make_operator_invoke_tx] or [Self::make_operator_proof_tx] instead.
632+
fn make_operator_invoke_tx_with_proof(
633+
&mut self,
634+
address: ContractAddress,
635+
function_name: &str,
636+
calldata: &[Felt],
637+
with_fee_charge: bool,
638+
should_revert: bool,
639+
proof_facts: ProofFacts,
597640
) {
598641
let nonce = self.nonce_manager.next(*OPERATOR_ADDRESS);
599642
let resource_bounds = if with_fee_charge {
@@ -613,7 +656,7 @@ impl BlobFactory {
613656
fee_data_availability_mode: DataAvailabilityMode::L1,
614657
account_deployment_data: AccountDeploymentData::default(),
615658
paymaster_data: PaymasterData::default(),
616-
proof_facts: ProofFacts::default(),
659+
proof_facts,
617660
};
618661
let tx_hash = rpc_tx_unsigned
619662
.calculate_transaction_hash(&CHAIN_ID, &TransactionVersion::THREE)
@@ -632,6 +675,43 @@ impl BlobFactory {
632675
self.next_txs.push(TxData { executable: executable.into(), internal, should_revert });
633676
}
634677

678+
/// Constructs valid SNOS proof facts referencing the hash of the retrospective block.
679+
fn make_snos_proof_facts(&self) -> ProofFacts {
680+
let block_context = self.next_block_context();
681+
let retrospective_block_number = block_context
682+
.block_info()
683+
.block_number
684+
.0
685+
.checked_sub(STORED_BLOCK_HASH_BUFFER)
686+
.unwrap_or_else(|| {
687+
panic!(
688+
"The current block number must be at least {STORED_BLOCK_HASH_BUFFER} blocks \
689+
ahead of the first block."
690+
)
691+
});
692+
let retrospective_block_hash =
693+
self.blocks[usize::try_from(retrospective_block_number).unwrap()].block_hash;
694+
let program_hash = *block_context
695+
.versioned_constants()
696+
.os_constants
697+
.allowed_virtual_os_program_hashes
698+
.first()
699+
.expect("No allowed virtual OS program hashes in versioned constants");
700+
let config_hash = OsChainInfo::from(&self.chain_info)
701+
.compute_virtual_os_config_hash()
702+
.expect("Failed to compute virtual OS config hash");
703+
proof_facts![
704+
PROOF_VERSION,
705+
VIRTUAL_SNOS,
706+
program_hash,
707+
VIRTUAL_OS_OUTPUT_VERSION,
708+
Felt::from(retrospective_block_number),
709+
retrospective_block_hash.0,
710+
config_hash,
711+
Felt::ZERO, // l2_to_l1_messages_segment_size
712+
]
713+
}
714+
635715
fn make_operator_deploy_tx(
636716
&mut self,
637717
contract_to_deploy: FeatureContract,
@@ -957,6 +1037,14 @@ async fn test_make_data() {
9571037
false, // should not revert
9581038
);
9591039
blob_factory.close_block().await;
1040+
blob_factory.make_operator_proof_tx(
1041+
test_contract_address_0,
1042+
"test_storage_read_write",
1043+
&[Felt::from(0x4000u32), Felt::from(0x4000u32)],
1044+
true, // charge fee
1045+
false, // should not revert
1046+
);
1047+
blob_factory.close_block().await;
9601048
blob_factory.make_operator_invoke_tx(
9611049
test_contract_address_0,
9621050
"catch_write_revert_panic",

crates/starknet_api/src/test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ macro_rules! compiled_class_hash {
165165
/// of felt values.
166166
#[macro_export]
167167
macro_rules! proof_facts {
168-
( $( $x:expr ),* ) => {
168+
( $( $x:expr ),* $(,)?) => {
169169
$crate::transaction::fields::ProofFacts(vec![$($x),*].into())
170170
};
171171
}

0 commit comments

Comments
 (0)