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

Commit

Permalink
Merge pull request #553 from starkware-libs/elin/merge-main-v0.12.0-i…
Browse files Browse the repository at this point in the history
…nto-main

Elin/merge main v0.12.0 into main
  • Loading branch information
elintul authored May 31, 2023
2 parents 4e075aa + 645feb5 commit b4f6cb3
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 76 deletions.
8 changes: 4 additions & 4 deletions crates/blockifier/src/execution/cairo1_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::execution::errors::{
PostExecutionError, PreExecutionError, VirtualMachineExecutionError,
};
use crate::execution::execution_utils::{
read_execution_retdata, stark_felt_to_felt, write_felt, write_maybe_relocatable, Args,
read_execution_retdata, stark_felt_to_felt, write_maybe_relocatable, write_stark_felt, Args,
ReadOnlySegments,
};
use crate::execution::syscalls::hint_processor::SyscallHintProcessor;
Expand Down Expand Up @@ -143,7 +143,7 @@ fn prepare_builtin_costs(
// additional `ret` statement).
let mut ptr = (vm.get_pc() + contract_class.program.data.len())?;
// Push a `ret` opcode.
write_felt(vm, &mut ptr, stark_felt!("0x208b7fff7fff7ffe"))?;
write_stark_felt(vm, &mut ptr, stark_felt!("0x208b7fff7fff7ffe"))?;
// Push a pointer to the builtin cost segment.
write_maybe_relocatable(vm, &mut ptr, builtin_cost_segment_start)?;

Expand Down Expand Up @@ -176,8 +176,8 @@ pub fn prepare_call_arguments(
let n_constructed = StarkFelt::default();
let n_destructed = StarkFelt::default();
write_maybe_relocatable(vm, &mut ptr, info_segment)?;
write_felt(vm, &mut ptr, n_constructed)?;
write_felt(vm, &mut ptr, n_destructed)?;
write_stark_felt(vm, &mut ptr, n_constructed)?;
write_stark_felt(vm, &mut ptr, n_destructed)?;

args.push(CairoArg::Single(ptr.into()));
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use crate::execution::entry_point::{
};
use crate::execution::errors::EntryPointExecutionError;
use crate::execution::execution_utils::{
felt_from_ptr, felt_range_from_ptr, stark_felt_to_felt, ReadOnlySegment, ReadOnlySegments,
felt_range_from_ptr, stark_felt_from_ptr, stark_felt_to_felt, ReadOnlySegment, ReadOnlySegments,
};
use crate::execution::hint_code;
use crate::state::errors::StateError;
Expand Down Expand Up @@ -247,7 +247,7 @@ impl<'a> DeprecatedSyscallHintProcessor<'a> {
&mut self,
vm: &mut VirtualMachine,
) -> DeprecatedSyscallResult<StarkFelt> {
let selector = felt_from_ptr(vm, &mut self.syscall_ptr)?;
let selector = stark_felt_from_ptr(vm, &mut self.syscall_ptr)?;

Ok(selector)
}
Expand Down Expand Up @@ -357,7 +357,7 @@ pub fn read_call_params(
vm: &VirtualMachine,
ptr: &mut Relocatable,
) -> DeprecatedSyscallResult<(EntryPointSelector, Calldata)> {
let function_selector = EntryPointSelector(felt_from_ptr(vm, ptr)?);
let function_selector = EntryPointSelector(stark_felt_from_ptr(vm, ptr)?);
let calldata = read_calldata(vm, ptr)?;

Ok((function_selector, calldata))
Expand Down Expand Up @@ -411,7 +411,7 @@ pub fn read_felt_array<TErr>(
where
TErr: From<StarknetApiError> + From<VirtualMachineError> + From<MemoryError>,
{
let array_size = felt_from_ptr(vm, ptr)?;
let array_size = stark_felt_from_ptr(vm, ptr)?;
let array_data_start_ptr = vm.get_relocatable(*ptr)?;
*ptr += 1;

Expand Down
33 changes: 17 additions & 16 deletions crates/blockifier/src/execution/deprecated_syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use crate::execution::entry_point::{
CallEntryPoint, CallType, MessageToL1, OrderedEvent, OrderedL2ToL1Message,
};
use crate::execution::execution_utils::{
execute_deployment, felt_from_ptr, write_felt, write_maybe_relocatable, ReadOnlySegment,
execute_deployment, stark_felt_from_ptr, write_maybe_relocatable, write_stark_felt,
ReadOnlySegment,
};

#[cfg(test)]
Expand Down Expand Up @@ -145,7 +146,7 @@ impl SyscallRequest for CallContractRequest {
vm: &VirtualMachine,
ptr: &mut Relocatable,
) -> DeprecatedSyscallResult<CallContractRequest> {
let contract_address = ContractAddress::try_from(felt_from_ptr(vm, ptr)?)?;
let contract_address = ContractAddress::try_from(stark_felt_from_ptr(vm, ptr)?)?;
let (function_selector, calldata) = read_call_params(vm, ptr)?;

Ok(CallContractRequest { contract_address, function_selector, calldata })
Expand Down Expand Up @@ -236,10 +237,10 @@ pub struct DeployRequest {

impl SyscallRequest for DeployRequest {
fn read(vm: &VirtualMachine, ptr: &mut Relocatable) -> DeprecatedSyscallResult<DeployRequest> {
let class_hash = ClassHash(felt_from_ptr(vm, ptr)?);
let contract_address_salt = ContractAddressSalt(felt_from_ptr(vm, ptr)?);
let class_hash = ClassHash(stark_felt_from_ptr(vm, ptr)?);
let contract_address_salt = ContractAddressSalt(stark_felt_from_ptr(vm, ptr)?);
let constructor_calldata = read_calldata(vm, ptr)?;
let deploy_from_zero = felt_from_ptr(vm, ptr)?;
let deploy_from_zero = stark_felt_from_ptr(vm, ptr)?;

Ok(DeployRequest {
class_hash,
Expand All @@ -260,7 +261,7 @@ impl SyscallResponse for DeployResponse {
// `constructor_retdata`.
// Nonempty constructor retdata is currently not supported.
fn write(self, vm: &mut VirtualMachine, ptr: &mut Relocatable) -> WriteResponseResult {
write_felt(vm, ptr, *self.contract_address.0.key())?;
write_stark_felt(vm, ptr, *self.contract_address.0.key())?;
write_maybe_relocatable(vm, ptr, 0)?;
write_maybe_relocatable(vm, ptr, 0)?;
Ok(())
Expand Down Expand Up @@ -329,7 +330,7 @@ pub fn emit_event(
_vm: &mut VirtualMachine,
syscall_handler: &mut DeprecatedSyscallHintProcessor<'_>,
) -> DeprecatedSyscallResult<EmitEventResponse> {
let mut execution_context = &mut syscall_handler.context;
let execution_context = &mut syscall_handler.context;
let ordered_event =
OrderedEvent { order: execution_context.n_emitted_events, event: request.content };
syscall_handler.events.push(ordered_event);
Expand Down Expand Up @@ -412,7 +413,7 @@ pub struct GetContractAddressResponse {

impl SyscallResponse for GetContractAddressResponse {
fn write(self, vm: &mut VirtualMachine, ptr: &mut Relocatable) -> WriteResponseResult {
write_felt(vm, ptr, *self.address.0.key())?;
write_stark_felt(vm, ptr, *self.address.0.key())?;
Ok(())
}
}
Expand Down Expand Up @@ -495,7 +496,7 @@ impl SyscallRequest for LibraryCallRequest {
vm: &VirtualMachine,
ptr: &mut Relocatable,
) -> DeprecatedSyscallResult<LibraryCallRequest> {
let class_hash = ClassHash(felt_from_ptr(vm, ptr)?);
let class_hash = ClassHash(stark_felt_from_ptr(vm, ptr)?);
let (function_selector, calldata) = read_call_params(vm, ptr)?;

Ok(LibraryCallRequest { class_hash, function_selector, calldata })
Expand Down Expand Up @@ -556,7 +557,7 @@ impl SyscallRequest for ReplaceClassRequest {
vm: &VirtualMachine,
ptr: &mut Relocatable,
) -> DeprecatedSyscallResult<ReplaceClassRequest> {
let class_hash = ClassHash(felt_from_ptr(vm, ptr)?);
let class_hash = ClassHash(stark_felt_from_ptr(vm, ptr)?);

Ok(ReplaceClassRequest { class_hash })
}
Expand Down Expand Up @@ -589,7 +590,7 @@ impl SyscallRequest for SendMessageToL1Request {
vm: &VirtualMachine,
ptr: &mut Relocatable,
) -> DeprecatedSyscallResult<SendMessageToL1Request> {
let to_address = EthAddress::try_from(felt_from_ptr(vm, ptr)?)?;
let to_address = EthAddress::try_from(stark_felt_from_ptr(vm, ptr)?)?;
let payload = L2ToL1Payload(read_felt_array::<DeprecatedSyscallExecutionError>(vm, ptr)?);

Ok(SendMessageToL1Request { message: MessageToL1 { to_address, payload } })
Expand All @@ -603,7 +604,7 @@ pub fn send_message_to_l1(
_vm: &mut VirtualMachine,
syscall_handler: &mut DeprecatedSyscallHintProcessor<'_>,
) -> DeprecatedSyscallResult<SendMessageToL1Response> {
let mut execution_context = &mut syscall_handler.context;
let execution_context = &mut syscall_handler.context;
let ordered_message_to_l1 = OrderedL2ToL1Message {
order: execution_context.n_sent_messages_to_l1,
message: request.message,
Expand All @@ -626,7 +627,7 @@ impl SyscallRequest for StorageReadRequest {
vm: &VirtualMachine,
ptr: &mut Relocatable,
) -> DeprecatedSyscallResult<StorageReadRequest> {
let address = StorageKey::try_from(felt_from_ptr(vm, ptr)?)?;
let address = StorageKey::try_from(stark_felt_from_ptr(vm, ptr)?)?;
Ok(StorageReadRequest { address })
}
}
Expand All @@ -638,7 +639,7 @@ pub struct StorageReadResponse {

impl SyscallResponse for StorageReadResponse {
fn write(self, vm: &mut VirtualMachine, ptr: &mut Relocatable) -> WriteResponseResult {
write_felt(vm, ptr, self.value)?;
write_stark_felt(vm, ptr, self.value)?;
Ok(())
}
}
Expand All @@ -664,8 +665,8 @@ impl SyscallRequest for StorageWriteRequest {
vm: &VirtualMachine,
ptr: &mut Relocatable,
) -> DeprecatedSyscallResult<StorageWriteRequest> {
let address = StorageKey::try_from(felt_from_ptr(vm, ptr)?)?;
let value = felt_from_ptr(vm, ptr)?;
let address = StorageKey::try_from(stark_felt_from_ptr(vm, ptr)?)?;
let value = stark_felt_from_ptr(vm, ptr)?;
Ok(StorageWriteRequest { address, value })
}
}
Expand Down
23 changes: 19 additions & 4 deletions crates/blockifier/src/execution/execution_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,18 @@ pub fn read_execution_retdata(
Ok(Retdata(felt_range_from_ptr(&vm, Relocatable::try_from(&retdata_ptr)?, retdata_size)?))
}

pub fn felt_from_ptr(
pub fn stark_felt_from_ptr(
vm: &VirtualMachine,
ptr: &mut Relocatable,
) -> Result<StarkFelt, VirtualMachineError> {
let felt = felt_to_stark_felt(vm.get_integer(*ptr)?.as_ref());
Ok(felt_to_stark_felt(&felt_from_ptr(vm, ptr)?))
}

pub fn felt_from_ptr(
vm: &VirtualMachine,
ptr: &mut Relocatable,
) -> Result<Felt252, VirtualMachineError> {
let felt = vm.get_integer(*ptr)?.into_owned();
*ptr += 1;
Ok(felt)
}
Expand Down Expand Up @@ -204,12 +211,20 @@ pub fn execute_deployment(
)
}

pub fn write_felt(
pub fn write_stark_felt(
vm: &mut VirtualMachine,
ptr: &mut Relocatable,
felt: StarkFelt,
) -> Result<(), MemoryError> {
write_maybe_relocatable(vm, ptr, stark_felt_to_felt(felt))
write_felt(vm, ptr, stark_felt_to_felt(felt))
}

pub fn write_felt(
vm: &mut VirtualMachine,
ptr: &mut Relocatable,
felt: Felt252,
) -> Result<(), MemoryError> {
write_maybe_relocatable(vm, ptr, felt)
}

pub fn write_maybe_relocatable<T: Into<MaybeRelocatable>>(
Expand Down
6 changes: 3 additions & 3 deletions crates/blockifier/src/execution/syscalls/hint_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::execution::entry_point::{
};
use crate::execution::errors::EntryPointExecutionError;
use crate::execution::execution_utils::{
felt_from_ptr, felt_range_from_ptr, stark_felt_to_felt, write_maybe_relocatable,
felt_range_from_ptr, stark_felt_from_ptr, stark_felt_to_felt, write_maybe_relocatable,
ReadOnlySegment, ReadOnlySegments,
};
use crate::execution::syscalls::{
Expand Down Expand Up @@ -233,7 +233,7 @@ impl<'a> SyscallHintProcessor<'a> {
}

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

Ok(selector)
}
Expand Down Expand Up @@ -402,7 +402,7 @@ pub fn read_call_params(
vm: &VirtualMachine,
ptr: &mut Relocatable,
) -> SyscallResult<(EntryPointSelector, Calldata)> {
let function_selector = EntryPointSelector(felt_from_ptr(vm, ptr)?);
let function_selector = EntryPointSelector(stark_felt_from_ptr(vm, ptr)?);
let calldata = read_calldata(vm, ptr)?;

Ok((function_selector, calldata))
Expand Down
Loading

0 comments on commit b4f6cb3

Please sign in to comment.