Documentation ¶
Index ¶
- Variables
- func BytesToIndexAndWeight(b []byte) (uint64, *big.Int, error)
- func HashPubKBytes(pubK *babyjub.PublicKey, weight *big.Int) ([]byte, error)
- func HashVote(chainID, processID uint64, vote []byte) (*big.Int, error)
- func HexToPublicKey(h string) (*babyjub.PublicKey, error)
- func IndexAndWeightToBytes(index uint64, weight *big.Int) []byte
- func Uint64ToIndex(u uint64) []byte
- type ByteArray
- type CensusProof
- type Process
- type ProcessStatus
- type Proof
- type ProofInDB
- type VotePackage
- type ZKCircuitMeta
- type ZKInputs
Constants ¶
This section is empty.
Variables ¶
var ( // MaxLevels indicates the maximum number of levels in the Census // MerkleTree MaxLevels int = 64 // MaxNLeafs indicates the maximum number of leaves in the Census // MerkleTree MaxNLeafs uint64 = uint64(math.MaxUint64) // MaxKeyLen indicates the maximum key (index) length in the Census // MerkleTree MaxKeyLen int = int(math.Ceil(float64(MaxLevels) / float64(8))) //nolint:gomnd // EmptyRoot is a byte array of 0s, with the length of the hash // function output length used in the Census MerkleTree EmptyRoot = make([]byte, arbo.HashFunctionPoseidon.Len()) )
var ( // HashLen indicates the length of the bytes representation of the // output of the Hash function used, Poseidon Hash in OVOTE's case. HashLen int = arbo.HashFunctionPoseidon.Len() )
Functions ¶
func BytesToIndexAndWeight ¶
BytesToIndexAndWeight returns the index and weight from the given byte array
func HashPubKBytes ¶
HashPubKBytes returns the bytes representation of the Poseidon hash of the given PublicKey together with its weight, that will be used as a leaf value in the MerkleTree. If no weight is provided (eg. nil), a weight of 1 is assigned.
func HexToPublicKey ¶
HexToPublicKey converts the given hex representation of a babyjub.PublicKeyComp, and returns the babyjub.PublicKey
func IndexAndWeightToBytes ¶
IndexAndWeightToBytes returns a byte array containing the given index and weight, encoded as: [ 8 | 32 ] [ index | weight ]
func Uint64ToIndex ¶
Uint64ToIndex returns the bytes representation of the given uint64 that will be used as a leaf index in the MerkleTree
Types ¶
type ByteArray ¶
type ByteArray []byte
ByteArray is a type alias over []byte to implement custom json marshalers in hex
func (ByteArray) MarshalJSON ¶
MarshalJSON implements the Marshaler interface for ByteArray types
func (*ByteArray) UnmarshalJSON ¶
UnmarshalJSON implements the Unmarshaler interface for ByteArray types
type CensusProof ¶
type CensusProof struct { Index uint64 `json:"index"` PublicKey *babyjub.PublicKey `json:"publicKey"` Weight *big.Int `json:"weight"` MerkleProof ByteArray `json:"merkleProof"` }
CensusProof contains the proof of a PublicKey in the Census Tree
type Process ¶
type Process struct { // ID is determined by the SmartContract, is unique for each Process ID uint64 // ProofID determines the ID assigned by the proof-server, is used to // retrieve the proof ProofID uint64 // CensusRoot indicates the CensusRoot of the Process, the same // CensusRoot can be reused by different Processes CensusRoot []byte // CensusSize determines the number of public keys placed in the // CensusTree leaves under the CensusRoot CensusSize uint64 // EthBlockNum indicates at which Ethereum block number the process has // been created EthBlockNum uint64 // ResPubStartBlock (Results Publishing Start Block) indicates the // EthBlockNum where the process ends, in which the results can be // published ResPubStartBlock uint64 // ResPubWindow (Results Publishing Window) indicates the window of // time (blocks), which starts at the ResPubStartBlock and ends at // ResPubStartBlock+ResPubWindow. During this window of time, the // results + zkProofs can be sent to the SmartContract. ResPubWindow uint64 // MinParticipation sets a threshold of minimum number of votes over // the total users in the census (% over CensusSize) MinParticipation uint8 // Type of process, where 0: multisig, 1: referendum Type uint8 // InsertedDatetime contains the datetime of when the process was // inserted in the db InsertedDatetime time.Time // Status determines the current status of the process Status ProcessStatus }
Process represents a voting process
type ProcessStatus ¶
type ProcessStatus int
ProcessStatus type is used to define the status of the Process
const ( // ProcessStatusOn indicates that the process is accepting vote (Voting // phase) ProcessStatusOn ProcessStatus = iota // ProcessStatusFrozen indicates that the process is in // ResultsPublishingPhase and is no longer accepting new votes, the // proof can now be generated ProcessStatusFrozen // ProcessStatusProofGenerating indicates that the process is no longer // accepting new votes and the zkProof is being generated ProcessStatusProofGenerating // ProcessStatusProofGenerated indicates that the process is finished, // and the zkProof is already generated ProcessStatusProofGenerated // ProcessStatusContractClosed indicates that the process has been // closed in the contract. ProcessStatusContractClosed )
type Proof ¶
type Proof struct { A [3]*big.Int `json:"pi_a"` B [3][2]*big.Int `json:"pi_b"` C [3]*big.Int `json:"pi_c"` Protocol string `json:"protocol"` }
Proof represents a Groth16 zkSNARK proof
type ProofInDB ¶
type ProofInDB struct { ProofID uint64 Proof []byte PublicInputs []byte InsertedDatetime time.Time ProofAddedDatetime time.Time ProcessID uint64 }
ProofInDB contains the proof data from an entry in the db
type VotePackage ¶
type VotePackage struct { Signature babyjub.SignatureComp `json:"signature"` CensusProof CensusProof `json:"censusProof"` Vote ByteArray `json:"vote"` }
VotePackage represents the vote sent by the User
type ZKCircuitMeta ¶
ZKCircuitMeta contains metadata related to the circuit configuration
type ZKInputs ¶
type ZKInputs struct { Meta ZKCircuitMeta `json:"-"` // public inputs ChainID *big.Int `json:"chainID"` ProcessID *big.Int `json:"processID"` CensusRoot *big.Int `json:"censusRoot"` ReceiptsRoot *big.Int `json:"receiptsRoot"` NVotes *big.Int `json:"nVotes"` Result *big.Int `json:"result"` WithReceipts *big.Int `json:"withReceipts"` ///// // private inputs Vote []*big.Int `json:"vote"` // user's key related Index []*big.Int `json:"index"` PkX []*big.Int `json:"pkX"` PkY []*big.Int `json:"pkY"` Weight []*big.Int `json:"weight"` // signatures S []*big.Int `json:"s"` R8x []*big.Int `json:"r8x"` R8y []*big.Int `json:"r8y"` // census proofs Siblings [][]*big.Int `json:"siblings"` ReceiptsSiblings [][]*big.Int `json:"receiptsSiblings"` }
ZKInputs contains the inputs used to generate the zkProof
func NewZKInputs ¶
NewZKInputs returns an initialized ZKInputs struct
func (*ZKInputs) ComputeReceipts ¶
ComputeReceipts builds a temp MerkleTree with all the given index & publicKeys (receiptsKeys & receiptsValues), to then compute the siblings of each recipt, adding the siblings & root of the receipts tree to ZKInputs.ReceiptsRoot & ZKInputs.ReceiptsSiblings.
func (ZKInputs) MarshalJSON ¶
MarshalJSON implements the json marshaler for ZKInputs