zk

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2020 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProvingKeyFormatJSON  = "json"
	ProvingKeyFormatBin   = "bin"
	ProvingKeyFormatGoBin = "go.bin"
)

Variables

This section is empty.

Functions

func G1ToBigInts

func G1ToBigInts(g1 *bn256.G1) [2]*big.Int

G1ToBigInts transforms a `*bn256.G1` into `*big.Int` format, to be used for example in snarkjs solidity verifiers.

func G2ToBigInts

func G2ToBigInts(g2 *bn256.G2) [2][2]*big.Int

G2ToBigInts transforms a `*bn256.G2` into `*big.Int` format, to be used for example in snarkjs solidity verifiers.

func InputsToMapStrings

func InputsToMapStrings(inputs interface{}) (map[string]interface{}, error)

InputsToMapStrings transforms the input signals map from *big.Int type (as used in witnesscalc) to quoted strings (as used in JSON encoding).

func PrintProof

func PrintProof(proof *zktypes.Proof)

PrintProof prints the zkp in JSON pretty format.

func ProofToBigInts

func ProofToBigInts(proof *zktypes.Proof) (a [2]*big.Int, b [2][2]*big.Int, c [2]*big.Int)

ProofToBigInts transforms a zkp (that uses `*bn256.G1` and `*bn256.G2`) into `*big.Int` format, to be used for example in snarkjs solidity verifiers.

Types

type ProvingKeyFormat

type ProvingKeyFormat string

type PubSignals

type PubSignals []*big.Int

PubSignals is a helper wrapper type over []*big.Int that is JSON friendly.

func (PubSignals) MarshalJSON

func (p PubSignals) MarshalJSON() ([]byte, error)

func (*PubSignals) UnmarshalJSON

func (p *PubSignals) UnmarshalJSON(data []byte) error

type ZkFiles

type ZkFiles struct {
	Url  string
	Path string
	// contains filtered or unexported fields
}

ZkFiles allows convenient access to the files required for zk proving and verifying.

func NewZkFiles

func NewZkFiles(url, path string, provingKeyFormat ProvingKeyFormat, hashes ZkFilesHashes, cacheProvingKey bool) *ZkFiles

NewZkFiles creates a new ZkFiles that will try to use the zk files from `path` checking that the `hashes` match with the files. If the files don't exist, they are downloaded into `path` from `url`. The proving key can be quite big: setting `cacheProvingKey` to false will make the ZkFiles not keep it in memory after requesting it, parsing it from disk every time it is required. The rest of the files are always cached.

func (*ZkFiles) DebugDownloadPrintHashes

func (z *ZkFiles) DebugDownloadPrintHashes(provingKeyFormat ProvingKeyFormat) error

DebugDownloadPrintHashes is a helper function that downloads all the zk files in a temporary directory, calculates their hashes, and prints the code of the `ZkFilesHashes` with the calculated hashes, ready to be pasted in real code.

func (*ZkFiles) DownloadAll

func (z *ZkFiles) DownloadAll() error

DownloadAll downloads all the zk files and checks their hashes.

func (*ZkFiles) DownloadProvingKey

func (z *ZkFiles) DownloadProvingKey() error

DownloadProvingKey downloads the ProvingKey and checks its hash.

func (*ZkFiles) DownloadVerificationKey

func (z *ZkFiles) DownloadVerificationKey() error

DownloadVerificationKey downloads the VerificationKey and checks its hash.

func (*ZkFiles) DownloadWitnessCalcWASM

func (z *ZkFiles) DownloadWitnessCalcWASM() error

DownloadWitnessCalcWASM downloads the WitnessCalcWASM and checks its hash.

func (*ZkFiles) InsecureCalcHashes

func (z *ZkFiles) InsecureCalcHashes() (*ZkFilesHashes, error)

InsecureCalcHashes calculates the hashes of the zkfiles without checking them.

func (*ZkFiles) InsecureDownloadAll

func (z *ZkFiles) InsecureDownloadAll() error

InsecureDownloadAll downloads all the zk files but doesn't check the hashes.

func (*ZkFiles) LoadAll

func (z *ZkFiles) LoadAll() error

LoadAll loads all the zk files, downloading them if necessary.

func (*ZkFiles) LoadProvingKey

func (z *ZkFiles) LoadProvingKey() error

LoadProvingKey loads the ProvingKey, downloading it if necessary.

func (*ZkFiles) LoadVerificationKey

func (z *ZkFiles) LoadVerificationKey() error

LoadVerificationKey loads the VerificationKey, downloading it if necessary.

func (*ZkFiles) LoadWitnessCalcWASM

func (z *ZkFiles) LoadWitnessCalcWASM() error

LoadWitnessCalcWASM loads the WitnessCalcWASM, downloading it if necessary.

func (*ZkFiles) ProvingKey

func (z *ZkFiles) ProvingKey() (*zktypes.Pk, error)

ProvingKey returns the ProvingKey, downloading and loading it if necessary.

func (*ZkFiles) VerificationKey

func (z *ZkFiles) VerificationKey() (*zktypes.Vk, error)

VerificationKey returns the VerificationKey, downloading and loading it if necessary.

func (*ZkFiles) WitnessCalcWASM

func (z *ZkFiles) WitnessCalcWASM() ([]byte, error)

WitnessCalcWASM returns the WitnessCalcWASM byte slice, downloading and loading it if necessary.

type ZkFilesBasename

type ZkFilesBasename struct {
	ProvingKey      string
	VerificationKey string
	WitnessCalcWASM string
}

type ZkFilesHashes

type ZkFilesHashes struct {
	ProvingKey      string
	VerificationKey string
	WitnessCalcWASM string
}

ZkFilesHashes are the sha256 hash in hex of the zk files

type ZkProofOut

type ZkProofOut struct {
	Proof      zktypes.Proof
	PubSignals []*big.Int
}

ZkProofOut is the output of calculating a zkp.

Jump to

Keyboard shortcuts

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