proof

package
v1.26.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2025 License: Apache-2.0, MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WinningPostChallengeCount = 66
	WinningPostSectorCount    = 1
	WindowPostChallengeCount  = 10
)
View Source
const CommPBuf = abi.UnpaddedPieceSize(commPBufPad - (commPBufPad / 128)) // can't use .Unpadded() for const
View Source
const MaxMemtreeSize = 256 << 20
View Source
const NODE_SIZE = 32

Variables

This section is empty.

Functions

func BuildSha254Memtree added in v1.25.1

func BuildSha254Memtree(rawIn io.Reader, size abi.UnpaddedPieceSize) ([]byte, error)

BuildSha254Memtree builds a sha256 memtree from the input data Returned slice should be released to the pool after use

func BuildTreeD

func BuildTreeD(data io.Reader, unpaddedData bool, outPath string, size abi.PaddedPieceSize) (_ cid.Cid, err error)

func ComputeBinShaParent added in v1.25.1

func ComputeBinShaParent(left, right [NODE_SIZE]byte) [NODE_SIZE]byte

func DecodeHasherDomain added in v1.23.1

func DecodeHasherDomain[H HasherDomain](r io.Reader) (H, error)

func DeriveInteractiveChallenges added in v1.23.1

func DeriveInteractiveChallenges(
	challengesPerPartition uint64,
	sectorNnodes SectorNodes,
	ReplicaID Commitment,
	Seed Ticket,
	k uint8,
) []uint64

func EncodeColumn added in v1.26.0

func EncodeColumn[H HasherDomain](w io.Writer, c Column[H]) error

func EncodeColumnProof added in v1.26.0

func EncodeColumnProof[H HasherDomain](w io.Writer, cp ColumnProof[H]) error

func EncodeCommit1OutRaw added in v1.26.0

func EncodeCommit1OutRaw(w io.Writer, c Commit1OutRaw) error

EncodeCommit1OutRaw serializes Commit1OutRaw into w in the same bincode style that DecodeCommit1OutRaw expects.

func EncodeCommitment added in v1.26.0

func EncodeCommitment(w io.Writer, c Commitment) error

EncodeCommitment is likewise just 32 raw bytes. Must match decoding logic.

func EncodeEncodingProof added in v1.26.0

func EncodeEncodingProof[H HasherDomain](w io.Writer, ep EncodingProof[H]) error

func EncodeHasherDomain added in v1.26.0

func EncodeHasherDomain[H HasherDomain](w io.Writer, h H) error

EncodeHasherDomain writes a HasherDomain (e.g. [32]byte) in LE order matching the decode. For a [32]byte it’s just 32 raw bytes, no reordering.

func EncodeInclusionPath added in v1.26.0

func EncodeInclusionPath[H HasherDomain](w io.Writer, ip InclusionPath[H]) error

func EncodeLabelingProof added in v1.26.0

func EncodeLabelingProof[H HasherDomain](w io.Writer, lp LabelingProof[H]) error

func EncodeLabels added in v1.23.1

func EncodeLabels(w io.Writer, labels TAuxLabels) error

func EncodeMerkleProof added in v1.26.0

func EncodeMerkleProof[H HasherDomain](w io.Writer, m MerkleProof[H]) error

EncodeMerkleProof writes a MerkleProof of type H.

func EncodePathElement added in v1.26.0

func EncodePathElement[H HasherDomain](w io.Writer, pe PathElement[H]) error

func EncodeProofData added in v1.26.0

func EncodeProofData[H HasherDomain](w io.Writer, pd ProofData[H]) error

EncodeProofData checks Single, Sub, or Top and writes the matching tag + data.

func EncodeReplicaColumnProof added in v1.26.0

func EncodeReplicaColumnProof[H HasherDomain](w io.Writer, rcp ReplicaColumnProof[H]) error

func EncodeSingleProof added in v1.26.0

func EncodeSingleProof[H HasherDomain](w io.Writer, sp SingleProof[H]) error

func EncodeStoreConfig added in v1.23.1

func EncodeStoreConfig(w io.Writer, sc StoreConfig) error

func EncodeSubProof added in v1.26.0

