From 429f520845d84d0f478f8d04407735c3b1872863 Mon Sep 17 00:00:00 2001 From: Nikita Orlov Date: Fri, 2 Aug 2024 12:08:31 +0200 Subject: [PATCH 1/2] small optimisations --- build.zig | 1 - src/cmd/cmd.zig | 2 +- src/vm/core.zig | 2 +- src/vm/memory/memory.zig | 7 ++----- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/build.zig b/build.zig index 3b3dc594..463e5232 100644 --- a/build.zig +++ b/build.zig @@ -114,7 +114,6 @@ pub fn build(b: *std.Build) void { .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, - .link_libc = false, .omit_frame_pointer = if (optimize == .ReleaseFast) null else false, .strip = if (optimize == .ReleaseFast) true else null, diff --git a/src/cmd/cmd.zig b/src/cmd/cmd.zig index 2139fe22..71158950 100644 --- a/src/cmd/cmd.zig +++ b/src/cmd/cmd.zig @@ -248,7 +248,7 @@ const UsageError = error{ /// Returns a `UsageError` if there's a misuse of the CLI, specifically if tracing is attempted /// while it's disabled in the build. fn execute() anyerror!void { - var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); + var arena = std.heap.ArenaAllocator.init(global_allocator); defer arena.deinit(); try runProgram(arena.allocator(), cfg); diff --git a/src/vm/core.zig b/src/vm/core.zig index 0b2798ce..623f793e 100644 --- a/src/vm/core.zig +++ b/src/vm/core.zig @@ -470,7 +470,7 @@ pub const CairoVM = struct { ) !void { // Check if tracing is disabled and log the current state if not. if (self.trace) |*trace| { - if (trace.capacity < trace.items.len + 1) + if (trace.capacity <= trace.items.len) try trace.ensureTotalCapacityPrecise(trace.capacity * 2); trace.appendAssumeCapacity( diff --git a/src/vm/memory/memory.zig b/src/vm/memory/memory.zig index 64b72e1e..7e70f0bf 100644 --- a/src/vm/memory/memory.zig +++ b/src/vm/memory/memory.zig @@ -370,7 +370,7 @@ pub const Memory = struct { /// - `MemoryError.DuplicatedRelocation` if there is an attempt to overwrite existing memory. /// # Safety /// This function assumes proper initialization and management of the VM memory. - pub fn set( + pub inline fn set( self: *Self, allocator: Allocator, address: Relocatable, @@ -380,9 +380,6 @@ pub const Memory = struct { var data = self.getDataFromSegmentIndex(address.segment_index); const insert_segment_index = address.getAdjustedSegmentIndex(); - // if (address.segment_index == 0 and value.isFelt()) - // std.debug.panic("set {any}, value {any}", .{ address, value }); - // Check if the data segment is allocated for the given segment index. if (data.len <= insert_segment_index) return MemoryError.UnallocatedSegment; @@ -902,7 +899,7 @@ pub const Memory = struct { return value; } - pub fn relAddress(self: *const Self, address: Relocatable) !MaybeRelocatable { + pub inline fn relAddress(self: *const Self, address: Relocatable) !MaybeRelocatable { // Attempt to retrieve relocation rules for the given segment index. if (address.segment_index < 0) if (self.relocation_rules.get(address.getAdjustedSegmentIndex())) |x| From b5d2f1f719183b706bc12798bf8fdda424d316db Mon Sep 17 00:00:00 2001 From: StringNick Date: Fri, 16 Aug 2024 10:22:08 +0200 Subject: [PATCH 2/2] fixed readme, fix bug with tab in comments --- README.md | 24 +++++++++++++++++++++++- src/hint_processor/math_hints.zig | 11 +++++------ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 38d0a0b7..0d7ed9de 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,18 @@ Alternatively, if you have [nix](https://nixos.org/) installed, you can get the full development environment `nix develop`. +- Also you need installed python, so we can compile cairo0 programs in benchmarks/integration tests, to insatll them just run: + ```bash + make deps + ``` + if u got macos: + ```bash + make deps-macos + ``` +- After you need compile all cairo0 programs, to use test or benchmarks: + ```bash + make compile-cairo-programs + ``` ## ⚡ Wanna get up to speed fast?
@@ -64,9 +76,19 @@ You can display the help message by running: ### Run a cairo program +Without proof mode: ```bash +./zig-out/bin/ziggy-starkdust execute --filename cairo_programs/fibonacci.json +``` -./zig-out/bin/ziggy-starkdust execute --filename cairo_programs/fibonacci.json --proof-mode=false +With proof mode: +```bash +./zig-out/bin/ziggy-starkdust execute --filename cairo_programs/fibonacci.json --proof-mode +``` + +With memory layout, trace, proof mode and custom layout: +```bash +./zig-out/bin/ziggy-starkdust execute --filename cairo_programs/fibonacci.json --memory-file=/dev/null --trace-file=/dev/null --proof-mode=true --layout all_cairo ``` diff --git a/src/hint_processor/math_hints.zig b/src/hint_processor/math_hints.zig index 3b52f374..07c834cc 100644 --- a/src/hint_processor/math_hints.zig +++ b/src/hint_processor/math_hints.zig @@ -65,15 +65,14 @@ pub fn isPositive(allocator: Allocator, vm: *CairoVM, ids_data: std.StringHashMa ), vm, ids_data, ap_tracking); } -// Implements hint:from starkware.cairo.common.math.cairo +//Implements hint:from starkware.cairo.common.math.cairo // -// %{ -// from starkware.cairo.common.math_utils import assert_integer -// assert_integer(ids.value) -// assert ids.value % PRIME != 0, f'assert_not_zero failed: {ids.value} = 0.' +//%{ +// from starkware.cairo.common.math_utils import assert_integer +// assert_integer(ids.value) +// assert ids.value % PRIME != 0, f'assert_not_zero failed: {ids.value} = 0.' // // %} - pub fn assertNonZero( vm: *CairoVM, ids_data: std.StringHashMap(HintReference),