summaryrefslogtreecommitdiff
path: root/crypto/compactcert/structs.go
blob: 1e02e4eafc47784b9f868e26d04b0dcfa7073db1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright (C) 2019-2021 Algorand, Inc.
// This file is part of go-algorand
//
// go-algorand is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// go-algorand is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand.  If not, see <https://www.gnu.org/licenses/>.

package compactcert

import (
	"github.com/algorand/go-algorand/crypto"
	"github.com/algorand/go-algorand/data/basics"
	"github.com/algorand/go-algorand/protocol"
)

// Params defines common parameters for the verifier and builder.
type Params struct {
	Msg          crypto.Hashable // Message to be cerified
	ProvenWeight uint64          // Weight threshold proven by the certificate
	SigRound     basics.Round    // Ephemeral signature round to expect
	SecKQ        uint64          // Security parameter (k+q) from analysis document
}

// CompactOneTimeSignature is crypto.OneTimeSignature with omitempty
type CompactOneTimeSignature struct {
	_struct struct{} `codec:",omitempty,omitemptyarray"`
	crypto.OneTimeSignature
}

// A sigslotCommit is a single slot in the sigs array that forms the certificate.
type sigslotCommit struct {
	_struct struct{} `codec:",omitempty,omitemptyarray"`

	// Sig is a signature by the participant on the expected message.
	Sig CompactOneTimeSignature `codec:"s"`

	// L is the total weight of signatures in lower-numbered slots.
	// This is initialized once the builder has collected a sufficient
	// number of signatures.
	L uint64 `codec:"l"`
}

func (ssc sigslotCommit) ToBeHashed() (protocol.HashID, []byte) {
	return protocol.CompactCertSig, protocol.Encode(&ssc)
}

// Reveal is a single array position revealed as part of a compact
// certificate.  It reveals an element of the signature array and
// the corresponding element of the participants array.
type Reveal struct {
	_struct struct{} `codec:",omitempty,omitemptyarray"`

	SigSlot sigslotCommit      `codec:"s"`
	Part    basics.Participant `codec:"p"`
}

// maxReveals is a bound on allocation and on numReveals to limit log computation
const maxReveals = 1024
const maxProofDigests = 20 * maxReveals

// Cert represents a compact certificate.
type Cert struct {
	_struct struct{} `codec:",omitempty,omitemptyarray"`

	SigCommit    crypto.Digest   `codec:"c"`
	SignedWeight uint64          `codec:"w"`
	SigProofs    []crypto.Digest `codec:"S,allocbound=maxProofDigests"`
	PartProofs   []crypto.Digest `codec:"P,allocbound=maxProofDigests"`

	// 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"`
}

// SortUint64 implements sorting by uint64 keys for
// canonical encoding of maps in msgpack format.
type SortUint64 = basics.SortUint64