-
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
5f70eab
commit 48c155d
Showing
18 changed files
with
195 additions
and
1 deletion.
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
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; |
71 changes: 71 additions & 0 deletions
71
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,71 @@ | ||
use starknet_api::{calldata, class_hash, contract_address, felt}; | ||
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` has a different `class_hash`. | ||
/// 5. Execution succeeds and returns `class_hash` = 0 if `address` is absent. | ||
#[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); | ||
|
||
// Test deployed contract. | ||
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[0] == class_hash); | ||
assert_eq!( | ||
positive_call_info.execution, | ||
CallExecution { | ||
retdata: retdata!(), | ||
gas_consumed: expected_gas, | ||
failed: false, | ||
..CallExecution::default() | ||
} | ||
); | ||
// Test undeployed contract - should return class_hash = 0 and succeed. | ||
let non_existing_address = felt!("0x333"); | ||
let class_hash_of_undeployed_contract = felt!("0x0"); | ||
|
||
let negative_entry_point_call = CallEntryPoint { | ||
calldata: calldata![non_existing_address, class_hash_of_undeployed_contract], | ||
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); | ||
|
||
// Sanity check: giving the wrong expected class hash to the test should make it fail. | ||
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
Oops, something went wrong.