Files
prysm/consensus-types/light-client/helpers.go
terence 774b9a7159 Migrate Prysm repo to Offchain Labs organization ahead of Pectra V6 (#15140)
* Migrate Prysm repo to Offchain Labs organization ahead of Pectra upgrade v6

* Replace prysmaticlabs with OffchainLabs on general markdowns

* Update mock

* Gazelle and add mock.go to excluded generated mock file
2025-04-10 15:40:39 +00:00

30 lines
865 B
Go

package light_client
import (
"fmt"
fieldparams "github.com/OffchainLabs/prysm/v6/config/fieldparams"
"github.com/OffchainLabs/prysm/v6/encoding/bytesutil"
)
type branchConstraint interface {
[4][fieldparams.RootLength]byte | [5][fieldparams.RootLength]byte | [6][fieldparams.RootLength]byte | [7][fieldparams.RootLength]byte
}
func createBranch[T branchConstraint](name string, input [][]byte, depth int) (T, error) {
var zero T
if len(input) != depth {
return zero, fmt.Errorf("%s branch has %d leaves instead of expected %d", name, len(input), depth)
}
var branch T
for i, leaf := range input {
if len(leaf) != fieldparams.RootLength {
return zero, fmt.Errorf("%s branch leaf at index %d has length %d instead of expected %d", name, i, len(leaf), fieldparams.RootLength)
}
branch[i] = bytesutil.ToBytes32(leaf)
}
return branch, nil
}