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: organize methods such that public methods are at bottom #432

Closed
Closed
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
42 changes: 21 additions & 21 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,13 @@ 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)
}

pub fn bytecode_length(&self) -> usize {
self.program.data_len()
}
Expand Down Expand Up @@ -219,30 +226,23 @@ 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)
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()?;

Ok(contract_class)
}

// 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(
pub 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()?;

Ok(contract_class)
}

/// Returns an empty contract class for testing purposes.
#[cfg(any(feature = "testing", test))]
pub fn empty_for_testing() -> Self {
Expand Down
Loading