Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to 0.12.0 #3

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
run: zig build test
4 changes: 2 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.{
.name = "verkle-crypto",
.version = "0.1.0",
.paths = .{""},
}
6 changes: 3 additions & 3 deletions src/banderwagon/banderwagon.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions src/bench.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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]);
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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]);
}
Expand Down Expand Up @@ -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]);
}
Expand Down
8 changes: 4 additions & 4 deletions src/fields/fields.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/fields/sqrt.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/ipa/ipa.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/msm/pippenger.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/msm/precomp.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
10 changes: 5 additions & 5 deletions src/multiproof/multiproof.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))]);

Expand All @@ -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{
Expand Down Expand Up @@ -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);
Expand Down
Loading