Skip to content

Commit cca9a48

Browse files
apollo_integration_tests: add regression tests for matching the proof generation
1 parent a338c87 commit cca9a48

10 files changed

Lines changed: 93 additions & 20 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/apollo_integration_tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ blockifier = { workspace = true, features = ["testing"] }
6464
blockifier_test_utils.workspace = true
6565
cairo-lang-starknet-classes.workspace = true
6666
clap = { workspace = true, features = ["derive"] }
67+
expect-test.workspace = true
6768
futures.workspace = true
6869
hex.workspace = true
6970
http.workspace = true

crates/apollo_integration_tests/src/state_reader.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ use assert_matches::assert_matches;
2121
use blockifier::context::ChainInfo;
2222
use blockifier_test_utils::cairo_versions::{CairoVersion, RunnableCairo1};
2323
use blockifier_test_utils::contracts::FeatureContract;
24+
use blockifier_test_utils::fee_token_addresses::EXPECTED_STRK_FEE_TOKEN_ADDRESS;
2425
use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
26+
use expect_test::{expect, Expect};
2527
use indexmap::IndexMap;
2628
use mempool_test_utils::starknet_api_test_utils::{AccountTransactionGenerator, Contract};
2729
use starknet_api::abi::abi_utils::get_fee_token_var_address;
@@ -376,8 +378,14 @@ fn initialize_papyrus_test_state(
376378
}
377379

378380
/// Global root that matches the proof flow fixtures.
379-
fn integration_test_genesis_global_root() -> GlobalRoot {
380-
GlobalRoot(felt!("0x68fed6a062d385db8d1dd9096060e822196feb311fc3bb4f0018635461ca85e"))
381+
/// Any change to this value requires regenerating the proof fixtures by running
382+
/// `cargo +nightly-2025-07-14 test -p starknet_os_flow_tests --features
383+
/// starknet_transaction_prover/stwo_proving --release generate_proof_fixtures -- --ignored`.
384+
pub const EXPECTED_PROOF_FLOW_GENESIS_GLOBAL_ROOT: Expect =
385+
expect!["0x68fed6a062d385db8d1dd9096060e822196feb311fc3bb4f0018635461ca85e"];
386+
387+
pub fn integration_test_genesis_global_root() -> GlobalRoot {
388+
GlobalRoot(Felt::from_hex_unchecked(EXPECTED_PROOF_FLOW_GENESIS_GLOBAL_ROOT.data()))
381389
}
382390

383391
fn prepare_state_diff(
@@ -667,6 +675,7 @@ impl<'a> ThinStateDiffBuilder<'a> {
667675
pub fn proof_flow_chain_info() -> ChainInfo {
668676
let mut chain_info = ChainInfo::create_for_testing();
669677
chain_info.fee_token_addresses.strk_fee_token_address =
670-
contract_address!("0x4ff17bf76a1c6cebb82601a43bcab4f9650aea543c44f28e8863f8b624e4b58");
678+
ContractAddress::try_from(Felt::from_hex_unchecked(EXPECTED_STRK_FEE_TOKEN_ADDRESS.data()))
679+
.unwrap();
671680
chain_info
672681
}

crates/apollo_integration_tests/tests/proof_flow_fixtures_verify.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
use apollo_integration_tests::utils::{load_proof_flow_proof, load_proof_flow_proof_facts};
2+
use blockifier::blockifier_versioned_constants::VersionedConstants;
3+
use starknet_api::transaction::fields::SnosProofFacts;
4+
use starknet_api::versioned_constants_logic::VersionedConstantsTrait;
25
use starknet_proof_verifier::verify_proof;
36

47
#[test]
@@ -14,3 +17,24 @@ fn proof_flow_fixtures_verify() {
1417
);
1518
}
1619
}
20+
21+
/// Guards against drift between the virtual-OS program hash baked into the proof-flow fixtures
22+
/// and the `allowed_virtual_os_program_hashes` list in the latest versioned constants. If the
23+
/// hash is no longer allowed, the proof fixtures must be regenerated.
24+
#[test]
25+
fn proof_flow_program_hash_is_allowed() {
26+
let proof_facts = load_proof_flow_proof_facts();
27+
let snos_proof_facts = SnosProofFacts::try_from(proof_facts)
28+
.expect("proof_facts.json is malformed; regenerate the fixtures");
29+
let allowed =
30+
&VersionedConstants::latest_constants().os_constants.allowed_virtual_os_program_hashes;
31+
assert!(
32+
allowed.contains(&snos_proof_facts.program_hash),
33+
"Virtual OS program hash {:#x} baked into the proof_flow fixtures is no longer in the \
34+
allowed list ({:?}). Regenerate the fixtures: `cargo +nightly-2025-07-14 test -p \
35+
starknet_os_flow_tests --features starknet_transaction_prover/stwo_proving --release \
36+
generate_proof_fixtures -- --ignored`.",
37+
snos_proof_facts.program_hash,
38+
allowed.iter().map(|h| format!("{h:#x}")).collect::<Vec<_>>(),
39+
);
40+
}

crates/blockifier_test_utils/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ cairo_native = []
1313
apollo_infra_utils = { workspace = true, features = ["testing"] }
1414
cairo-lang-starknet-classes.workspace = true
1515
digest.workspace = true
16+
expect-test.workspace = true
1617
serde_json = { workspace = true, features = ["arbitrary_precision"] }
1718
sha2.workspace = true
1819
starknet-types-core.workspace = true
@@ -22,7 +23,6 @@ tempfile.workspace = true
2223
tracing.workspace = true
2324

2425
[dev-dependencies]
25-
expect-test.workspace = true
2626
pretty_assertions.workspace = true
2727
rstest.workspace = true
2828
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use expect_test::{expect, Expect};
2+
3+
/// The STRK fee token address that is deployed when initializing the default initial state used
4+
/// by the virtual-OS flow tests and the apollo proof-flow integration tests. The resulting
5+
/// address depends on the nonce of the deploying account — if extra init transactions are added
6+
/// before the STRK fee token is deployed, the address must be updated. Run any failing test with
7+
/// `UPDATE_EXPECT=1` to refresh, then regenerate the proof fixtures by running
8+
/// `cargo +nightly-2025-07-14 test -p starknet_os_flow_tests --features
9+
/// starknet_transaction_prover/stwo_proving --release generate_proof_fixtures -- --ignored`.
10+
pub const EXPECTED_STRK_FEE_TOKEN_ADDRESS: Expect =
11+
expect!["0x4ff17bf76a1c6cebb82601a43bcab4f9650aea543c44f28e8863f8b624e4b58"];

crates/blockifier_test_utils/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ pub mod cairo_versions;
33
pub mod calldata;
44
pub mod compile_cache;
55
pub mod contracts;
6+
pub mod fee_token_addresses;
67
pub mod types;

crates/starknet_os_flow_tests/src/initial_state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use blockifier::transaction::transaction_execution::Transaction;
77
use blockifier_test_utils::cairo_versions::{CairoVersion, RunnableCairo1};
88
use blockifier_test_utils::calldata::create_calldata;
99
use blockifier_test_utils::contracts::FeatureContract;
10+
use blockifier_test_utils::fee_token_addresses::EXPECTED_STRK_FEE_TOKEN_ADDRESS;
1011
use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
1112
use starknet_api::block::BlockNumber;
1213
use starknet_api::contract_class::compiled_class_hash::{HashVersion, HashableCompiledClass};
@@ -44,7 +45,6 @@ use starknet_types_core::felt::Felt;
4445

4546
use crate::test_manager::{
4647
block_context_for_flow_tests,
47-
EXPECTED_STRK_FEE_TOKEN_ADDRESS,
4848
FUNDED_ACCOUNT_ADDRESS,
4949
STRK_FEE_TOKEN_ADDRESS,
5050
};
@@ -388,6 +388,6 @@ pub(crate) fn get_deploy_fee_token_tx_and_address(nonce: Nonce) -> (Transaction,
388388
nonce,
389389
ValidResourceBounds::create_for_testing_no_fee_enforcement(),
390390
);
391-
EXPECTED_STRK_FEE_TOKEN_ADDRESS.assert_debug_eq(&**address);
391+
EXPECTED_STRK_FEE_TOKEN_ADDRESS.assert_eq(&address.to_hex_string());
392392
(tx, address)
393393
}

