Skip to content

Refactor create_entry_code #2020

Open
Open
@FrancoGiachetta

Description

@FrancoGiachetta

The function crate_entry_code has increased in it’s size to a point in which it has become very tedious and hard to read, and understand. The main objective of this refactor would be to separe the main parts of it into smaller functions to improve its readability, primarily to make it easier to debug if that was the case. So this does not imply any other action than moving code.

Currently, create_entry_code can be divided into four groups (which must be in the order stated):

  1. Initialize arguments. This include:
    1. Initializing builtin segments.
    2. Initializing variables for the return types.
  2. Copy return values. This include:
    1. Serialize return values
    2. Copy serialized values to the output segment.
  3. Validate segment arena. This include:
    1. Call the hint that relocates all dictionaries
    2. Verify every segment in the SegmentArena is contiguos (in after each other).
  4. Finalize builder.

NOTE: group 3 is inside group 2, This is because of how the function was coded. Since both coping outputs and verifying the segment arena only happen during proof mode, the latter group is inside the former.

With these four steps performed in the function, we could take the first 3 and separate them into 3 different functions:

fn initialize_arguments(
    ctx: &mut CasmBuilderconfig, 
    config: &Cairo1RunConfig, 
    ...
);

fn copy_return_values_to_output(
    ctx: &mut CasmBuilderconfig, 
    config: &Cairo1RunConfig, 
    ...
);

fn validate_segment_arena(
    ctx: &mut CasmBuilderconfig, 
    config: &Cairo1RunConfig, 
    ...
);

Since the fourth step is to simply finalize the builder, it fine to leave it in the main function.
These three new functions must be called in the order stated above as it is a requirement for vm to be able to work properly.

NOTE: Since copy return values implies validating the SegmentArena, since both occur only in proof_mode. validate_segment_arena is called inside copy_return_values_to_output after copying return values.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions