zk

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2023 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package zk provides utilities around the zkSNARK (Groth16) tooling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToArboStr added in v1.4.0

func BytesToArboStr(input []byte) []string

BytesToArboStr calculates the sha256 hash (32 bytes) of the slice of bytes provided. Then, splits the hash into a two parts of 16 bytes, swap the endianess of that parts, encodes they into a two big.Ints and return both as strings into a []string.

func LittleEndianToNBytes added in v1.4.0

func LittleEndianToNBytes(num *big.Int, n int) *big.Int

LittleEndianToNBytes truncate the most significant n bytes of the provided little endian number provided and returns into a new big.Int.

func ProtobufZKProofToProverProof added in v1.4.0

func ProtobufZKProofToProverProof(p *models.ProofZkSNARK) (*prover.Proof, error)

ProtobufZKProofToProverProof parses the provided protobuf ready proof struct into a prover ready proof struct.

func ProverProofToProtobufZKProof added in v1.4.0

func ProverProofToProtobufZKProof(p *prover.Proof,
	electionId, censusRoot, nullifier types.HexBytes, weight *big.Int) (*models.ProofZkSNARK, error)

ProverProofToProtobufZKProof encodes the proof provided into a protobuf ready struct using including the index of the circuit used. If the provided proof does not contains a defined public signals, the rest of the arguments are required to calculate that parameter. If the provided proof does not contains a defined public signals and any of the rest of the parameters is nil, the resulting struct will not contains any defined PublicInputs value.

Types

type ZkAddress added in v1.4.0

type ZkAddress struct {
	// Privkey contains the big.Int version of the BabyJubJub private key
	PrivKey *big.Int
	// PubKey contains the big.Int poseidon hash of the BabyJubJub public key
	// (x and y coordinates of a point of the curve)
	PubKey *big.Int
	// contains filtered or unexported fields
}

ZkAddress struct allow to create and encoding properly the zk-snark compatible address for the vochain. This address is calculated from a BabyJubJub key pair, based on a seed. The address has 20 bytes of size and it is the truncated version of the poseidon hash of the BabyJubJub publicKey.

func AddressFromBytes added in v1.4.0

func AddressFromBytes(seed []byte) (*ZkAddress, error)

AddressFromBytes returns a new ZkAddress based on the seed provided. The seed has to be at least 32 bytes. Using it, a BabyJubJub key pair is calculated and based on it. The ZkAddress components are:

  • ZkAddress.PrivKey: The BabyJubJub private key big.Int value, following the EdDSA standard, and using blake-512 hash.
  • ZkAddress.PublicKey: The poseidon hash of the BabyJubJub public key components (X and Y coordinates as big.Int).
  • ZkAddress.addr: The last 20 bytes of the ZkAddress.PublicKey. This is calculated by truncating PublicKey (a little endian number) to the defaultZkAddrLen.

func AddressFromSignKeys added in v1.4.0

func AddressFromSignKeys(acc *ethereum.SignKeys) (*ZkAddress, error)

AddressFromSignKeys gets the private key from the ethereum.SignKeys provided and pass its string representation as []byte to AddressFromBytes function.

func AddressFromString added in v1.4.0

func AddressFromString(seed string) (*ZkAddress, error)

AddressFromString wraps AddressFromBytes function transforming the seed from string to []byte.

func NewRandAddress added in v1.4.0

func NewRandAddress() (*ZkAddress, error)

NewRandAddress returns a ZkAddress based on a random BabyJubJub private key.

func (*ZkAddress) Bytes added in v1.4.0

func (zk *ZkAddress) Bytes() []byte

Bytes returns the current ZkAddress.addr transformed to types.HexBytes using the arbo.BigIntToBytes() function.

func (*ZkAddress) Nullifier added in v1.4.0

func (zk *ZkAddress) Nullifier(electionId []byte) (*big.Int, error)

Nullifier returns ZkSnark ready vote nullifier based on the current ZkAddress.PrivKey and the electionId provided. The nullifier is calculated following this definition:

nullifier = poseidon(jubjubPrivKey, sha256(electionId))

func (*ZkAddress) String added in v1.4.0

func (zk *ZkAddress) String() string

String function returns the current ZkAddress.Bytes() result transformed to string using the types.HexBytes.String() function.

Directories

Path Synopsis
prover package abstracts the logic and types of go-rapidsnark (https://github.com/iden3/go-rapidsnark) to support basic operations for the rest of vocdoni-node project.
prover package abstracts the logic and types of go-rapidsnark (https://github.com/iden3/go-rapidsnark) to support basic operations for the rest of vocdoni-node project.

Jump to

Keyboard shortcuts

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