ballotproof

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const NumberOfPublicInputs = 3

NumberOfPublicInputs is the number of public inputs for the ballot proof circom circuit.

Variables

View Source
var (
	// CircomCircuitWasm contains the ballot proof Circom circuit compiled to WASM.
	CircomCircuitWasm = circomartifacts.BallotProofWasm

	// CircomProvingKey contains the Groth16 proving key for the ballot proof circuit.
	CircomProvingKey = circomartifacts.BallotProofProvingKey

	// CircomVerificationKey contains the Groth16 verification key for the ballot proof circuit.
	CircomVerificationKey = circomartifacts.BallotProofVerificationKey
)

Artifacts contains the circuit artifacts for the ballot proof verification, it only contains the verification key because the proving key is used by the voter to generate the proof.

Functions

func BallotInputsHashGnark

func BallotInputsHashGnark(
	processID types.ProcessID,
	ballotMode spec.BallotMode,
	encryptionKey ecc.Point,
	address types.HexBytes,
	voteID types.VoteID,
	ballot *elgamal.Ballot,
	weight *types.BigInt,
) (*types.BigInt, error)

BallotInputsHash helper function calculates the hash of the public inputs of the ballot proof circuit. This hash is used to verify the proof generated by the user and is also used to generate the voteID. The hash is calculated using the poseidon hash function and includes the process ID, ballot mode, encryption key, address, ballot and weight, in that particular order. The function transforms the inputs to the correct format:

  • processID and address are converted to FF
  • encryption key is converted to twisted edwards form
  • ballot mode is converted to circuit ballot mode
  • ballot is converted to twisted edwards form

func BallotInputsHashIden3

func BallotInputsHashIden3(
	processID types.ProcessID,
	ballotMode spec.BallotMode,
	encryptionKey ecc.Point,
	address types.HexBytes,
	voteID types.VoteID,
	ballot *elgamal.Ballot,
	weight *types.BigInt,
) (*types.BigInt, error)

Types

type BallotProofInputs

type BallotProofInputs struct {
	ProcessID     types.ProcessID `json:"processId"`
	Address       types.HexBytes  `json:"address"`
	EncryptionKey []*types.BigInt `json:"encryptionKey"`
	K             *types.BigInt   `json:"k"`
	BallotMode    spec.BallotMode `json:"ballotMode"`
	Weight        *types.BigInt   `json:"weight"`
	FieldValues   []*types.BigInt `json:"fieldValues"`
}

BallotProofInputs struct contains the required inputs to compose the data to generate the witness for a ballot proof using the circom circuit.

func (*BallotProofInputs) VoteID

func (b *BallotProofInputs) VoteID() (types.VoteID, error)

VoteID generates a unique identifier for the vote based on the process ID, address and k value. This ID is used to sign the vote and prove ownership. It returns the vote ID as a HexBytes type or an error if the inputs are invalid or something goes wrong during the generation of the ID. It calls the VoteID function with the process ID, address and k value converted to the appropriate types.

type BallotProofInputsResult

type BallotProofInputsResult struct {
	ProcessID        types.ProcessID `json:"processId"`
	Address          types.HexBytes  `json:"address"`
	Weight           *types.BigInt   `json:"weight"`
	Ballot           *elgamal.Ballot `json:"ballot"`
	BallotInputsHash *types.BigInt   `json:"ballotInputsHash"`
	VoteID           types.VoteID    `json:"voteId"`
	CircomInputs     *CircomInputs   `json:"circomInputs"`
}

BallotProofInputsResult struct contains the result of composing the data to generate the witness for a ballot proof using the circom circuit. Includes the inputs for the circom circuit but also the required data to cast a vote sending it to the sequencer API. It includes the BallotInputsHash, which is used by the API to verify the resulting circom proof and the voteID, which is signed by the user to prove the ownership of the vote.

func GenerateBallotProofInputs

func GenerateBallotProofInputs(
	inputs *BallotProofInputs,
) (*BallotProofInputsResult, error)

GenerateBallotProofInputs composes the data to generate the inputs required to generate the witness for a ballot proof using the circom circuit and also the data required to cast a vote sending it to the sequencer API. It receives the BallotProofWasmInputs struct and returns the BallotProofWasmResult struct. This method parses the public encryption key for the desired process and encrypts the ballot fields with the secret K provided.

type CircomInputs

type CircomInputs struct {
	Fields        []*types.BigInt `json:"fields"`
	BallotMode    *types.BigInt   `json:"packed_ballot_mode"`
	Address       *types.BigInt   `json:"address"`
	Weight        *types.BigInt   `json:"weight"`
	ProcessID     *types.BigInt   `json:"process_id"`
	VoteID        *types.BigInt   `json:"vote_id"`
	EncryptionKey []*types.BigInt `json:"encryption_pubkey"`
	K             *types.BigInt   `json:"k"`
	Cipherfields  []*types.BigInt `json:"cipherfields"`
	InputsHash    *types.BigInt   `json:"inputs_hash"`
}

CircomInputs struct contains the data of the witness to generate a ballot proof using the circom circuit.

Jump to

Keyboard shortcuts

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