Skip to content

Commit

Permalink
chore: organize methods such that public methods are at bottom
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Aug 14, 2024
1 parent ce82441 commit 376a76d
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions crates/blockifier/src/execution/contract_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,6 @@ impl ContractClassV0 {
self.entry_points_by_type.values().map(|vec| vec.len()).sum()
}

pub fn n_builtins(&self) -> usize {
self.program.builtins_len()
}

pub fn bytecode_length(&self) -> usize {
self.program.data_len()
}

fn estimate_casm_hash_computation_resources(&self) -> ExecutionResources {
let hashed_data_size = (constants::CAIRO0_ENTRY_POINT_STRUCT_SIZE * self.n_entry_points())
+ self.n_builtins()
Expand All @@ -145,6 +137,14 @@ impl ContractClassV0 {
}
}

pub fn n_builtins(&self) -> usize {
self.program.builtins_len()
}

pub fn bytecode_length(&self) -> usize {
self.program.data_len()
}

pub fn try_from_json_string(raw_contract_class: &str) -> Result<ContractClassV0, ProgramError> {
let contract_class: ContractClassV0Inner = serde_json::from_str(raw_contract_class)?;
Ok(ContractClassV0(Arc::new(contract_class)))
Expand Down Expand Up @@ -185,6 +185,23 @@ impl ContractClassV1 {
Some(self.0.entry_points_by_type[&EntryPointType::Constructor].first()?.selector)
}

/// Returns the estimated VM resources required for computing Casm hash.
/// This is an empiric measurement of several bytecode lengths, which constitutes as the
/// dominant factor in it.
fn estimate_casm_hash_computation_resources(&self) -> ExecutionResources {
estimate_casm_hash_computation_resources(&self.bytecode_segment_lengths)
}

// Returns the set of segments that were visited according to the given visited PCs.
// Each visited segment must have its starting PC visited, and is represented by it.
fn get_visited_segments(
&self,
visited_pcs: &HashSet<usize>,
) -> Result<Vec<usize>, TransactionExecutionError> {
let mut reversed_visited_pcs: Vec<_> = visited_pcs.iter().cloned().sorted().rev().collect();
get_visited_segments(&self.bytecode_segment_lengths, &mut reversed_visited_pcs, &mut 0)
}

pub fn bytecode_length(&self) -> usize {
self.program.data_len()
}
Expand Down Expand Up @@ -219,23 +236,6 @@ impl ContractClassV1 {
}
}

/// Returns the estimated VM resources required for computing Casm hash.
/// This is an empiric measurement of several bytecode lengths, which constitutes as the
/// dominant factor in it.
fn estimate_casm_hash_computation_resources(&self) -> ExecutionResources {
estimate_casm_hash_computation_resources(&self.bytecode_segment_lengths)
}

// Returns the set of segments that were visited according to the given visited PCs.
// Each visited segment must have its starting PC visited, and is represented by it.
fn get_visited_segments(
&self,
visited_pcs: &HashSet<usize>,
) -> Result<Vec<usize>, TransactionExecutionError> {
let mut reversed_visited_pcs: Vec<_> = visited_pcs.iter().cloned().sorted().rev().collect();
get_visited_segments(&self.bytecode_segment_lengths, &mut reversed_visited_pcs, &mut 0)
}

pub fn try_from_json_string(raw_contract_class: &str) -> Result<ContractClassV1, ProgramError> {
let casm_contract_class: CasmContractClass = serde_json::from_str(raw_contract_class)?;
let contract_class: ContractClassV1 = casm_contract_class.try_into()?;
Expand Down

0 comments on commit 376a76d

Please sign in to comment.