-
Notifications
You must be signed in to change notification settings - Fork 39
feat: support spec test using test sig scheme #508
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
Open
GrapeBaBa
wants to merge
24
commits into
main
Choose a base branch
from
sig_spec_test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
4924e83
feat: impl sig spec test
GrapeBaBa 0233f7d
feat: add signature spec test
GrapeBaBa a27a789
fix: fix signature test
GrapeBaBa 5e56317
fix: bootstrap spectest:run when missing generated index
ff26975
fix(spectest): support verify_signatures attestations + proofs
71c50b4
chore: fix zig fmt step and rust lint
164aca4
Apply suggestion from @Copilot
GrapeBaBa ffe61b6
fix(spectest): stop using ctx allocator in signature parsing
c45ec58
Merge branch 'main' of github.com:blockblaz/zeam into sig_spec_test
ebb40d1
refactor: align latest spec test
f6abf9c
Merge branch 'main' into sig_spec_test
GrapeBaBa 9fe4b7b
refactor: hashsig test scheme
cf0df8f
fix: fix test
1a33798
fix: fix lint
9b24b2b
fix: fix review comments
961ee03
fix: fix review comments
fc8eb66
Merge remote-tracking branch 'origin/main' into sig_spec_test
4e7046f
Merge branch 'main' into sig_spec_test
GrapeBaBa 51f2ff4
feat: add API endpoint versioning (#514)
ch4r10t33r 074c1c6
refactor: rename justified endpoint to /lean/v0/checkpoints/justified…
ch4r10t33r bdb711a
fix snappy frame decoding boundaries for req/resp (#515)
shariqnaiyer 5c6b6f1
add OCI labels for git commit and branch to docker images (#493)
KatyaRyazantseva 97e2760
update to use SSZ hasher agnostic hashTreeRoot API (#474)
chetanyb 28f4bca
Merge remote-tracking branch 'origin/main' into sig_spec_test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule leanSpec
updated
66 files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,170 @@ const types = @import("@zeam/types"); | |
| const zeam_metrics = @import("@zeam/metrics"); | ||
| const ssz = @import("ssz"); | ||
| const Allocator = std.mem.Allocator; | ||
| const JsonValue = std.json.Value; | ||
|
|
||
| pub const XmssTestConfig = struct { | ||
| scheme: xmss.HashSigScheme, | ||
| signature_ssz_len: usize, | ||
| allow_placeholder_aggregated_proof: bool, | ||
|
|
||
| pub fn fromLeanEnv(lean_env: ?[]const u8) XmssTestConfig { | ||
| const scheme = schemeFromLeanEnv(lean_env); | ||
| return .{ | ||
| .scheme = scheme, | ||
| .signature_ssz_len = xmss.signatureSszLenForScheme(scheme), | ||
| .allow_placeholder_aggregated_proof = scheme == .@"test", | ||
| }; | ||
| } | ||
| }; | ||
|
|
||
| pub const TestKeyManagerError = error{ | ||
| DuplicateKeyIndex, | ||
| InvalidKeyFile, | ||
| InvalidKeyIndex, | ||
| InvalidPublicKey, | ||
| NoKeysFound, | ||
| PublicKeyNotFound, | ||
| }; | ||
|
|
||
| pub const TestKeyManager = struct { | ||
| allocator: Allocator, | ||
| config: XmssTestConfig, | ||
| pubkeys: std.AutoHashMap(usize, types.Bytes52), | ||
|
|
||
| const Self = @This(); | ||
|
|
||
| pub fn init(allocator: Allocator, lean_env: ?[]const u8) Self { | ||
| return Self{ | ||
| .allocator = allocator, | ||
| .config = XmssTestConfig.fromLeanEnv(lean_env), | ||
| .pubkeys = std.AutoHashMap(usize, types.Bytes52).init(allocator), | ||
| }; | ||
| } | ||
|
|
||
| pub fn deinit(self: *Self) void { | ||
| self.pubkeys.deinit(); | ||
| } | ||
|
|
||
| pub fn loadLeanSpecKeys(self: *Self, keys_root: []const u8) !void { | ||
| const scheme_dir_name = switch (self.config.scheme) { | ||
| .@"test" => "test_scheme", | ||
| .prod => "prod_scheme", | ||
| }; | ||
| const scheme_dir_path = try std.fs.path.join(self.allocator, &.{ keys_root, scheme_dir_name }); | ||
| defer self.allocator.free(scheme_dir_path); | ||
| try self.loadKeysFromDir(scheme_dir_path); | ||
| } | ||
|
|
||
| pub fn loadKeysFromDir(self: *Self, keys_dir_path: []const u8) !void { | ||
| var dir = try std.fs.cwd().openDir(keys_dir_path, .{ .iterate = true }); | ||
| defer dir.close(); | ||
|
|
||
| self.pubkeys.clearRetainingCapacity(); | ||
|
|
||
| var it = dir.iterate(); | ||
| while (try it.next()) |entry| { | ||
| if (entry.kind != .file) continue; | ||
| const index = parseKeyIndex(entry.name) catch continue; | ||
| const pubkey = try readPublicKeyFromJson(self.allocator, dir, entry.name); | ||
|
|
||
| const gop = try self.pubkeys.getOrPut(index); | ||
| if (gop.found_existing) { | ||
| return TestKeyManagerError.DuplicateKeyIndex; | ||
| } | ||
| gop.value_ptr.* = pubkey; | ||
| } | ||
|
|
||
| if (self.pubkeys.count() == 0) { | ||
| return TestKeyManagerError.NoKeysFound; | ||
| } | ||
| } | ||
|
|
||
| pub fn getPublicKeyBytes(self: *const Self, validator_index: usize) !types.Bytes52 { | ||
| return self.pubkeys.get(validator_index) orelse TestKeyManagerError.PublicKeyNotFound; | ||
| } | ||
|
|
||
| pub fn getAllPubkeys( | ||
| self: *const Self, | ||
| allocator: Allocator, | ||
| num_validators: usize, | ||
| ) ![]types.Bytes52 { | ||
| const pubkeys = try allocator.alloc(types.Bytes52, num_validators); | ||
| errdefer allocator.free(pubkeys); | ||
|
|
||
| for (0..num_validators) |i| { | ||
| pubkeys[i] = try self.getPublicKeyBytes(i); | ||
| } | ||
|
|
||
| return pubkeys; | ||
| } | ||
|
|
||
| pub fn signatureSszLen(self: *const Self) usize { | ||
| return self.config.signature_ssz_len; | ||
| } | ||
|
|
||
| pub fn allowPlaceholderAggregatedProof(self: *const Self) bool { | ||
| return self.config.allow_placeholder_aggregated_proof; | ||
| } | ||
| }; | ||
|
|
||
| fn schemeFromLeanEnv(lean_env: ?[]const u8) xmss.HashSigScheme { | ||
| const env = lean_env orelse return .prod; | ||
| if (std.ascii.eqlIgnoreCase(env, "test")) return .@"test"; | ||
| return .prod; | ||
| } | ||
|
|
||
| fn parseKeyIndex(file_name: []const u8) !usize { | ||
| if (!std.mem.endsWith(u8, file_name, ".json")) { | ||
| return TestKeyManagerError.InvalidKeyIndex; | ||
| } | ||
| const stem = file_name[0 .. file_name.len - ".json".len]; | ||
| if (stem.len == 0) { | ||
| return TestKeyManagerError.InvalidKeyIndex; | ||
| } | ||
| return std.fmt.parseInt(usize, stem, 10) catch TestKeyManagerError.InvalidKeyIndex; | ||
| } | ||
|
Comment on lines
+38
to
+47
|
||
|
|
||
| fn readPublicKeyFromJson( | ||
| allocator: Allocator, | ||
| dir: std.fs.Dir, | ||
| file_name: []const u8, | ||
| ) !types.Bytes52 { | ||
| const max_bytes: usize = 2 * 1024 * 1024; | ||
|
GrapeBaBa marked this conversation as resolved.
Outdated
|
||
| const payload = dir.readFileAlloc(allocator, file_name, max_bytes) catch { | ||
| return TestKeyManagerError.InvalidKeyFile; | ||
| }; | ||
| defer allocator.free(payload); | ||
|
|
||
| var parsed = std.json.parseFromSlice(JsonValue, allocator, payload, .{ .ignore_unknown_fields = true }) catch { | ||
| return TestKeyManagerError.InvalidKeyFile; | ||
| }; | ||
| defer parsed.deinit(); | ||
|
|
||
| const obj = switch (parsed.value) { | ||
| .object => |map| map, | ||
| else => return TestKeyManagerError.InvalidKeyFile, | ||
| }; | ||
| const pub_val = obj.get("public") orelse return TestKeyManagerError.InvalidKeyFile; | ||
| const pub_hex = switch (pub_val) { | ||
| .string => |s| s, | ||
| else => return TestKeyManagerError.InvalidKeyFile, | ||
| }; | ||
|
|
||
| return parsePublicKeyHex(pub_hex); | ||
| } | ||
|
|
||
| fn parsePublicKeyHex(input: []const u8) !types.Bytes52 { | ||
| const hex_str = if (std.mem.startsWith(u8, input, "0x")) input[2..] else input; | ||
| if (hex_str.len != 104) { | ||
|
GrapeBaBa marked this conversation as resolved.
Outdated
|
||
| return TestKeyManagerError.InvalidPublicKey; | ||
| } | ||
| var bytes: types.Bytes52 = undefined; | ||
| _ = std.fmt.hexToBytes(&bytes, hex_str) catch { | ||
| return TestKeyManagerError.InvalidPublicKey; | ||
| }; | ||
| return bytes; | ||
| } | ||
|
|
||
| const KeyManagerError = error{ | ||
| ValidatorKeyNotFound, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,23 @@ | ||
| pub const FixtureKind = enum { | ||
| state_transition, | ||
| fork_choice, | ||
| verify_signatures, | ||
|
|
||
| pub fn runnerModule(self: FixtureKind) []const u8 { | ||
| return switch (self) { | ||
| .state_transition => "state_transition", | ||
| .fork_choice => "fork_choice", | ||
| .verify_signatures => "verify_signatures", | ||
| }; | ||
| } | ||
|
|
||
| pub fn handlerSubdir(self: FixtureKind) []const u8 { | ||
| return switch (self) { | ||
| .state_transition => "state_transition", | ||
| .fork_choice => "fc", | ||
| .verify_signatures => "verify_signatures", | ||
| }; | ||
| } | ||
| }; | ||
|
|
||
| pub const all = [_]FixtureKind{ .state_transition, .fork_choice }; | ||
| pub const all = [_]FixtureKind{ .state_transition, .fork_choice, .verify_signatures }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.