-
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.
build(blockifier): add get class hash at syscall
- Loading branch information
1 parent
1ed9911
commit 7888dec
Showing
13 changed files
with
150 additions
and
3 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
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
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
1 change: 1 addition & 0 deletions
1
crates/blockifier/src/execution/syscalls/syscall_tests/constants.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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub const REQUIRED_GAS_CALL_CONTRACT_TEST: u64 = 170370; | ||
pub const REQUIRED_GAS_STORAGE_READ_WRITE_TEST: u64 = 16990; | ||
pub const REQUIRED_GAS_GET_CLASS_HASH_AT_TEST: u64 = 7830; | ||
pub const REQUIRED_GAS_LIBRARY_CALL_TEST: u64 = 167970; |
69 changes: 69 additions & 0 deletions
69
crates/blockifier/src/execution/syscalls/syscall_tests/get_class_hash_at.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,69 @@ | ||
use starknet_api::{calldata, class_hash, contract_address}; | ||
use test_case::test_case; | ||
|
||
use crate::abi::abi_utils::selector_from_name; | ||
use crate::context::ChainInfo; | ||
use crate::execution::call_info::CallExecution; | ||
use crate::execution::entry_point::CallEntryPoint; | ||
use crate::execution::syscalls::syscall_tests::constants::REQUIRED_GAS_GET_CLASS_HASH_AT_TEST; | ||
use crate::retdata; | ||
use crate::test_utils::contracts::FeatureContract; | ||
use crate::test_utils::initial_test_state::test_state; | ||
use crate::test_utils::{trivial_external_entry_point_new, CairoVersion, BALANCE}; | ||
|
||
/// Tests the `get_class_hash_at` syscall, ensuring that: | ||
/// 1. `accessed_contract_addresses` contains `address` for a valid entry. | ||
/// 2. `read_class_hash_values` includes `class_hash`. | ||
/// 3. Execution succeeds with expected gas for valid cases. | ||
/// 4. Execution fails if `address` is absent or has a different `class_hash`. | ||
#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1), REQUIRED_GAS_GET_CLASS_HASH_AT_TEST; "VM")] | ||
fn test_get_class_hash_at(test_contract: FeatureContract, expected_gas: u64) { | ||
let chain_info = &ChainInfo::create_for_testing(); | ||
let mut state = test_state(chain_info, BALANCE, &[(test_contract, 1)]); | ||
let address = contract_address!("0x111"); | ||
let class_hash = class_hash!("0x222"); | ||
state.state.address_to_class_hash.insert(address, class_hash); | ||
|
||
// Positive case: address and class_hash are correct | ||
let positive_entry_point_call = CallEntryPoint { | ||
calldata: calldata![address.into(), class_hash.0], | ||
entry_point_selector: selector_from_name("test_get_class_hash_at"), | ||
..trivial_external_entry_point_new(test_contract) | ||
}; | ||
let positive_call_info = positive_entry_point_call.execute_directly(&mut state).unwrap(); | ||
assert!(positive_call_info.accessed_contract_addresses.contains(&address)); | ||
assert!(positive_call_info.read_class_hash_values.contains(&class_hash)); | ||
assert_eq!( | ||
positive_call_info.execution, | ||
CallExecution { | ||
retdata: retdata!(), | ||
gas_consumed: expected_gas, | ||
failed: false, | ||
..CallExecution::default() | ||
} | ||
); | ||
|
||
// Negative case: address not present in state | ||
let non_existing_address = contract_address!("0x333"); | ||
let negative_entry_point_call = CallEntryPoint { | ||
calldata: calldata![non_existing_address.into(), class_hash.0], | ||
entry_point_selector: selector_from_name("test_get_class_hash_at"), | ||
..trivial_external_entry_point_new(test_contract) | ||
}; | ||
assert!(negative_entry_point_call.execute_directly(&mut state).unwrap().execution.failed); | ||
|
||
// Case with existing address but different class_hash | ||
let different_class_hash = class_hash!("0x444"); | ||
let different_class_hash_entry_point_call = CallEntryPoint { | ||
calldata: calldata![address.into(), different_class_hash.0], | ||
entry_point_selector: selector_from_name("test_get_class_hash_at"), | ||
..trivial_external_entry_point_new(test_contract) | ||
}; | ||
assert!( | ||
different_class_hash_entry_point_call | ||
.execute_directly(&mut state) | ||
.unwrap() | ||
.execution | ||
.failed | ||
); | ||
} |
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