Skip to content

Commit

Permalink
feat: native poseidon hashing func (keep-starknet-strange#303)
Browse files Browse the repository at this point in the history
* native poseidon hashing func

* comment for constants

* removed unused commented func in fields

* code generation for poseidon round key consts

* small refactoring

* update hash of zig cli

* additional comments
  • Loading branch information
StringNick authored Jan 13, 2024
1 parent b7a716e commit 9c7f666
Show file tree
Hide file tree
Showing 9 changed files with 1,515 additions and 7 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ test-filter: libstarknet_crypto.a
build-integration-test:
@zig build integration_test

build-and-run-poseidon-consts-gen:
@zig build poseidon_consts_gen
> ./src/math/crypto/poseidon/gen/constants.zig
./zig-out/bin/poseidon_consts_gen
@zig fmt ./src/math/crypto/poseidon/gen/constants.zig

libstarknet_crypto.a:
@rm -f src/math/crypto/starknet_crypto/libstarknet_crypto.a
@cd src/math/crypto/starknet_crypto/starknet_crypto && cargo build --release
Expand Down
23 changes: 23 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ pub fn build(b: *std.Build) void {

integration_test(b, optimize, target);

// This creates a build step. It will be visible in the `zig build --help` menu,
// and can be selected like this: `zig build poseidon_consts_gen`
poseidon_consts_gen(b, optimize, target);

// This creates a build step. It will be visible in the `zig build --help` menu,
// and can be selected like this: `zig build run`
// This will evaluate the `run` step rather than the default, which is "install".
Expand Down Expand Up @@ -180,3 +184,22 @@ fn integration_test(
const install_step = b.addInstallArtifact(binary, .{});
integration_test_build.dependOn(&install_step.step);
}

fn poseidon_consts_gen(
b: *std.Build,
mode: std.builtin.Mode,
target: std.Build.ResolvedTarget,
) void {
const binary = b.addExecutable(.{
.name = "poseidon_consts_gen",
.root_source_file = .{ .path = "src/poseidon_consts_gen.zig" },
.target = target,
.optimize = mode,
});

const poseidon_consts_gen_build = b.step("poseidon_consts_gen", "Cli: poseidon consts generator");
poseidon_consts_gen_build.dependOn(&binary.step);

const install_step = b.addInstallArtifact(binary, .{});
poseidon_consts_gen_build.dependOn(&install_step.step);
}
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
.dependencies = .{
.@"zig-cli" = .{
.url = "https://github.com/sam701/zig-cli/archive/refs/heads/main.tar.gz",
.hash = "1220b1cc7c256080eb3229d95a8519d6a33035dc83558a8ca1ed6e407008a38fe2c2",
.hash = "12208a4377c7699927605e5a797bad5ae2ba8be4b49f68b9f522b3a755597a21f1cf",
},
},
}
2 changes: 2 additions & 0 deletions src/lib.zig
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub const math = struct {
pub usingnamespace @import("math/fields/fields.zig");
pub usingnamespace @import("math/fields/stark_felt_252_gen_fp.zig");
pub usingnamespace @import("math/fields/starknet.zig");
pub usingnamespace @import("math/crypto/poseidon/poseidon.zig");

pub usingnamespace @import("math/crypto/pedersen_hash.zig");
pub usingnamespace @import("math/fields/elliptic_curve.zig");
};
Expand Down
461 changes: 461 additions & 0 deletions src/math/crypto/poseidon/gen/config.json

Large diffs are not rendered by default.

Loading

0 comments on commit 9c7f666

Please sign in to comment.