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

chore(blockifier): small fixes #1456

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,7 @@ impl<'a> DeprecatedSyscallHintProcessor<'a> {
&mut self,
vm: &mut VirtualMachine,
) -> DeprecatedSyscallResult<Felt> {
let selector = felt_from_ptr(vm, &mut self.syscall_ptr)?;

Ok(selector)
Ok(felt_from_ptr(vm, &mut self.syscall_ptr)?)
}

fn increment_syscall_count(&mut self, selector: &DeprecatedSyscallSelector) {
Expand Down Expand Up @@ -466,9 +464,9 @@ impl HintProcessorLogic for DeprecatedSyscallHintProcessor<'_> {
}

pub fn felt_to_bool(felt: Felt) -> DeprecatedSyscallResult<bool> {
if felt == Felt::from(0_u8) {
if felt == Felt::ZERO {
Ok(false)
} else if felt == Felt::from(1_u8) {
} else if felt == Felt::ONE {
Ok(true)
} else {
Err(DeprecatedSyscallExecutionError::InvalidSyscallInput {
Expand Down
13 changes: 6 additions & 7 deletions crates/blockifier/src/execution/syscalls/hint_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,11 @@ pub struct SyscallHintProcessor<'a> {

pub sha256_segment_end_ptr: Option<Relocatable>,

// Execution info, for get_execution_info syscall; allocated on-demand.
execution_info_ptr: Option<Relocatable>,

// Additional fields.
hints: &'a HashMap<String, Hint>,
// Transaction info. and signature segments; allocated on-demand.
execution_info_ptr: Option<Relocatable>,
}

impl<'a> SyscallHintProcessor<'a> {
Expand Down Expand Up @@ -535,9 +536,7 @@ impl<'a> SyscallHintProcessor<'a> {
}

fn read_next_syscall_selector(&mut self, vm: &mut VirtualMachine) -> SyscallResult<Felt> {
let selector = felt_from_ptr(vm, &mut self.syscall_ptr)?;

Ok(selector)
Ok(felt_from_ptr(vm, &mut self.syscall_ptr)?)
}

pub fn increment_syscall_count_by(&mut self, selector: &SyscallSelector, n: usize) {
Expand Down Expand Up @@ -761,9 +760,9 @@ impl HintProcessorLogic for SyscallHintProcessor<'_> {
}

pub fn felt_to_bool(felt: Felt, error_info: &str) -> SyscallResult<bool> {
if felt == Felt::from(0_u8) {
if felt == Felt::ZERO {
Ok(false)
} else if felt == Felt::from(1_u8) {
} else if felt == Felt::ONE {
Ok(true)
} else {
Err(SyscallExecutionError::InvalidSyscallInput { input: felt, info: error_info.into() })
Expand Down
8 changes: 4 additions & 4 deletions crates/blockifier/src/execution/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ impl<T: SyscallResponse> SyscallResponse for SyscallResponseWrapper<T> {
Self::Success { gas_counter, response } => {
write_felt(vm, ptr, Felt::from(gas_counter))?;
// 0 to indicate success.
write_felt(vm, ptr, Felt::from(0_u8))?;
write_felt(vm, ptr, Felt::ZERO)?;
response.write(vm, ptr)
}
Self::Failure { gas_counter, error_data } => {
write_felt(vm, ptr, Felt::from(gas_counter))?;
// 1 to indicate failure.
write_felt(vm, ptr, Felt::from(1_u8))?;
write_felt(vm, ptr, Felt::ONE)?;

// Write the error data to a new memory segment.
let revert_reason_start = vm.add_memory_segment();
Expand Down Expand Up @@ -579,7 +579,7 @@ pub struct StorageReadRequest {
impl SyscallRequest for StorageReadRequest {
fn read(vm: &VirtualMachine, ptr: &mut Relocatable) -> SyscallResult<StorageReadRequest> {
let address_domain = felt_from_ptr(vm, ptr)?;
if address_domain != Felt::from(0_u8) {
if address_domain != Felt::ZERO {
return Err(SyscallExecutionError::InvalidAddressDomain { address_domain });
}
let address = StorageKey::try_from(felt_from_ptr(vm, ptr)?)?;
Expand Down Expand Up @@ -620,7 +620,7 @@ pub struct StorageWriteRequest {
impl SyscallRequest for StorageWriteRequest {
fn read(vm: &VirtualMachine, ptr: &mut Relocatable) -> SyscallResult<StorageWriteRequest> {
let address_domain = felt_from_ptr(vm, ptr)?;
if address_domain != Felt::from(0_u8) {
if address_domain != Felt::ZERO {
return Err(SyscallExecutionError::InvalidAddressDomain { address_domain });
}
let address = StorageKey::try_from(felt_from_ptr(vm, ptr)?)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/fee/fee_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub fn get_balance_and_if_covers_fee(
balance_high,
// TODO(Dori,1/10/2023): If/when fees can be more than 128 bit integers, this should be
// updated.
balance_high > Felt::from(0_u8) || balance_low >= Felt::from(fee.0),
balance_high > Felt::ZERO || balance_low >= Felt::from(fee.0),
))
}

Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/transaction/account_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ impl AccountTransaction {
// The least significant 128 bits of the amount transferred.
let lsb_amount = Felt::from(actual_fee.0);
// The most significant 128 bits of the amount transferred.
let msb_amount = Felt::from(0_u8);
let msb_amount = Felt::ZERO;

let TransactionContext { block_context, tx_info } = tx_context.as_ref();
let storage_address = tx_context.fee_token_address();
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/transaction/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1901,7 +1901,7 @@ fn test_validate_accounts_tx(
additional_data: Some(vec![
Felt::from(CURRENT_BLOCK_NUMBER_FOR_VALIDATE),
Felt::from(CURRENT_BLOCK_TIMESTAMP_FOR_VALIDATE),
Felt::from(0_u64), // Sequencer address for validate.
Felt::ZERO, // Sequencer address for validate.
]),
declared_contract: Some(FeatureContract::Empty(declared_contract_cairo_version)),
resource_bounds: ValidResourceBounds::create_for_testing(),
Expand Down
2 changes: 1 addition & 1 deletion crates/papyrus_storage/src/state/state_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ fn revert_state() {
assert!(state_reader.get_nonce_at(state_number, &contract1).unwrap().is_none());
assert_eq!(
state_reader.get_storage_at(state_number, contract0, &updated_storage_key).unwrap(),
Felt::from(0_u8)
Felt::ZERO
);
assert!(txn.get_casm(&class2).unwrap().is_none());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ pub(crate) fn create_contract_state_leaf_entry(val: u128) -> (StorageKey, Storag
},
storage_tries: HashMap::from([
(
ContractAddress(Felt::from(0_u128)),
ContractAddress(Felt::ZERO),
OriginalSkeletonTreeImpl {
nodes: create_expected_skeleton_nodes(
vec![
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ pub fn create_root_edge_entry(
Felt::from(old_root)
.to_bytes_be()
.into_iter()
.chain(Felt::from(0_u128).to_bytes_be())
.chain(Felt::ZERO.to_bytes_be())
.chain([length])
.collect(),
);
Expand Down
Loading