Documentation ¶
Index ¶
Constants ¶
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 ¶
var BaseDir = func() string { home, err := os.UserHomeDir() if err != nil { panic(err) } return filepath.Join(home, ".cache", "vocdoni", "zkCircuits") }()
BaseDir is where the artifact cache is expected to be found. If the artifacts are not found there, they will be downloaded and stored.
Defaults to ~/.cache/vocdoni/zkCircuits/
In any case, the LocalDir path associated with the circuit config will be appended at the end
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("0xe359b256e5e3c78acaccf8dab5dc4bea99a2f07b2a05e935b5ca658c714dea4a"),
ProvingKeyFilename: "proving_key.zkey",
VerificationKeyHash: hexToBytes("0x235e55571812f8e324e73e37e53829db0c4ac8f68469b9b953876127c97b425f"),
VerificationKeyFilename: "verification_key.json",
WasmHash: hexToBytes("0x80a73567f6a4655d4332301efcff4bc5711bb48176d1c71fdb1e48df222ac139"),
WasmFilename: "circuit.wasm",
},
"prod": {
URI: "https://raw.githubusercontent.com/vocdoni/" +
"zk-franchise-proof-circuit/master",
CircuitPath: "artifacts/zkCensus/dev/160",
Levels: 160,
ProvingKeyHash: hexToBytes("0xe359b256e5e3c78acaccf8dab5dc4bea99a2f07b2a05e935b5ca658c714dea4a"),
ProvingKeyFilename: "proving_key.zkey",
VerificationKeyHash: hexToBytes("0x235e55571812f8e324e73e37e53829db0c4ac8f68469b9b953876127c97b425f"),
VerificationKeyFilename: "verification_key.json",
WasmHash: hexToBytes("0x80a73567f6a4655d4332301efcff4bc5711bb48176d1c71fdb1e48df222ac139"),
WasmFilename: "circuit.wasm",
},
}
CircuitsConfigurations 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 { // Public inputs ElectionId []string `json:"electionId"` Nullifier string `json:"nullifier"` AvailableWeight string `json:"availableWeight"` VoteHash []string `json:"voteHash"` SIKRoot string `json:"sikRoot"` CensusRoot string `json:"censusRoot"` // Private inputs Address string `json:"address"` Password string `json:"password"` Signature string `json:"signature"` VoteWeight string `json:"voteWeight"` CensusSiblings []string `json:"censusSiblings"` SIKSiblings []string `json:"sikSiblings"` }
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(p CircuitInputsParameters) (*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.
func (*CircuitInputs) String ¶ added in v1.9.0
func (ci *CircuitInputs) String() string
type CircuitInputsParameters ¶ added in v1.9.0
type CircuitInputsParameters struct { Account *ethereum.SignKeys Password []byte ElectionId []byte CensusRoot []byte SIKRoot []byte CensusSiblings []string SIKSiblings []string VoteWeight *big.Int AvailableWeight *big.Int }
CircuitInputsParameters struct envolves all the parameters to generate the inputs for the current ZK circuit.
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 ¶
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 ¶
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 ¶
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 ¶
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 types.HexBytes `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 types.HexBytes `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 types.HexBytes `json:"wasmHash"` // FilenameWasm defines the name of the file of the circuit wasm compiled // version WasmFilename string `json:"wasmFilename"` // circuit.wasm // contains filtered or unexported fields }
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 (conf *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).
func (*ZkCircuitConfig) MaxCensusSize ¶ added in v1.9.0
func (conf *ZkCircuitConfig) MaxCensusSize() *big.Int
MaxCensusSize returns the maximum number of keys that circuit merkle tree for the census supports. The method checks if it is already precalculated or not. If it is not precalculated, it will calculate and initialise it. In any case, the value is returned as big.Int.
func (*ZkCircuitConfig) SupportsCensusSize ¶ added in v1.9.0
func (conf *ZkCircuitConfig) SupportsCensusSize(maxCensusSize uint64) bool
SupportsCensusSize returns if the provided censusSize is supported by the current circuit configuration. It ensures that the provided value is lower than 2^config.Levels.