From b046a8bec9807a029ffd750c12b458220d152a24 Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Thu, 25 Apr 2024 09:54:26 +0200 Subject: [PATCH] upgrade to 0.12.0 --- .github/workflows/ci.yml | 8 ++++---- build.zig | 4 ++-- build.zig.zon | 1 + src/banderwagon/banderwagon.zig | 6 +++--- src/bench.zig | 10 +++++----- src/fields/fields.zig | 8 ++++---- src/fields/sqrt.zig | 2 +- src/ipa/ipa.zig | 4 ++-- src/msm/pippenger.zig | 2 +- src/msm/precomp.zig | 2 +- src/multiproof/multiproof.zig | 10 +++++----- 11 files changed, 29 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 296342f..5b2a9cb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Zig uses: korandoru/setup-zig@v1 with: - zig-version: 0.11.0 + zig-version: 0.12.0 - name: Build run: zig build @@ -29,7 +29,7 @@ jobs: - name: Set up Zig uses: korandoru/setup-zig@v1 with: - zig-version: 0.11.0 + zig-version: 0.12.0 - name: Lint run: zig fmt --check src/*.zig @@ -42,7 +42,7 @@ jobs: - name: Set up Zig uses: korandoru/setup-zig@v1 with: - zig-version: 0.11.0 + zig-version: 0.12.0 - name: Test - run: zig build test \ No newline at end of file + run: zig build test diff --git a/build.zig b/build.zig index 02d1df2..743e40a 100644 --- a/build.zig +++ b/build.zig @@ -5,7 +5,7 @@ pub fn build(b: *std.Build) !void { const optimize = b.standardOptimizeOption(.{}); const verkle_crypto_module = b.createModule(.{ - .source_file = .{ .path = "src/main.zig" }, + .root_source_file = .{ .path = "src/main.zig" }, }); try b.modules.put(b.dupe("verkle-crypto"), verkle_crypto_module); @@ -27,7 +27,7 @@ pub fn build(b: *std.Build) !void { // run_test.has_side_effects = true; test_step.dependOn(&run_test.step); - var bench = b.addExecutable(.{ + const bench = b.addExecutable(.{ .name = "bench", .root_source_file = .{ .path = "src/bench.zig" }, .target = target, diff --git a/build.zig.zon b/build.zig.zon index 3e7da9b..a111250 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,4 +1,5 @@ .{ .name = "verkle-crypto", .version = "0.1.0", + .paths = .{""}, } diff --git a/src/banderwagon/banderwagon.zig b/src/banderwagon/banderwagon.zig index 643b553..5cee9b5 100644 --- a/src/banderwagon/banderwagon.zig +++ b/src/banderwagon/banderwagon.zig @@ -220,7 +220,7 @@ pub const ElementMSM = struct { // fromBytes deserializes an element from a byte array. // The spec serialization is the X coordinate in big endian form. pub fn fromBytes(bytes: [Element.BytesSize]u8) !ElementMSM { - const bi = std.mem.readIntSlice(u256, &bytes, std.builtin.Endian.Big); + const bi = std.mem.readInt(u256, &bytes, .big); if (bi >= Fp.Modulo) { return error.BytesNotCanonical; } @@ -308,13 +308,13 @@ test "Element -> ElementNormalized" { test "bytes canonical" { const max_value_fp = Fp.Modulo - 1; var bytes: [Fp.BytesSize]u8 = undefined; - std.mem.writeInt(u256, &bytes, max_value_fp, std.builtin.Endian.Big); + std.mem.writeInt(u256, &bytes, max_value_fp, .big); // Must succeed. _ = try ElementMSM.fromBytes(bytes); for (0..3) |i| { const bigger_than_modulus = Fp.Modulo + i; - std.mem.writeInt(u256, &bytes, bigger_than_modulus, std.builtin.Endian.Big); + std.mem.writeInt(u256, &bytes, bigger_than_modulus, .big); const must_error = ElementMSM.fromBytes(bytes); try std.testing.expectError(error.BytesNotCanonical, must_error); } diff --git a/src/bench.zig b/src/bench.zig index 3398c06..9b5c95a 100644 --- a/src/bench.zig +++ b/src/bench.zig @@ -18,7 +18,7 @@ pub fn main() !void { const deinit_status = gpa.deinit(); if (deinit_status == .leak) std.testing.expect(false) catch @panic("memory leak"); } - var allocator = gpa.allocator(); + const allocator = gpa.allocator(); try benchFields(); try benchPedersenHash(allocator); @@ -106,7 +106,7 @@ fn benchPedersenHash(allocator: Allocator) !void { } } - var start = std.time.microTimestamp(); + const start = std.time.microTimestamp(); for (0..N) |i| { _ = try xcrs.commit(vecs[i][0..vec_len]); } @@ -223,7 +223,7 @@ fn benchMultiproofs(allocator: Allocator) !void { var copied_cs = try allocator.alloc(banderwagon.Element, vec_openings.len); defer allocator.free(copied_cs); for (0..vec_openings.len) |i| copied_cs[i] = vec_openings[i].C; - var cs_msms = try allocator.alloc(banderwagon.ElementMSM, vec_openings.len); + const cs_msms = try allocator.alloc(banderwagon.ElementMSM, vec_openings.len); defer allocator.free(cs_msms); banderwagon.ElementMSM.fromElements(cs_msms, copied_cs); @@ -294,7 +294,7 @@ fn analyzePedersenHashConfigs(allocator: Allocator) !void { const vec_lens = .{ 1, 5, 8, 16, 64, 128, 256 }; inline for (vec_lens) |vec_len| { - var start = std.time.microTimestamp(); + const start = std.time.microTimestamp(); for (0..N) |_| { _ = try precomp.msm(scalars[0..vec_len]); } @@ -322,7 +322,7 @@ fn analyzePedersenHashConfigs(allocator: Allocator) !void { const vec_lens = .{ 5, 8, 16, 64, 128, 256 }; inline for (vec_lens) |vec_len| { - var start = std.time.microTimestamp(); + const start = std.time.microTimestamp(); for (0..N) |_| { _ = try hybprecomp.msm(scalars[0..vec_len]); } diff --git a/src/fields/fields.zig b/src/fields/fields.zig index 1761062..33f636d 100644 --- a/src/fields/fields.zig +++ b/src/fields/fields.zig @@ -28,7 +28,7 @@ fn Field(comptime F: type, comptime mod: u256) type { pub fn fromInteger(num: u256) Self { var lbe: [BytesSize]u8 = [_]u8{0} ** BytesSize; - std.mem.writeInt(u256, lbe[0..], num % Modulo, std.builtin.Endian.Little); + std.mem.writeInt(u256, lbe[0..], num % Modulo, .little); var nonMont: F.NonMontgomeryDomainFieldElement = undefined; F.fromBytes(&nonMont, lbe); @@ -54,7 +54,7 @@ fn Field(comptime F: type, comptime mod: u256) type { pub fn fromBytes(bytes: [BytesSize]u8) Self { var non_mont: F.NonMontgomeryDomainFieldElement = undefined; inline for (0..4) |i| { - non_mont[i] = std.mem.readIntSlice(u64, bytes[i * 8 .. (i + 1) * 8], std.builtin.Endian.Little); + non_mont[i] = std.mem.readInt(u64, bytes[i * 8 .. (i + 1) * 8], .little); } var ret: Self = undefined; F.toMontgomery(&ret.fe, non_mont); @@ -67,7 +67,7 @@ fn Field(comptime F: type, comptime mod: u256) type { F.fromMontgomery(&non_mont, self.fe); var ret: [BytesSize]u8 = undefined; inline for (0..4) |i| { - std.mem.writeIntSlice(u64, ret[i * 8 .. (i + 1) * 8], non_mont[i], std.builtin.Endian.Little); + std.mem.writeInt(u64, ret[i * 8 .. (i + 1) * 8], non_mont[i], .little); } return ret; @@ -210,7 +210,7 @@ fn Field(comptime F: type, comptime mod: u256) type { var bytes: [BytesSize]u8 = [_]u8{0} ** BytesSize; F.toBytes(&bytes, non_mont); - return std.mem.readInt(u256, &bytes, std.builtin.Endian.Little); + return std.mem.readInt(u256, &bytes, .little); } pub fn sqrt(x: Self) ?Self { diff --git a/src/fields/sqrt.zig b/src/fields/sqrt.zig index 4f4449d..fde5eeb 100644 --- a/src/fields/sqrt.zig +++ b/src/fields/sqrt.zig @@ -287,7 +287,7 @@ pub fn sqrtAlg_ComputeRelevantPowers( test "correctness" { for (0..1_000) |i| { // Take a random fp. - var a: Fp = Fp.fromInteger(i); + const a: Fp = Fp.fromInteger(i); const sqrt_fast = Fp.sqrt(a); if (sqrt_fast == null) { diff --git a/src/ipa/ipa.zig b/src/ipa/ipa.zig index 621034e..9b1f56d 100644 --- a/src/ipa/ipa.zig +++ b/src/ipa/ipa.zig @@ -259,13 +259,13 @@ test "basic proof" { const output_point_check_hex = std.fmt.bytesToHex(output_point_check.toBytes(), std.fmt.Case.lower); try std.testing.expectEqualStrings("4a353e70b03c89f161de002e8713beec0d740a5e20722fd5bd68b30540a33208", &output_point_check_hex); - var query = VKTIPA.ProverQuery{ + const query = VKTIPA.ProverQuery{ .commitment = commitment, .A = lagrange_poly, .eval_point = eval_point, }; - var ipa_proof = try ipa.createProof(xcrs, &prover_transcript, query); + const ipa_proof = try ipa.createProof(xcrs, &prover_transcript, query); // Lets check the state of the transcript by squeezing out another challenge const p_challenge = prover_transcript.challengeScalar("state"); diff --git a/src/msm/pippenger.zig b/src/msm/pippenger.zig index 880372a..52d68f8 100644 --- a/src/msm/pippenger.zig +++ b/src/msm/pippenger.zig @@ -40,7 +40,7 @@ pub fn msmWithWindowSize(base_allocator: Allocator, c: u4, basis: []const Elemen defer arena.deinit(); var allocator = arena.allocator(); - var scalars_windows = try signedDigitDecomposition(allocator, c, num_windows, scalars_mont); + const scalars_windows = try signedDigitDecomposition(allocator, c, num_windows, scalars_mont); var result: ?Element = null; var buckets = try allocator.alloc(?Element, num_buckets); diff --git a/src/msm/precomp.zig b/src/msm/precomp.zig index c309175..da659e3 100644 --- a/src/msm/precomp.zig +++ b/src/msm/precomp.zig @@ -98,7 +98,7 @@ pub fn PrecompMSM( fillWindow(window_basis, nn_table[w * window_size .. (w + 1) * window_size]); } - var table = try allocator.alloc(ElementMSM, window_size * num_windows); + const table = try allocator.alloc(ElementMSM, window_size * num_windows); ElementMSM.fromElements(table, nn_table); return Self{ diff --git a/src/multiproof/multiproof.zig b/src/multiproof/multiproof.zig index bc3ac69..9a9512d 100644 --- a/src/multiproof/multiproof.zig +++ b/src/multiproof/multiproof.zig @@ -118,7 +118,7 @@ pub const MultiProof = struct { const polynomial = h_minus_g; const eval_point = t; - var query = IPA.ProverQuery{ + const query = IPA.ProverQuery{ .commitment = ipa_commitment, .A = polynomial, .eval_point = eval_point, @@ -242,7 +242,7 @@ pub const MultiProof = struct { for (0..crs.DomainSize) |i| { if (i != indexIsize) { const den = @as(isize, @intCast(inverses.len)); - var num = @as(isize, @intCast(i)) - indexIsize; + const num = @as(isize, @intCast(i)) - indexIsize; var inv_idx = @mod(num, den); q[i] = Fr.mul(Fr.sub(f.evaluations[i], y), inverses[@as(usize, @intCast(inv_idx))]); @@ -259,7 +259,7 @@ pub const MultiProof = struct { }; test "basic" { - var allocator = std.testing.allocator; + const allocator = std.testing.allocator; // Polynomials in lagrange basis const poly_eval_a = [_]Fr{ @@ -367,8 +367,8 @@ test "basic" { ); var verifier_transcript = Transcript.init("test"); - var vquery_a = VerifierQuery{ .C = ElementNormalized.fromElement(Cs[0]), .z = zs[0], .y = ys[0] }; - var vquery_b = VerifierQuery{ .C = ElementNormalized.fromElement(Cs[1]), .z = zs[1], .y = ys[1] }; + const vquery_a = VerifierQuery{ .C = ElementNormalized.fromElement(Cs[0]), .z = zs[0], .y = ys[0] }; + const vquery_b = VerifierQuery{ .C = ElementNormalized.fromElement(Cs[1]), .z = zs[1], .y = ys[1] }; const ok = try multiproof.verifyProof(allocator, &verifier_transcript, &[_]VerifierQuery{ vquery_a, vquery_b }, proof); try std.testing.expect(ok);