Skip to content

Commit 25c222d

Browse files
authored
Merge pull request #3 from gballet/upgrade-to-0.12.0
upgrade to 0.12.0
2 parents 55015f6 + b046a8b commit 25c222d

File tree

11 files changed

+29
-28
lines changed

11 files changed

+29
-28
lines changed

.github/workflows/ci.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Set up Zig
1717
uses: korandoru/setup-zig@v1
1818
with:
19-
zig-version: 0.11.0
19+
zig-version: 0.12.0
2020

2121
- name: Build
2222
run: zig build
@@ -29,7 +29,7 @@ jobs:
2929
- name: Set up Zig
3030
uses: korandoru/setup-zig@v1
3131
with:
32-
zig-version: 0.11.0
32+
zig-version: 0.12.0
3333

3434
- name: Lint
3535
run: zig fmt --check src/*.zig
@@ -42,7 +42,7 @@ jobs:
4242
- name: Set up Zig
4343
uses: korandoru/setup-zig@v1
4444
with:
45-
zig-version: 0.11.0
45+
zig-version: 0.12.0
4646

4747
- name: Test
48-
run: zig build test
48+
run: zig build test

build.zig

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub fn build(b: *std.Build) !void {
55
const optimize = b.standardOptimizeOption(.{});
66

77
const verkle_crypto_module = b.createModule(.{
8-
.source_file = .{ .path = "src/main.zig" },
8+
.root_source_file = .{ .path = "src/main.zig" },
99
});
1010
try b.modules.put(b.dupe("verkle-crypto"), verkle_crypto_module);
1111

@@ -27,7 +27,7 @@ pub fn build(b: *std.Build) !void {
2727
// run_test.has_side_effects = true;
2828
test_step.dependOn(&run_test.step);
2929

30-
var bench = b.addExecutable(.{
30+
const bench = b.addExecutable(.{
3131
.name = "bench",
3232
.root_source_file = .{ .path = "src/bench.zig" },
3333
.target = target,

build.zig.zon

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.{
22
.name = "verkle-crypto",
33
.version = "0.1.0",
4+
.paths = .{""},
45
}

src/banderwagon/banderwagon.zig

+3-3
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ pub const ElementMSM = struct {
220220
// fromBytes deserializes an element from a byte array.
221221
// The spec serialization is the X coordinate in big endian form.
222222
pub fn fromBytes(bytes: [Element.BytesSize]u8) !ElementMSM {
223-
const bi = std.mem.readIntSlice(u256, &bytes, std.builtin.Endian.Big);
223+
const bi = std.mem.readInt(u256, &bytes, .big);
224224
if (bi >= Fp.Modulo) {
225225
return error.BytesNotCanonical;
226226
}
@@ -308,13 +308,13 @@ test "Element -> ElementNormalized" {
308308
test "bytes canonical" {
309309
const max_value_fp = Fp.Modulo - 1;
310310
var bytes: [Fp.BytesSize]u8 = undefined;
311-
std.mem.writeInt(u256, &bytes, max_value_fp, std.builtin.Endian.Big);
311+
std.mem.writeInt(u256, &bytes, max_value_fp, .big);
312312
// Must succeed.
313313
_ = try ElementMSM.fromBytes(bytes);
314314

315315
for (0..3) |i| {
316316
const bigger_than_modulus = Fp.Modulo + i;
317-
std.mem.writeInt(u256, &bytes, bigger_than_modulus, std.builtin.Endian.Big);
317+
std.mem.writeInt(u256, &bytes, bigger_than_modulus, .big);
318318
const must_error = ElementMSM.fromBytes(bytes);
319319
try std.testing.expectError(error.BytesNotCanonical, must_error);
320320
}

src/bench.zig

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn main() !void {
1818
const deinit_status = gpa.deinit();
1919
if (deinit_status == .leak) std.testing.expect(false) catch @panic("memory leak");
2020
}
21-
var allocator = gpa.allocator();
21+
const allocator = gpa.allocator();
2222

2323
try benchFields();
2424
try benchPedersenHash(allocator);
@@ -106,7 +106,7 @@ fn benchPedersenHash(allocator: Allocator) !void {
106106
}
107107
}
108108

109-
var start = std.time.microTimestamp();
109+
const start = std.time.microTimestamp();
110110
for (0..N) |i| {
111111
_ = try xcrs.commit(vecs[i][0..vec_len]);
112112
}
@@ -223,7 +223,7 @@ fn benchMultiproofs(allocator: Allocator) !void {
223223
var copied_cs = try allocator.alloc(banderwagon.Element, vec_openings.len);
224224
defer allocator.free(copied_cs);
225225
for (0..vec_openings.len) |i| copied_cs[i] = vec_openings[i].C;
226-
var cs_msms = try allocator.alloc(banderwagon.ElementMSM, vec_openings.len);
226+
const cs_msms = try allocator.alloc(banderwagon.ElementMSM, vec_openings.len);
227227
defer allocator.free(cs_msms);
228228
banderwagon.ElementMSM.fromElements(cs_msms, copied_cs);
229229

@@ -294,7 +294,7 @@ fn analyzePedersenHashConfigs(allocator: Allocator) !void {
294294

295295
const vec_lens = .{ 1, 5, 8, 16, 64, 128, 256 };
296296
inline for (vec_lens) |vec_len| {
297-
var start = std.time.microTimestamp();
297+
const start = std.time.microTimestamp();
298298
for (0..N) |_| {
299299
_ = try precomp.msm(scalars[0..vec_len]);
300300
}
@@ -322,7 +322,7 @@ fn analyzePedersenHashConfigs(allocator: Allocator) !void {
322322

323323
const vec_lens = .{ 5, 8, 16, 64, 128, 256 };
324324
inline for (vec_lens) |vec_len| {
325-
var start = std.time.microTimestamp();
325+
const start = std.time.microTimestamp();
326326
for (0..N) |_| {
327327
_ = try hybprecomp.msm(scalars[0..vec_len]);
328328
}

src/fields/fields.zig

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn Field(comptime F: type, comptime mod: u256) type {
2828

2929
pub fn fromInteger(num: u256) Self {
3030
var lbe: [BytesSize]u8 = [_]u8{0} ** BytesSize;
31-
std.mem.writeInt(u256, lbe[0..], num % Modulo, std.builtin.Endian.Little);
31+
std.mem.writeInt(u256, lbe[0..], num % Modulo, .little);
3232

3333
var nonMont: F.NonMontgomeryDomainFieldElement = undefined;
3434
F.fromBytes(&nonMont, lbe);
@@ -54,7 +54,7 @@ fn Field(comptime F: type, comptime mod: u256) type {
5454
pub fn fromBytes(bytes: [BytesSize]u8) Self {
5555
var non_mont: F.NonMontgomeryDomainFieldElement = undefined;
5656
inline for (0..4) |i| {
57-
non_mont[i] = std.mem.readIntSlice(u64, bytes[i * 8 .. (i + 1) * 8], std.builtin.Endian.Little);
57+
non_mont[i] = std.mem.readInt(u64, bytes[i * 8 .. (i + 1) * 8], .little);
5858
}
5959
var ret: Self = undefined;
6060
F.toMontgomery(&ret.fe, non_mont);
@@ -67,7 +67,7 @@ fn Field(comptime F: type, comptime mod: u256) type {
6767
F.fromMontgomery(&non_mont, self.fe);
6868
var ret: [BytesSize]u8 = undefined;
6969
inline for (0..4) |i| {
70-
std.mem.writeIntSlice(u64, ret[i * 8 .. (i + 1) * 8], non_mont[i], std.builtin.Endian.Little);
70+
std.mem.writeInt(u64, ret[i * 8 .. (i + 1) * 8], non_mont[i], .little);
7171
}
7272

7373
return ret;
@@ -210,7 +210,7 @@ fn Field(comptime F: type, comptime mod: u256) type {
210210
var bytes: [BytesSize]u8 = [_]u8{0} ** BytesSize;
211211
F.toBytes(&bytes, non_mont);
212212

213-
return std.mem.readInt(u256, &bytes, std.builtin.Endian.Little);
213+
return std.mem.readInt(u256, &bytes, .little);
214214
}
215215

216216
pub fn sqrt(x: Self) ?Self {

src/fields/sqrt.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ pub fn sqrtAlg_ComputeRelevantPowers(
287287
test "correctness" {
288288
for (0..1_000) |i| {
289289
// Take a random fp.
290-
var a: Fp = Fp.fromInteger(i);
290+
const a: Fp = Fp.fromInteger(i);
291291

292292
const sqrt_fast = Fp.sqrt(a);
293293
if (sqrt_fast == null) {

src/ipa/ipa.zig

+2-2
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,13 @@ test "basic proof" {
259259
const output_point_check_hex = std.fmt.bytesToHex(output_point_check.toBytes(), std.fmt.Case.lower);
260260
try std.testing.expectEqualStrings("4a353e70b03c89f161de002e8713beec0d740a5e20722fd5bd68b30540a33208", &output_point_check_hex);
261261

262-
var query = VKTIPA.ProverQuery{
262+
const query = VKTIPA.ProverQuery{
263263
.commitment = commitment,
264264
.A = lagrange_poly,
265265
.eval_point = eval_point,
266266
};
267267

268-
var ipa_proof = try ipa.createProof(xcrs, &prover_transcript, query);
268+
const ipa_proof = try ipa.createProof(xcrs, &prover_transcript, query);
269269

270270
// Lets check the state of the transcript by squeezing out another challenge
271271
const p_challenge = prover_transcript.challengeScalar("state");

src/msm/pippenger.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn msmWithWindowSize(base_allocator: Allocator, c: u4, basis: []const Elemen
4040
defer arena.deinit();
4141
var allocator = arena.allocator();
4242

43-
var scalars_windows = try signedDigitDecomposition(allocator, c, num_windows, scalars_mont);
43+
const scalars_windows = try signedDigitDecomposition(allocator, c, num_windows, scalars_mont);
4444

4545
var result: ?Element = null;
4646
var buckets = try allocator.alloc(?Element, num_buckets);

src/msm/precomp.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub fn PrecompMSM(
9898
fillWindow(window_basis, nn_table[w * window_size .. (w + 1) * window_size]);
9999
}
100100

101-
var table = try allocator.alloc(ElementMSM, window_size * num_windows);
101+
const table = try allocator.alloc(ElementMSM, window_size * num_windows);
102102
ElementMSM.fromElements(table, nn_table);
103103

104104
return Self{

src/multiproof/multiproof.zig

+5-5
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub const MultiProof = struct {
118118
const polynomial = h_minus_g;
119119
const eval_point = t;
120120

121-
var query = IPA.ProverQuery{
121+
const query = IPA.ProverQuery{
122122
.commitment = ipa_commitment,
123123
.A = polynomial,
124124
.eval_point = eval_point,
@@ -242,7 +242,7 @@ pub const MultiProof = struct {
242242
for (0..crs.DomainSize) |i| {
243243
if (i != indexIsize) {
244244
const den = @as(isize, @intCast(inverses.len));
245-
var num = @as(isize, @intCast(i)) - indexIsize;
245+
const num = @as(isize, @intCast(i)) - indexIsize;
246246
var inv_idx = @mod(num, den);
247247
q[i] = Fr.mul(Fr.sub(f.evaluations[i], y), inverses[@as(usize, @intCast(inv_idx))]);
248248

@@ -259,7 +259,7 @@ pub const MultiProof = struct {
259259
};
260260

261261
test "basic" {
262-
var allocator = std.testing.allocator;
262+
const allocator = std.testing.allocator;
263263

264264
// Polynomials in lagrange basis
265265
const poly_eval_a = [_]Fr{
@@ -367,8 +367,8 @@ test "basic" {
367367
);
368368

369369
var verifier_transcript = Transcript.init("test");
370-
var vquery_a = VerifierQuery{ .C = ElementNormalized.fromElement(Cs[0]), .z = zs[0], .y = ys[0] };
371-
var vquery_b = VerifierQuery{ .C = ElementNormalized.fromElement(Cs[1]), .z = zs[1], .y = ys[1] };
370+
const vquery_a = VerifierQuery{ .C = ElementNormalized.fromElement(Cs[0]), .z = zs[0], .y = ys[0] };
371+
const vquery_b = VerifierQuery{ .C = ElementNormalized.fromElement(Cs[1]), .z = zs[1], .y = ys[1] };
372372
const ok = try multiproof.verifyProof(allocator, &verifier_transcript, &[_]VerifierQuery{ vquery_a, vquery_b }, proof);
373373

374374
try std.testing.expect(ok);

0 commit comments

Comments
 (0)