crates/starknet_os_flow_tests/src/test_manager.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use blockifier::transaction::objects::TransactionExecutionInfo;
1313
use blockifier::transaction::transaction_execution::Transaction as BlockifierTransaction;
1414
use blockifier_test_utils::calldata::create_calldata;
1515
use blockifier_test_utils::contracts::FeatureContract;
16+
use blockifier_test_utils::fee_token_addresses::EXPECTED_STRK_FEE_TOKEN_ADDRESS;
1617
use cairo_vm::types::builtin_name::BuiltinName;
17-
use expect_test::{expect, Expect};
1818
use itertools::Itertools;
1919
use starknet_api::abi::abi_utils::{get_fee_token_var_address, selector_from_name};
2020
use starknet_api::block::{BlockHash, BlockInfo, BlockNumber, PreviousBlockNumber};
@@ -95,23 +95,12 @@ use crate::utils::{
9595
ExecutionOutput,
9696
};
9797

98-
/// The STRK fee token address that was deployed when initializing the default initial state.
99-
/// The resulting address depends on the nonce of the deploying account - if extra init transactions
100-
/// are added to the initial state construction before the STRK fee token is deployed, the address
101-
/// must be updated.
102-
pub(crate) const EXPECTED_STRK_FEE_TOKEN_ADDRESS: Expect = expect![
103-
r#"
104-
0x4ff17bf76a1c6cebb82601a43bcab4f9650aea543c44f28e8863f8b624e4b58
105-
"#
106-
];
10798
const SEQUENCER_ADDRESS_FELT: Felt = Felt::from_hex_unchecked(TEST_SEQUENCER_ADDRESS);
10899

