-
Notifications
You must be signed in to change notification settings - Fork 12
Poseidon hasher integration #53
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
base: master
Are you sure you want to change the base?
Conversation
b6ac7df to
fbb1efe
Compare
…poseidon2 operations
gballet
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically what we discussed during the team meeting
| const deserialize = libssz.deserialize; | ||
| const hashTreeRoot = libssz.hashTreeRoot; | ||
| const std = @import("std"); | ||
| const build_options = @import("build_options"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as discussed during the call, please get rid of that option - the user should be the one deciding what hasher they use.
| } | ||
|
|
||
| test "Validator struct hash tree root" { | ||
| if (build_options.poseidon_enabled) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and so the tests can use sha256, that's fine. And you can add some poseidon-specific tests if you want, although they could also be in the zeam repo so that we don't impose a new dependency on ssz.zig
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or in the poseidon-zig repo, see what is the simplest
|
|
||
| // Configure the hasher based on build options | ||
| pub const Hasher = if (build_options.poseidon_enabled) blk: { | ||
| const hash_zig = @import("hash_zig"); | ||
| const poseidon2 = hash_zig.poseidon2; | ||
| const poseidon_wrapper = @import("./poseidon_wrapper.zig"); | ||
| const Poseidon2Type = poseidon2.Poseidon2KoalaBear24Plonky3; | ||
| // Wrap with SHA256-compatible API | ||
| break :blk poseidon_wrapper.PoseidonHasher(Poseidon2Type); | ||
| } else sha256; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you shouldn't be needing this, pass the hasher as a type or anytype into functions
|
|
||
| pub fn mixInLength2(root: [32]u8, length: usize, out: *[32]u8) void { | ||
| var hasher = sha256.init(sha256.Options{}); | ||
| var hasher = Hasher.init(Hasher.Options{}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so here, for example, do
mixInLength2(Hasher: type, root, ... ) {
var hasher = Hasher.init(Hasher.Options{});
Summary
Integrates Poseidon2 (KoalaBear, width‑24) as an optional SSZ Merkle hasher via the hash-zig dependency, with a SHA256-compatible API wrapper specialized for 64-byte SSZ compressions.
Features
-Dposeidon=true.Important Notes
buffer_len == 64.Build Examples