share

package
v0.0.0-...-c49b056 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Size is a system-wide size of a share, including both data and namespace GetNamespace
	Size = appconsts.ShareSize
)

Variables

View Source
var (
	MaxReservedNamespace     = Namespace(appns.MaxReservedNamespace.Bytes())
	ParitySharesNamespace    = Namespace(appns.ParitySharesNamespace.Bytes())
	TailPaddingNamespace     = Namespace(appns.TailPaddingNamespace.Bytes())
	ReservedPaddingNamespace = Namespace(appns.ReservedPaddingNamespace.Bytes())
	TxNamespace              = Namespace(appns.TxNamespace.Bytes())
	PayForBlobNamespace      = Namespace(appns.PayForBlobNamespace.Bytes())
)

Various reserved namespaces.

View Source
var DefaultRSMT2DCodec = appconsts.DefaultCodec

DefaultRSMT2DCodec sets the default rsmt2d.Codec for shares.

MaxSquareSize is currently the maximum size supported for unerasured data in rsmt2d.ExtendedDataSquare.

Functions

func BlobMinSquareSize

func BlobMinSquareSize(shareCount int) int

BlobMinSquareSize returns the minimum square size that can contain shareCount number of shares.

func GetData

func GetData(s Share) []byte

GetData slices out data of the Share.

func NewReservedBytes

func NewReservedBytes(byteIndex uint32) ([]byte, error)

NewReservedBytes returns a byte slice of length appconsts.CompactShareReservedBytes that contains the byteIndex of the first unit that starts in a compact share.

func NewSHA256Hasher

func NewSHA256Hasher() hash.Hash

NewSHA256Hasher returns a new instance of a SHA-256 hasher.

func ParseReservedBytes

func ParseReservedBytes(reservedBytes []byte) (uint32, error)

ParseReservedBytes parses a byte slice of length appconsts.CompactShareReservedBytes into a byteIndex.

func RoundDownPowerOfTwo

func RoundDownPowerOfTwo[I constraints.Integer](input I) (I, error)

RoundDownPowerOfTwo returns the next power of two less than or equal to input.

func RoundUpPowerOfTwo

func RoundUpPowerOfTwo[I constraints.Integer](input I) I

RoundUpPowerOfTwo returns the next power of two greater than or equal to input.

func SparseSharesNeeded

func SparseSharesNeeded(sequenceLen uint32) (sharesNeeded int)

func SubTreeWidth

func SubTreeWidth(shareCount, subtreeRootThreshold int) int

SubTreeWidth determines the maximum number of leaves per subtree in the share commitment over a given blob. The input should be the total number of shares used by that blob.

func ToBytes

func ToBytes(shares []AppShare) (bytes [][]byte)

Types

type API

type API struct {
	SharesAvailable func(context.Context, *header.ExtendedHeader) error `perm:"read"`
	GetShare        func(
		ctx context.Context,
		eh *header.ExtendedHeader,
		row, col int,
	) (*Share, error) `perm:"read"`
	GetEDS func(
		ctx context.Context,
		eh *header.ExtendedHeader,
	) (*rsmt2d.ExtendedDataSquare, error) `perm:"read"`
	GetSharesByNamespace func(
		ctx context.Context,
		eh *header.ExtendedHeader,
		namespace Namespace,
	) (*NamespacedShares, error) `perm:"read"`
	GetRange func(
		ctx context.Context,
		height uint64,
		start, end int,
	) (*GetRangeResult, error) `perm:"read"`
}

type AppShare

type AppShare struct {
	// contains filtered or unexported fields
}

func FromBytes

func FromBytes(bytes [][]byte) (shares []AppShare, err error)

func NamespacePaddingShare

func NamespacePaddingShare(ns namespace.Namespace) (AppShare, error)

NamespacePaddingShare returns a share that acts as padding. Namespace padding shares follow a blob so that the next blob may start at an index that conforms to blob share commitment rules. The ns parameter provided should be the namespace of the blob that precedes this padding in the data square.

func NamespacePaddingShares

