Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Remove unwraps in execution_entry_point module #1137

Merged
merged 1 commit into from
Nov 10, 2023
Merged
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
30 changes: 16 additions & 14 deletions src/execution/execution_entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use cairo_vm::{
relocatable::{MaybeRelocatable, Relocatable},
},
vm::{
errors::runner_errors::RunnerError,
runners::cairo_runner::{CairoArg, CairoRunner, ExecutionResources, RunResources},
vm_core::VirtualMachine,
},
Expand Down Expand Up @@ -469,24 +470,24 @@ impl ExecutionEntryPoint {

/// Returns the hash of the executed contract class.
fn get_code_class_hash<S: State>(&self, state: &mut S) -> Result<[u8; 32], TransactionError> {
if self.class_hash.is_some() {
if let Some(class_hash) = self.class_hash {
match self.call_type {
CallType::Delegate => return Ok(self.class_hash.unwrap()),
CallType::Delegate => return Ok(class_hash),
_ => return Err(TransactionError::CallTypeIsNotDelegate),
}
}
let code_address = match self.call_type {
CallType::Call => Some(self.contract_address.clone()),
CallType::Call => &self.contract_address,
CallType::Delegate => {
if self.code_address.is_some() {
self.code_address.clone()
if let Some(ref code_address) = self.code_address {
code_address
} else {
return Err(TransactionError::AttempToUseNoneCodeAddress);
}
}
};

get_deployed_address_class_hash_at_address(state, &code_address.unwrap())
get_deployed_address_class_hash_at_address(state, code_address)
}

fn _execute_version0_class<S: StateReader>(
Expand Down Expand Up @@ -653,7 +654,6 @@ impl ExecutionEntryPoint {
);
let mut runner = StarknetRunner::new(cairo_runner, vm, hint_processor);

// TODO: handle error cases
// Load builtin costs
let builtin_costs: Vec<MaybeRelocatable> =
vec![0.into(), 0.into(), 0.into(), 0.into(), 0.into()];
Expand All @@ -664,14 +664,16 @@ impl ExecutionEntryPoint {
.into();

// Load extra data
let core_program_end_ptr =
(runner.cairo_runner.program_base.unwrap() + program.data_len()).unwrap();
let core_program_end_ptr = (runner
.cairo_runner
.program_base
.ok_or(RunnerError::NoProgBase)?
+ program.data_len())?;
let program_extra_data: Vec<MaybeRelocatable> =
vec![0x208B7FFF7FFF7FFE.into(), builtin_costs_ptr];
runner
.vm
.load_data(core_program_end_ptr, &program_extra_data)
.unwrap();
.load_data(core_program_end_ptr, &program_extra_data)?;

// Positional arguments are passed to *args in the 'run_from_entrypoint' function.
let data = self.calldata.iter().map(|d| d.into()).collect();
Expand All @@ -687,7 +689,7 @@ impl ExecutionEntryPoint {
.collect();
entrypoint_args.push(CairoArg::Single(alloc_pointer.clone()));
entrypoint_args.push(CairoArg::Single(
alloc_pointer.add_usize(self.calldata.len()).unwrap(),
alloc_pointer.add_usize(self.calldata.len())?,
));

let ref_vec: Vec<&CairoArg> = entrypoint_args.iter().collect();
Expand All @@ -711,11 +713,11 @@ impl ExecutionEntryPoint {
.get_initial_fp()
.ok_or(TransactionError::MissingInitialFp)?;

let args_ptr = initial_fp - (entrypoint_args.len() + 2);
let args_ptr = (initial_fp - (entrypoint_args.len() + 2))?;

runner
.vm
.mark_address_range_as_accessed(args_ptr.unwrap(), entrypoint_args.len())?;
.mark_address_range_as_accessed(args_ptr, entrypoint_args.len())?;

*resources_manager = runner
.hint_processor
Expand Down