Documentation
¶
Index ¶
- Constants
- Variables
- func BigIntToBytes(b *big.Int) []byte
- func BytesToBigInt(b []byte) *big.Int
- func EncodeKey(key *big.Int) []byte
- func IndexContainsBallot(db db.Database, processID types.ProcessID, ballotIndex types.BallotIndex) (bool, error)
- func RootExists(db db.Database, processId types.ProcessID, root *big.Int) error
- type ArboProof
- type ArboTransition
- type BallotLeaf
- type BlobData
- type ProcessProofs
- type State
- func (o *State) AddVotesBatch(votes []*Vote) error
- func (st *State) ApplyBlobToState(blob *types.Blob) error
- func (o *State) ArboProofsFromAddOrUpdate(key types.StateKey, v []*big.Int) (*arbo.GnarkVerifierProof, *arbo.GnarkVerifierProof, error)
- func (o *State) BallotLeaf(ballotIndex types.BallotIndex) (*BallotLeaf, error)
- func (o *State) BallotMode() *big.Int
- func (st *State) BlobEvalData() (*blobs.BlobEvalData, error)
- func (o *State) CensusOrigin() *big.Int
- func (o *State) Close() error
- func (o *State) ContainsBallot(ballotIndex types.BallotIndex) bool
- func (o *State) ContainsVoteID(voteID types.VoteID) bool
- func (o *State) EncryptedBallot(ballotIndex types.BallotIndex) (*elgamal.Ballot, error)
- func (o *State) EncryptionKey() circuits.EncryptionKey[*big.Int]
- func (o *State) GenArboProof(key types.StateKey) (*ArboProof, error)
- func (o *State) Initialize(censusOrigin *big.Int, ballotMode *big.Int, encryptionKey types.EncryptionKey) error
- func (o *State) NewResults() *elgamal.Ballot
- func (o *State) OldResults() *elgamal.Ballot
- func (o *State) OverwrittenVotesCount() int
- func (o *State) PaddedVotes() []*Vote
- func (o *State) Process() circuits.Process[*big.Int]
- func (o *State) ProcessID() *big.Int
- func (o *State) ProcessProofs() ProcessProofs
- func (o *State) ProcessSerializeBigInts() []*big.Int
- func (o *State) Results() (*elgamal.Ballot, error)
- func (o *State) Root() ([]byte, error)
- func (o *State) RootAsBigInt() (*big.Int, error)
- func (o *State) RootExists(root *big.Int) error
- func (o *State) RootHashBefore() *big.Int
- func (o *State) SetResults(results *elgamal.Ballot)
- func (o *State) SetRoot(newRoot []byte) error
- func (o *State) SetRootAsBigInt(newRoot *big.Int) error
- func (o *State) VotersCount() int
- func (o *State) Votes() []*Vote
- func (o *State) VotesProofs() VotesProofs
- type Vote
- type VotesProofs
Constants ¶
const ( BlobTxBytesPerFieldElement = gethparams.BlobTxBytesPerFieldElement BlobTxFieldElementsPerBlob = gethparams.BlobTxFieldElementsPerBlob )
Variables ¶
var ( // HashFn is the hash function used in the state tree. HashFn = arbo.HashFunctionMultiPoseidon // Curve is the curve used for the encryption Curve = curves.New(bjj.CurveType) )
var ( KeyProcessID = types.StateKey(params.StateKeyProcessID) KeyBallotMode = types.StateKey(params.StateKeyBallotMode) KeyEncryptionKey = types.StateKey(params.StateKeyEncryptionKey) KeyResults = types.StateKey(params.StateKeyResults) KeyCensusOrigin = types.StateKey(params.StateKeyCensusOrigin) ErrStateAlreadyInitialized = fmt.Errorf("state already initialized") )
var ( // ErrNotFound is returned when a key is not found in the state ErrKeyNotFound = fmt.Errorf("not found") )
Functions ¶
func BigIntToBytes ¶
BigIntToBytes method converts a big.Int to a byte array. It is a wrapper around the arbo.BigIntToBytes function, which uses the maximum key length for the hash function.
func BytesToBigInt ¶
BytesToBigInt method converts a byte array to a big.Int. It is a wrapper around the arbo.BytesToBigInt function.
func EncodeKey ¶
EncodeKey encodes a key to a byte array using the maximum key length for the current number of levels in the state tree and the hash function length.
func IndexContainsBallot ¶ added in v0.0.2
func IndexContainsBallot(db db.Database, processID types.ProcessID, ballotIndex types.BallotIndex) (bool, error)
IndexContainsBallot checks if an address has voted in a given process. It opens the current process state and checks for the address. If found, it returns true, otherwise false. If there's an error opening the state or during the check, it returns the error.
Types ¶
type ArboProof ¶
type ArboProof struct {
// Key+Value hashed through Siblings path, should produce Root hash
Root *big.Int
Siblings []*big.Int
Key *big.Int
Value *big.Int
}
ArboProof stores the proof in arbo native types
type ArboTransition ¶
type ArboTransition struct {
// NewKey + NewValue hashed through Siblings path, should produce NewRoot hash
NewRoot *big.Int
Siblings []*big.Int
NewKey *big.Int
NewValue *big.Int
// OldKey + OldValue hashed through same Siblings should produce OldRoot hash
OldRoot *big.Int
OldKey *big.Int
OldValue *big.Int
IsOld0 int
Fnc0 int
Fnc1 int
}
ArboTransition stores a pair of leaves and root hashes, and a single path common to both proofs
func ArboTransitionFromAddOrUpdate ¶
func ArboTransitionFromAddOrUpdate(o *State, k types.StateKey, v ...*big.Int) (*ArboTransition, error)
ArboTransitionFromAddOrUpdate adds or updates a key in the tree, and returns a ArboTransition.
func ArboTransitionFromArboProofPair ¶
func ArboTransitionFromArboProofPair(before, after *arbo.GnarkVerifierProof) *ArboTransition
ArboTransitionFromArboProofPair generates a ArboTransition based on the pair of proofs passed
func ArboTransitionFromNoop ¶
func ArboTransitionFromNoop(o *State) (*ArboTransition, error)
ArboTransitionFromNoop returns a NOOP ArboTransition.
type BallotLeaf ¶ added in v0.0.7
type BlobData ¶
BlobData represents the structured data extracted from a blob
func ParseBlobData ¶
ParseBlobData extracts vote and results data from a blob.
type ProcessProofs ¶
type ProcessProofs struct {
ID *ArboProof
CensusOrigin *ArboProof
BallotMode *ArboProof
EncryptionKey *ArboProof
}
ProcessProofs stores the Merkle proofs for the process, including the ID census root, ballot mode, and encryption key proofs.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State represents a state tree
func LoadOnRoot ¶
LoadOnRoot loads a State from the database using the provided processId and root. It creates a new State with the given processId and sets the root of the tree to the provided root. It returns an error if the processId is not found in the database or if the root cannot be set. The root provided is formatted to the arbo format before being set in the state tree.
func New ¶
New creates or opens a State stored in the passed database. The processID is used as a prefix for the keys in the database.
func (*State) AddVotesBatch ¶ added in v0.0.2
func (*State) ApplyBlobToState ¶
ApplyBlobToState applies the data from a blob to restore state
func (*State) ArboProofsFromAddOrUpdate ¶
func (o *State) ArboProofsFromAddOrUpdate(key types.StateKey, v []*big.Int) (*arbo.GnarkVerifierProof, *arbo.GnarkVerifierProof, error)
ArboProofsFromAddOrUpdate generates an ArboProof before adding (or updating) the given leaf, and another ArboProof after updating, and returns both.
func (*State) BallotLeaf ¶ added in v0.0.7
func (o *State) BallotLeaf(ballotIndex types.BallotIndex) (*BallotLeaf, error)
BallotLeaf returns the stored ballot leaf associated with a ballot index.
func (*State) BallotMode ¶
BallotMode returns the packed ballot mode of the state as a *big.Int.
func (*State) BlobEvalData ¶ added in v0.0.4
func (st *State) BlobEvalData() (*blobs.BlobEvalData, error)
BlobEvalData returns the cached blob evaluation data for the current batch.
blob layout:
- Results (params.FieldsPerBallot * 4 coordinates)
- VotersCount
- Votes sequentially for exactly VotersCount entries: Each vote: voteID + address + ballotIndex + weight + reencryptedBallot coordinates
func (*State) CensusOrigin ¶
CensusOrigin returns the census origin of the state as a *big.Int.
func (*State) ContainsBallot ¶ added in v0.0.2
func (o *State) ContainsBallot(ballotIndex types.BallotIndex) bool
ContainsBallot checks if the state contains an address
func (*State) ContainsVoteID ¶
ContainsVoteID checks if the state contains a vote ID
func (*State) EncryptedBallot ¶
EncryptedBallot returns the ballot associated with a address
func (*State) EncryptionKey ¶
func (o *State) EncryptionKey() circuits.EncryptionKey[*big.Int]
EncryptionKey returns the encryption key of the state as a circuits.EncryptionKey[*big.Int].
func (*State) GenArboProof ¶
GenArboProof generates a ArboProof for the given key
func (*State) Initialize ¶
func (o *State) Initialize( censusOrigin *big.Int, ballotMode *big.Int, encryptionKey types.EncryptionKey, ) error
Initialize creates a new State, initialized with the passed parameters. After Initialize, caller is expected to StartBatch, AddVote, EndBatch, StartBatch...
func (*State) NewResults ¶ added in v0.0.7
NewResults returns the new results ballot of the current batch.
func (*State) OldResults ¶ added in v0.0.7
OldResults returns the old results ballot of the current batch.
func (*State) OverwrittenVotesCount ¶
OverwrittenVotesCount returns the number of ballots overwritten in the current batch.
func (*State) PaddedVotes ¶
PaddedVotes returns the votes added in the current batch, padded to circuits.VotesPerBatch. The padding is done by adding empty votes with zero values.
func (*State) ProcessProofs ¶
func (o *State) ProcessProofs() ProcessProofs
ProcessProofs returns a pointer to the process proofs for the state.
func (*State) ProcessSerializeBigInts ¶
ProcessSerializeBigInts returns
process.ID process.CensusOrigin process.BallotMode process.EncryptionKey
func (*State) Results ¶ added in v0.0.7
Results returns the results of the state as an elgamal.Ballot.
func (*State) RootAsBigInt ¶
RootAsBigInt method returns the root of the tree as a big.Int.
func (*State) RootExists ¶
RootExists checks if the provided root exists in the tree. Returns nil if the root exists, or an error if it does not.
func (*State) RootHashBefore ¶
RootHashBefore returns the root hash before state transition.
func (*State) SetResults ¶ added in v0.0.7
SetResults sets the results directly in the state tree.
func (*State) SetRootAsBigInt ¶
SetRootAsBigInt method sets the root of the tree to the provided one as a big.Int.
func (*State) VotersCount ¶
VotersCount returns the number of voters participating in the current batch, i.e. either casting their first vote or overwriting a previous one.
func (*State) VotesProofs ¶
func (o *State) VotesProofs() VotesProofs
VotesProofs returns a pointer to the votes proofs for the state.
type Vote ¶
type Vote struct {
Address *big.Int
BallotIndex types.BallotIndex
VoteID types.VoteID
Ballot *elgamal.Ballot
OverwrittenBallot *elgamal.Ballot
Weight *big.Int
ReencryptedBallot *elgamal.Ballot // Reencrypted ballot for the state transition circuit
}
Vote describes a vote with homomorphic ballot
func (*Vote) TreeLeafValues ¶ added in v0.0.7
TreeLeafValues returns the ballot leaf values in this order: ballot coordinates, address, weight.
type VotesProofs ¶
type VotesProofs struct {
Results *ArboTransition
Ballot [params.VotesPerBatch]*ArboTransition
VoteID [params.VotesPerBatch]*ArboTransition
}
VotesProofs stores the Merkle transitions for the votes: the results transition, as well as the ballot and vote ID transitions.