prover

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2021 License: AGPL-3.0 Imports: 10 Imported by: 0

README

Test Prover

Server Proof API

It is necessary to have a docker with server locally.

The instructions in the following link can be followed: https://github.com/hermeznetwork/test-info/tree/main/cli-prover

It is necessary to consult the pre-requirements to follow the steps of the next summary

A summary of the steps to follow to run docker would be:

  • Clone the repository: https://github.com/hermeznetwork/test-info
  • cd cli-prover
  • ./cli-prover.sh -s localhost -v ~/prover_data -r 22
  • To enter docker: docker exec -ti docker_cusnarks bash
  • Inside the docker: cd cusnarks; make docker_all FORCE_CPU=1
  • Inside the docker: cd config; python3 cusnarks_config.py 22 BN256
  • To exit docker: exit
  • Now, the server API can be used. Helper can be consulted with: ./cli-prover.sh -h
  • Is necessary to initialize the server with: ./cli-prover.sh --post-start <session>
  • When ./cli-prover.sh --get-status <session> is ready can be run the test.

The session can be consulted with tmux ls. The session will be the number of the last session on the list.

Test

INTEGRATION=1 go test

Documentation

Index

Constants

View Source
const (
	// GET is an HTTP GET
	GET apiMethod = "GET"
	// POST is an HTTP POST with maybe JSON body
	POST apiMethod = "POST"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Non-blocking
	CalculateProof(ctx context.Context, zkInputs *common.ZKInputs) error
	// Blocking.  Returns the Proof and Public Data (public inputs)
	GetProof(ctx context.Context) (*Proof, []*big.Int, error)
	// Non-Blocking
	Cancel(ctx context.Context) error
	// Blocking
	WaitReady(ctx context.Context) error
}

Client is the interface to a ServerProof that calculates zk proofs

type ErrorServer

type ErrorServer struct {
	Status  StatusCode `json:"status"`
	Message string     `json:"msg"`
}

ErrorServer is the return struct for an API error

func (ErrorServer) Error

func (e ErrorServer) Error() string

Error message for ErrorServer

type MockClient

type MockClient struct {
	Delay time.Duration
	// contains filtered or unexported fields
}

MockClient is a mock ServerProof to be used in tests. It doesn't calculate anything

func (*MockClient) CalculateProof

func (p *MockClient) CalculateProof(ctx context.Context, zkInputs *common.ZKInputs) error

CalculateProof sends the *common.ZKInputs to the ServerProof to compute the Proof

func (*MockClient) Cancel

func (p *MockClient) Cancel(ctx context.Context) error

Cancel cancels any current proof computation

func (*MockClient) GetProof

func (p *MockClient) GetProof(ctx context.Context) (*Proof, []*big.Int, error)

GetProof retrieves the Proof from the ServerProof

func (*MockClient) WaitReady

func (p *MockClient) WaitReady(ctx context.Context) error

WaitReady waits until the prover is ready

type Proof

type Proof struct {
	PiA      [3]*big.Int    `json:"pi_a"`
	PiB      [3][2]*big.Int `json:"pi_b"`
	PiC      [3]*big.Int    `json:"pi_c"`
	Protocol string         `json:"protocol"`
}

Proof TBD this type will be received from the proof server

func (*Proof) UnmarshalJSON

func (p *Proof) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the proof from a JSON encoded proof with the big ints as strings

type ProofServerClient

type ProofServerClient struct {
	URL string
	// contains filtered or unexported fields
}

ProofServerClient contains the data related to a ProofServerClient

func NewProofServerClient

func NewProofServerClient(URL string, pollInterval time.Duration) *ProofServerClient

NewProofServerClient creates a new ServerProof

func (*ProofServerClient) CalculateProof

func (p *ProofServerClient) CalculateProof(ctx context.Context, zkInputs *common.ZKInputs) error

CalculateProof sends the *common.ZKInputs to the ServerProof to compute the Proof

func (*ProofServerClient) Cancel

func (p *ProofServerClient) Cancel(ctx context.Context) error

Cancel cancels any current proof computation

func (*ProofServerClient) GetProof

func (p *ProofServerClient) GetProof(ctx context.Context) (*Proof, []*big.Int, error)

GetProof retrieves the Proof and Public Data (public inputs) from the ServerProof, blocking until the proof is ready.

func (*ProofServerClient) WaitReady

func (p *ProofServerClient) WaitReady(ctx context.Context) error

WaitReady waits until the serverProof is ready

type PublicInputs

type PublicInputs []*big.Int

PublicInputs are the public inputs of the proof

func (*PublicInputs) UnmarshalJSON

func (p *PublicInputs) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the JSON into the public inputs where the bigInts are in decimal as quoted strings

type Status

type Status struct {
	Status  StatusCode `json:"status"`
	Proof   string     `json:"proof"`
	PubData string     `json:"pubData"`
}

Status is the return struct for the status API endpoint

type StatusCode

type StatusCode string

StatusCode is the status string of the ProofServer

const (
	// StatusCodeAborted means prover is ready to take new proof. Previous
	// proof was aborted.
	StatusCodeAborted StatusCode = "aborted"
	// StatusCodeBusy means prover is busy computing proof.
	StatusCodeBusy StatusCode = "busy"
	// StatusCodeFailed means prover is ready to take new proof. Previous
	// proof failed
	StatusCodeFailed StatusCode = "failed"
	// StatusCodeSuccess means prover is ready to take new proof. Previous
	// proof succeeded
	StatusCodeSuccess StatusCode = "success"
	// StatusCodeUnverified means prover is ready to take new proof.
	// Previous proof was unverified
	StatusCodeUnverified StatusCode = "unverified"
	// StatusCodeUninitialized means prover is not initialized
	StatusCodeUninitialized StatusCode = "uninitialized"
	// StatusCodeUndefined means prover is in an undefined state. Most
	// likely is booting up. Keep trying
	StatusCodeUndefined StatusCode = "undefined"
	// StatusCodeInitializing means prover is initializing and not ready yet
	StatusCodeInitializing StatusCode = "initializing"
	// StatusCodeReady means prover initialized and ready to do first proof
	StatusCodeReady StatusCode = "ready"
)

func (StatusCode) IsInitialized

func (status StatusCode) IsInitialized() bool

IsInitialized returns true when the prover is initialized

func (StatusCode) IsReady

func (status StatusCode) IsReady() bool

IsReady returns true when the prover is ready

Jump to

Keyboard shortcuts

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