stateproof

package
v0.0.0-...-5ac3edc Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HashType = crypto.Sumhash
	HashSize = crypto.SumhashDigestSize

	MaxReveals = 640 // MaxReveals is a bound on allocation and on numReveals to limit log computation
	// VersionForCoinGenerator is used as part of the seed for Fiat-Shamir. We would change this
	// value if the state proof verifier algorithm changes. This will allow us to make different coins for different state proof verification algorithms
	VersionForCoinGenerator = byte(0)
	// MaxTreeDepth defines the maximal size of a merkle tree depth the state proof allows.
	MaxTreeDepth = 20
	// MessageHashType is the type of hash used to generate MessageHash
	MessageHashType = crypto.Sha256
)

HashType/ hashSize relate to the type of hash this package uses.

View Source
const SigPartProofMaxSize = 35353

SigPartProofMaxSize is the maximum valid size of SigProofs and PartProofs elements of the Stateproof struct in bytes. It is equal to merklearray.ProofMaxSizeByElements(config.StateProofTopVoters/2) See merklearray.Proof comment for explanation on the bound calculation

View Source
const VotersAllocBound = 1024

VotersAllocBound should be equal to config.Consensus[protocol.ConsensusCurrentVersion].StateProofTopVoters

Variables

View Source
var (
	ErrPositionOutOfBound     = errors.New("requested position is out of bounds")
	ErrPositionAlreadyPresent = errors.New("requested position is already present")
	ErrPositionWithZeroWeight = errors.New("position has zero weight")
	ErrCoinIndexError         = errors.New("could not find corresponding index for a given coin")
)

Errors for the StateProof prover

View Source
var (
	ErrCoinNotInRange    = errors.New("coin is not within slot weight range")
	ErrNoRevealInPos     = errors.New("no reveal for position")
	ErrTreeDepthTooLarge = errors.New("tree depth is too large")
)

Errors for the StateProof verifier

View Source
var (
	ErrSignedWeightLessThanProvenWeight = errors.New("signed weight is less than or equal to proven weight")
	ErrTooManyReveals                   = errors.New("too many reveals in state proof")
	ErrZeroSignedWeight                 = errors.New("signed weight cannot be zero")
	ErrIllegalInputForLnApprox          = errors.New("cannot calculate a ln integer value for 0")
	ErrInsufficientSignedWeight         = errors.New("the number of reveals is not large enough to prove that the desired weight signed, with the desired security level")
	ErrNegativeNumOfRevealsEquation     = errors.New("state proof creation failed: weights will not be able to satisfy the verification equation")
)

errors for the weights verification

View Source
var ErrIndexOutOfBound = errors.New("index is out of bound")

ErrIndexOutOfBound returned when an index is out of the array's bound

Functions

func LnIntApproximation

func LnIntApproximation(x uint64) (uint64, error)

LnIntApproximation returns a uint64 approximation

func MessageHashMaxSize

func MessageHashMaxSize() (s int)

MaxSize returns a maximum valid message size for this message type

func ProverMaxSize

func ProverMaxSize() (s int)

MaxSize returns a maximum valid message size for this message type

func ProverPersistedFieldsMaxSize

func ProverPersistedFieldsMaxSize() (s int)

MaxSize returns a maximum valid message size for this message type

func RevealMaxSize

func RevealMaxSize() (s int)

MaxSize returns a maximum valid message size for this message type

func SigslotCommitMaxSize

func SigslotCommitMaxSize() (s int)

MaxSize returns a maximum valid message size for this message type

func StateProofMaxSize

func StateProofMaxSize() (s int)

MaxSize returns a maximum valid message size for this message type

Types

type MessageHash

type MessageHash [32]byte

MessageHash represents the message that a state proof will attest to.

func (*MessageHash) CanMarshalMsg

func (_ *MessageHash) CanMarshalMsg(z interface{}) bool

func (*MessageHash) CanUnmarshalMsg

func (_ *MessageHash) CanUnmarshalMsg(z interface{}) bool

func (*MessageHash) MarshalMsg

func (z *MessageHash) MarshalMsg(b []byte) (o []byte)

MarshalMsg implements msgp.Marshaler

func (*MessageHash) MsgIsZero

func (z *MessageHash) MsgIsZero() bool

MsgIsZero returns whether this is a zero value

func (*MessageHash) Msgsize

