Skip to content

Commit

Permalink
Feat: Small optimizations and doc fixes (#533)
Browse files Browse the repository at this point in the history
* small optimisations

* fixed readme, fix bug with tab in comments
  • Loading branch information
StringNick authored Aug 20, 2024
1 parent 55d83e6 commit cadff14
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 15 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?

<details>
Expand Down Expand Up @@ -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
```


Expand Down
1 change: 0 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/cmd.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 5 additions & 6 deletions src/hint_processor/math_hints.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/vm/core.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 2 additions & 5 deletions src/vm/memory/memory.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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|
Expand Down

0 comments on commit cadff14

Please sign in to comment.