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(ssz): Implement basic generalized index stuff #837

Merged
merged 34 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
bet
  • Loading branch information
itsdevbear committed Apr 22, 2024
commit 15f4ef0177cc362f93f9cf89e5a1fab4208c3245
5 changes: 1 addition & 4 deletions mod/da/types/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ func (b *BlobSidecar) HasValidInclusionProof(
}

gIndex := kzgOffset + b.Index
// TODO:
// gindex = get_subtree_index(get_generalized_index(
// BeaconBlockBody, 'blob_kzg_commitments', blob_sidecar.index))

// Verify the inclusion proof.
return merkle.IsValidMerkleBranch(
Expand All @@ -96,7 +93,7 @@ func (b *BlobSidecar) HasValidInclusionProof(
//#nosec:G701 // safe.
uint8(
len(b.InclusionProof),
), // TODO: KZG_COMMITMENT_INCLUSION_PROOF_DEPTH
), // TODO: mak
gIndex,
b.BeaconBlockHeader.BodyRoot,
)
Expand Down
10 changes: 10 additions & 0 deletions mod/primitives/math/u64.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ func (u U64) ILog2Ceil() uint8 {
return U64NumBits - uint8(bits.LeadingZeros64(uint64(u-1)))
}

// ILog2Floor returns the floor of the base 2 logarithm of the U64.
func (u U64) ILog2Floor() uint8 {
// Log2(0) is undefined, should we panic?
if u == 0 {
return 0
}
//#nosec:G701 // we handle the case of u == 0 above, so this is safe.
return U64NumBits - uint8(bits.LeadingZeros64(uint64(u)))
}

// type U64Vector[U ~uint64] []U

// func (v U64Vector[U]) HashTreeRoot() ([32]byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion mod/primitives/ssz/merkle/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewGeneralizedIndex[RootT ~[32]byte](

// Length returns the length of the generalized index.
func (g GeneralizedIndex[RootT]) Length() uint64 {
return uint64(math.U64(g).ILog2Ceil())
return uint64(math.U64(g).ILog2Floor())
}

// IndexBit returns the bit at the specified position in a generalized index.
Expand Down
Loading