func (z *MessageHash) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*MessageHash) UnmarshalMsg

func (z *MessageHash) UnmarshalMsg(bts []byte) (o []byte, err error)

func (*MessageHash) UnmarshalMsgWithState

func (z *MessageHash) UnmarshalMsgWithState(bts []byte, st msgp.UnmarshalState) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Prover

type Prover struct {
	ProverPersistedFields
	// contains filtered or unexported fields
}

Prover keeps track of signatures on a message and eventually produces a state proof for that message.

func MakeProver

func MakeProver(data MessageHash, round uint64, provenWeight uint64, part []basics.Participant, parttree *merklearray.Tree, strengthTarget uint64) (*Prover, error)

MakeProver constructs an empty sp-prover. After adding enough signatures and signed weight, this sp-prover is used to create a stateproof.

func (*Prover) Add

func (b *Prover) Add(pos uint64, sig merklesignature.Signature) error

Add a signature to the set of signatures available for building a proof.

func (*Prover) AllocSigs

func (b *Prover) AllocSigs()

AllocSigs should only be used after decoding msgpacked Prover, as the sigs field is not exported and encoded

func (*Prover) CanMarshalMsg

func (_ *Prover) CanMarshalMsg(z interface{}) bool

func (*Prover) CanUnmarshalMsg

func (_ *Prover) CanUnmarshalMsg(z interface{}) bool

func (*Prover) CreateProof

func (b *Prover) CreateProof() (*StateProof, error)

CreateProof returns a state proof, if the prover has accumulated enough signatures to construct it.

func (*Prover) IsValid

func (b *Prover) IsValid(pos uint64, sig *merklesignature.Signature, verifySig bool) error

IsValid verifies that the participant along with the signature can be inserted to the prover. verifySig can be set to false when the signature is already verified (e.g. loaded from the DB)

func (*Prover) MarshalMsg

func (z *Prover) MarshalMsg(b []byte) (o []byte)

MarshalMsg implements msgp.Marshaler

func (*Prover) MsgIsZero

func (z *Prover) MsgIsZero() bool

MsgIsZero returns whether this is a zero value

func (*Prover) Msgsize

func (z *Prover) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Prover) Present

func (b *Prover) Present(pos uint64) (bool, error)

Present checks if the prover already contains a signature at a particular offset.

func (*Prover) Ready

func (b *Prover) Ready() bool

Ready returns whether the state proof is ready to be built.

func (*Prover) SignedWeight

func (b *Prover) SignedWeight() uint64

SignedWeight returns the total weight of signatures added so far.

func (*Prover) UnmarshalMsg

func (z *Prover) UnmarshalMsg(bts []byte) (o []byte, err error)

func (*Prover) UnmarshalMsgWithState

func (z *Prover) UnmarshalMsgWithState(bts []byte, st msgp.UnmarshalState) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type ProverPersistedFields

type ProverPersistedFields struct {
	Data           MessageHash          `codec:"data"`
	Round          uint64               `codec:"rnd"`
	Participants   []basics.Participant `codec:"parts,allocbound=VotersAllocBound"`
	Parttree       *merklearray.Tree    `codec:"parttree"`
	LnProvenWeight uint64               `codec:"lnprv"`
	ProvenWeight   uint64               `codec:"prv"`
	StrengthTarget uint64               `codec:"str"`
	// contains filtered or unexported fields
}

ProverPersistedFields is the set of fields from the crypto state proof prover that are persisted to disk.

func (*ProverPersistedFields) CanMarshalMsg

func (_ *ProverPersistedFields) CanMarshalMsg(z interface{}) bool

func (*ProverPersistedFields) CanUnmarshalMsg

func (_ *ProverPersistedFields) CanUnmarshalMsg(z interface{}) bool

func (*ProverPersistedFields) MarshalMsg

func (z *ProverPersistedFields) MarshalMsg(b []byte) (o []byte)

MarshalMsg implements msgp.Marshaler

func (*ProverPersistedFields) MsgIsZero

func (z *ProverPersistedFields) MsgIsZero() bool

MsgIsZero returns whether this is a zero value

func (*ProverPersistedFields) Msgsize

func (z *ProverPersistedFields) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*ProverPersistedFields) UnmarshalMsg

func (z *ProverPersistedFields) UnmarshalMsg(bts []byte) (o []byte, err error)

