Documentation ¶
Index ¶
- Constants
- Variables
- func BasicTransferScript() string
- func BasicTransferScriptCommitment() []byte
- func CoinbaseValidationProgram() string
- func LoadZKPublicParameters()
- func LurkCommit(expr string) ([]byte, error)
- func LurkDecrypt(ciphertext [][32]byte, key [32]byte) ([][32]byte, error)
- func LurkEncrypt(plaintext [][32]byte, key [32]byte) ([][32]byte, error)
- func MakeMultisigUnlockingParams(pubkeys []crypto.PubKey, sigs [][]byte, sigHash []byte) (string, error)
- func MintValidationProgram() string
- func MultisigScript() string
- func MultisigScriptCommitment() []byte
- func PasswordScript() string
- func Prove(lurkProgram string, privateParams Parameters, publicParams Parameters, ...) ([]byte, error)
- func PublicAddressScript() string
- func PublicAddressScriptCommitment() []byte
- func RandomFieldElement() ([32]byte, error)
- func StakeValidationProgram() string
- func StandardValidationProgram() string
- func TimelockedMultisigScript() string
- func TimelockedMultisigScriptCommitment() []byte
- func TreasuryValidationProgram() string
- func Verify(lurkProgram string, publicParams Parameters, proof []byte) (bool, error)
- func VerifyInputScript(script string, lockingParams Parameters, unlockingParams Parameters, ...) (bool, error)
- type Expr
- type LurkProver
- type LurkVerifier
- type MockProver
- type MockVerifier
- type Parameters
- type Prover
- type Tag
- type Verifier
Constants ¶
const ( // EstimatedProofSize is the estimated size (in bytes) of the transaction // proofs. These vary slightly for each transaction type. EstimatedProofSize = 12516 // LurkMaxFieldElement is the maximum value for a field element in lurk. // In practice this means lurk script variables cannot exceed this value. LurkMaxFieldElement = "30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000000" )
const CommitmentLen = 32
CommitmentLen is the length of the Lurk Commitment
Variables ¶
var ( OutputTrue = []byte{31, 92, 240, 53, 64, 81, 52, 184, 242, 164, 206, 155, 203, 246, 62, 58, 99, 64, 80, 9, 206, 22, 104, 13, 186, 172, 246, 192, 146, 161, 140, 76} OutputFalse = []byte{29, 85, 200, 194, 103, 218, 100, 115, 6, 158, 39, 183, 243, 138, 4, 149, 54, 111, 248, 230, 51, 5, 165, 229, 248, 91, 9, 187, 12, 36, 47, 3} )
Functions ¶
func BasicTransferScript ¶
func BasicTransferScript() string
BasicTransferScript returns the basic transfer lurk script
func BasicTransferScriptCommitment ¶
func BasicTransferScriptCommitment() []byte
BasicTransferScriptCommitment returns the script commitment hash for the basic transfer script.
func CoinbaseValidationProgram ¶
func CoinbaseValidationProgram() string
CoinbaseValidationProgram returns the coinbase validation lurk program script
func LoadZKPublicParameters ¶
func LoadZKPublicParameters()
LoadZKPublicParameters loads the lurk public parameters from disk into memory or generates them if this is the first startup.
func LurkCommit ¶
LurkCommit returns poseidon hash of provided lurk expression. This is the same exact hashing algorithm used inside lurk circuits.
func LurkDecrypt ¶
LurkDecrypt decrypts the ciphertext using the key
func LurkEncrypt ¶
LurkEncrypt is a stream cipher algorithm that can be computed inside the circuit. It operates on a lurk list where each item in the list is a lurk field element.
This implementation operates outside the circuit as is used for computing an output's ciphertext field.
There is a small probability that a ciphertext chunk may exceed the maximum field element resulting in a loss of one bit precision. To avoid this we brute force the nonce key to make sure no precision is lost.
NOTE: for most transactions you want to use crypto/Encrypt which uses curve25519. This is only to be used if you have a script where you need to verify ciphertext inside the script for some reason.
func MakeMultisigUnlockingParams ¶
func MakeMultisigUnlockingParams(pubkeys []crypto.PubKey, sigs [][]byte, sigHash []byte) (string, error)
MakeMultisigUnlockingParams takes in a list of public keys and signatures and returns a lurk expression for the signatures that can be used as unlocking params for the multisig script.
Note: The public keys here must be in the same order as they appear in the locking params. Note2: The signatures must be in the same order as the public keys they belong to. // Fixme: this function can be refactored to remove this requirement
func MintValidationProgram ¶
func MintValidationProgram() string
MintValidationProgram returns the mint validation lurk program script
func MultisigScriptCommitment ¶
func MultisigScriptCommitment() []byte
MultisigScriptCommitment returns the script commitment hash for the multisig script.
func Prove ¶
func Prove(lurkProgram string, privateParams Parameters, publicParams Parameters, maxSteps ...uint64) ([]byte, error)
func PublicAddressScript ¶
func PublicAddressScript() string
PublicAddressScript returns the public address lurk script
func PublicAddressScriptCommitment ¶
func PublicAddressScriptCommitment() []byte
PublicAddressScriptCommitment returns the script commitment hash for the public address script.
func RandomFieldElement ¶
func StakeValidationProgram ¶
func StakeValidationProgram() string
StakeValidationProgram returns the stake validation lurk program script
func StandardValidationProgram ¶
func StandardValidationProgram() string
StandardValidationProgram returns the standard validation lurk program script
func TimelockedMultisigScript ¶
func TimelockedMultisigScript() string
TimelockedMultisigScript returns the timelocked multisig lurk script
func TimelockedMultisigScriptCommitment ¶
func TimelockedMultisigScriptCommitment() []byte
TimelockedMultisigScriptCommitment returns the script commitment hash for the timelocked multisig script.
func TreasuryValidationProgram ¶
func TreasuryValidationProgram() string
TreasuryValidationProgram is an alias for the coinbase validation program as they use the same script.
func VerifyInputScript ¶
func VerifyInputScript(script string, lockingParams Parameters, unlockingParams Parameters, inputIndex uint32, privateParams Parameters, publicParams Parameters) (bool, error)
VerifyInputScript is a function that can be used to test locking scripts. You provide the script and the set of parameters as they would look in a transaction and the script will be executed.
Example: script := "(lambda (a b c d e) (= c 10))" valid, err := VerifyInputScript(script, Expr("nil"), Expr("nil"), 10, Expr("nil"), Expr("nil"))
Types ¶
type LurkProver ¶
type LurkProver struct{}
LurkProver is an implementation of the Prover interface that creates lurk zk-snark proofs.
func (*LurkProver) Prove ¶
func (l *LurkProver) Prove(program string, privateParams Parameters, publicParams Parameters, maxSteps ...uint64) (proof []byte, err error)
Prove creates a proof that the private and public params make the program return true.
type LurkVerifier ¶
type LurkVerifier struct{}
LurkVerifier is an implementation of the Verifier interface that verifies lurk zk-snark proofs.
func (*LurkVerifier) Verify ¶
func (l *LurkVerifier) Verify(program string, publicParams Parameters, proof []byte) (valid bool, err error)
Verify uses the public params and the proof to verify that the program returned true.
type MockProver ¶
type MockProver struct {
// contains filtered or unexported fields
}
MockProver is a mock implementation of the Prover interface. It does validate that the private and public parameters make the program return true, but it does not actually create the proof. Instead, it just returns random bytes.
func (*MockProver) Prove ¶
func (m *MockProver) Prove(program string, privateParams Parameters, publicParams Parameters, maxSteps ...uint64) ([]byte, error)
Prove creates a proof that the private and public params make the program return true.
func (*MockProver) SetProofLen ¶
func (m *MockProver) SetProofLen(length int)
SetProofLen sets the length of the mock proof returned by the Prove method.
type MockVerifier ¶
type MockVerifier struct {
// contains filtered or unexported fields
}
MockVerifier does nto validate the proof at all and just returns the value of valid instead.
func (*MockVerifier) SetValid ¶
func (m *MockVerifier) SetValid(valid bool)
SetValid sets the return value for the Verify method
func (*MockVerifier) Verify ¶
func (m *MockVerifier) Verify(program string, publicParams Parameters, proof []byte) (valid bool, err error)
Verify uses the public params and the proof to verify that the program returned true.
type Parameters ¶
type Parameters interface { // ToExpr marshals the Parameters to a string // expression used by lurk. ToExpr() (string, error) }
Parameters is an interface for script private or public parameters that converts a struct to a lurk list usable by a script.
type Prover ¶
type Prover interface { // Prove creates a proof that the private and public params // make the program return true. // // maxSteps is optional if you want to limit the number of steps // before terminating the proof creation. Prove(program string, privateParams Parameters, publicParams Parameters, maxSteps ...uint64) (proof []byte, err error) }
Prover is an interface to the zk-snark prove function.
type Tag ¶
type Tag uint8
Tag represents a Lurk data type
func Eval ¶
func Eval(lurkProgram string, privateParams Parameters, publicParams Parameters, debug ...bool) (Tag, []byte, int, error)
func TagFromBytes ¶
TagFromBytes returns a tag from a big endian byte slice