commp

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2023 License: Apache-2.0, MIT Imports: 5 Imported by: 34

README

go-fil-commp-hashhash

A hash.Hash implementation of fil-commitment-unsealed

GoDoc GoReport

Package commp allows calculating a Filecoin Unsealed Commitment (commP/commD) given a bytestream. It is implemented as a standard hash.Hash() interface, with the entire padding and treebuilding algorithm written in golang.

The returned digest is a 32-byte raw commitment payload. Use something like DataCommitmentV1ToCID in order to convert it to a proper cid.Cid.

The output of this library is 100% identical to ffi.GeneratePieceCIDFromFile()

Lead Maintainer

Peter 'ribasushi' Rabbitson

License

SPDX-License-Identifier: Apache-2.0 OR MIT

Documentation

Overview

Package commp allows calculating a Filecoin Unsealed Commitment (commP/commD) given a bytestream. It is implemented as a standard hash.Hash() interface, with the entire padding and treebuilding algorithm written in golang.

The returned digest is a 32-byte raw commitment payload. Use something like https://pkg.go.dev/github.com/filecoin-project/go-fil-commcid#DataCommitmentV1ToCID in order to convert it to a proper cid.Cid.

The output of this library is 100% identical to https://github.com/filecoin-project/filecoin-ffi/blob/d82899449741ce19/proofs.go#L177-L196

Index

Constants

View Source
const MaxLayers = uint(31) // result of log2( 64 GiB / 32 )

MaxLayers is the current maximum height of the rust-fil-proofs proving tree.

View Source
const MaxPiecePayload = MaxPieceSize / 128 * 127

MaxPiecePayload is the maximum amount of data that one can Write() to the Calc object, before needing to derive a Digest(). Constrained by the value of MaxLayers.

View Source
const MaxPieceSize = uint64(1 << (MaxLayers + 5))

MaxPieceSize is the current maximum size of the rust-fil-proofs proving tree.

View Source
const MinPiecePayload = uint64(65)

MinPiecePayload is the smallest amount of data for which FR32 padding has a defined result. It is not possible to derive a Digest() before Write()ing at least this amount of bytes.

Variables

This section is empty.

Functions

func PadCommP

func PadCommP(sourceCommP []byte, sourcePaddedSize, targetPaddedSize uint64) ([]byte, error)

PadCommP is experimental, do not use it.

Types

type Calc

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

Calc is an implementation of a commP "hash" calculator, implementing the familiar hash.Hash interface. The zero-value of this object is ready to accept Write()s without further initialization.

func (*Calc) BlockSize

func (cp *Calc) BlockSize() int

BlockSize is the amount of bytes consumed by the commP algorithm in one go. Write()ing data in multiples of BlockSize would obviate the need to maintain an internal carry buffer. The BlockSize of this module is 127 bytes.

func (*Calc) Digest

func (cp *Calc) Digest() (commP []byte, paddedPieceSize uint64, err error)

Digest collapses the internal hash state and returns the resulting raw 32 bytes of commP and the padded piece size, or alternatively an error in case of insufficient accumulated state. On success invokes Reset(), which terminates all goroutines kicked off by Write().

func (*Calc) Reset

func (cp *Calc) Reset()

Reset re-initializes the accumulator object, clearing its state and terminating all background goroutines. It is safe to Reset() an accumulator in any state.

func (*Calc) Size

func (cp *Calc) Size() int

Size is the amount of bytes returned on Sum()/Digest(), which is 32 bytes for this module.

func (*Calc) Sum

func (cp *Calc) Sum(buf []byte) []byte

Sum is a thin wrapper around Digest() and is provided solely to satisfy the hash.Hash interface. It panics on errors returned from Digest(). Note that unlike classic (hash.Hash).Sum(), calling this method is destructive: the internal state is reset and all goroutines kicked off by Write() are terminated.

func (*Calc) Write

func (cp *Calc) Write(input []byte) (int, error)

Write adds bytes to the accumulator, for a subsequent Digest(). Upon the first call of this method a few goroutines are started in the background to service each layer of the digest tower. If you wrote some data and then decide to abandon the object without invoking Digest(), you need to call Reset() to terminate all remaining background workers. Unlike a typical (hash.Hash).Write, calling this method can return an error when the total amount of bytes is about to go over the maximum currently supported by Filecoin.

Directories

Path Synopsis
cmd
stream-commp Module

Jump to

Keyboard shortcuts

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