func EncodeSubProof[H HasherDomain](w io.Writer, sp SubProof[H]) error

func EncodeTAux added in v1.23.1

func EncodeTAux(w io.Writer, taux TemporaryAux) error

func EncodeTicket added in v1.26.0

func EncodeTicket(w io.Writer, t Ticket) error

EncodeTicket is simply 32 raw bytes. Must match decoding logic.

func EncodeTopProof added in v1.26.0

func EncodeTopProof[H HasherDomain](w io.Writer, tp TopProof[H]) error

func EncodeVanillaStackedProof added in v1.26.0

func EncodeVanillaStackedProof(w io.Writer, v VanillaStackedProof) error

EncodeVanillaStackedProof serializes a single VanillaStackedProof.

func EnsureTauxForType added in v1.23.1

func EnsureTauxForType(spt abi.RegisteredSealProof, path string) error

EnsureTauxForType ensures that the t_aux file exists in the specified path for the specified seal proof type. If the file does not exist, it will be created with the default values for the specified seal proof type.

func NodeLevel added in v1.25.1

func NodeLevel(leaves, arity int64) int

func ReadLE added in v1.23.1

func ReadLE[T any](r io.Reader) (T, error)

func ReadString added in v1.23.1

func ReadString(r io.Reader) (string, error)

func StringProofFromAbi added in v1.26.0

func StringProofFromAbi(p abi.RegisteredSealProof) (string, error)

func VerifyWindowPoStVanilla added in v1.26.0

func VerifyWindowPoStVanilla(pvi proof.WindowPoStVerifyInfo) (bool, error)

func WriteLE added in v1.23.1

func WriteLE[T any](w io.Writer, data T) error

func WriteString added in v1.23.1

func WriteString(w io.Writer, s string) error

Types

type Column added in v1.23.1

type Column[H HasherDomain] struct {
	Index uint32 `json:"index"`
	Rows  []H    `json:"rows"`
	H     any    `json:"_h"`
}

func DecodeColumn added in v1.23.1

func DecodeColumn[H HasherDomain](r io.Reader) (Column[H], error)

type ColumnProof added in v1.23.1

type ColumnProof[H HasherDomain] struct {
	Column         Column[H]      `json:"column"`
	InclusionProof MerkleProof[H] `json:"inclusion_proof"`
}

func DecodeColumnProof added in v1.23.1

func DecodeColumnProof[H HasherDomain](r io.Reader) (ColumnProof[H], error)

type Commit1OutRaw added in v1.23.1

type Commit1OutRaw struct {
	CommD           Commitment                `json:"comm_d"`
	CommR           Commitment                `json:"comm_r"`
	RegisteredProof StringRegisteredProofType `json:"registered_proof"`
	ReplicaID       Commitment                `json:"replica_id"`
	Seed            Ticket                    `json:"seed"`
	Ticket          Ticket                    `json:"ticket"`

	// ProofType -> [partitions] -> [challenge_index?] -> Proof
	VanillaProofs map[StringRegisteredProofType][][]VanillaStackedProof `json:"vanilla_proofs"`
}

func DecodeCommit1OutRaw added in v1.23.1

func DecodeCommit1OutRaw(r io.Reader) (Commit1OutRaw, error)

type Commitment added in v1.23.1

type Commitment [32]byte

func DecodeCommitment added in v1.23.1

func DecodeCommitment(r io.Reader) (Commitment, error)

type DataCIDSize added in v1.23.1

type DataCIDSize struct {
	PayloadSize int64
	PieceSize   abi.PaddedPieceSize
	PieceCID    cid.Cid
}

type DataCidWriter added in v1.23.1

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

DataCidWriter is used as follows:

cc := new(DataCidWriter) _, err = io.Copy(cc, f) dc, err := cc.Sum()

This computes CommP / PieceCID from a stream, also returns piece and payload sizes.

func (*DataCidWriter) Sum added in v1.23.1

func (w *DataCidWriter) Sum() (DataCIDSize, error)

func (*DataCidWriter) Write added in v1.23.1

func (w *DataCidWriter) Write(p []byte) (int, error)

type EncodingProof added in v1.23.1

