Documentation
¶
Index ¶
- func WithProverTargetSolidityVerifier(bid backend.ID) backend.ProverOption
- func WithVerifierTargetSolidityVerifier(bid backend.ID) backend.VerifierOption
- type ExportConfig
- type ExportOption
- func WithConstants(r io.Reader) ExportOption
- func WithConstructor(r io.Reader) ExportOption
- func WithFunctions(r io.Reader) ExportOption
- func WithHashToFieldFunction(hFunc hash.Hash) ExportOption
- func WithImport(r io.Reader) ExportOption
- func WithInterface(r io.Reader) ExportOption
- func WithPragmaVersion(version string) ExportOption
- type VerifyingKey
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithProverTargetSolidityVerifier ¶
func WithProverTargetSolidityVerifier(bid backend.ID) backend.ProverOption
WithProverTargetSolidityVerifier returns a prover option that sets all the necessary prover options which are suitable for verifying the proofs in the Solidity verifier.
For PLONK this is a no-op option as the Solidity verifier is directly compatible with the default prover options. Regardless, it is recommended to use this option for consistency and possible future changes in the Solidity verifier.
For Groth16 this option sets the hash function used for hashing bytes to field to sha3.NewLegacyKeccak256 as the Solidity verifier does not support the standard hash-to-field function. We use legacy Keccak256 in Solidity for the cheapest gas usage.
func WithVerifierTargetSolidityVerifier ¶
func WithVerifierTargetSolidityVerifier(bid backend.ID) backend.VerifierOption
WithVerifierTargetSolidityVerifier returns a verifier option that sets all the necessary verifier options which are suitable for verifying the proofs targeted for the Solidity verifier. See the comments in WithProverTargetSolidityVerifier.
Types ¶
type ExportConfig ¶
type ExportConfig struct {
PragmaVersion string
HashToFieldFn hash.Hash
// Imports contains additional import statements to include in the generated contract.
// Each key is an import statement (without semicolon), sorted by key for deterministic output.
Imports map[string]struct{}
// Interfaces contains the interface names that the contract implements.
Interfaces []string
// Constants contains additional constant declarations to include in the contract.
Constants string
// Constructor contains the constructor code to include in the contract.
Constructor string
// Functions contains additional functions to include in the contract.
Functions string
}
ExportConfig is the configuration for the prover with the options applied.
func NewExportConfig ¶
func NewExportConfig(opts ...ExportOption) (ExportConfig, error)
NewExportConfig returns a default ExportConfig with given export options opts applied.
func (ExportConfig) InterfaceDeclaration ¶ added in v0.15.0
func (cfg ExportConfig) InterfaceDeclaration() string
InterfaceDeclaration returns the interface declaration string for the contract. Returns empty string if no interfaces are defined.
func (ExportConfig) SortedImports ¶ added in v0.15.0
func (cfg ExportConfig) SortedImports() []string
SortedImports returns the imports sorted alphabetically for deterministic output.
type ExportOption ¶
type ExportOption func(*ExportConfig) error
ExportOption defines option for altering the behavior of the prover in Prove, ReadAndProve and IsSolved methods. See the descriptions of functions returning instances of this type for implemented options.
func WithConstants ¶ added in v0.15.0
func WithConstants(r io.Reader) ExportOption
WithConstants adds additional constant declarations to the generated Solidity contract. The constants are inserted after the existing constants in the template.
Example:
solidity.WithConstants(strings.NewReader("bytes32 private immutable CHAIN_CONFIGURATION;"))
func WithConstructor ¶ added in v0.15.0
func WithConstructor(r io.Reader) ExportOption
WithConstructor adds a constructor to the generated Solidity contract.
Example:
solidity.WithConstructor(strings.NewReader("constructor() { }"))
func WithFunctions ¶ added in v0.15.0
func WithFunctions(r io.Reader) ExportOption
WithFunctions adds additional functions to the generated Solidity contract. The functions are inserted before the closing brace of the contract.
Example:
solidity.WithFunctions(strings.NewReader("function foo() public { }"))
func WithHashToFieldFunction ¶
func WithHashToFieldFunction(hFunc hash.Hash) ExportOption
WithHashToFieldFunction changes the hash function used for hashing bytes to field. If not set then the default hash function based on RFC 9380 is used. Used mainly for compatibility between different systems and efficient recursion.
func WithImport ¶ added in v0.15.0
func WithImport(r io.Reader) ExportOption
WithImport adds an import statement to the generated Solidity contract. Can be called multiple times to add multiple imports. The imports are sorted alphabetically for deterministic output.
Example:
solidity.WithImport(strings.NewReader(`import { Mimc } from "../../../libraries/Mimc.sol";`))
func WithInterface ¶ added in v0.15.0
func WithInterface(r io.Reader) ExportOption
WithInterface adds an interface name that the contract implements. Can be called multiple times to add multiple interfaces.
Example:
solidity.WithInterface(strings.NewReader("IPlonkVerifier"))
func WithPragmaVersion ¶
func WithPragmaVersion(version string) ExportOption
WithPragmaVersion changes the pragma version used in the solidity verifier.
type VerifyingKey ¶
type VerifyingKey interface {
NbPublicWitness() int
ExportSolidity(io.Writer, ...ExportOption) error
}
VerifyingKey is the interface for verifying keys in the Solidity backend.