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

Cheatcode for getting hash of the block #2648

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4298e64
cheatcode block_hash
PedroRosalba Nov 6, 2024
7243cfd
fix: names
PedroRosalba Nov 6, 2024
8abeeca
Merge remote-tracking branch 'upstream/master'
PedroRosalba Nov 7, 2024
9c95d80
fix: types
PedroRosalba Nov 8, 2024
26f10c4
still in progress
PedroRosalba Nov 8, 2024
df1a1ee
Merge branch 'master' into master
kkawula Nov 12, 2024
59c5d76
minor fix
Nov 12, 2024
65b4839
minor fix: undo create book
Nov 12, 2024
9fee226
Merge remote-tracking branch 'origin/master'
Nov 12, 2024
845a2d9
minor fix
Nov 12, 2024
2b1690f
ran scarbfmt.sh
Nov 12, 2024
2fe2baa
Merge branch 'master' into master
kkawula Nov 12, 2024
a450fa1
added changelog and fix imports Felt252
Nov 12, 2024
7bc764f
added module to lib and fmt code
Nov 13, 2024
b35e0dd
Merge branch 'master' into master
kkawula Nov 14, 2024
9b77098
fix: adding import
PedroRosalba Nov 17, 2024
cf6e429
Ignore .cargo/ and .rustup/ directories
PedroRosalba Dec 1, 2024
ab96aca
updates
PedroRosalba Dec 1, 2024
8b75ef5
updating. should I get the contractAddress from the cheated block num…
PedroRosalba Dec 4, 2024
40caccc
Merge branch 'foundry-rs:master' into master
PedroRosalba Dec 13, 2024
634bb44
updating
PedroRosalba Dec 13, 2024
cad9900
Merge branch 'master' into master
kkawula Dec 20, 2024
cb477c1
Apply suggestions from code review
kkawula Dec 20, 2024
2101152
Merge branch 'master' into master
kkawula Dec 20, 2024
e7b95f4
Merge branch 'master' into master
PedroRosalba Jan 8, 2025
9d48bb0
updating
PedroRosalba Jan 8, 2025
1ca9f84
Merge branch 'master' into master
kkawula Jan 9, 2025
50759d0
Merge branch 'master' into master
kkawula Jan 10, 2025
49096fc
Merge branch 'master' into master
kkawula Jan 17, 2025
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
use crate::abi::constants;
use self::hint_processor::{
create_retdata_segment,
execute_inner_call,
execute_library_call,
felt_to_bool,
read_call_params,
read_calldata,
read_felt_array,
write_segment,
EmitEventError,
SyscallExecutionError,
SyscallHintProcessor,
BLOCK_NUMBER_OUT_OF_RANGE_ERROR,
};

use crate::runtime_extensions::call_to_blockifier_runtime_extension::execution::entry_point::execute_constructor_entry_point;
use crate::runtime_extensions::call_to_blockifier_runtime_extension::CheatnetState;
use blockifier::execution::syscalls::hint_processor::SyscallHintProcessor;
Expand Down Expand Up @@ -65,15 +81,30 @@ pub fn get_block_hash_syscall(
_remaining_gas: &mut u64,
) -> SyscallResult<GetBlockHashResponse> {

let execution_info_ptr = syscall_handler.get_or_allocate_execution_info_segment(vm)?;
// let execution_info_ptr = syscall_handler.get_or_allocate_execution_info_segment(vm)?;

let cheated_data = cheatnet_state.get_cheated_data(syscall_handler.storage_address());
// let cheated_data = cheatnet_state.get_cheated_data(syscall_handler.storage_address());

// let ptr_cheated_block_info = get_cheated_block_info_ptr(vm, execution_info_ptr, &cheated_data);

let cheated_block_number = cheatnet_state.block_info.block_number;

let requested_block_number = request.block_number;

if cheated_block_number < constants::STORED_BLOCK_HASH_BUFFER
|| requested_block_number > cheated_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 ptr_cheated_block_info = get_cheated_block_info_ptr(vm, execution_info_ptr, &cheated_data);
let block_hash_contract_address =
ContractAddress::try_from(Felt::from(constants::BLOCK_HASH_CONTRACT_ADDRESS))?;

//TODO: how to get the cheated block number using the ptr_cheated_block_info?
//why is the get_cheated_block_info not public?
//why is BlockHash not public?
//should I get the contractAddress from the cheated block number? how do I do that?

let cheated_block_hash = BlockHash(syscall_handler.state.get_storage_at(block_hash_contract_address, key)?);

PedroRosalba marked this conversation as resolved.
Show resolved Hide resolved
Expand Down