109100
pub(crate) static STRK_FEE_TOKEN_ADDRESS: LazyLock<ContractAddress> = LazyLock::new(|| {
110101
ContractAddress(
111-
PatriciaKey::try_from(Felt::from_hex_unchecked(
112-
EXPECTED_STRK_FEE_TOKEN_ADDRESS.data.trim(),
113-
))
114-
.unwrap(),
102+
PatriciaKey::try_from(Felt::from_hex_unchecked(EXPECTED_STRK_FEE_TOKEN_ADDRESS.data()))
103+
.unwrap(),
115104
)
116105
});
117106
/// The address of a funded account that is able to pay fees for transactions.

crates/starknet_os_flow_tests/src/virtual_os_test.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
use std::path::Path;
22

3+
use apollo_integration_tests::state_reader::EXPECTED_PROOF_FLOW_GENESIS_GLOBAL_ROOT;
34
use blockifier::execution::contract_class::TrackedResource;
45
use blockifier::test_utils::dict_state_reader::DictStateReader;
56
use blockifier::test_utils::get_valid_virtual_os_program_hash;
67
use blockifier::transaction::test_utils::ExpectedExecutionInfo;
78
use blockifier_test_utils::cairo_versions::{CairoVersion, RunnableCairo1};
89
use blockifier_test_utils::calldata::create_calldata;
910
use blockifier_test_utils::contracts::FeatureContract;
11+
use blockifier_test_utils::fee_token_addresses::EXPECTED_STRK_FEE_TOKEN_ADDRESS;
1012
use rstest::rstest;
1113
use starknet_api::abi::abi_utils::selector_from_name;
1214
use starknet_api::block::{BlockInfo, BlockNumber, BlockTimestamp};
1315
use starknet_api::core::EthAddress;
16+
use starknet_api::hash::StateRoots;
1417
use starknet_api::test_utils::{CURRENT_BLOCK_TIMESTAMP, TEST_SEQUENCER_ADDRESS};
1518
use starknet_api::transaction::fields::{ProofFacts, TransactionSignature};
1619
use starknet_api::transaction::{
@@ -22,7 +25,9 @@ use starknet_api::transaction::{
2225
use starknet_api::{calldata, contract_address, invoke_tx_args};
2326
use starknet_types_core::felt::Felt;
2427

28+
use crate::initial_state::create_default_initial_state_data;
2529
use crate::test_manager::{
30+
block_context_for_flow_tests,
2631
EventPredicateExpectation,
2732
TestBuilder,
2833
TestBuilderConfig,
@@ -308,3 +313,35 @@ async fn generate_proof_fixtures() {
308313
.expect("write proof_facts.json");
309314
std::fs::write(&proof_path, output.proof.0.as_slice()).expect("write proof.bin");
310315
}
316+
317+
/// Guards against drift between the STRK fee token address used by the proof-flow integration
318+
/// test and the one produced by the virtual OS test pipeline. Run with `UPDATE_EXPECT=1` to refresh
319+
/// the constant in `blockifier_test_utils::fee_token_addresses`, then regenerate the proof fixtures
320+
/// by running `cargo +nightly-2025-07-14 test -p starknet_os_flow_tests --features
321+
/// starknet_transaction_prover/stwo_proving --release generate_proof_fixtures -- --ignored`.
322+
#[test]
323+
fn proof_flow_chain_info_matches_virtual_os_test() {
324+
let virtual_os_strk_fee_token_address = block_context_for_flow_tests(BlockNumber(0), false)
325+
.chain_info()
326+
.fee_token_addresses
327+
.strk_fee_token_address;
328+
EXPECTED_STRK_FEE_TOKEN_ADDRESS.assert_eq(&virtual_os_strk_fee_token_address.to_hex_string());
329+
}
330+
331+
/// Guards against drift between the genesis global root the proof-flow integration test seeds into
332+
/// storage and the initial global root produced by the virtual OS test pipeline. Run with
333+
/// `UPDATE_EXPECT=1` to refresh the constant in `apollo_integration_tests::state_reader`, then
334+
/// regenerate the proof fixtures by running `cargo +nightly-2025-07-14 test -p
335+
/// starknet_os_flow_tests --features starknet_transaction_prover/stwo_proving --release
336+
/// generate_proof_fixtures -- --ignored`.
337+
#[tokio::test(flavor = "multi_thread")]
338+
async fn proof_flow_global_root_matches_virtual_os_test() {
339+
let (initial_state_data, []) =
340+
create_default_initial_state_data::<DictStateReader, 0>([]).await;
341+
let virtual_os_global_root = StateRoots {
342+
contracts_trie_root_hash: initial_state_data.initial_state.contracts_trie_root_hash,
343+
classes_trie_root_hash: initial_state_data.initial_state.classes_trie_root_hash,
344+
}
345+
.global_root();
346+
EXPECTED_PROOF_FLOW_GENESIS_GLOBAL_ROOT.assert_eq(&virtual_os_global_root.0.to_hex_string());
347+
}

0 commit comments

Comments
 (0)