type EncodingProof[H HasherDomain] struct {
	Parents    []H    `json:"parents"`
	LayerIndex uint32 `json:"layer_index"`
	Node       uint64 `json:"node"`
}

func DecodeEncodingProof added in v1.23.1

func DecodeEncodingProof[H HasherDomain](r io.Reader) (EncodingProof[H], error)

type FallbackPoStSectorProof added in v1.26.0

type FallbackPoStSectorProof struct {
	SectorID     uint64         `json:"sector_id"`
	CommR        PoseidonDomain `json:"comm_r"`
	VanillaProof VanillaProof   `json:"vanilla_proof"`
}

FallbackPoStSectorProof corresponds to Rust:

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct FallbackPoStSectorProof<Tree: MerkleTreeTrait> {
    pub sector_id: SectorId,
    pub comm_r: <Tree::Hasher as Hasher>::Domain,
    pub vanilla_proof: Proof<<Tree as MerkleTreeTrait>::Proof>,
}

func DecodeFallbackPoStSectorProof added in v1.26.0

func DecodeFallbackPoStSectorProof(r io.Reader) (FallbackPoStSectorProof, error)

DecodeFallbackPoStSectorProof decodes a single FallbackPoStSectorProof from the reader.

Rust struct reference for context: #[derive(Clone, Debug, Serialize, Deserialize)]

pub struct FallbackPoStSectorProof<Tree: MerkleTreeTrait> {
    pub sector_id: SectorId,
    pub comm_r: <Tree::Hasher as Hasher>::Domain,
    pub vanilla_proof: Proof<<Tree as MerkleTreeTrait>::Proof>,
}

type HasherDomain added in v1.23.1

type HasherDomain = any

type InclusionPath added in v1.23.1

type InclusionPath[H HasherDomain] struct {
	Path []PathElement[H] `json:"path"`
}

func DecodeInclusionPath added in v1.23.1

func DecodeInclusionPath[H HasherDomain](r io.Reader) (InclusionPath[H], error)

type Label added in v1.23.1

type Label struct {
	ID            string `json:"id"`
	Path          string `json:"path"`
	RowsToDiscard int    `json:"rows_to_discard"`
	Size          int    `json:"size"`
}

type LabelingProof added in v1.23.1

type LabelingProof[H HasherDomain] struct {
	Parents    []H    `json:"parents"`
	LayerIndex uint32 `json:"layer_index"`
	Node       uint64 `json:"node"`
}

func DecodeLabelingProof added in v1.23.1

func DecodeLabelingProof[H HasherDomain](r io.Reader) (LabelingProof[H], error)

type Labels added in v1.23.1

type Labels struct {
	H      any     `json:"_h"` // todo ?
	Labels []Label `json:"labels"`
}

type MerkleProof added in v1.23.1

type MerkleProof[H HasherDomain] struct {
	Data ProofData[H] `json:"data"`
}

func DecodeMerkleProof added in v1.23.1

func DecodeMerkleProof[H HasherDomain](r io.Reader) (MerkleProof[H], error)

type PathElement added in v1.23.1

type PathElement[H HasherDomain] struct {
	Hashes []H    `json:"hashes"`
	Index  uint64 `json:"index"`
}

func DecodePathElement added in v1.23.1

func DecodePathElement[H HasherDomain](r io.Reader) (PathElement[H], error)

type PoStConfig added in v1.26.0

type PoStConfig struct {
	PoStType       PoStType
	SectorSize     abi.SectorSize
	SectorCount    int
	ChallengeCount int
	Priority       bool
}

PoStConfig: controlling how many sectors per partition, how many challenges, etc.

func GetPoStConfig added in v1.26.0

func GetPoStConfig(sectorSize abi.SectorSize) *PoStConfig
fn window_post_info(sector_size: u64, api_version: ApiVersion) -> CircuitInfo {
    with_shape!(
        sector_size,
        get_window_post_info,
        &PoStConfig {
            sector_size: SectorSize(sector_size),
            challenge_count: WINDOW_POST_CHALLENGE_COUNT,
            sector_count: *WINDOW_POST_SECTOR_COUNT
                .read()
                .expect("WINDOW_POST_SECTOR_COUNT poisoned")
                .get(&sector_size)
                .expect("unknown sector size"),
            typ: PoStType::Window,
            priority: true,
            api_version,
        }
    )
}

