Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
50118d4
added tests for calculating generalized indices
fernantho Oct 15, 2025
e77e465
added first version of GI calculation walking the specified path with…
fernantho Oct 16, 2025
e00c804
refactored code. Detached PathElement processing, currently done at t…
fernantho Oct 17, 2025
83596c5
added an updateRoot function with the GI formula. more refactoring
fernantho Oct 17, 2025
787bb13
added changelog
fernantho Oct 17, 2025
253c1b6
replaced TODO tag
fernantho Oct 17, 2025
ed62201
udpated some comments
fernantho Oct 17, 2025
a2154e3
simplified code - removed duplicated code in processingLengthField fu…
fernantho Oct 17, 2025
62646ff
Merge branch 'develop' into feat/ssz-ql-parse-path-to-generalized-index
fernantho Oct 17, 2025
fe4d7fe
run gazelle
fernantho Oct 17, 2025
96f1c4d
merging all input path processing into path.go
fernantho Oct 20, 2025
9e0314e
reviewed Jun's feedback
fernantho Oct 20, 2025
a1de521
removed unnecessary idx pointer var + fixed error with length data ty…
fernantho Oct 20, 2025
24a1fff
refactored path.go after merging path elements from generalized_indic…
fernantho Oct 20, 2025
43835e3
re-computed GIs for tests as VariableTestContainer added a new field.
fernantho Oct 20, 2025
eb7637c
added minor comment - rawPath MUST be snake case
fernantho Oct 20, 2025
1baa32a
fixed vector GI calculation - updated tests GIs
fernantho Oct 20, 2025
d5b1227
removed updateRoot function in favor of inline code
fernantho Oct 20, 2025
e9741e4
path input data enforced to be snake case
fernantho Oct 21, 2025
73e3ee7
added sanity checks for accessing outbound element indices - checked …
fernantho Oct 21, 2025
b65fff9
Merge branch 'develop' into feat/ssz-ql-parse-path-to-generalized-index
fernantho Oct 21, 2025
d800a18
fixed issues triggered after merging develop
fernantho Oct 21, 2025
b276b68
Removed redundant comment
fernantho Oct 21, 2025
e0c8878
removed unreachable condition as `strings.Split` always return a slic…
fernantho Oct 21, 2025
9dfa152
added tests to cover edge cases + cleaned code (toLower is no longer …
fernantho Oct 21, 2025
6478e00
added Jun's feedback + more testing
fernantho Oct 21, 2025
5eac34f
postponed snake case conversion to do it on a per-element-basis. Adde…
fernantho Oct 21, 2025
f3a1b4f
addressed several Jun's comments.
fernantho Oct 21, 2025
2718dc9
added sanity check to prevent length of a multi-dimensional array. ad…
fernantho Oct 21, 2025
1268a2c
Merge branch 'develop' into feat/ssz-ql-parse-path-to-generalized-index
fernantho Oct 21, 2025
349a993
Update encoding/ssz/query/generalized_index.go
fernantho Oct 22, 2025
f2cc4ac
Update encoding/ssz/query/generalized_index.go
fernantho Oct 22, 2025
7977386
Update encoding/ssz/query/generalized_index.go
fernantho Oct 22, 2025
f03dade
placed constant bitsPerChunk in the right place. Exported BitsPerChun…
fernantho Oct 22, 2025
c317936
added helpers for computing GI of each data type
fernantho Oct 22, 2025
0972263
Merge branch 'develop' into feat/ssz-ql-parse-path-to-generalized-index
fernantho Oct 22, 2025
ad3dc9f
changed %q in favor of %s
fernantho Oct 22, 2025
4293063
Update encoding/ssz/query/path.go
fernantho Oct 22, 2025
0303b90
removed the least restrictive condition isBasicType
fernantho Oct 23, 2025
57bb141
replaced length of containerInfo.order for containerInfo.fields for c…
fernantho Oct 23, 2025
b6505eb
removed outdated comment
fernantho Oct 23, 2025
7a808ca
removed toSnakeCase conversion.
fernantho Oct 23, 2025
da278ed
moved isBasicType func to its natural place, SSZType
fernantho Oct 23, 2025
f3f9a60
cosmetic refactor
fernantho Oct 23, 2025
0b05112
cleaned tests
fernantho Oct 23, 2025
6485eb7
Merge branch 'develop' into feat/ssz-ql-parse-path-to-generalized-index
fernantho Oct 23, 2025
385650d
renamed "root" to "index"
fernantho Oct 23, 2025
83284c7
removed unnecessary check for negative integers. Replaced %q for %s.
fernantho Oct 23, 2025
900f971
refactored regex variables and prevented re-assignation
fernantho Oct 23, 2025
2c8885b
added length regex explanation
fernantho Oct 24, 2025
212d31b
added more testing for stressing regex for path processing
fernantho Oct 24, 2025
4aa7b82
renamed currentIndex to parentIndex for clarity and documented the re…
fernantho Oct 24, 2025
9d850e6
Update encoding/ssz/query/generalized_index.go
fernantho Oct 24, 2025
30fc2a7
Merge branch 'develop' into feat/ssz-ql-parse-path-to-generalized-index
rkapka Oct 27, 2025
c61cdf7
run gazelle
fernantho Oct 27, 2025
6107655
fixed never asserted error. Updated error message
fernantho Oct 27, 2025
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
3 changes: 3 additions & 0 deletions changelog/fernantho_ssz-ql-calculate-generalized-indices.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Added

- Added GeneralizedIndicesFromPath function to calculate the GIs for a given sszInfo object and a PathElement
25 changes: 14 additions & 11 deletions encoding/ssz/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import (
"github.com/prysmaticlabs/go-bitfield"
)

const bytesPerChunk = 32
const (
BitsPerChunk = 256
BytesPerChunk = 32
)

// BitlistRoot returns the mix in length of a bitwise Merkleized bitfield.
func BitlistRoot(bfield bitfield.Bitfield, maxCapacity uint64) ([32]byte, error) {
Expand Down Expand Up @@ -54,14 +57,14 @@ func BitwiseMerkleize(chunks [][32]byte, count, limit uint64) ([32]byte, error)
}

// PackByChunk a given byte array's final chunk with zeroes if needed.
func PackByChunk(serializedItems [][]byte) ([][bytesPerChunk]byte, error) {
var emptyChunk [bytesPerChunk]byte
func PackByChunk(serializedItems [][]byte) ([][BytesPerChunk]byte, error) {
var emptyChunk [BytesPerChunk]byte
// If there are no items, we return an empty chunk.
if len(serializedItems) == 0 {
return [][bytesPerChunk]byte{emptyChunk}, nil
} else if len(serializedItems[0]) == bytesPerChunk {
return [][BytesPerChunk]byte{emptyChunk}, nil
} else if len(serializedItems[0]) == BytesPerChunk {
// If each item has exactly BYTES_PER_CHUNK length, we return the list of serialized items.
chunks := make([][bytesPerChunk]byte, 0, len(serializedItems))
chunks := make([][BytesPerChunk]byte, 0, len(serializedItems))
for _, c := range serializedItems {
chunks = append(chunks, bytesutil.ToBytes32(c))
}
Expand All @@ -75,12 +78,12 @@ func PackByChunk(serializedItems [][]byte) ([][bytesPerChunk]byte, error) {
// If all our serialized item slices are length zero, we
// exit early.
if len(orderedItems) == 0 {
return [][bytesPerChunk]byte{emptyChunk}, nil
return [][BytesPerChunk]byte{emptyChunk}, nil
}
numItems := len(orderedItems)
var chunks [][bytesPerChunk]byte
for i := 0; i < numItems; i += bytesPerChunk {
j := i + bytesPerChunk
var chunks [][BytesPerChunk]byte
for i := 0; i < numItems; i += BytesPerChunk {
j := i + BytesPerChunk
// We create our upper bound index of the chunk, if it is greater than numItems,
// we set it as numItems itself.
if j > numItems {
Expand All @@ -89,7 +92,7 @@ func PackByChunk(serializedItems [][]byte) ([][bytesPerChunk]byte, error) {
// We create chunks from the list of items based on the
// indices determined above.
// Right-pad the last chunk with zero bytes if it does not
// have length bytesPerChunk from the helper.
// have length BytesPerChunk from the helper.
// The ToBytes32 helper allocates a 32-byte array, before
// copying the ordered items in. This ensures that even if
// the last chunk is != 32 in length, we will right-pad it with
Expand Down
7 changes: 6 additions & 1 deletion encoding/ssz/query/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ go_library(
"bitlist.go",
"bitvector.go",
"container.go",
"generalized_index.go",
"list.go",
"path.go",
"query.go",
Expand All @@ -18,12 +19,16 @@ go_library(
],
importpath = "github.com/OffchainLabs/prysm/v6/encoding/ssz/query",
visibility = ["//visibility:public"],
deps = ["@com_github_prysmaticlabs_go_bitfield//:go_default_library"],
deps = [
"//encoding/ssz:go_default_library",
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
],
)

go_test(
name = "go_default_test",
srcs = [
"generalized_index_test.go",
"path_test.go",
"query_test.go",
"tag_parser_test.go",
Expand Down
Loading
Loading