Skip to content

Commit

Permalink
Rename compact cert (#3984)
Browse files Browse the repository at this point in the history
* rename compcat cert to stateproof in transcation and blockheader

* rename stateproof package to stateproof msg

* rename cc on header

* change txn type and rename ledger state

* rename compact cert type

* ledger renaming

* rename compactcert package

* rename crypto cert package

* more rename

* complete crypto rename + swagger

* rename cc e2e test

* rename hash id

* more renaming

* fix comments and names
  • Loading branch information
id-ms authored May 15, 2022
1 parent 103a025 commit 1df452a
Show file tree
Hide file tree
Showing 89 changed files with 4,413 additions and 4,526 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ GOLDFLAGS := $(GOLDFLAGS_BASE) \
UNIT_TEST_SOURCES := $(sort $(shell GOPATH=$(GOPATH) && GO111MODULE=off && go list ./... | grep -v /go-algorand/test/ ))
ALGOD_API_PACKAGES := $(sort $(shell GOPATH=$(GOPATH) && GO111MODULE=off && cd daemon/algod/api; go list ./... ))

MSGP_GENERATE := ./protocol ./protocol/test ./crypto ./crypto/merklearray ./crypto/merklesignature ./crypto/compactcert ./data/basics ./data/transactions ./data/stateproof ./data/committee ./data/bookkeeping ./data/hashable ./agreement ./rpcs ./node ./ledger ./ledger/ledgercore ./compactcert ./data/account ./daemon/algod/api/spec/v2
MSGP_GENERATE := ./protocol ./protocol/test ./crypto ./crypto/merklearray ./crypto/merklesignature ./crypto/stateproof ./data/basics ./data/transactions ./data/stateproofmsg ./data/committee ./data/bookkeeping ./data/hashable ./agreement ./rpcs ./node ./ledger ./ledger/ledgercore ./stateproof ./data/account ./daemon/algod/api/spec/v2

default: build

Expand Down
538 changes: 269 additions & 269 deletions agreement/msgp_gen.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ const LedgerFilenamePrefix = "ledger"
// It is used to recover from node crashes.
const CrashFilename = "crash.sqlite"

// CompactCertFilename is the name of the compact certificate database file.
// It is used to track in-progress compact certificates.
const CompactCertFilename = "compactcert.sqlite"
// StateProofFileName is the name of the state proof database file.
// It is used to track in-progress state proofs.
const StateProofFileName = "stateproof.sqlite"

// ParticipationRegistryFilename is the name of the participation registry database file.
// It is used for tracking participation key metadata.
Expand Down
79 changes: 39 additions & 40 deletions config/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,49 +344,48 @@ type ConsensusParams struct {
// to limit the maximum size of a single balance record
MaximumMinimumBalance uint64

// CompactCertRounds defines the frequency with which compact
// certificates are generated. Every round that is a multiple
// of CompactCertRounds, the block header will include a Merkle
// StateProofInterval defines the frequency with which state
// proofs are generated. Every round that is a multiple
// of StateProofInterval, the block header will include a vector
// commitment to the set of online accounts (that can vote after
// another CompactCertRounds rounds), and that block will be signed
// (forming a compact certificate) by the voters from the previous
// such Merkle tree commitment. A value of zero means no compact
// certificates.
CompactCertRounds uint64

// CompactCertTopVoters is a bound on how many online accounts get to
// participate in forming the compact certificate, by including the
// top CompactCertTopVoters accounts (by normalized balance) into the
// Merkle commitment.
CompactCertTopVoters uint64

// CompactCertVotersLookback is the number of blocks we skip before
// publishing a Merkle commitment to the online accounts. Namely,
// if block number N contains a Merkle commitment to the online
// accounts (which, incidentally, means N%CompactCertRounds=0),
// another StateProofInterval rounds), and that block will be signed
// (forming a state proof) by the voters from the previous
// such vector commitment. A value of zero means no state proof.
StateProofInterval uint64

// StateProofTopVoters is a bound on how many online accounts get to
// participate in forming the state proof, by including the
// top StateProofTopVoters accounts (by normalized balance) into the
// vector commitment.
StateProofTopVoters uint64

// StateProofVotersLookback is the number of blocks we skip before
// publishing a vector commitment to the online accounts. Namely,
// if block number N contains a vector commitment to the online
// accounts (which, incidentally, means N%StateProofInterval=0),
// then the balances reflected in that commitment must come from
// block N-CompactCertVotersLookback. This gives each node some
// time (CompactCertVotersLookback blocks worth of time) to
// construct this Merkle tree, so as to avoid placing the
// construction of this Merkle tree (and obtaining the requisite
// block N-StateProofVotersLookback. This gives each node some
// time (StateProofVotersLookback blocks worth of time) to
// construct this vector commitment, so as to avoid placing the
// construction of this vector commitment (and obtaining the requisite
// accounts and balances) in the critical path.
CompactCertVotersLookback uint64
StateProofVotersLookback uint64

// CompactCertWeightThreshold specifies the fraction of top voters weight
// that must sign the message (block header) for security. The compact
// certificate ensures this threshold holds; however, forming a valid
// compact certificate requires a somewhat higher number of signatures,
// and the more signatures are collected, the smaller the compact cert
// StateProofWeightThreshold specifies the fraction of top voters weight
// that must sign the message (block header) for security. The state
// proof ensures this threshold holds; however, forming a valid
// state proof requires a somewhat higher number of signatures,
// and the more signatures are collected, the smaller the state proof
// can be.
//
// This threshold can be thought of as the maximum fraction of
// malicious weight that compact certificates defend against.
// malicious weight that state proof defend against.
//
// The threshold is computed as CompactCertWeightThreshold/(1<<32).
CompactCertWeightThreshold uint32
// The threshold is computed as StateProofWeightThreshold/(1<<32).
StateProofWeightThreshold uint32

// CompactCertStrengthTarget represents either k+q (for pre-quantum security) or k+2q (for post-quantum security)
CompactCertStrengthTarget uint64
// StateProofStrengthTarget represents either k+q (for pre-quantum security) or k+2q (for post-quantum security)
StateProofStrengthTarget uint64

// EnableAssetCloseAmount adds an extra field to the ApplyData. The field contains the amount of the remaining
// asset that were sent to the close-to address.
Expand Down Expand Up @@ -1136,12 +1135,12 @@ func initConsensusProtocols() {
// FilterTimeout for period 0 should take a new optimized, configured value, need to revisit this later
vFuture.AgreementFilterTimeoutPeriod0 = 4 * time.Second

// Enable compact certificates.
vFuture.CompactCertRounds = 256
vFuture.CompactCertTopVoters = 1024 * 1024
vFuture.CompactCertVotersLookback = 16
vFuture.CompactCertWeightThreshold = (1 << 32) * 30 / 100
vFuture.CompactCertStrengthTarget = 256
// Enable state proofs.
vFuture.StateProofInterval = 256
vFuture.StateProofTopVoters = 1024 * 1024
vFuture.StateProofVotersLookback = 16
vFuture.StateProofWeightThreshold = (1 << 32) * 30 / 100
vFuture.StateProofStrengthTarget = 256

vFuture.LogicSigVersion = 7
vFuture.MinInnerApplVersion = 4
Expand Down
8 changes: 4 additions & 4 deletions config/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ func TestConsensusUpgradeWindow(t *testing.T) {
}
}

func TestConsensusCompactCertParams(t *testing.T) {
func TestConsensusStateProofParams(t *testing.T) {
partitiontest.PartitionTest(t)

for _, params := range Consensus {
if params.CompactCertRounds != 0 {
require.Equal(t, uint64(1<<16), (params.MaxKeyregValidPeriod+1)/params.CompactCertRounds,
"Validity period divided by CompactCertRounds should allow for no more than %d generated keys", 1<<16)
if params.StateProofInterval != 0 {
require.Equal(t, uint64(1<<16), (params.MaxKeyregValidPeriod+1)/params.StateProofInterval,
"Validity period divided by StateProofInterval should allow for no more than %d generated keys", 1<<16)
}
}
}
2 changes: 1 addition & 1 deletion crypto/merklesignature/kats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func generateMssKat(startRound, atRound, numOfKeys uint64, messageToSign []byte)
return mssKat{}, fmt.Errorf("error: Signature round cann't be smaller then start round")
}

interval := config.Consensus[protocol.ConsensusFuture].CompactCertRounds
interval := config.Consensus[protocol.ConsensusFuture].StateProofInterval
stateProofSecrets, err := New(startRound, startRound+(interval*numOfKeys)-1, interval)
if err != nil {
return mssKat{}, fmt.Errorf("error: %w", err)
Expand Down
36 changes: 18 additions & 18 deletions crypto/compactcert/builder.go → crypto/stateproof/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// 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
package stateproof

import (
"errors"
Expand All @@ -26,6 +26,14 @@ import (
"github.com/algorand/go-algorand/data/basics"
)

// Errors for the StateProof builder
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")
)

//msgp:ignore sigslot
type sigslot struct {
// Weight is the weight of the participant signing this message.
Expand All @@ -40,9 +48,9 @@ type sigslot struct {
}

// Builder keeps track of signatures on a message and eventually produces
// a compact certificate for that message.
// a stater proof for that message.
type Builder struct {
data StateProofMessageHash
data MessageHash
round uint64
sigs []sigslot // Indexed by pos in participants
signedWeight uint64 // Total weight of signatures so far
Expand All @@ -53,16 +61,8 @@ type Builder struct {
strengthTarget uint64
}

// Errors for the CompactCert builder
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")
)

// MkBuilder constructs an empty builder. After adding enough signatures and signed weight, this builder is used to create a compact cert.
func MkBuilder(data StateProofMessageHash, round uint64, provenWeight uint64, part []basics.Participant, parttree *merklearray.Tree, strengthTarget uint64) (*Builder, error) {
// MkBuilder constructs an empty builder. After adding enough signatures and signed weight, this builder is used to create a stateproof.
func MkBuilder(data MessageHash, round uint64, provenWeight uint64, part []basics.Participant, parttree *merklearray.Tree, strengthTarget uint64) (*Builder, error) {
npart := len(part)
lnProvenWt, err := lnIntApproximation(provenWeight)
if err != nil {
Expand Down Expand Up @@ -122,7 +122,7 @@ func (b *Builder) IsValid(pos uint64, sig merklesignature.Signature, verifySig b
return nil
}

// Add a signature to the set of signatures available for building a certificate.
// Add a signature to the set of signatures available for building a proof.
func (b *Builder) Add(pos uint64, sig merklesignature.Signature) error {
isPresent, err := b.Present(pos)
if err != nil {
Expand All @@ -141,7 +141,7 @@ func (b *Builder) Add(pos uint64, sig merklesignature.Signature) error {
return nil
}

// Ready returns whether the certificate is ready to be built.
// Ready returns whether the state proof is ready to be built.
func (b *Builder) Ready() bool {
return b.signedWeight > b.provenWeight
}
Expand Down Expand Up @@ -180,9 +180,9 @@ again:
goto again
}

// Build returns a compact certificate, if the builder has accumulated
// Build returns a state proof, if the builder has accumulated
// enough signatures to construct it.
func (b *Builder) Build() (*Cert, error) {
func (b *Builder) Build() (*StateProof, error) {
if !b.Ready() {
return nil, fmt.Errorf("%w: %d <= %d", ErrSignedWeightLessThanProvenWeight, b.signedWeight, b.provenWeight)
}
Expand All @@ -199,7 +199,7 @@ func (b *Builder) Build() (*Cert, error) {
}

// Reveal sufficient number of signatures
c := &Cert{
c := &StateProof{
SigCommit: sigtree.Root(),
SignedWeight: b.signedWeight,
Reveals: make(map[uint64]Reveal),
Expand Down
Loading

0 comments on commit 1df452a

Please sign in to comment.