-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(blockifier): share get_block_hash syscall code between native
and casm
- Loading branch information
1 parent
86461e3
commit 913d484
Showing
5 changed files
with
42 additions
and
37 deletions.
There are no files selected for viewing
Submodule cairo_native
updated
72 files
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use starknet_api::core::ContractAddress; | ||
use starknet_api::state::StorageKey; | ||
use starknet_types_core::felt::Felt; | ||
|
||
use crate::abi::constants; | ||
use crate::execution::syscalls::hint_processor::{ | ||
SyscallExecutionError, | ||
BLOCK_NUMBER_OUT_OF_RANGE_ERROR, | ||
}; | ||
|
||
pub type SyscallResult<T> = Result<T, SyscallExecutionError>; | ||
|
||
pub fn get_block_hash_base( | ||
current_block_number: u64, | ||
requested_block_number: u64, | ||
) -> SyscallResult<(StorageKey, ContractAddress)> { | ||
if current_block_number < constants::STORED_BLOCK_HASH_BUFFER | ||
|| requested_block_number > current_block_number - constants::STORED_BLOCK_HASH_BUFFER | ||
{ | ||
let out_of_range_error = | ||
Felt::from_hex(BLOCK_NUMBER_OUT_OF_RANGE_ERROR).map_err(SyscallExecutionError::from)?; | ||
return Err(SyscallExecutionError::SyscallError { error_data: vec![out_of_range_error] }); | ||
} | ||
|
||
let key = StorageKey::try_from(Felt::from(requested_block_number))?; | ||
let block_hash_contract_address = | ||
ContractAddress::try_from(Felt::from(constants::BLOCK_HASH_CONTRACT_ADDRESS))?; | ||
Ok((key, block_hash_contract_address)) | ||
} |
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