func (*ProverPersistedFields) UnmarshalMsgWithState

func (z *ProverPersistedFields) UnmarshalMsgWithState(bts []byte, st msgp.UnmarshalState) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Reveal

type Reveal struct {
	SigSlot sigslotCommit      `codec:"s"`
	Part    basics.Participant `codec:"p"`
	// contains filtered or unexported fields
}

Reveal is a single array position revealed as part of a state proof. It reveals an element of the signature array and the corresponding element of the participants array.

func (*Reveal) CanMarshalMsg

func (_ *Reveal) CanMarshalMsg(z interface{}) bool

func (*Reveal) CanUnmarshalMsg

func (_ *Reveal) CanUnmarshalMsg(z interface{}) bool

func (*Reveal) MarshalMsg

func (z *Reveal) MarshalMsg(b []byte) (o []byte)

MarshalMsg implements msgp.Marshaler

func (*Reveal) MsgIsZero

func (z *Reveal) MsgIsZero() bool

MsgIsZero returns whether this is a zero value

func (*Reveal) Msgsize

func (z *Reveal) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Reveal) UnmarshalMsg

func (z *Reveal) UnmarshalMsg(bts []byte) (o []byte, err error)

func (*Reveal) UnmarshalMsgWithState

func (z *Reveal) UnmarshalMsgWithState(bts []byte, st msgp.UnmarshalState) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type SortUint64

type SortUint64 = basics.SortUint64

SortUint64 implements sorting by uint64 keys for canonical encoding of maps in msgpack format.

type StateProof

type StateProof struct {
	SigCommit                  crypto.GenericDigest `codec:"c"`
	SignedWeight               uint64               `codec:"w"`
	SigProofs                  merklearray.Proof    `codec:"S,maxtotalbytes=SigPartProofMaxSize"`
	PartProofs                 merklearray.Proof    `codec:"P,maxtotalbytes=SigPartProofMaxSize"`
	MerkleSignatureSaltVersion byte                 `codec:"v"`
	// Reveals is a sparse map from the position being revealed
	// to the corresponding elements from the sigs and participants
	// arrays.
	Reveals           map[uint64]Reveal `codec:"r,allocbound=MaxReveals"`
	PositionsToReveal []uint64          `codec:"pr,allocbound=MaxReveals"`
	// contains filtered or unexported fields
}

StateProof represents a proof on Algorand's state.

func (*StateProof) CanMarshalMsg

func (_ *StateProof) CanMarshalMsg(z interface{}) bool

func (*StateProof) CanUnmarshalMsg

func (_ *StateProof) CanUnmarshalMsg(z interface{}) bool

func (*StateProof) MarshalMsg

func (z *StateProof) MarshalMsg(b []byte) (o []byte)

MarshalMsg implements msgp.Marshaler

func (*StateProof) MsgIsZero

func (z *StateProof) MsgIsZero() bool

MsgIsZero returns whether this is a zero value

func (*StateProof) Msgsize

func (z *StateProof) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (StateProof) String

func (s StateProof) String() string

func (*StateProof) UnmarshalMsg

func (z *StateProof) UnmarshalMsg(bts []byte) (o []byte, err error)

func (*StateProof) UnmarshalMsgWithState

func (z *StateProof) UnmarshalMsgWithState(bts []byte, st msgp.UnmarshalState) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Verifier

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

Verifier is used to verify a state proof. those fields represent all the verifier's trusted data

func MkVerifier

func MkVerifier(partcom crypto.GenericDigest, provenWeight uint64, strengthTarget uint64) (*Verifier, error)

MkVerifier constructs a verifier to check the state proof. the arguments for this function represent all the verifier's trusted data

func MkVerifierWithLnProvenWeight

func MkVerifierWithLnProvenWeight(partcom crypto.GenericDigest, lnProvenWt uint64, strengthTarget uint64) *Verifier

MkVerifierWithLnProvenWeight constructs a verifier to check the state proof. the arguments for this function represent all the verifier's trusted data. This function uses the Ln(provenWeight) approximation value

func (*Verifier) Verify

func (v *Verifier) Verify(round uint64, data MessageHash, s *StateProof) error

Verify checks if s is a valid state proof for the data on a round. it uses the trusted data from the Verifier struct

Jump to

Keyboard shortcuts

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