Skip to content

feat: implement fromReference method for HintReference #291

Open
@tcoratger

Description

@tcoratger

In order to transform a Reference instance into a HintReference instance:

  • Reference structure

    pub const Reference = struct {
    /// Tracking data for the register associated with the reference.
    ap_tracking_data: ApTracking,
    /// Program counter (pc) tied to the reference (optional, defaults to null).
    pc: ?usize,
    /// Value of the reference.
    value: []const u8,
    };

  • HintReference structure

    pub const HintReference = struct {
    const Self = @This();
    /// First offset value within the hint reference.
    offset1: OffsetValue,
    /// Second offset value within the hint reference.
    offset2: ?OffsetValue,
    /// Flag indicating dereference within the hint reference.
    dereference: bool,
    /// Ap tracking data associated with the hint reference (optional, defaults to null).
    ap_tracking_data: ?ApTracking,
    /// Cairo type information related to the hint reference (optional, defaults to null).
    cairo_type: ?[]const u8,
    /// Initializes a hint reference with specified offsets and dereference flags.
    ///
    /// Params:
    /// - `offset1`: First offset value.
    /// - `offset2`: Second offset value.
    /// - `inner_dereference`: Flag for inner dereference within the first offset value.
    /// - `dereference`: Flag for dereference within the hint reference.
    pub fn init(
    offset1: i32,
    offset2: i32,
    inner_dereference: bool,
    dereference: bool,
    ) Self {
    return .{
    .offset1 = .{ .reference = .{ .FP, offset1, inner_dereference } },
    .offset2 = .{ .value = offset2 },
    .dereference = dereference,
    .ap_tracking_data = null,
    .cairo_type = null,
    };
    }
    /// Initializes a simple hint reference with the specified offset.
    ///
    /// Params:
    /// - `offset1`: First offset value for the hint reference.
    pub fn initSimple(offset1: i32) Self {
    return .{
    .offset1 = .{ .reference = .{ .FP, offset1, false } },
    .offset2 = .{ .value = 0 },
    .dereference = true,
    .ap_tracking_data = null,
    .cairo_type = null,
    };
    }
    };

we need a fromReference method similar to:

https://github.com/lambdaclass/cairo-vm/blob/8a2ef24c1ca258f1d1d230cbbd1478cd1d4cf9db/vm/src/hint_processor/hint_processor_definition.rs#L133-L153

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions