diff --git a/src/vm/air_input_public.zig b/src/vm/air_input_public.zig index 46770677..15714d24 100644 --- a/src/vm/air_input_public.zig +++ b/src/vm/air_input_public.zig @@ -1,6 +1,7 @@ const std = @import("std"); const Felt252 = @import("starknet").fields.Felt252; const RelocatedTraceEntry = @import("trace_context.zig").RelocatedTraceEntry; +const RelocatedFelt252 = @import("trace_context.zig").RelocatedFelt252; const HintProcessor = @import("../hint_processor/hint_processor_def.zig").CairoVMHintProcessor; const Config = @import("config.zig").Config; @@ -117,7 +118,7 @@ pub const PublicInput = struct { // new - creating new PublicInput, all arguments caller is owner pub fn new( allocator: std.mem.Allocator, - memory: []const ?Felt252, + memory: []const RelocatedFelt252, layout: []const u8, public_memory_addresses: []const std.meta.Tuple(&.{ usize, usize }), memory_segment_addresses: std.StringHashMap(std.meta.Tuple(&.{ usize, usize })), @@ -125,7 +126,7 @@ pub const PublicInput = struct { rc_limits: std.meta.Tuple(&.{ isize, isize }), ) !Self { const memory_entry = (struct { - fn func(mem: []const ?Felt252, addresses: std.meta.Tuple(&.{ usize, usize })) !PublicMemoryEntry { + fn func(mem: []const RelocatedFelt252, addresses: std.meta.Tuple(&.{ usize, usize })) !PublicMemoryEntry { const address, const page = addresses; return .{ .address = address, @@ -181,7 +182,7 @@ pub const PublicMemoryEntry = struct { address: usize, value: struct { /// using struct only for json parse abstraction - value: ?Felt252, + value: RelocatedFelt252, pub fn jsonParse(allocator: std.mem.Allocator, source: anytype, options: std.json.ParseOptions) !@This() { _ = allocator; // autofix @@ -200,7 +201,7 @@ pub const PublicMemoryEntry = struct { } pub fn jsonStringify(self: @This(), out: anytype) !void { - if (self.value) |v| try out.print("\"0x{x}\"", .{v.toU256()}) else try out.write(null); + if (self.value.getValue()) |v| try out.print("\"0x{x}\"", .{v.toU256()}) else try out.write(null); } }, page: usize, diff --git a/src/vm/cairo_run.zig b/src/vm/cairo_run.zig index 7a732699..d71d00a7 100644 --- a/src/vm/cairo_run.zig +++ b/src/vm/cairo_run.zig @@ -43,11 +43,11 @@ pub fn writeEncodedTrace(relocated_trace: []const RelocatedTraceEntry, dest: any /// /// - `relocated_memory`: The post-execution memory, relocated. /// - `dest`: The destination file that the memory is to be written. -pub fn writeEncodedMemory(relocated_memory: []?Felt252, dest: anytype) !void { +pub fn writeEncodedMemory(relocated_memory: []RelocatedFelt252, dest: anytype) !void { var buf: [8]u8 = undefined; for (relocated_memory, 0..) |memory_cell, i| { - if (memory_cell) |cell| { + if (memory_cell.getValue()) |cell| { std.mem.writeInt(u64, &buf, i, .little); _ = try dest.write(&buf); _ = try dest.write(&cell.toBytesLe()); @@ -217,7 +217,6 @@ pub fn runConfig(allocator: Allocator, config: Config) !CairoRunner { &hint_processor, ); - try runner.vm.verifyAutoDeductions(allocator); // cairo_runner.read_return_values(allow_missing_builtins)?; @@ -228,7 +227,6 @@ pub fn runConfig(allocator: Allocator, config: Config) !CairoRunner { if (secure_run) try security.verifySecureRunner(allocator, &runner, true, null); - if (config.print_output) { var buf = try std.ArrayList(u8).initCapacity(allocator, 100); defer buf.deinit(); diff --git a/src/vm/core.zig b/src/vm/core.zig index 6fd4613d..0b2798ce 100644 --- a/src/vm/core.zig +++ b/src/vm/core.zig @@ -492,10 +492,10 @@ pub const CairoVM = struct { try self.opcodeAssertions(instruction, operands_result); // Constants for offset bit manipulation. - const OFFSET = 1 << 15; - const off_0 = instruction.off_0 + OFFSET; - const off_1 = instruction.off_1 + OFFSET; - const off_2 = instruction.off_2 + OFFSET; + const OFFSET: u16 = 1 << 15; + const off_0 = @as(isize, instruction.off_0) + OFFSET; + const off_1 = @as(isize, instruction.off_1) + OFFSET; + const off_2 = @as(isize, instruction.off_2) + OFFSET; // Calculate and update relocation limits. self.rc_limits = if (self.rc_limits) |limits| .{ diff --git a/src/vm/instructions.zig b/src/vm/instructions.zig index cc42e5a1..96c22f8d 100644 --- a/src/vm/instructions.zig +++ b/src/vm/instructions.zig @@ -136,15 +136,16 @@ pub const Instruction = struct { /// Offset 0 /// /// In the range [-2**15, 2*15) = [-2**(OFFSET_BITS-1), 2**(OFFSET_BITS-1)). - off_0: isize = 0, + /// 16 bit signed integer + off_0: i16 = 0, /// Offset 1 /// /// In the range [-2**15, 2*15) = [-2**(OFFSET_BITS-1), 2**(OFFSET_BITS-1)). - off_1: isize = 0, + off_1: i16 = 0, /// Offset 2 /// /// In the range [-2**15, 2*15) = [-2**(OFFSET_BITS-1), 2**(OFFSET_BITS-1)). - off_2: isize = 0, + off_2: i16 = 0, /// Destination register. dst_reg: Register = .FP, /// Operand 0 register. diff --git a/src/vm/runners/cairo_runner.zig b/src/vm/runners/cairo_runner.zig index d61a487d..61efc906 100644 --- a/src/vm/runners/cairo_runner.zig +++ b/src/vm/runners/cairo_runner.zig @@ -156,7 +156,7 @@ pub const CairoRunner = struct { run_ended: bool = false, execution_public_memory: ?std.ArrayList(usize) = null, relocated_trace: ?[]RelocatedTraceEntry = null, - relocated_memory: ArrayList(?Felt252), + relocated_memory: ArrayList(RelocatedFelt252), execution_scopes: ExecutionScopes = undefined, segments_finalized: bool, @@ -184,7 +184,7 @@ pub const CairoRunner = struct { .instructions = instructions, .vm = vm, .runner_mode = if (proof_mode) .proof_mode_canonical else .execution_mode, - .relocated_memory = ArrayList(?Felt252).init(allocator), + .relocated_memory = ArrayList(RelocatedFelt252).init(allocator), .execution_scopes = exec_scopes, .entrypoint = program.shared_program_data.main, .segments_finalized = false, @@ -939,14 +939,14 @@ pub const CairoRunner = struct { // Resize `relocated_memory` if needed. if (self.relocated_memory.items.len <= relocated_address) { - self.relocated_memory.appendNTimesAssumeCapacity(null, relocated_address - self.relocated_memory.items.len + 1); + self.relocated_memory.appendNTimesAssumeCapacity(RelocatedFelt252.NONE, relocated_address - self.relocated_memory.items.len + 1); } // Update the entry in `relocated_memory` with the relocated value of the memory cell. - self.relocated_memory.items[relocated_address] = try cell.relocateValue(relocation_table); + self.relocated_memory.items[relocated_address] = RelocatedFelt252.init(try cell.relocateValue(relocation_table)); } else { // If the memory cell is null, append `null` to `relocated_memory`. - self.relocated_memory.appendAssumeCapacity(null); + self.relocated_memory.appendAssumeCapacity(RelocatedFelt252.NONE); } } }