Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved compiled snos import to allowing using snos as a dependency #407

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions crates/bin/prove_block/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ use starknet_os::error::SnOsError::{self};
use starknet_os::execution::helper::{ContractStorageMap, ExecutionHelperWrapper};
use starknet_os::io::input::StarknetOsInput;
use starknet_os::io::output::StarknetOsOutput;
use starknet_os::run_os;
use starknet_os::starknet::business_logic::fact_state::contract_state_objects::ContractState;
use starknet_os::starknet::starknet_storage::CommitmentInfo;
use starknet_os::starkware_utils::commitment_tree::base_types::Height;
use starknet_os::starkware_utils::commitment_tree::errors::TreeError;
use starknet_os::starkware_utils::commitment_tree::patricia_tree::patricia_tree::PatriciaTree;
use starknet_os::{config, run_os};
use starknet_os_types::chain_id::chain_id_from_felt;
use starknet_os_types::error::ContractClassError;
use starknet_os_types::starknet_core_addons::LegacyContractDecompressionError;
Expand Down Expand Up @@ -109,6 +109,7 @@ fn compute_class_commitment(
}

pub async fn prove_block(
compiled_os: &[u8],
block_number: u64,
rpc_provider: &str,
layout: LayoutName,
Expand Down Expand Up @@ -334,7 +335,7 @@ pub async fn prove_block(
(old_block_number, old_block_hash),
);

Ok(run_os(config::DEFAULT_COMPILED_OS, layout, os_input, block_context, execution_helper)?)
Ok(run_os(compiled_os, layout, os_input, block_context, execution_helper)?)
}

pub fn debug_prove_error(err: ProveBlockError) -> ProveBlockError {
Expand Down
4 changes: 3 additions & 1 deletion crates/bin/prove_block/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use cairo_vm::types::layout_name::LayoutName;
use clap::Parser;
use prove_block::debug_prove_error;

pub const DEFAULT_COMPILED_OS: &[u8] = include_bytes!("../../../../build/os_latest.json");

#[derive(Parser, Debug)]
struct Args {
/// Block to prove.
Expand Down Expand Up @@ -30,7 +32,7 @@ async fn main() {
let block_number = args.block_number;
let layout = LayoutName::all_cairo;

let result = prove_block::prove_block(block_number, &args.rpc_provider, layout, true).await;
let result = prove_block::prove_block(DEFAULT_COMPILED_OS, block_number, &args.rpc_provider, layout, true).await;
let (pie, _snos_output) = result.map_err(debug_prove_error).expect("Block proven");
pie.run_validity_checks().expect("Valid PIE");
}
11 changes: 7 additions & 4 deletions crates/bin/prove_block/tests/prove_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use cairo_vm::vm::runners::cairo_pie::CairoPie;
use prove_block::{debug_prove_error, prove_block};
use rstest::rstest;

pub const DEFAULT_COMPILED_OS: &[u8] = include_bytes!("../../../../build/os_latest.json");

// # These blocks verify the following issues:
// # * 76793: the first block that we managed to prove, only has a few invoke txs
// # * 76766 / 76775: additional basic blocks
Expand Down Expand Up @@ -63,10 +65,11 @@ use rstest::rstest;
#[tokio::test(flavor = "multi_thread")]
async fn test_prove_selected_blocks(#[case] block_number: u64) {
let endpoint = std::env::var("PATHFINDER_RPC_URL").expect("Missing PATHFINDER_RPC_URL in env");
let (snos_pie, _snos_output) = prove_block(block_number, &endpoint, LayoutName::all_cairo, true)
.await
.map_err(debug_prove_error)
.expect("OS generate Cairo PIE");
let (snos_pie, _snos_output) =
prove_block(DEFAULT_COMPILED_OS, block_number, &endpoint, LayoutName::all_cairo, true)
.await
.map_err(debug_prove_error)
.expect("OS generate Cairo PIE");
snos_pie.run_validity_checks().expect("Valid SNOS PIE");

if let Some(reference_pie_bytes) = get_reference_pie_bytes(block_number) {
Expand Down
2 changes: 0 additions & 2 deletions crates/starknet-os/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ pub const fn default_layout() -> LayoutName {
// https://github.com/starkware-libs/blockifier/blob/8da582b285bfbc7d4c21178609bbd43f80a69240/crates/native_blockifier/src/py_block_executor.rs#L44
const MAX_STEPS_PER_TX: u32 = 4_000_000;

pub const DEFAULT_COMPILED_OS: &[u8] = include_bytes!("../../../build/os_latest.json");

const DEFAULT_CONFIG_PATH: &str = "../../cairo-lang/src/starkware/starknet/definitions/general_config.yml";
pub const STORED_BLOCK_HASH_BUFFER: u64 = 10;
pub const BLOCK_HASH_CONTRACT_ADDRESS: u64 = 1;
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub mod state;
pub mod transaction_utils;
pub mod utils;

pub const DEFAULT_COMPILED_OS: &[u8] = include_bytes!("../../../build/os_latest.json");

#[fixture]
pub fn setup_runner() -> CairoRunner {
let program_content = fs::read("../build/programs/fact.json").unwrap();
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/common/transaction_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,7 @@ where
}

pub async fn execute_txs_and_run_os<S>(
compiled_os: &[u8],
state: CachedState<SharedState<S, PedersenHash>>,
block_context: BlockContext,
txs: Vec<Transaction>,
Expand All @@ -905,7 +906,7 @@ where
.await;

let layout = config::default_layout();
let result = run_os(config::DEFAULT_COMPILED_OS, layout, os_input, block_context, execution_helper);
let result = run_os(compiled_os, layout, os_input, block_context, execution_helper);

match &result {
Err(Runner(VmException(vme))) => {
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/declare_txn_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ async fn declare_v3_cairo1_account(

let txs = vec![declare_tx].into_iter().map(Into::into).collect();
let _result = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
block_context,
txs,
Expand Down Expand Up @@ -149,6 +150,7 @@ async fn declare_cairo1_account(

let txs = vec![declare_tx].into_iter().map(Into::into).collect();
let _result = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
block_context,
txs,
Expand Down Expand Up @@ -207,6 +209,7 @@ async fn declare_v1_cairo0_account(

let txs = vec![declare_tx].into_iter().map(Into::into).collect();
let _result = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
block_context,
txs,
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/deploy_txn_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ async fn deploy_cairo0_account(

let txs = vec![deploy_account_tx].into_iter().map(Into::into).collect();
let _result = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
block_context,
txs,
Expand Down Expand Up @@ -194,6 +195,7 @@ async fn deploy_cairo1_account(

let txs = vec![AccountTransaction::DeployAccount(deploy_account_tx)].into_iter().map(Into::into).collect();
let _result = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
block_context,
txs,
Expand Down
11 changes: 11 additions & 0 deletions tests/integration/deprecated_syscalls_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ async fn test_syscall_library_call_cairo0(
let txs = vec![Transaction::AccountTransaction(tx)];

let (_pie, os_output) = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
block_context.clone(),
txs,
Expand Down Expand Up @@ -110,6 +111,7 @@ async fn test_syscall_get_block_number_cairo0(
let txs = vec![Transaction::AccountTransaction(tx)];

let (_pie, os_output) = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
block_context.clone(),
txs,
Expand Down Expand Up @@ -151,6 +153,7 @@ async fn test_syscall_get_block_timestamp_cairo0(
let txs = vec![Transaction::AccountTransaction(tx)];

let (_pie, os_output) = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
block_context.clone(),
txs,
Expand Down Expand Up @@ -212,6 +215,7 @@ async fn test_syscall_get_tx_info_cairo0(
let txs = vec![Transaction::AccountTransaction(tx)];

let (_pie, os_output) = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
block_context.clone(),
txs,
Expand Down Expand Up @@ -270,6 +274,7 @@ async fn test_syscall_get_tx_signature_cairo0(
let txs = vec![Transaction::AccountTransaction(tx)];

let (_pie, os_output) = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
block_context.clone(),
txs,
Expand Down Expand Up @@ -315,6 +320,7 @@ async fn test_syscall_replace_class_cairo0(

// TODO: use a different class hash and check that it is reflected in the OS output.
let (_pie, _os_output) = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
block_context.clone(),
txs,
Expand Down Expand Up @@ -374,6 +380,7 @@ async fn test_syscall_deploy_cairo0(
let txs = vec![Transaction::AccountTransaction(tx)];

let (_pie, os_output) = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
block_context.clone(),
txs,
Expand Down Expand Up @@ -426,6 +433,7 @@ async fn test_syscall_get_sequencer_address_cairo0(
let txs = vec![Transaction::AccountTransaction(tx)];

let (_pie, os_output) = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
block_context.clone(),
txs,
Expand Down Expand Up @@ -482,6 +490,7 @@ async fn test_syscall_get_contract_address_cairo0(
let txs = vec![Transaction::AccountTransaction(tx)];

let (_pie, os_output) = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
block_context.clone(),
txs,
Expand Down Expand Up @@ -534,6 +543,7 @@ async fn test_syscall_emit_event_cairo0(
let txs = vec![Transaction::AccountTransaction(tx)];

let (_pie, _os_output) = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
block_context.clone(),
txs,
Expand Down Expand Up @@ -581,6 +591,7 @@ async fn test_syscall_send_message_to_l1_cairo0(

let txs = vec![Transaction::AccountTransaction(tx)];
let (_pie, os_output) = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
block_context.clone(),
txs,
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/kzg_da_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ async fn test_kzg_da_cairo_1(#[future] initial_state_cairo1: StarknetTestState,
};
let txs = vec![l1_tx].into_iter().map(Into::into).collect();
let (_, output) = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
BlockContext::create_for_account_testing_with_kzg(true),
txs,
Expand Down Expand Up @@ -64,6 +65,7 @@ async fn test_kzg_da_cairo_0(#[future] initial_state_cairo0: StarknetTestState,
};
let txs = vec![l1_tx].into_iter().map(Into::into).collect();
let (_, output) = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
BlockContext::create_for_account_testing_with_kzg(true),
txs,
Expand Down
1 change: 1 addition & 0 deletions tests/integration/l1_handler_txn_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ async fn l1_handler<F>(
};
let txs = vec![l1_tx].into_iter().map(Into::into).collect();
let _result = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
block_context,
txs,
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ async fn return_result_cairo0_account(

let txs = vec![return_result_tx].into_iter().map(Into::into).collect();
let _result = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
block_context,
txs,
Expand Down Expand Up @@ -86,6 +87,7 @@ async fn return_result_cairo1_account(

let txs = vec![return_result_tx].into_iter().map(Into::into).collect();
let _result = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
block_context,
txs,
Expand Down Expand Up @@ -196,6 +198,7 @@ async fn syscalls_cairo1(
.collect();

let _result = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
block_context,
txs,
Expand Down
1 change: 1 addition & 0 deletions tests/integration/run_os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ async fn run_os_tests(#[future] initial_state_full_itests: StarknetTestState) {
let cached_state = CachedState::from(shared_state);

let (_pie, os_output) = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
cached_state,
block_context,
txs,
Expand Down
1 change: 1 addition & 0 deletions tests/integration/segments_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ async fn test_segment_arena(
let txs = vec![Transaction::AccountTransaction(tx)];

let (_pie, _os_output) = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
block_context,
txs,
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/syscalls_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ async fn test_syscall_library_call_cairo1(
let txs = vec![Transaction::AccountTransaction(tx)];

let (_pie, os_output) = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
block_context.clone(),
txs,
Expand Down Expand Up @@ -99,6 +100,7 @@ async fn test_syscall_replace_class_cairo1(
let txs = vec![Transaction::AccountTransaction(tx)];

let (_pie, _os_output) = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
block_context.clone(),
txs,
Expand Down Expand Up @@ -138,6 +140,7 @@ async fn test_syscall_keccak_cairo1(
let txs = vec![Transaction::AccountTransaction(tx)];

let (_pie, _os_output) = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
block_context.clone(),
txs,
Expand Down Expand Up @@ -180,6 +183,7 @@ async fn test_syscall_test_secp_cairo1(
let txs = vec![Transaction::AccountTransaction(tx)];

let (_pie, os_output) = execute_txs_and_run_os(
crate::common::DEFAULT_COMPILED_OS,
initial_state.cached_state,
block_context.clone(),
txs,
Expand Down
Loading