cairo-vm is a Rust implementation of the Cairo VM. Cairo (CPU Algebraic Intermediate Representation) is a programming language for writing provable programs, where one party can prove to another that a certain computation was executed correctly without the need for this party to re-execute the same program.
In the initialize_state function of the CairoRunner structure, there is redundant code in my opinion, that can be improved for clarity and efficiency.
At the beginning of the function, there is a conditional check (if let Some(prog_base) = self.program_base) to ensure that self.program_base is not None.
However, a few lines later, the unwrap method is used again on self.program_base to obtain base, and in case of None, it sets base to Relocatable::from((0, 0)).
This redundant check and assignment can be eliminated because the None case will never happen inside the if statement, making the base declaration unnecessary. Instead, we can directly use the prog_base variable in the loop to mark memory segments as accessed.
Issue Description
In the
initialize_state
function of theCairoRunner
structure, there is redundant code in my opinion, that can be improved for clarity and efficiency.At the beginning of the function, there is a conditional check (
if let Some(prog_base) = self.program_base
) to ensure thatself.program_base
is notNone
.https://github.com/lambdaclass/cairo-vm/blob/4ea224a1068b43aaa3899d24e834475106e8a78f/vm/src/vm/runners/cairo_runner.rs#L414-L431
However, a few lines later, the
unwrap
method is used again onself.program_base
to obtainbase
, and in case ofNone
, it setsbase
toRelocatable::from((0, 0))
.https://github.com/lambdaclass/cairo-vm/blob/4ea224a1068b43aaa3899d24e834475106e8a78f/vm/src/vm/runners/cairo_runner.rs#L425-L427
This redundant check and assignment can be eliminated because the
None
case will never happen inside theif
statement, making thebase
declaration unnecessary. Instead, we can directly use theprog_base
variable in the loop to mark memory segments as accessed.