aggregator

package
v0.0.0-...-41d1e4a Latest Latest
Warning

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

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

Documentation

Overview

aggregator package contains the Gnark circuit defiinition that aggregates some votes and proves the validity of the aggregation. The circuit checks every single verification proof generating a single proof for the whole aggregation. Every voter proof should use the same values for the following inputs:

  • MaxCount
  • ForceUniqueness
  • MaxValue
  • MinValue
  • MaxTotalCost
  • MinTotalCost
  • CostExp
  • CostFromWeight
  • EncryptionPubKey
  • ProcessId
  • CensusRoot

All these values are common for the same process.

The circuit also checks the other inputs that are unique for each voter:

  • Nullifier
  • Commitment
  • Address
  • EncryptedBallots
  • VerifyProof (generated with the VerifyVoteCircuit)

Index

Constants

View Source
const (
	MaxVotes  = 10
	MaxFields = ballotproof.NFields
)

Variables

This section is empty.

Functions

func DummyAssigment

func DummyAssigment() *dummyCircuit

DummyPlaceholder function returns the assigment of a dummy circtuit.

func DummyPlaceholder

func DummyPlaceholder(mainCircuit constraint.ConstraintSystem) *dummyCircuit

DummyPlaceholder function returns the placeholder of a dummy circtuit for the constraint.ConstraintSystem provided.

func EncodeProofsSelector

func EncodeProofsSelector(nValidProofs int) *big.Int

EncodeProofsSelector function returns a number that its base2 representation contains the first nValidProofs bits set to one. It allows to encode the number of valid proofs as selector to switch between main circuit vk and the dummy one.

func FillWithDummyFixed

func FillWithDummyFixed(placeholder, assigments *AggregatorCircuit, main constraint.ConstraintSystem, fromIdx int) error

FillWithDummyFixed function fills the placeholder and the assigments provided with a dummy circuit stuff and proofs compiled for the main constraint.ConstraintSystem provided. It starts to fill from the index provided and fixes the dummy verification key. Returns an error if something fails.

func GenInputsForTest

func GenInputsForTest(processId []byte, nValidVoters int) (
	*AggregateTestResults, *AggregatorCircuit, *AggregatorCircuit, error,
)

GenInputsForTest returns the AggregateTestResults, the placeholder ant the assigments of a AggregatorCircuit for the processId provided generating nValidVoters. If something fails it returns an error.

Types

type AggregateTestResults

type AggregateTestResults struct {
	ProcessId             []byte
	CensusRoot            *big.Int
	EncryptionPubKey      [2]*big.Int
	Nullifiers            []*big.Int
	Commitments           []*big.Int
	Addresses             []*big.Int
	EncryptedBallots      [][ballotproof.NFields][2][2]*big.Int
	PlainEncryptedBallots []*big.Int
}

AggregateTestResults struct includes relevant data after AggregateCircuit inputs generation, including the encrypted ballots in both formats: matrix and plain (for hashing)

type AggregatorCircuit

type AggregatorCircuit struct {
	InputsHash frontend.Variable `gnark:",public"`
	ValidVotes frontend.Variable `gnark:",public"`
	// The following variables are priv-public inputs, so should be hashed and
	// compared with the InputsHash. All the variables should be hashed in the
	// same order as they are defined here.
	MaxCount         frontend.Variable                            // Part of InputsHash
	ForceUniqueness  frontend.Variable                            // Part of InputsHash
	MaxValue         frontend.Variable                            // Part of InputsHash
	MinValue         frontend.Variable                            // Part of InputsHash
	MaxTotalCost     frontend.Variable                            // Part of InputsHash
	MinTotalCost     frontend.Variable                            // Part of InputsHash
	CostExp          frontend.Variable                            // Part of InputsHash
	CostFromWeight   frontend.Variable                            // Part of InputsHash
	EncryptionPubKey [2]frontend.Variable                         // Part of InputsHash
	ProcessId        frontend.Variable                            // Part of InputsHash
	CensusRoot       frontend.Variable                            // Part of InputsHash
	Nullifiers       [MaxVotes]frontend.Variable                  // Part of InputsHash
	Commitments      [MaxVotes]frontend.Variable                  // Part of InputsHash
	Addresses        [MaxVotes]frontend.Variable                  // Part of InputsHash
	EncryptedBallots [MaxVotes][MaxFields][2][2]frontend.Variable // Part of InputsHash
	// VerifyCircuit proofs
	VerifyProofs       [MaxVotes]groth16.Proof[sw_bls12377.G1Affine, sw_bls12377.G2Affine]
	VerifyPublicInputs [MaxVotes]groth16.Witness[sw_bls12377.ScalarField]
	// VerificationKeys should contain the dummy circuit and the main circuit
	// verification keys in that particular order
	VerificationKeys [2]groth16.VerifyingKey[sw_bls12377.G1Affine, sw_bls12377.G2Affine, sw_bls12377.GT] `gnark:"-"`
}

func (*AggregatorCircuit) Define

func (c *AggregatorCircuit) Define(api frontend.API) error

Jump to

Keyboard shortcuts

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