Skip to content

Commit

Permalink
Merge pull request #22 from optimism-java/atte-data
Browse files Browse the repository at this point in the history
feat: add ssz test for AttestationData
  • Loading branch information
GrapeBaBa authored Nov 9, 2024
2 parents 659508f + ba6fa88 commit 82985b5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
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

0 comments on commit 82985b5

Please sign in to comment.