Skip to content

Commit 020f4ea

Browse files
authored
chore: replace zlinter with the default zig linter (#33)
2 parents a459e65 + 63fa674 commit 020f4ea

File tree

8 files changed

+30
-50
lines changed

8 files changed

+30
-50
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: Verify Zig installation
3030
run: zig version
3131

32-
- name: Run lint
32+
- name: Run lint (zig fmt --check)
3333
run: zig build lint
3434

3535
test:
@@ -72,4 +72,4 @@ jobs:
7272
version: 0.14.1
7373

7474
- name: Build library
75-
run: zig build-lib src/root.zig --name hash_zig
75+
run: zig build

build.zig

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const std = @import("std");
33
pub fn build(b: *std.Build) void {
44
const target = b.standardTargetOptions(.{});
55
const optimize = b.standardOptimizeOption(.{});
6+
const enable_docs = b.option(bool, "docs", "Enable docs generation") orelse false;
67

78
// Create the module
89
const hash_zig_module = b.addModule("hash-zig", .{
@@ -19,21 +20,10 @@ pub fn build(b: *std.Build) void {
1920
});
2021
b.installArtifact(lib);
2122

22-
// Lint (using zlinter)
23-
const zlinter = @import("zlinter");
24-
const lint_step = b.step("lint", "Run zlinter");
25-
lint_step.dependOn(step: {
26-
var builder = zlinter.builder(b, .{});
27-
builder.addPaths(.{
28-
.include = &.{ b.path("src/"), b.path("examples/"), b.path("test/") },
29-
});
30-
builder.addRule(.{ .builtin = .field_naming }, .{});
31-
builder.addRule(.{ .builtin = .declaration_naming }, .{});
32-
builder.addRule(.{ .builtin = .function_naming }, .{});
33-
builder.addRule(.{ .builtin = .no_unused }, .{});
34-
builder.addRule(.{ .builtin = .no_deprecated }, .{});
35-
break :step builder.build();
36-
});
23+
// Lint (using built-in formatter in check mode)
24+
const lint_cmd = b.addSystemCommand(&.{ "zig", "fmt", "--check", "src", "examples" });
25+
const lint_step = b.step("lint", "Run lint (zig fmt --check)");
26+
lint_step.dependOn(&lint_cmd.step);
3727

3828
// Tests
3929
const lib_unit_tests = b.addTest(.{
@@ -177,12 +167,14 @@ pub fn build(b: *std.Build) void {
177167
// const optimized_benchmark_step = b.step("optimized-benchmark", "Run optimized performance benchmark");
178168
// optimized_benchmark_step.dependOn(&run_optimized_benchmark.step);
179169

180-
// Documentation
181-
const docs_step = b.step("docs", "Generate documentation");
182-
const install_docs = b.addInstallDirectory(.{
183-
.source_dir = lib.getEmittedDocs(),
184-
.install_dir = .prefix,
185-
.install_subdir = "docs",
186-
});
187-
docs_step.dependOn(&install_docs.step);
170+
// Documentation (opt-in to avoid enabling -femit-docs on default builds)
171+
if (enable_docs) {
172+
const docs_step = b.step("docs", "Generate documentation");
173+
const install_docs = b.addInstallDirectory(.{
174+
.source_dir = lib.getEmittedDocs(),
175+
.install_dir = .prefix,
176+
.install_subdir = "docs",
177+
});
178+
docs_step.dependOn(&install_docs.step);
179+
}
188180
}

build.zig.zon

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@
44
.fingerprint = 0xc2f8b6b2acaee93c,
55
.minimum_zig_version = "0.14.1",
66

7-
.dependencies = .{
8-
.zlinter = .{
9-
.url = "git+https://github.com/kurtwagner/zlinter?ref=0.14.x#61d13720da00e47855d67397a8a36a7827aba165",
10-
.hash = "1220ef236272ded3155b3fa6e198f3cf57c9c82606fcb18ca4f76e1b2242fad2dfd2",
11-
},
12-
},
7+
.dependencies = .{},
138

149
.paths = .{
1510
"build.zig",

examples/profiling.zig

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,52 +21,48 @@ pub fn main() !void {
2121

2222
// Profile individual WOTS operations
2323
std.debug.print("--- Single WOTS Operation Profile ---\n", .{});
24-
24+
2525
const wots_priv_start_ts = std.time.nanoTimestamp();
2626
const priv_key = try sig_scheme.wots.generatePrivateKey(allocator, &seed, 0);
2727
const wots_priv_end_ts = std.time.nanoTimestamp();
28-
28+
2929
const pub_key = try sig_scheme.wots.generatePublicKey(allocator, priv_key);
3030
const wots_pub_end_ts = std.time.nanoTimestamp();
31-
31+
3232
const priv_time = @as(f64, @floatFromInt(wots_priv_end_ts - wots_priv_start_ts)) / 1_000_000.0;
3333
const pub_time = @as(f64, @floatFromInt(wots_pub_end_ts - wots_priv_end_ts)) / 1_000_000.0;
34-
34+
3535
std.debug.print(" generatePrivateKey: {d:.3} ms\n", .{priv_time});
3636
std.debug.print(" generatePublicKey: {d:.3} ms\n", .{pub_time});
3737
std.debug.print(" Total per leaf: {d:.3} ms\n\n", .{priv_time + pub_time});
38-
38+
3939
for (priv_key) |k| allocator.free(k);
4040
allocator.free(priv_key);
4141
allocator.free(pub_key);
4242

4343
// Profile hash operations
4444
std.debug.print("--- Hash Operation Profile ---\n", .{});
4545
const test_data = "test data for hashing";
46-
46+
4747
const hash_start_ts = std.time.nanoTimestamp();
4848
const hash_result = try sig_scheme.wots.hash.hash(allocator, test_data, 0);
4949
const hash_end_ts = std.time.nanoTimestamp();
5050
allocator.free(hash_result);
51-
51+
5252
const hash_time = @as(f64, @floatFromInt(hash_end_ts - hash_start_ts)) / 1_000_000.0;
5353
std.debug.print(" Single hash call: {d:.3} ms\n\n", .{hash_time});
5454

5555
// Calculate expected times
5656
const num_leaves = @as(usize, 1) << @intCast(params.tree_height);
5757
const chain_length = @as(u32, 1) << @intCast(@ctz(params.winternitz_w));
58-
58+
5959
std.debug.print("--- Theoretical Breakdown for 1,024 leaves ---\n", .{});
6060
std.debug.print(" Chain length: {}\n", .{chain_length});
6161
std.debug.print(" Chains per leaf: ~86\n", .{});
6262
std.debug.print(" Hashes per leaf: ~86 * {} = ~{}\n", .{ chain_length, 86 * chain_length });
6363
std.debug.print(" Total hashes: 1024 * {} = ~{}\n", .{ 86 * chain_length, 1024 * 86 * chain_length });
64-
std.debug.print(" Expected hash time: {d:.1} seconds\n", .{
65-
@as(f64, @floatFromInt(1024 * 86 * chain_length)) * hash_time / 1000.0
66-
});
67-
std.debug.print(" Expected leaf gen: {d:.1} seconds\n\n", .{
68-
@as(f64, @floatFromInt(num_leaves)) * (priv_time + pub_time) / 1000.0
69-
});
64+
std.debug.print(" Expected hash time: {d:.1} seconds\n", .{@as(f64, @floatFromInt(1024 * 86 * chain_length)) * hash_time / 1000.0});
65+
std.debug.print(" Expected leaf gen: {d:.1} seconds\n\n", .{@as(f64, @floatFromInt(num_leaves)) * (priv_time + pub_time) / 1000.0});
7066

7167
// Now do full keygen with timing
7268
std.debug.print("--- Full Key Generation ---\n", .{});
@@ -85,4 +81,3 @@ pub fn main() !void {
8581
std.debug.print(" Merkle tree: ~{d:.1}%\n", .{100.0 - leaf_gen_percent});
8682
std.debug.print(" Other overhead: ~{d:.1}%\n", .{@max(0.0, 100.0 - leaf_gen_percent - 10.0)});
8783
}
88-

src/merkle.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub const MerkleTree = struct {
132132
defer allocator.free(threads);
133133
// Spawn workers
134134
for (0..num_threads) |t| {
135-
threads[t] = try std.Thread.spawn(.{}, nodeWorker, .{ &ctx });
135+
threads[t] = try std.Thread.spawn(.{}, nodeWorker, .{&ctx});
136136
}
137137
// Join
138138
for (threads) |th| th.join();
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
// KoalaBear field: p = 2^31 - 2^24 + 1 = 127 * 2^24 + 1 = 2130706433 = 0x7f000001
22
pub const montgomery_field = @import("../generic_montgomery.zig").MontgomeryField31(127 * (1 << 24) + 1);
3-

src/poseidon2/poseidon2.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn Poseidon2(
4040
permutation(&state);
4141
var result: [output_len]F.FieldElem = undefined;
4242
inline for (0..output_len) |i| {
43-
// Add input[i] to montgomery form state[i]
43+
// Add input[i] to montgomery form state[i]
4444
var input_mont: F.MontFieldElem = undefined;
4545
F.toMontgomery(&input_mont, input[i]);
4646
F.add(&state[i], state[i], input_mont);

src/poseidon2/root.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@ pub const koalabear16 = @import("instances/koalabear16.zig");
1313
// Re-export the main types (snake_case per lint)
1414
pub const poseidon2_koalabear16 = koalabear16.poseidon2_type;
1515
pub const koalabear_field = koalabear_montgomery.montgomery_field;
16-

0 commit comments

Comments
 (0)