-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(blockifier_reexecution): convert declare starknet api to declar…
…e blockifier
- Loading branch information
1 parent
f625b13
commit 63e0d12
Showing
7 changed files
with
103 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
crates/blockifier_reexecution/src/state_reader/reexecution_state_reader.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use blockifier::execution::contract_class::ClassInfo; | ||
use blockifier::transaction::transaction_execution::Transaction as BlockifierTransaction; | ||
use papyrus_execution::DEPRECATED_CONTRACT_SIERRA_SIZE; | ||
use starknet_api::core::ClassHash; | ||
use starknet_api::transaction::{Transaction, TransactionHash}; | ||
use starknet_core::types::ContractClass as StarknetContractClass; | ||
|
||
use super::compile::{legacy_to_contract_class_v0, sierra_to_contact_class_v1}; | ||
use crate::state_reader::errors::ReexecutionError; | ||
use crate::state_reader::test_state_reader::ReexecutionResult; | ||
|
||
pub(crate) trait ReexecutionStateReader { | ||
fn get_contract_class(&self, class_hash: ClassHash) | ||
-> ReexecutionResult<StarknetContractClass>; | ||
|
||
fn get_class_info(&self, class_hash: ClassHash) -> ReexecutionResult<ClassInfo> { | ||
match self.get_contract_class(class_hash)? { | ||
StarknetContractClass::Sierra(sierra) => { | ||
let abi_length = sierra.abi.len(); | ||
let sierra_length = sierra.sierra_program.len(); | ||
Ok(ClassInfo::new(&sierra_to_contact_class_v1(sierra)?, sierra_length, abi_length)?) | ||
} | ||
StarknetContractClass::Legacy(legacy) => { | ||
let abi_length = | ||
legacy.abi.clone().expect("legendary contract should have abi").len(); | ||
Ok(ClassInfo::new( | ||
&legacy_to_contract_class_v0(legacy)?, | ||
DEPRECATED_CONTRACT_SIERRA_SIZE, | ||
abi_length, | ||
)?) | ||
} | ||
} | ||
} | ||
|
||
// TODO(Aner): extend/refactor to accomodate all types of transactions. | ||
fn api_txs_to_blockifier_txs( | ||
&self, | ||
txs_and_hashes: Vec<(Transaction, TransactionHash)>, | ||
) -> ReexecutionResult<Vec<BlockifierTransaction>> { | ||
txs_and_hashes | ||
.into_iter() | ||
.map(|(tx, tx_hash)| match tx { | ||
Transaction::Invoke(_) | Transaction::DeployAccount(_) => { | ||
BlockifierTransaction::from_api(tx, tx_hash, None, None, None, false) | ||
.map_err(ReexecutionError::from) | ||
} | ||
Transaction::Declare(ref declare_tx) => { | ||
let class_info = self | ||
.get_class_info(declare_tx.class_hash()) | ||
.map_err(ReexecutionError::from)?; | ||
BlockifierTransaction::from_api( | ||
tx, | ||
tx_hash, | ||
Some(class_info), | ||
None, | ||
None, | ||
false, | ||
) | ||
.map_err(ReexecutionError::from) | ||
} | ||
Transaction::L1Handler(_) => todo!("Implement L1Handler transaction converter"), | ||
Transaction::Deploy(_) => todo!("Implement Deploy transaction converter"), | ||
}) | ||
.collect::<Result<Vec<_>, _>>() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters