proof

package
v2.12.0-beta1 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: MIT Imports: 14 Imported by: 4

Documentation

Index

Constants

View Source
const OnChainResponseLength = ProofLength +

	32 // blocknum

OnChainResponseLength is the length of the MarshaledOnChainResponse. The extra 32 bytes are for blocknumber (as a uint256), which goes at the end. The seed is rewritten with the preSeed. (See MarshalForVRFCoordinator and ProofResponse#ActualProof.)

View Source
const ProofLength = 64 +
	64 +
	32 +
	32 +
	32 +
	32 +
	64 +
	64 +

	32 // zInv  (Leave Output out, because that can be efficiently calculated)

Length of marshaled proof, in bytes

Variables

This section is empty.

Functions

func FinalSeed

func FinalSeed(s PreSeedData) (finalSeed *big.Int)

FinalSeed is the seed which is actually passed to the VRF proof generator, given the pre-seed and the hash of the block in which the VRFCoordinator emitted the log for the request this is responding to.

func FinalSeedV2

func FinalSeedV2(s PreSeedDataV2) (finalSeed *big.Int)

func FinalSeedV2Plus added in v2.4.0

func FinalSeedV2Plus(s PreSeedDataV2Plus) (finalSeed *big.Int)

func UnmarshalSolidityProof

func UnmarshalSolidityProof(proof []byte) (rv vrfkey.Proof, err error)

Types

type MarshaledOnChainResponse

type MarshaledOnChainResponse [OnChainResponseLength]byte

MarshaledOnChainResponse is the flat bytes which are sent back to the VRFCoordinator.

func GenerateProofResponse

func GenerateProofResponse(keystore keystore.VRF, id string, s PreSeedData) (
	MarshaledOnChainResponse, error)

func GenerateProofResponseFromProof

func GenerateProofResponseFromProof(proof vrfkey.Proof, s PreSeedData) (MarshaledOnChainResponse, error)

type MarshaledProof

type MarshaledProof [ProofLength]byte

MarshaledProof contains a VRF proof for randomValueFromVRFProof.

NB: when passing one of these to randomValueFromVRFProof via the geth blockchain simulator, it must be passed as a slice ("proof[:]"). Passing it as-is sends hundreds of single bytes, each padded to their own 32-byte word.

func MarshalForSolidityVerifier

func MarshalForSolidityVerifier(p *vrfkey.Proof) (MarshaledProof, error)

MarshalForSolidityVerifier renders p as required by randomValueFromVRFProof

func (MarshaledProof) String

func (m MarshaledProof) String() string

String returns m as 0x-hex bytes

type PreSeedData

type PreSeedData struct {
	PreSeed   Seed        // Seed to be mixed with hash of containing block
	BlockHash common.Hash // Hash of block containing VRF request
	BlockNum  uint64      // Cardinal number of block containing VRF request
}

PreSeedData contains the data the VRF provider needs to compute the final VRF output and marshal the proof for transmission to the VRFCoordinator contract.

func TestXXXSeedData

func TestXXXSeedData(t *testing.T, preSeed *big.Int, blockHash common.Hash,
	blockNum int) PreSeedData

type PreSeedDataV2

type PreSeedDataV2 struct {
	PreSeed          Seed        // Seed to be mixed with hash of containing block
	BlockHash        common.Hash // Hash of block containing VRF request
	BlockNum         uint64      // Cardinal number of block containing VRF request
	SubId            uint64
	CallbackGasLimit uint32
	NumWords         uint32
	Sender           common.Address
}

type PreSeedDataV2Plus added in v2.4.0

type PreSeedDataV2Plus struct {
	PreSeed          Seed        // Seed to be mixed with hash of containing block
	BlockHash        common.Hash // Hash of block containing VRF request
	BlockNum         uint64      // Cardinal number of block containing VRF request
	SubId            *big.Int
	CallbackGasLimit uint32
	NumWords         uint32
	Sender           common.Address
	ExtraArgs        []byte
}

type ProofResponse

type ProofResponse struct {
	// Approximately the proof which will be checked on-chain. Note that this
	// contains the pre-seed in place of the final seed. That should be computed
	// as in FinalSeed.
	P        vrfkey.Proof
	PreSeed  Seed   // Seed received during VRF request
	BlockNum uint64 // Height of the block in which this request was made
}

ProofResponse is the data which is sent back to the VRFCoordinator, so that it can verify that the seed the oracle finally used is correct.

func UnmarshalProofResponse

func UnmarshalProofResponse(m MarshaledOnChainResponse) (*ProofResponse, error)

UnmarshalProofResponse returns the ProofResponse represented by the bytes in m

func (ProofResponse) CryptoProof

func (p ProofResponse) CryptoProof(s PreSeedData) (vrfkey.Proof, error)

CryptoProof returns the proof implied by p, with the correct seed

func (*ProofResponse) MarshalForVRFCoordinator

func (p *ProofResponse) MarshalForVRFCoordinator() (
	response MarshaledOnChainResponse, err error)

MarshalForVRFCoordinator constructs the flat bytes which are sent to the VRFCoordinator.

type Seed

type Seed [32]byte

Seed represents a VRF seed as a serialized uint256

func BigToSeed

func BigToSeed(x *big.Int) (Seed, error)

BigToSeed returns seed x represented as a Seed, or an error if x is too big

func (*Seed) Big

func (s *Seed) Big() *big.Int

Big returns the uint256 seed represented by s

type SolidityProof

type SolidityProof struct {
	P                           *vrfkey.Proof  // The core proof
	UWitness                    common.Address // Address of P.C*P.PK+P.S*G
	CGammaWitness, SHashWitness kyber.Point    // P.C*P.Gamma, P.S*HashToCurve(P.Seed)
	ZInv                        *big.Int       // Inverse of Z coord from ProjectiveECAdd(CGammaWitness, SHashWitness)
}

SolidityProof contains precalculations which VRF.sol needs to verify proofs

func SolidityPrecalculations

func SolidityPrecalculations(p *vrfkey.Proof) (*SolidityProof, error)

SolidityPrecalculations returns the precomputed values needed by the solidity verifier, or an error on failure.

func (*SolidityProof) MarshalForSolidityVerifier

func (p *SolidityProof) MarshalForSolidityVerifier() (proof MarshaledProof)

MarshalForSolidityVerifier renders p as required by randomValueFromVRFProof

func (*SolidityProof) String

func (p *SolidityProof) String() string

String returns the values in p, in hexadecimal format

Jump to

Keyboard shortcuts

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