Skip to content

Commit

Permalink
Use ContractExecutor save/load instead of NativeContractClass save/load.
Browse files Browse the repository at this point in the history
  • Loading branch information
PearsonWhite committed Sep 18, 2024
1 parent 70a7417 commit 2e4d323
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
6 changes: 3 additions & 3 deletions vm/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vm/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ edition = "2021"
[dependencies]
serde = "1.0.171"
serde_json = { version = "1.0.96", features = ["raw_value"] }
blockifier = { git = "https://github.com/NethermindEth/sequencer", rev = "cb4db93330ab4a7a0e2aa5ea210a7c5880b9736a" }
starknet_api = { git = "https://github.com/NethermindEth/sequencer", rev = "cb4db93330ab4a7a0e2aa5ea210a7c5880b9736a" }
blockifier = { git = "https://github.com/NethermindEth/sequencer", rev = "95258a0797b22c877e1ddda14c5de77dc5150cb9" }
starknet_api = { git = "https://github.com/NethermindEth/sequencer", rev = "95258a0797b22c877e1ddda14c5de77dc5150cb9" }
cairo-lang-sierra = "2.8.0"
cairo-lang-starknet = "2.8.0"
cairo-lang-starknet-classes = "2.8.0"
Expand Down
25 changes: 10 additions & 15 deletions vm/rust/src/juno_state_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ pub fn class_info_from_json_str(
} else if let Ok(class) = {
println!("native contract");
let library_output_path = generate_library_path(class_hash);
native_try_from_json_string(class_def.as_str(), class_hash, &library_output_path)
native_try_from_json_string(class_def.as_str(), &library_output_path)
} {
class.into()
} else {
Expand All @@ -311,23 +311,18 @@ pub fn class_info_from_json_str(
/// and save the compilation artifact to library_output_path.
fn native_try_from_json_string(
raw_contract_class: &str,
class_hash: ClassHash,
library_output_path: &PathBuf,
) -> Result<NativeContractClassV1, Box<dyn std::error::Error>> {
// todo(rodro): we are having two instances of a sierra program, one it's object form
// and another in its felt encoded form. This can be avoided by either:
// 1. Having access to the encoding/decoding functions
// 2. Refactoring the code on the Cairo mono-repo

Ok(
NativeContractClassV1::load(&library_output_path).unwrap_or({
let sierra_contract_class: cairo_lang_starknet_classes::contract_class::ContractClass =
serde_json::from_str(raw_contract_class)?;
let sierra_program = sierra_contract_class.extract_sierra_program()?;
let sierra_contract_class: cairo_lang_starknet_classes::contract_class::ContractClass =
serde_json::from_str(raw_contract_class)?;
let sierra_program = sierra_contract_class.extract_sierra_program()?;
let executor = ContractExecutor::load(&library_output_path).unwrap_or({
let executor = ContractExecutor::new(&sierra_program, OptLevel::Default)?;
executor.save(&library_output_path);
NativeContractClassV1::new(Arc::new(executor), sierra_contract_class)?
}))
executor.save(&library_output_path)?;
executor
});
let contract_executor = NativeContractClassV1::new(Arc::new(executor), sierra_contract_class)?;
Ok(contract_executor)
}

// todo(xrvdg) once [class_info_from_json_str] is part of JunoStateReader
Expand Down

0 comments on commit 2e4d323

Please sign in to comment.