Skip to content

Commit 8737d63

Browse files
central_systest_blobs: add proof tx to test privacy feature
1 parent 884af7d commit 8737d63

6 files changed

Lines changed: 99 additions & 14 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ apollo_class_manager_types = { workspace = true, features = ["testing"] }
1313
apollo_consensus.workspace = true
1414
apollo_consensus_orchestrator = { workspace = true, features = ["testing"] }
1515
apollo_infra_utils.workspace = true
16+
apollo_starknet_os_program.workspace = true
1617
blockifier = { workspace = true, features = ["reexecution", "testing"] }
1718
blockifier_test_utils.workspace = true
1819
expect-test.workspace = true
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: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use apollo_consensus_orchestrator::cende::{
2020
};
2121
use apollo_consensus_orchestrator::fee_market::FeeMarketInfo;
2222
use apollo_infra_utils::compile_time_cargo_manifest_dir;
23+
use apollo_starknet_os_program::PROGRAM_HASHES;
2324
use blockifier::abi::constants::STORED_BLOCK_HASH_BUFFER;
2425
use blockifier::blockifier::config::TransactionExecutorConfig;
2526
use blockifier::blockifier::transaction_executor::TransactionExecutor;
@@ -99,6 +100,9 @@ use starknet_api::transaction::fields::{
99100
ResourceBounds,
100101
Tip,
101102
TransactionSignature,
103+
PROOF_VERSION,
104+
VIRTUAL_OS_OUTPUT_VERSION,
105+
VIRTUAL_SNOS,
102106
};
103107
use starknet_api::transaction::{
104108
CalculateContractAddress,
@@ -110,7 +114,7 @@ use starknet_api::transaction::{
110114
TransactionOffsetInBlock,
111115
TransactionVersion,
112116
};
113-
use starknet_api::{calldata, contract_address};
117+
use starknet_api::{calldata, contract_address, proof_facts};
114118
use starknet_committer::block_committer::input::StateDiff;
115119
use starknet_committer::db::facts_db::FactsDb;
116120
use starknet_committer::db::forest_trait::StorageInitializer;
@@ -594,6 +598,46 @@ impl BlobFactory {
594598
calldata: &[Felt],
595599
with_fee_charge: bool,
596600
should_revert: bool,
601+
) {
602+
self.make_operator_invoke_tx_with_proof(
603+
address,
604+
function_name,
605+
calldata,
606+
with_fee_charge,
607+
should_revert,
608+
ProofFacts::default(),
609+
)
610+
}
611+
612+
/// Same as [Self::make_operator_invoke_tx], but with virtual SNOS proof facts.
613+
fn make_operator_proof_tx(
614+
&mut self,
615+
address: ContractAddress,
616+
function_name: &str,
617+
calldata: &[Felt],
618+
with_fee_charge: bool,
619+
should_revert: bool,
620+
) {
621+
self.make_operator_invoke_tx_with_proof(
622+
address,
623+
function_name,
624+
calldata,
625+
with_fee_charge,
626+
should_revert,
627+
self.make_snos_proof_facts(),
628+
);
629+
}
630+
631+
/// Utility method to share code between invokes with and without proofs. Should not be called
632+
/// directly, use [Self::make_operator_invoke_tx] or [Self::make_operator_proof_tx] instead.
633+
fn make_operator_invoke_tx_with_proof(
634+
&mut self,
635+
address: ContractAddress,
636+
function_name: &str,
637+
calldata: &[Felt],
638+
with_fee_charge: bool,
639+
should_revert: bool,
640+
proof_facts: ProofFacts,
597641
) {
598642
let nonce = self.nonce_manager.next(*OPERATOR_ADDRESS);
599643
let resource_bounds = if with_fee_charge {
@@ -613,7 +657,7 @@ impl BlobFactory {
613657
fee_data_availability_mode: DataAvailabilityMode::L1,
614658
account_deployment_data: AccountDeploymentData::default(),
615659
paymaster_data: PaymasterData::default(),
616-
proof_facts: ProofFacts::default(),
660+
proof_facts,
617661
};
618662
let tx_hash = rpc_tx_unsigned
619663
.calculate_transaction_hash(&CHAIN_ID, &TransactionVersion::THREE)
@@ -632,6 +676,37 @@ impl BlobFactory {
632676
self.next_txs.push(TxData { executable: executable.into(), internal, should_revert });
633677
}
634678

679+
/// Constructs valid SNOS proof facts referencing the hash of the retrospective block.
680+
fn make_snos_proof_facts(&self) -> ProofFacts {
681+
let block_context = self.next_block_context();
682+
let retrospective_block_number = block_context
683+
.block_info()
684+
.block_number
685+
.0
686+
.checked_sub(STORED_BLOCK_HASH_BUFFER)
687+
.unwrap_or_else(|| {
688+
panic!(
689+
"The current block number must be at least {STORED_BLOCK_HASH_BUFFER} blocks \
690+
ahead of the first block."
691+
)
692+
});
693+
let retrospective_block_hash =
694+
self.blocks[usize::try_from(retrospective_block_number).unwrap()].block_hash;
695+
let config_hash = OsChainInfo::from(&self.chain_info)
696+
.compute_virtual_os_config_hash()
697+
.expect("Failed to compute virtual OS config hash");
698+
proof_facts![
699+
PROOF_VERSION,
700+
VIRTUAL_SNOS,
701+
PROGRAM_HASHES.virtual_os,
702+
VIRTUAL_OS_OUTPUT_VERSION,
703+
Felt::from(retrospective_block_number),
704+
retrospective_block_hash.0,
705+
config_hash,
706+
Felt::ZERO, // l2_to_l1_messages_segment_size
707+
]
708+
}
709+
635710
fn make_operator_deploy_tx(
636711
&mut self,
637712
contract_to_deploy: FeatureContract,
@@ -957,6 +1032,14 @@ async fn test_make_data() {
9571032
false, // should not revert
9581033
);
9591034
blob_factory.close_block().await;
1035+
blob_factory.make_operator_proof_tx(
1036+
test_contract_address_0,
1037+
"test_storage_read_write",
1038+
&[Felt::from(0x4000u32), Felt::from(0x4000u32)],
1039+
true, // charge fee
1040+
false, // should not revert
1041+
);
1042+
blob_factory.close_block().await;
9601043
blob_factory.make_operator_invoke_tx(
9611044
test_contract_address_0,
9621045
"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)