Skip to content

Commit cadff14

Browse files
authored
Feat: Small optimizations and doc fixes (#533)
* small optimisations * fixed readme, fix bug with tab in comments
1 parent 55d83e6 commit cadff14

File tree

6 files changed

+32
-15
lines changed

6 files changed

+32
-15
lines changed

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@
2727

2828
Alternatively, if you have [nix](https://nixos.org/) installed, you can get the full development environment `nix develop`.
2929

30+
- Also you need installed python, so we can compile cairo0 programs in benchmarks/integration tests, to insatll them just run:
31+
```bash
32+
make deps
33+
```
34+
if u got macos:
35+
```bash
36+
make deps-macos
37+
```
38+
- After you need compile all cairo0 programs, to use test or benchmarks:
39+
```bash
40+
make compile-cairo-programs
41+
```
3042
## ⚡ Wanna get up to speed fast?
3143

3244
<details>
@@ -64,9 +76,19 @@ You can display the help message by running:
6476

6577
### Run a cairo program
6678

79+
Without proof mode:
6780
```bash
81+
./zig-out/bin/ziggy-starkdust execute --filename cairo_programs/fibonacci.json
82+
```
6883

69-
./zig-out/bin/ziggy-starkdust execute --filename cairo_programs/fibonacci.json --proof-mode=false
84+
With proof mode:
85+
```bash
86+
./zig-out/bin/ziggy-starkdust execute --filename cairo_programs/fibonacci.json --proof-mode
87+
```
88+
89+
With memory layout, trace, proof mode and custom layout:
90+
```bash
91+
./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
7092
```
7193

7294

build.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ pub fn build(b: *std.Build) void {
114114
.root_source_file = b.path("src/main.zig"),
115115
.target = target,
116116
.optimize = optimize,
117-
118117
.link_libc = false,
119118
.omit_frame_pointer = if (optimize == .ReleaseFast) null else false,
120119
.strip = if (optimize == .ReleaseFast) true else null,

src/cmd/cmd.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ const UsageError = error{
248248
/// Returns a `UsageError` if there's a misuse of the CLI, specifically if tracing is attempted
249249
/// while it's disabled in the build.
250250
fn execute() anyerror!void {
251-
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
251+
var arena = std.heap.ArenaAllocator.init(global_allocator);
252252
defer arena.deinit();
253253

254254
try runProgram(arena.allocator(), cfg);

src/hint_processor/math_hints.zig

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,14 @@ pub fn isPositive(allocator: Allocator, vm: *CairoVM, ids_data: std.StringHashMa
6565
), vm, ids_data, ap_tracking);
6666
}
6767

68-
// Implements hint:from starkware.cairo.common.math.cairo
68+
//Implements hint:from starkware.cairo.common.math.cairo
6969
//
70-
// %{
71-
// from starkware.cairo.common.math_utils import assert_integer
72-
// assert_integer(ids.value)
73-
// assert ids.value % PRIME != 0, f'assert_not_zero failed: {ids.value} = 0.'
70+
//%{
71+
// from starkware.cairo.common.math_utils import assert_integer
72+
// assert_integer(ids.value)
73+
// assert ids.value % PRIME != 0, f'assert_not_zero failed: {ids.value} = 0.'
7474
//
7575
// %}
76-
7776
pub fn assertNonZero(
7877
vm: *CairoVM,
7978
ids_data: std.StringHashMap(HintReference),

src/vm/core.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ pub const CairoVM = struct {
470470
) !void {
471471
// Check if tracing is disabled and log the current state if not.
472472
if (self.trace) |*trace| {
473-
if (trace.capacity < trace.items.len + 1)
473+
if (trace.capacity <= trace.items.len)
474474
try trace.ensureTotalCapacityPrecise(trace.capacity * 2);
475475

476476
trace.appendAssumeCapacity(

src/vm/memory/memory.zig

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ pub const Memory = struct {
370370
/// - `MemoryError.DuplicatedRelocation` if there is an attempt to overwrite existing memory.
371371
/// # Safety
372372
/// This function assumes proper initialization and management of the VM memory.
373-
pub fn set(
373+
pub inline fn set(
374374
self: *Self,
375375
allocator: Allocator,
376376
address: Relocatable,
@@ -380,9 +380,6 @@ pub const Memory = struct {
380380
var data = self.getDataFromSegmentIndex(address.segment_index);
381381
const insert_segment_index = address.getAdjustedSegmentIndex();
382382

383-
// if (address.segment_index == 0 and value.isFelt())
384-
// std.debug.panic("set {any}, value {any}", .{ address, value });
385-
386383
// Check if the data segment is allocated for the given segment index.
387384
if (data.len <= insert_segment_index)
388385
return MemoryError.UnallocatedSegment;
@@ -902,7 +899,7 @@ pub const Memory = struct {
902899
return value;
903900
}
904901

905-
pub fn relAddress(self: *const Self, address: Relocatable) !MaybeRelocatable {
902+
pub inline fn relAddress(self: *const Self, address: Relocatable) !MaybeRelocatable {
906903
// Attempt to retrieve relocation rules for the given segment index.
907904
if (address.segment_index < 0)
908905
if (self.relocation_rules.get(address.getAdjustedSegmentIndex())) |x|

0 commit comments

Comments
 (0)