circuit

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: 17 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultCircuitConfigurationTag = "dev"

DefaultCircuitConfigurationTag constant contains the tag value that points to the default ZkSnark circuit configuration. It ensures that at least one circuit configuration is available so the configuration referred by this tag must be defined.

Variables

View Source
var BaseDir = ""

BaseDir is where the artifact cache is expected to be found. If the artifacts are not found there, they will be downloaded and stored. If unset ("") it will default to ~/.cache/vocdoni/zkCircuits/

In any case, the LocalDir path associated with the circuit config will be appended at the end

View Source
var CircuitsConfigurations = map[string]ZkCircuitConfig{
	"dev": {
		URI: "https://raw.githubusercontent.com/vocdoni/" +
			"zk-franchise-proof-circuit/master",
		CircuitPath:             "artifacts/zkCensus/dev/160",
		Levels:                  160,
		ProvingKeyHash:          hexToBytes("0x48596c390d24a173c796b0dae68f3c08db034171917ca1b2f253ce9476a35945"),
		ProvingKeyFilename:      "proving_key.zkey",
		VerificationKeyHash:     hexToBytes("0x411c78a012d6d163e02704d9ce33b6d84e84ee67f62179f53158ffabd88da44a"),
		VerificationKeyFilename: "verification_key.json",
		WasmHash:                hexToBytes("0xcc1af3eb9462788840284e83dd777d5b43782d9a7ca89ce8d88709237a2e18e9"),
		WasmFilename:            "circuit.wasm",
	},
}

CircuitsConfiguration stores the relation between the different vochain nets and the associated circuit configuration. Any circuit configuration must have the remote and local location of the circuits artifacts and their metadata such as artifacts hash or the number of parameters.

Functions

This section is empty.

Types

type CircuitInputs

type CircuitInputs struct {
	CensusRoot     string   `json:"censusRoot"`
	CensusSiblings []string `json:"censusSiblings"`
	VotingWeight   string   `json:"votingWeight"`
	FactoryWeight  string   `json:"factoryWeight"`
	PrivateKey     string   `json:"privateKey"`
	VoteHash       []string `json:"voteHash"`
	ProcessId      []string `json:"processId"`
	Nullifier      string   `json:"nullifier"`
}

CircuitInputs wraps all the necessary circuit parameters. They must all be strings or slices of strings, and the struct must be able to be encoded in json.

func GenerateCircuitInput

func GenerateCircuitInput(zkAddr *zk.ZkAddress, censusRoot, electionId []byte,
	factoryWeight, votingWeight *big.Int, censusSiblings []string) (*CircuitInputs, error)

GenerateCircuitInput receives the required parameters to encode them correctly to return the expected CircuitInputs. This function uses the ZkAddress to get the private key and generates the nullifier. Also encodes the census root, the election id and the weight provided, and includes the census siblings provided into the result.

type ZkCircuit

type ZkCircuit struct {
	ProvingKey      []byte
	VerificationKey []byte
	Wasm            []byte
	Config          ZkCircuitConfig
}

ZkCircuit struct wraps the circuit configuration and contains the file content of the circuit artifacts (provingKey, verificationKey and wasm)

func LoadZkCircuit

func LoadZkCircuit(ctx context.Context, config ZkCircuitConfig) (*ZkCircuit, error)

LoadZkCircuit load the circuit artifacts based on the configuration provided. First, tries to load the artifacts from local storage, if they are not available, tries to download from their remote location.

func LoadZkCircuitByTag

func LoadZkCircuitByTag(configTag string) (*ZkCircuit, error)

LoadZkCircuitByTag gets the circuit configuration associated to the provided tag or gets the default one and load its artifacts to prepare the circuit to be used.

func (*ZkCircuit) LoadLocal

func (circuit *ZkCircuit) LoadLocal() error

LoadLocal tries to read the content of current circuit artifacts from its local path (provingKey, verificationKey and wasm). If any of the read operations fails, returns an error.

func (*ZkCircuit) LoadRemote

func (circuit *ZkCircuit) LoadRemote(ctx context.Context) error

LoadRemote downloads the content of the current circuit artifacts from its remote location. If any of the downloads fails, returns an error.

func (*ZkCircuit) VerifiedCircuitArtifacts

func (circuit *ZkCircuit) VerifiedCircuitArtifacts() (bool, error)

VerifiedCircuitArtifacts checks that the computed hash of every circuit artifact matches with the expected hash, from the circuit config.

type ZkCircuitConfig

type ZkCircuitConfig struct {
	// URI defines the URI from where to download the files
	URI string `json:"uri"`
	// CircuitPath defines the path from where the files are downloaded.
	// Locally, they will be cached inside circuit.BaseDir path,
	// under that directory it will follow the CircuitPath dir structure
	CircuitPath string `json:"circuitPath"`
	// Levels refers the number of levels that the merkle tree associated to the
	// current circuit configuration artifacts has
	Levels int `json:"levels"`
	// ProvingKeyHash contains the expected hash for the file filenameZKey
	ProvingKeyHash []byte `json:"zKeyHash"`
	// FilenameProvingKey defines the name of the file of the circom ProvingKey
	ProvingKeyFilename string `json:"zKeyFilename"` // proving_key.zkey
	// VerificationKeyHash contains the expected hash for the file filenameVK
	VerificationKeyHash []byte `json:"vKeyHash"`
	// FilenameVerificationKey defines the name of the file of the circom
	// VerificationKey
	VerificationKeyFilename string `json:"vKeyFilename"` // verification_key.json
	// WasmHash contains the expected hash for the file filenameWasm
	WasmHash []byte `json:"wasmHash"`
	// FilenameWasm defines the name of the file of the circuit wasm compiled
	// version
	WasmFilename string `json:"wasmFilename"` // circuit.wasm
}

ZkCircuitConfig defines the configuration of the files to be downloaded

func GetCircuitConfiguration

func GetCircuitConfiguration(configTag string) ZkCircuitConfig

GetCircuitConfiguration returns the circuit configuration associated with the provided tag or gets the default one.

func (ZkCircuitConfig) KeySize

func (config ZkCircuitConfig) KeySize() int

KeySize returns the maximum number of bytes of a leaf key according to the number of levels of the current circuit (nBytes = nLevels / 8).

Jump to

Keyboard shortcuts

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