Documentation ¶
Index ¶
- Constants
- Variables
- func LnIntApproximation(x uint64) (uint64, error)
- func MessageHashMaxSize() (s int)
- func ProverMaxSize() (s int)
- func ProverPersistedFieldsMaxSize() (s int)
- func RevealMaxSize() (s int)
- func SigslotCommitMaxSize() (s int)
- func StateProofMaxSize() (s int)
- type MessageHash
- func (_ *MessageHash) CanMarshalMsg(z interface{}) bool
- func (_ *MessageHash) CanUnmarshalMsg(z interface{}) bool
- func (z *MessageHash) MarshalMsg(b []byte) (o []byte)
- func (z *MessageHash) MsgIsZero() bool
- func (z *MessageHash) Msgsize() (s int)
- func (z *MessageHash) UnmarshalMsg(bts []byte) (o []byte, err error)
- func (z *MessageHash) UnmarshalMsgWithState(bts []byte, st msgp.UnmarshalState) (o []byte, err error)
- type Prover
- func (b *Prover) Add(pos uint64, sig merklesignature.Signature) error
- func (b *Prover) AllocSigs()
- func (_ *Prover) CanMarshalMsg(z interface{}) bool
- func (_ *Prover) CanUnmarshalMsg(z interface{}) bool
- func (b *Prover) CreateProof() (*StateProof, error)
- func (b *Prover) IsValid(pos uint64, sig *merklesignature.Signature, verifySig bool) error
- func (z *Prover) MarshalMsg(b []byte) (o []byte)
- func (z *Prover) MsgIsZero() bool
- func (z *Prover) Msgsize() (s int)
- func (b *Prover) Present(pos uint64) (bool, error)
- func (b *Prover) Ready() bool
- func (b *Prover) SignedWeight() uint64
- func (z *Prover) UnmarshalMsg(bts []byte) (o []byte, err error)
- func (z *Prover) UnmarshalMsgWithState(bts []byte, st msgp.UnmarshalState) (o []byte, err error)
- type ProverPersistedFields
- func (_ *ProverPersistedFields) CanMarshalMsg(z interface{}) bool
- func (_ *ProverPersistedFields) CanUnmarshalMsg(z interface{}) bool
- func (z *ProverPersistedFields) MarshalMsg(b []byte) (o []byte)
- func (z *ProverPersistedFields) MsgIsZero() bool
- func (z *ProverPersistedFields) Msgsize() (s int)
- func (z *ProverPersistedFields) UnmarshalMsg(bts []byte) (o []byte, err error)
- func (z *ProverPersistedFields) UnmarshalMsgWithState(bts []byte, st msgp.UnmarshalState) (o []byte, err error)
- type Reveal
- func (_ *Reveal) CanMarshalMsg(z interface{}) bool
- func (_ *Reveal) CanUnmarshalMsg(z interface{}) bool
- func (z *Reveal) MarshalMsg(b []byte) (o []byte)
- func (z *Reveal) MsgIsZero() bool
- func (z *Reveal) Msgsize() (s int)
- func (z *Reveal) UnmarshalMsg(bts []byte) (o []byte, err error)
- func (z *Reveal) UnmarshalMsgWithState(bts []byte, st msgp.UnmarshalState) (o []byte, err error)
- type SortUint64
- type StateProof
- func (_ *StateProof) CanMarshalMsg(z interface{}) bool
- func (_ *StateProof) CanUnmarshalMsg(z interface{}) bool
- func (z *StateProof) MarshalMsg(b []byte) (o []byte)
- func (z *StateProof) MsgIsZero() bool
- func (z *StateProof) Msgsize() (s int)
- func (s StateProof) String() string
- func (z *StateProof) UnmarshalMsg(bts []byte) (o []byte, err error)
- func (z *StateProof) UnmarshalMsgWithState(bts []byte, st msgp.UnmarshalState) (o []byte, err error)
- type Verifier
Constants ¶
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.
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
const VotersAllocBound = 1024
VotersAllocBound should be equal to config.Consensus[protocol.ConsensusCurrentVersion].StateProofTopVoters
Variables ¶
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
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
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
var ErrIndexOutOfBound = errors.New("index is out of bound")
ErrIndexOutOfBound returned when an index is out of the array's bound
Functions ¶
func LnIntApproximation ¶
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) CanUnmarshalMsg ¶
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 ¶
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 ¶
MarshalMsg implements msgp.Marshaler
func (*Prover) Msgsize ¶
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*Prover) Present ¶
Present checks if the prover already contains a signature at a particular offset.
func (*Prover) SignedWeight ¶
SignedWeight returns the total weight of signatures added so far.
func (*Prover) UnmarshalMsgWithState ¶
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) CanUnmarshalMsg ¶
func (*Reveal) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
func (*Reveal) Msgsize ¶
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*Reveal) UnmarshalMsgWithState ¶
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