func NamespacePaddingShares(ns namespace.Namespace, n int) ([]AppShare, error)

NamespacePaddingShares returns n namespace padding shares.

func NewShare

func NewShare(data []byte) (*AppShare, error)

func SplitBlobs

func SplitBlobs(blobs ...core.CoreBlob) ([]AppShare, error)

SplitBlobs splits the provided blobs into shares.

func (*AppShare) DoesSupportVersions

func (s *AppShare) DoesSupportVersions(supportedShareVersions []uint8) error

func (*AppShare) InfoByte

func (s *AppShare) InfoByte() (InfoByte, error)

func (*AppShare) IsCompactShare

func (s *AppShare) IsCompactShare() (bool, error)

IsCompactShare returns true if this is a compact share.

func (*AppShare) IsPadding

func (s *AppShare) IsPadding() (bool, error)

IsPadding returns whether this *share is padding or not.

func (*AppShare) IsSequenceStart

func (s *AppShare) IsSequenceStart() (bool, error)

IsSequenceStart returns true if this is the first share in a sequence.

func (*AppShare) Len

func (s *AppShare) Len() int

func (*AppShare) Namespace

func (s *AppShare) Namespace() (namespace.Namespace, error)

func (*AppShare) RawData

func (s *AppShare) RawData() (rawData []byte, err error)

RawData returns the raw share data. The raw share data does not contain the namespace ID, info byte, sequence length, or reserved bytes.

func (*AppShare) RawDataUsingReserved

func (s *AppShare) RawDataUsingReserved() (rawData []byte, err error)

RawDataWithReserved returns the raw share data while taking reserved bytes into account.

func (*AppShare) SequenceLen

func (s *AppShare) SequenceLen() (sequenceLen uint32, err error)

SequenceLen returns the sequence length of this *share and optionally an error. It returns 0, nil if this is a continuation share (i.e. doesn't contain a sequence length).

func (*AppShare) ToBytes

func (s *AppShare) ToBytes() []byte

func (*AppShare) Version

func (s *AppShare) Version() (uint8, error)

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

func NewBuilder

func NewBuilder(ns namespace.Namespace, shareVersion uint8, isFirstShare bool) *Builder

Init() needs to be called right after this method

func NewEmptyBuilder

func NewEmptyBuilder() *Builder

func (*Builder) AddData

func (b *Builder) AddData(rawData []byte) (rawDataLeftOver []byte)

func (*Builder) AvailableBytes

func (b *Builder) AvailableBytes() int

func (*Builder) Build

func (b *Builder) Build() (*AppShare, error)

func (*Builder) FlipSequenceStart

func (b *Builder) FlipSequenceStart()

FlipSequenceStart flips the sequence start indicator of the share provided

func (*Builder) ImportRawShare

func (b *Builder) ImportRawShare(rawBytes []byte) *Builder

func (*Builder) Init

func (b *Builder) Init() (*Builder, error)

func (*Builder) IsEmptyShare

func (b *Builder) IsEmptyShare() bool

IsEmptyShare returns true if no data has been written to the share

func (*Builder) MaybeWriteReservedBytes

func (b *Builder) MaybeWriteReservedBytes() error

MaybeWriteReservedBytes will be a no-op if the reserved bytes have already been populated. If the reserved bytes are empty, it will write the location of the next unit of data to the reserved bytes.

func (*Builder) WriteSequenceLen

func (b *Builder) WriteSequenceLen(sequenceLen uint32) error

writeSequenceLen writes the sequence length to the first share.

func (*Builder) ZeroPadIfNecessary

func (b *Builder) ZeroPadIfNecessary() (bytesOfPadding int)

type DataHash

type DataHash []byte

DataHash is a representation of the Root hash.

func MustDataHashFromString

func MustDataHashFromString(datahash string) DataHash

MustDataHashFromString converts a hex string to a valid datahash.

func (DataHash) String

func (dh DataHash) String() string

func (DataHash) Validate

func (dh DataHash) Validate() error

type GetRangeResult

type GetRangeResult struct {
	Shares []Share
	Proof  *ShareProof
}

GetRangeResult wraps the return value of the GetRange endpoint because Json-RPC doesn't support more than two return values.

type InfoByte

type InfoByte byte

InfoByte is a byte with the following structure: the first 7 bits are reserved for version information in big endian form (initially `0000000`). The last bit is a "sequence start indicator", that is `1` if this is the first share of a sequence and `0` if this is a continuation share.

func NewInfoByte

func NewInfoByte(version uint8, isSequenceStart bool) (InfoByte, error)

func ParseInfoByte

func ParseInfoByte(i byte) (InfoByte, error)

func (InfoByte) IsSequenceStart

func (i InfoByte) IsSequenceStart() bool

IsSequenceStart returns whether this share is the start of a sequence.

func (InfoByte) Version

func (i InfoByte) Version() uint8

Version returns the version encoded in this InfoByte. Version is expected to be between 0 and appconsts.MaxShareVersion (inclusive).

type NMTProof

type NMTProof struct {
	// Start index of this proof.
	Start int32 `protobuf:"varint,1,opt,name=start,proto3" json:"start,omitempty"`
	// End index of this proof.
	End int32 `protobuf:"varint,2,opt,name=end,proto3" json:"end,omitempty"`
	// Nodes that together with the corresponding leaf values can be used to
	// recompute the root and verify this proof. Nodes should consist of the max
	// and min namespaces along with the actual hash, resulting in each being 48
	// bytes each
	Nodes [][]byte `protobuf:"bytes,3,rep,name=nodes,proto3" json:"nodes,omitempty"`
	// leafHash are nil if the namespace is present in the NMT. In case the
	// namespace to be proved is in the min/max range of the tree but absent, this
	// will contain the leaf hash necessary to verify the proof of absence. Leaf
	// hashes should consist of the namespace along with the actual hash,
	// resulting 40 bytes total.
	LeafHash []byte `protobuf:"bytes,4,opt,name=leaf_hash,json=leafHash,proto3" json:"leaf_hash,omitempty"`
}

NMTProof is a proof of a namespace.ID in an NMT. In case this proof proves the absence of a namespace.ID in a tree it also contains the leaf hashes of the range where that namespace would be.

type Namespace

type Namespace []byte

Namespace represents namespace of a Share. Consists of version byte and namespace ID.

func GetNamespace

func GetNamespace(s Share) Namespace

GetNamespace slices Namespace out of the Share.

func NamespaceFromBytes

func NamespaceFromBytes(b []byte) (Namespace, error)

NamespaceFromBytes converts bytes into Namespace and validates it.

func NewBlobNamespaceV0

func NewBlobNamespaceV0(id []byte) (Namespace, error)

NewBlobNamespaceV0 takes a variable size byte slice and creates a valid version 0 Blob Namespace. The byte slice must be <= 10 bytes. If it is less than 10 bytes, it will be left padded to size 10 with 0s. Use predefined namespaces above, if non-blob namespace is needed.

func (Namespace) Equals

func (n Namespace) Equals(target Namespace) bool

Equals compares two Namespaces.

func (Namespace) ID

func (n Namespace) ID() namespace.ID

ID reports ID of the Namespace.

func (Namespace) IsAboveMax

func (n Namespace) IsAboveMax(nodeHash []byte) bool

IsAboveMax checks if the namespace is above the maximum namespace of the given hash.

func (Namespace) IsBelowMin

func (n Namespace) IsBelowMin(nodeHash []byte) bool

IsBelowMin checks if the target namespace is below the minimum namespace of the given hash.

func (Namespace) IsGreater

func (n Namespace) IsGreater(target Namespace) bool

IsGreater reports if the Namespace is greater than the target.

func (Namespace) IsGreaterOrEqualThan

func (n Namespace) IsGreaterOrEqualThan(target Namespace) bool

IsGreaterOrEqualThan reports if the Namespace is greater or equal than the target.

func (Namespace) IsLess

func (n Namespace) IsLess(target Namespace) bool

IsLess reports if the Namespace is less than the target.

func (Namespace) IsLessOrEqual

func (n Namespace) IsLessOrEqual(target Namespace) bool

IsLessOrEqual reports if the Namespace is less than the target.

func (Namespace) IsOutsideRange

func (n Namespace) IsOutsideRange(leftNodeHash, rightNodeHash []byte) bool

IsOutsideRange checks if the namespace is outside the min-max range of the given hashes.

func (Namespace) Len

func (n Namespace) Len() int

Len reports the total length of the namespace.

func (Namespace) Repeat

func (n Namespace) Repeat(t int) []Namespace

Repeat copies the Namespace t times.

func (Namespace) String

func (n Namespace) String() string

String stringifies the Namespace.

func (Namespace) ToAppNamespace

func (n Namespace) ToAppNamespace() appns.Namespace

ToAppNamespace converts the Namespace to App's definition of Namespace. TODO: Unify types between node and app

func (Namespace) ToNMT

func (n Namespace) ToNMT() namespace.ID

type.

func (Namespace) Validate

func (n Namespace) Validate() error

Validate checks if the namespace is correct.

func (Namespace) ValidateForBlob

func (n Namespace) ValidateForBlob() error

ValidateForBlob checks if the Namespace is valid blob namespace.

func (Namespace) ValidateForData

func (n Namespace) ValidateForData() error

ValidateForData checks if the Namespace is of real/useful data.

func (Namespace) Version

func (n Namespace) Version() byte

Version reports version of the Namespace.

type NamespacedRow

type NamespacedRow struct {
	Shares []Share    `json:"shares"`
	Proof  *nmt.Proof `json:"proof"`
}

NamespacedRow represents all shares with proofs within a specific namespace of a single EDS row.

type NamespacedShares

type NamespacedShares []NamespacedRow

NamespacedShares represents all shares with proofs within a specific namespace of an EDS.

type Root

Root represents root commitment to multiple Shares. In practice, it is a commitment to all the Data in a square.

type Share

type Share = []byte

Share contains the raw share data without the corresponding namespace. NOTE: Alias for the byte is chosen to keep maximal compatibility, especially with rsmt2d. Ideally, we should define reusable type elsewhere and make everyone(Core, rsmt2d, ipld) to rely on it.

type ShareProof

type ShareProof struct {
	// Data are the raw shares that are being proven.
	Data [][]byte `json:"data"`
	// ShareProofs are NMT proofs that the shares in Data exist in a set of
	// rows. There will be one ShareProof per row that the shares occupy.
	ShareProofs []*NMTProof `json:"share_proofs"`
	// NamespaceID is the namespace id of the shares being proven. This
	// namespace id is used when verifying the proof. If the namespace id doesn't
	// match the namespace of the shares, the proof will fail verification.
	NamespaceID      []byte          `json:"namespace_id"`
	RowProof         proofs.RowProof `json:"row_proof"`
	NamespaceVersion uint32          `json:"namespace_version"`
}

ShareProof is an NMT proof that a set of shares exist in a set of rows and a Merkle proof that those rows exist in a Merkle tree with a given data root.

type SparseShareSplitter

type SparseShareSplitter struct {
	// contains filtered or unexported fields
}

SparseShareSplitter lazily splits blobs into shares that will eventually be included in a data square. It also has methods to help progressively count how many shares the blobs written take up.

func NewSparseShareSplitter

func NewSparseShareSplitter() *SparseShareSplitter

func (*SparseShareSplitter) Count

func (sss *SparseShareSplitter) Count() int

Count returns the current number of shares that will be made if exporting.

func (*SparseShareSplitter) Export

func (sss *SparseShareSplitter) Export() []AppShare

Export finalizes and returns the underlying shares.

func (*SparseShareSplitter) Write

func (sss *SparseShareSplitter) Write(blob coretypes.CoreBlob) error

func (*SparseShareSplitter) WriteNamespacePaddingShares

func (sss *SparseShareSplitter) WriteNamespacePaddingShares(count int) error

WriteNamespacePaddingShares adds padding shares with the namespace of the last written This is useful to follow the non-interactive default rules. This function assumes that at least one share has already been written.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL