merklesignature

package
v0.0.0-...-ff2c966 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MerkleSignatureSchemeHashFunction = crypto.Sumhash
	MerkleSignatureSchemeRootSize     = crypto.SumhashDigestSize
	// KeyLifetimeDefault defines the default lifetime of a key in the merkle signature scheme (in rounds).
	KeyLifetimeDefault = 256

	// SchemeSaltVersion is the current salt version of merkleSignature
	SchemeSaltVersion = byte(0)

	// CryptoPrimitivesID is an identification that the Merkle Signature Scheme uses a subset sum hash function
	// and a falcon signature scheme.
	CryptoPrimitivesID = uint16(0)
)

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

Variables

View Source
var (
	ErrStartBiggerThanEndRound           = errors.New("cannot create Merkle Signature Scheme because end round is smaller then start round")
	ErrKeyLifetimeIsZero                 = errors.New("received zero KeyLifetime")
	ErrNoStateProofKeyForRound           = errors.New("no stateproof key exists for this round")
	ErrSignatureSchemeVerificationFailed = errors.New("merkle signature verification failed")
	ErrSignatureSaltVersionMismatch      = errors.New("the signature's salt version does not match")
)

Errors for the merkle signature scheme

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

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

View Source
var NoKeysCommitment = Commitment{}

NoKeysCommitment is a const hash value of the empty MerkleSignature Commitment.

Functions

func CommitmentMaxSize

func CommitmentMaxSize() (s int)

MaxSize returns a maximum valid message size for this message type

func InstallStateProofTable

func InstallStateProofTable(tx *sql.Tx) error

InstallStateProofTable creates (or migrates if exists already) the StateProofKeys database table

func KeyRoundPairMaxSize

func KeyRoundPairMaxSize() (s int)

MaxSize returns a maximum valid message size for this message type

func KeysBuilder

func KeysBuilder(numberOfKeys uint64) ([]crypto.FalconSigner, error)

KeysBuilder Responsible for generate slice of falcon keys

func SecretsMaxSize

func SecretsMaxSize() (s int)

MaxSize returns a maximum valid message size for this message type

func SignatureMaxSize

func SignatureMaxSize() (s int)

MaxSize returns a maximum valid message size for this message type

func SignerContextMaxSize

func SignerContextMaxSize() (s int)

MaxSize returns a maximum valid message size for this message type

func VerifierMaxSize

func VerifierMaxSize() (s int)

MaxSize returns a maximum valid message size for this message type

Types

type Commitment

Commitment represents the root of the vector commitment tree built upon the MSS keys.

func (*Commitment) CanMarshalMsg

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

func (*Commitment) CanUnmarshalMsg

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

func (*Commitment) IsEmpty

func (v *Commitment) IsEmpty() bool

IsEmpty returns true if the verifier contains an empty key

func (*Commitment) MarshalMsg

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

MarshalMsg implements msgp.Marshaler

func (*Commitment) MsgIsZero

func (z *Commitment) MsgIsZero() bool

MsgIsZero returns whether this is a zero value

func (*Commitment) Msgsize

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

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

func (*Commitment) UnmarshalMsg

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

func (*Commitment) UnmarshalMsgWithState

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

UnmarshalMsg implements msgp.Unmarshaler

type CommittablePublicKey

type CommittablePublicKey struct {
	VerifyingKey crypto.FalconVerifier
	Round        uint64
}

CommittablePublicKey is used to create a binary representation of public keys in the merkle signature scheme.

func (*CommittablePublicKey) ToBeHashed

func (e *CommittablePublicKey) ToBeHashed() (protocol.HashID, []byte)

ToBeHashed returns the sequence of bytes that would be used as an input for the hash function when creating a merkle tree. In order to create a more SNARK-friendly commitment we must avoid using the msgpack infrastructure. msgpack creates a compressed representation of the struct which might be varied in length, this will be bad for creating SNARK

type KeyRoundPair

type KeyRoundPair struct {
	Round uint64               `codec:"rnd"`
	Key   *crypto.FalconSigner `codec:"key"`
	// contains filtered or unexported fields
}

KeyRoundPair represents an ephemeral signing key with it's corresponding round

func (*KeyRoundPair) CanMarshalMsg

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

func (*KeyRoundPair) CanUnmarshalMsg

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

func (*KeyRoundPair) MarshalMsg

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

MarshalMsg implements msgp.Marshaler

func (*KeyRoundPair) MsgIsZero

func (z *KeyRoundPair) MsgIsZero() bool

MsgIsZero returns whether this is a zero value

func (*KeyRoundPair) Msgsize

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

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

func (*KeyRoundPair) UnmarshalMsg

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

func (*KeyRoundPair) UnmarshalMsgWithState

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

UnmarshalMsg implements msgp.Unmarshaler

type Secrets

type Secrets struct {
	SignerContext
	// contains filtered or unexported fields
}

Secrets contains the private data needed by the merkle signature scheme.

func New

func New(firstValid, lastValid, keyLifetime uint64) (*Secrets, error)

New creates secrets needed for the merkle signature scheme. This function generates one key for each round within the participation period [firstValid, lastValid] (inclusive bounds) which holds round % interval == 0.

func (*Secrets) CanMarshalMsg

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

func (*Secrets) CanUnmarshalMsg

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

func (*Secrets) GetAllKeys

func (s *Secrets) GetAllKeys() []KeyRoundPair

GetAllKeys returns all stateproof secrets. An empty array will be return if no stateproof secrets are found

func (*Secrets) GetKey

func (s *Secrets) GetKey(round uint64) *crypto.FalconSigner

GetKey retrieves key from memory the function return nil if the key does not exists

func (*Secrets) GetSigner

func (s *Secrets) GetSigner(round uint64) *Signer

GetSigner returns the secret keys required for the specified round as well as the rest of the required state proof immutable data

func (*Secrets) GetVerifier

func (s *Secrets) GetVerifier() *Verifier

GetVerifier can be used to store the commitment and verifier for this signer.

func (*Secrets) MarshalMsg

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

MarshalMsg implements msgp.Marshaler

func (*Secrets) MsgIsZero

func (z *Secrets) MsgIsZero() bool

MsgIsZero returns whether this is a zero value

func (*Secrets) Msgsize

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

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

func (*Secrets) Persist

func (s *Secrets) Persist(store db.Accessor) error

Persist dumps the keys into the database and deletes the reference to them in Secrets

func (*Secrets) RestoreAllSecrets

func (s *Secrets) RestoreAllSecrets(store db.Accessor) error

RestoreAllSecrets fetch all stateproof secrets from a persisted storage into memory

func (*Secrets) UnmarshalMsg

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

func (*Secrets) UnmarshalMsgWithState

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

UnmarshalMsg implements msgp.Unmarshaler

type Signature

type Signature struct {
	Signature             crypto.FalconSignature      `codec:"sig"`
	VectorCommitmentIndex uint64                      `codec:"idx"`
	Proof                 merklearray.SingleLeafProof `codec:"prf"`
	VerifyingKey          crypto.FalconVerifier       `codec:"vkey"`
	// contains filtered or unexported fields
}

Signature represents a signature in the merkle signature scheme using falcon signatures as an underlying crypto scheme. It consists of an ephemeral public key, a signature, a merkle verification path and an index. The merkle signature considered valid only if the Signature is verified under the ephemeral public key and the Merkle verification path verifies that the ephemeral public key is located at the given index of the tree (for the root given in the long-term public key). More details can be found on Algorand's spec

func (*Signature) CanMarshalMsg

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

func (*Signature) CanUnmarshalMsg

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

func (*Signature) GetFixedLengthHashableRepresentation

func (s *Signature) GetFixedLengthHashableRepresentation() ([]byte, error)

GetFixedLengthHashableRepresentation returns the signature as a hashable byte sequence. the format details can be found in the Algorand's spec.

func (*Signature) MarshalMsg

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

MarshalMsg implements msgp.Marshaler

func (*Signature) MsgIsZero

func (z *Signature) MsgIsZero() bool

MsgIsZero returns whether this is a zero value

func (*Signature) Msgsize

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

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

func (*Signature) UnmarshalMsg

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

func (*Signature) UnmarshalMsgWithState

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

UnmarshalMsg implements msgp.Unmarshaler

func (*Signature) ValidateSaltVersion

func (s *Signature) ValidateSaltVersion(version byte) error

ValidateSaltVersion validates that the version of the signature is matching the expected version

type Signer

type Signer struct {
	SigningKey *crypto.FalconSigner

	// The round for which the signature would be valid
	Round uint64

	SignerContext
}

Signer represents the StateProof signer for a specified round.

func (*Signer) FirstRoundInKeyLifetime

func (s *Signer) FirstRoundInKeyLifetime() (uint64, error)

FirstRoundInKeyLifetime calculates the round of the valid key for a given round by lowering to the closest KeyLiftime divisor.

func (*Signer) SignBytes

func (s *Signer) SignBytes(msg []byte) (Signature, error)

SignBytes signs a given message. The signature is valid on a specific round

type SignerContext

type SignerContext struct {
	FirstValid  uint64           `codec:"fv"`
	KeyLifetime uint64           `codec:"iv"`
	Tree        merklearray.Tree `codec:"tree"`
	// contains filtered or unexported fields
}

SignerContext contains all the immutable data and metadata related to merklesignature.Secrets (without the secret keys)

func (*SignerContext) CanMarshalMsg

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

func (*SignerContext) CanUnmarshalMsg

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

func (*SignerContext) GetVerifier

func (s *SignerContext) GetVerifier() *Verifier

GetVerifier can be used to store the commitment and verifier for this signer.

func (*SignerContext) MarshalMsg

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

MarshalMsg implements msgp.Marshaler

func (*SignerContext) MsgIsZero

func (z *SignerContext) MsgIsZero() bool

MsgIsZero returns whether this is a zero value

func (*SignerContext) Msgsize

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

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

func (*SignerContext) UnmarshalMsg

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

func (*SignerContext) UnmarshalMsgWithState

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

UnmarshalMsg implements msgp.Unmarshaler

type Verifier

type Verifier struct {
	Commitment  Commitment `codec:"cmt"`
	KeyLifetime uint64     `codec:"lf"`
	// contains filtered or unexported fields
}

Verifier is used to verify a merklesignature.Signature produced by merklesignature.Secrets.

func (*Verifier) CanMarshalMsg

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

func (*Verifier) CanUnmarshalMsg

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

func (*Verifier) FirstRoundInKeyLifetime

func (v *Verifier) FirstRoundInKeyLifetime(round uint64) (uint64, error)

FirstRoundInKeyLifetime calculates the round of the valid key for a given round by lowering to the closest KeyLiftime divisor.

func (*Verifier) MarshalMsg

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

MarshalMsg implements msgp.Marshaler

func (*Verifier) MsgIsZero

func (z *Verifier) MsgIsZero() bool

MsgIsZero returns whether this is a zero value

func (*Verifier) Msgsize

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

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

func (*Verifier) UnmarshalMsg

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

func (*Verifier) UnmarshalMsgWithState

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

UnmarshalMsg implements msgp.Unmarshaler

func (*Verifier) VerifyBytes

func (v *Verifier) VerifyBytes(round uint64, msg []byte, sig *Signature) error

VerifyBytes verifies that a merklesignature sig is valid, on a specific round, under a given public key

Jump to

Keyboard shortcuts

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