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

feat: add ssz test for AttestationData #22

Merged
merged 1 commit into from
Nov 9, 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 src/spec_tests/ssz_static/root.zig
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const StructMultiPhase = union {
// test cases for all phases
const CommonUnion = union {
// AggregateAndProof: types.AggregateAndProof,
// AttestationData: types.AttestationData,
AttestationData: types.AttestationData,
// AttesterSlashing: types.AttesterSlashing,
// BeaconBlock: types.BeaconBlock,
BeaconBlockHeader: types.BeaconBlockHeader,
Expand All @@ -71,9 +71,9 @@ const CommonUnion = union {
Eth1Data: types.Eth1Data,
Fork: types.Fork,
ForkData: types.ForkData,
// HistoricalBatch: types.HistoricalBatch,
// IndexedAttestation: types.IndexedAttestation,
// PendingAttestation: types.PendingAttestation,
// HistoricalBatch: types.HistoricalBatch, // need to know the lenght in spec
// IndexedAttestation: types.IndexedAttestation, // need to know the limit in spec
// PendingAttestation: types.PendingAttestation, // parse yaml
// ProposerSlashing: types.ProposerSlashing,
// SignedBeaconBlock: types.SignedBeaconBlock,
// SignedBeaconBlockHeader: types.SignedBeaconBlockHeader,
Expand Down
34 changes: 33 additions & 1 deletion src/ssz/ssz.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1028,12 +1028,44 @@ pub fn hashTreeRoot(value: anytype, out: *[32]u8, allocator: Allocator) !void {
switch (type_info.pointer.size) {
.One => try hashTreeRoot(value.*, out, allocator),
.Slice => {
switch (@typeInfo(type_info.pointer.child)) {
const slice_info = @typeInfo(type_info.pointer.child);
switch (slice_info) {
.int => {
var list = ArrayList(u8).init(allocator);
defer list.deinit();
const chunks = try pack(value, &list);
// TODO: slice should have a limit
try merkleize(chunks, null, out);
var length: [32]u8 = [_]u8{0} ** 32;
std.mem.writeInt(u64, length[0..8], value.len, .little);
mixInLength(out.*, length, out);
},
.array => {
switch (@typeInfo(slice_info.array.child)) {
.int => {
var list = ArrayList(u8).init(allocator);
defer list.deinit();
const chunks = try pack(value, &list);
try merkleize(chunks, null, out);
},
.bool => {
var list = ArrayList(u8).init(allocator);
defer list.deinit();
const chunks = try packBits(value, list);
try merkleize(chunks, null, out);
},
.array => {
var chunks = ArrayList(chunk).init(allocator);
defer chunks.deinit();
var tmp: chunk = undefined;
for (value) |item| {
try hashTreeRoot(item, &tmp, allocator);
try chunks.append(tmp);
}
try merkleize(chunks.items, null, out);
},
else => return error.NotSupported,
}
},
else => return error.UnSupportedPointerType,
}
Expand Down
4 changes: 4 additions & 0 deletions src/yaml/parse.zig
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,10 @@ const Parser = struct {
self.token_it.seekBy(-1);
break;
},
.flow_map_end => {
self.token_it.seekTo(key_pos + 1);
break;
},
else => {
// TODO key not being a literal
// return error.Unhandled;
Expand Down
Loading