type PoStType added in v1.26.0

type PoStType int
const (
	PoStTypeWindow PoStType = iota
	PoStTypeWinning
)

type PoseidonDomain added in v1.23.1

type PoseidonDomain [32]byte // Fr

func (PoseidonDomain) MarshalJSON added in v1.26.0

func (p PoseidonDomain) MarshalJSON() ([]byte, error)

type PreCommit1OutRaw added in v1.23.1

type PreCommit1OutRaw struct {
	LotusSealRand []byte `json:"_lotus_SealRandomness"`

	CommD           Commitment                           `json:"comm_d"`
	Config          Label                                `json:"config"`
	Labels          map[StringRegisteredProofType]Labels `json:"labels"`
	RegisteredProof StringRegisteredProofType            `json:"registered_proof"`
}

type ProofData added in v1.23.1

type ProofData[H HasherDomain] struct {
	Single *SingleProof[H] `json:"Single,omitempty"`
	Sub    *SubProof[H]    `json:"Sub,omitempty"`
	Top    *TopProof[H]    `json:"Top,omitempty"`
}

func DecodeProofData added in v1.23.1

func DecodeProofData[H HasherDomain](r io.Reader) (ProofData[H], error)

type PublicReplicaInfo added in v1.26.0

type PublicReplicaInfo struct {
	CommR PoseidonDomain
}

type RawMerkleProof added in v1.25.1

type RawMerkleProof struct {
	Leaf  [32]byte
	Proof [][32]byte
	Root  [32]byte
}

func MemtreeProof added in v1.25.1

func MemtreeProof(memtree []byte, leafIndex int64) (*RawMerkleProof, error)

MemtreeProof generates a Merkle proof for the given leaf index from the memtree. The memtree is a byte slice containing all the nodes of the Merkle tree, including leaves and internal nodes.

type ReplicaColumnProof added in v1.23.1

type ReplicaColumnProof[H HasherDomain] struct {
	C_X        ColumnProof[H]   `json:"c_x"`
	DrgParents []ColumnProof[H] `json:"drg_parents"`
	ExpParents []ColumnProof[H] `json:"exp_parents"`
}

func DecodeReplicaColumnProof added in v1.23.1

func DecodeReplicaColumnProof[H HasherDomain](r io.Reader) (ReplicaColumnProof[H], error)

type SectorNodes added in v1.23.1

type SectorNodes uint64

SectorNodes is sector size as node count

type SectorProof added in v1.26.0

type SectorProof struct {
	// One or more “MerkleProof” objects describing the inclusion paths
	InclusionProofs []MerkleProof[PoseidonDomain] `json:"inclusion_proofs"`

	CommC     PoseidonDomain `json:"comm_c"`
	CommRLast PoseidonDomain `json:"comm_r_last"`
}

SectorProof parallels Rust’s

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SectorProof<Proof: MerkleProofTrait> {
    pub inclusion_proofs: Vec<MerkleProof<...>>,
    pub comm_c: <Proof::Hasher as Hasher>::Domain,
    pub comm_r_last: <Proof::Hasher as Hasher>::Domain,
}

func DecodeSectorProof added in v1.26.0

func DecodeSectorProof(r io.Reader) (SectorProof, error)

DecodeSectorProof decodes a single SectorProof from the reader.

Rust struct reference for context: #[derive(Debug, Clone, Serialize, Deserialize)]

pub struct SectorProof<Proof: MerkleProofTrait> {
    pub inclusion_proofs: Vec<Proof>,
    pub comm_c: <Proof::Hasher as Hasher>::Domain,
    pub comm_r_last: <Proof::Hasher as Hasher>::Domain,
}

type Sha256Domain added in v1.23.1

type Sha256Domain [32]byte

func (Sha256Domain) MarshalJSON added in v1.26.0

func (s Sha256Domain) MarshalJSON() ([]byte, error)

type SingleProof added in v1.23.1

type SingleProof[H HasherDomain] struct {
	Root H                `json:"root"`
	Leaf H                `json:"leaf"`
	Path InclusionPath[H] `json:"path"`
}

