Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Use BlockNumber in GetBlockHashRequest. #604

Merged
Merged
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
19 changes: 13 additions & 6 deletions crates/blockifier/src/execution/syscalls/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cairo_felt::Felt252;
use cairo_vm::types::relocatable::Relocatable;
use cairo_vm::vm::vm_core::VirtualMachine;
use starknet_api::block::BlockHash;
use starknet_api::block::{BlockHash, BlockNumber};
use starknet_api::core::{
calculate_contract_address, ClassHash, ContractAddress, EntryPointSelector,
};
Expand All @@ -11,6 +11,7 @@ use starknet_api::state::StorageKey;
use starknet_api::transaction::{
Calldata, ContractAddressSalt, EthAddress, EventContent, EventData, EventKey, L2ToL1Payload,
};
use starknet_api::StarknetApiError;

use self::hint_processor::{
create_retdata_segment, execute_inner_call, execute_library_call, felt_to_bool,
Expand Down Expand Up @@ -288,15 +289,21 @@ pub fn emit_event(
// GetBlockHash syscall.

#[derive(Debug, Eq, PartialEq)]

// TODO(Arni, 8/6/2023): Consider replacing `BlockNumber`.
pub struct GetBlockHashRequest {
pub block_number: StarkFelt,
pub block_number: BlockNumber,
}

// TODO(Arni, 20/6/2023): Implement in starknet-api, the conversions:
// fn try_from(felt: StarkFelt) -> Result<u64, _>
impl SyscallRequest for GetBlockHashRequest {
fn read(vm: &VirtualMachine, ptr: &mut Relocatable) -> SyscallResult<GetBlockHashRequest> {
let block_number = stark_felt_from_ptr(vm, ptr)?;
let block_number_as_felt = stark_felt_from_ptr(vm, ptr)?;
let block_number =
BlockNumber(u64::try_from(usize::try_from(block_number_as_felt)?).map_err(|_| {
SyscallExecutionError::StarknetApiError(StarknetApiError::OutOfRange {
string: block_number_as_felt.to_string(),
})
})?);
Ok(GetBlockHashRequest { block_number })
}
}
Expand All @@ -323,7 +330,7 @@ pub fn get_block_hash(
syscall_handler: &mut SyscallHintProcessor<'_>,
_remaining_gas: &mut Felt252,
) -> SyscallResult<GetBlockHashResponse> {
let key = StorageKey::try_from(request.block_number)?;
let key = StorageKey::try_from(StarkFelt::from(request.block_number.0))?;
let block_hash_contract_address =
ContractAddress::try_from(StarkFelt::from(constants::BLOCK_HASH_CONTRACT_ADDRESS))?;
let block_hash =
Expand Down
Loading