func DecodeSingleProof added in v1.23.1

func DecodeSingleProof[H HasherDomain](r io.Reader) (SingleProof[H], error)

type Snap added in v1.26.0

type Snap struct {
	ProofType abi.RegisteredUpdateProof

	OldR Commitment `json:"old_r"`
	NewR Commitment `json:"new_r"`
	NewD Commitment `json:"new_d"`

	// rust-fil-proofs bincoded repr; Todo is implementing types in Go
	Proofs [][]byte
}

type StoreConfig added in v1.23.1

type StoreConfig struct {
	// A directory in which data (a merkle tree) can be persisted.
	Path string

	// A unique identifier used to help specify the on-disk store location for this particular data.
	ID string

	// The number of elements in the DiskStore. This field is optional, and unused internally.
	Size *uint64

	// The number of merkle tree rows_to_discard then cache on disk.
	RowsToDiscard uint64
}

func DecodeStoreConfig added in v1.23.1

func DecodeStoreConfig(r io.Reader) (StoreConfig, error)

type StringRegisteredProofType added in v1.23.1

type StringRegisteredProofType string // e.g. "StackedDrg2KiBV1", StackedDrg32GiBV1_1

func (StringRegisteredProofType) ToABI added in v1.26.0

// These enumerations must match the proofs library and never change. type RegisteredSealProof int64

const (

RegisteredSealProof_StackedDrg2KiBV1   = RegisteredSealProof(0)
RegisteredSealProof_StackedDrg8MiBV1   = RegisteredSealProof(1)
RegisteredSealProof_StackedDrg512MiBV1 = RegisteredSealProof(2)
RegisteredSealProof_StackedDrg32GiBV1  = RegisteredSealProof(3)
RegisteredSealProof_StackedDrg64GiBV1  = RegisteredSealProof(4)

RegisteredSealProof_StackedDrg2KiBV1_1   = RegisteredSealProof(5)
RegisteredSealProof_StackedDrg8MiBV1_1   = RegisteredSealProof(6)
RegisteredSealProof_StackedDrg512MiBV1_1 = RegisteredSealProof(7)
RegisteredSealProof_StackedDrg32GiBV1_1  = RegisteredSealProof(8)
RegisteredSealProof_StackedDrg64GiBV1_1  = RegisteredSealProof(9)

RegisteredSealProof_StackedDrg2KiBV1_1_Feat_SyntheticPoRep   = RegisteredSealProof(10)
RegisteredSealProof_StackedDrg8MiBV1_1_Feat_SyntheticPoRep   = RegisteredSealProof(11)
RegisteredSealProof_StackedDrg512MiBV1_1_Feat_SyntheticPoRep = RegisteredSealProof(12)
RegisteredSealProof_StackedDrg32GiBV1_1_Feat_SyntheticPoRep  = RegisteredSealProof(13)
RegisteredSealProof_StackedDrg64GiBV1_1_Feat_SyntheticPoRep  = RegisteredSealProof(14)

RegisteredSealProof_StackedDrg2KiBV1_2_Feat_NiPoRep   = RegisteredSealProof(15)
RegisteredSealProof_StackedDrg8MiBV1_2_Feat_NiPoRep   = RegisteredSealProof(16)
RegisteredSealProof_StackedDrg512MiBV1_2_Feat_NiPoRep = RegisteredSealProof(17)
RegisteredSealProof_StackedDrg32GiBV1_2_Feat_NiPoRep  = RegisteredSealProof(18)
RegisteredSealProof_StackedDrg64GiBV1_2_Feat_NiPoRep  = RegisteredSealProof(19)

)

Rust: /// Available seal proofs. // Enum is append-only: once published, a `RegisteredSealProof` value must never change. #[allow(non_camel_case_types)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]

pub enum RegisteredSealProof {
    StackedDrg2KiBV1,
    StackedDrg8MiBV1,
    StackedDrg512MiBV1,
    StackedDrg32GiBV1,
    StackedDrg64GiBV1,

    StackedDrg2KiBV1_1,
    StackedDrg8MiBV1_1,
    StackedDrg512MiBV1_1,
    StackedDrg32GiBV1_1,
    StackedDrg64GiBV1_1,

    StackedDrg2KiBV1_1_Feat_SyntheticPoRep,
    StackedDrg8MiBV1_1_Feat_SyntheticPoRep,
    StackedDrg512MiBV1_1_Feat_SyntheticPoRep,
    StackedDrg32GiBV1_1_Feat_SyntheticPoRep,
    StackedDrg64GiBV1_1_Feat_SyntheticPoRep,

    // NOTE: The SyntheticPoRep feature was added in proofs API
    // version 1.2, however the published proof name has the incorrect
    // version 1_1 coded into it.
    //
    // Non-interactive PoRep is also a feature added at API version
    // 1.2, so the naming has been corrected before publication.
    StackedDrg2KiBV1_2_Feat_NonInteractivePoRep,
    StackedDrg8MiBV1_2_Feat_NonInteractivePoRep,
    StackedDrg512MiBV1_2_Feat_NonInteractivePoRep,
    StackedDrg32GiBV1_2_Feat_NonInteractivePoRep,
    StackedDrg64GiBV1_2_Feat_NonInteractivePoRep,
}

type SubProof added in v1.23.1

type SubProof[H HasherDomain] struct {
	BaseProof InclusionPath[H] `json:"base_proof"`
	SubProof  InclusionPath[H] `json:"sub_proof"`
	Root      H                `json:"root"`
	Leaf      H                `json:"leaf"`
}

func DecodeSubProof added in v1.23.1

func DecodeSubProof[H HasherDomain](r io.Reader) (SubProof[H], error)

type TAuxLabels added in v1.23.1

type TAuxLabels struct {
	Labels []StoreConfig
}

func DecodeLabels added in v1.23.1

func DecodeLabels(r io.Reader) (*TAuxLabels, error)

type TemporaryAux added in v1.23.1

type TemporaryAux struct {
	Labels      TAuxLabels
	TreeDConfig StoreConfig
	TreeRConfig StoreConfig
	TreeCConfig StoreConfig
}

func DecodeTAux added in v1.23.1

func DecodeTAux(r io.Reader) (*TemporaryAux, error)

type Ticket added in v1.23.1

type Ticket [32]byte

func DecodeTicket added in v1.23.1

func DecodeTicket(r io.Reader) (Ticket, error)

type TopProof added in v1.23.1

type TopProof[H HasherDomain] struct {
	BaseProof InclusionPath[H] `json:"base_proof"`
	SubProof  InclusionPath[H] `json:"sub_proof"`
	TopProof  InclusionPath[H] `json:"top_proof"`

	Root H `json:"root"`
	Leaf H `json:"leaf"`
}

func DecodeTopProof added in v1.23.1

func DecodeTopProof[H HasherDomain](r io.Reader) (TopProof[H], error)

type VanillaProof added in v1.26.0

type VanillaProof struct {
	// Each “SectorProof” holds merkle inclusion proofs, comm_c, comm_r_last, etc.
	Sectors []SectorProof `json:"sectors"`
}

VanillaProof parallels Rust’s

pub struct Proof<P: MerkleProofTrait> {
    pub sectors: Vec<SectorProof<P>>
}

func DecodeVanillaProof added in v1.26.0

func DecodeVanillaProof(r io.Reader) (VanillaProof, error)

DecodeVanillaProof decodes a VanillaProof from the reader.

Rust struct reference for context:

pub struct Proof<P: MerkleProofTrait> {
    pub sectors: Vec<SectorProof<P>>
}

type VanillaStackedProof added in v1.23.1

type VanillaStackedProof struct {
	CommDProofs    MerkleProof[Sha256Domain]   `json:"comm_d_proofs"`
	CommRLastProof MerkleProof[PoseidonDomain] `json:"comm_r_last_proof"`

	ReplicaColumnProofs ReplicaColumnProof[PoseidonDomain] `json:"replica_column_proofs"`
	LabelingProofs      []LabelingProof[PoseidonDomain]    `json:"labeling_proofs"`
	EncodingProof       EncodingProof[PoseidonDomain]      `json:"encoding_proof"`
}

func DecodeVanillaStackedProof added in v1.23.1

func DecodeVanillaStackedProof(r io.Reader) (VanillaStackedProof, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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