poet

package
v0.0.0-...-f9e9dd4 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2019 License: MIT Imports: 13 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HashSize = *flag.Int("Hash_Size_Bytes", 32, "Set the hash size") // TODO: Set Dynamically based on hash library

)

Functions

func BinaryIDListEqual

func BinaryIDListEqual(b1 []*BinaryID, b2 []*BinaryID) bool

func ComputeLabel

func ComputeLabel(node *BinaryID, cOpts *ComputeOpts) []byte

ComputeLabel of a node id

func DebugOutput

func DebugOutput()

func DebugSupress

func DebugSupress()

func Index

func Index(b *BinaryID, dag_n int) (index int)

func PrintDAG

func PrintDAG(b *BinaryID, dag_n int, store StorageIO, pre string)

func StringList

func StringList(bList []*BinaryID) string

Pretty printing function for a list of BinaryID's. Primarily for Debugging

func TreeSize

func TreeSize(b *BinaryID, dag_n int) (size int)

Types

type BinaryID

type BinaryID struct {
	Val    []byte `json:"Values"`
	Length int    `json:"Length"`
}

BinaryID is a binary representation of the ID of a node. The length is needed because we need to identify between 0 and 00 for example. Note: added json Marshalling. Currently, encoding is base64 (for []byte). This is default for []byte in Go, but can change as needed.

func CalcNIPChallenge

func CalcNIPChallenge(rootHash []byte, cOpts *ComputeOpts) (b_list []*BinaryID)

func CheckAndAdd

func CheckAndAdd(BinIDs []*BinaryID, BinID *BinaryID) ([]*BinaryID, bool)

CheckAndAdd checks if the BinID is already in the list then adds it if it wasn't already there. Also returns true if the BinID was added to the list.

func GammaToBinaryIDs

func GammaToBinaryIDs(gamma []byte, dag_n int) ([]*BinaryID, error)

func GetParents

func GetParents(node *BinaryID, dag_n int) ([]*BinaryID, error)

GetParents get parents of a node

func NewBinaryID

func NewBinaryID(val uint, length int) (*BinaryID, error)

func NewBinaryIDBytes

func NewBinaryIDBytes(v []byte) *BinaryID

func NewBinaryIDCopy

func NewBinaryIDCopy(b *BinaryID) (b2 *BinaryID)

func NewBinaryIDInt

func NewBinaryIDInt(val uint) *BinaryID

func Siblings

func Siblings(node *BinaryID, left bool) ([]*BinaryID, error)

Siblings returns the list of siblings along the path to the root

Takes in an instance of class BinaryString and returns a list of the siblings of the nodes of the path to to root of a binary tree. Also returns the node itself, so there are N+1 items in the list for a tree with length N.

func (*BinaryID) AddBit

func (b *BinaryID) AddBit(n int) error

Adds 0 or 1 to lsb of BinaryID. Returns error if not 0 or 1

func (*BinaryID) Encode

func (b *BinaryID) Encode() (v []byte)

Encode outputs a []byte encoded in utf8

func (*BinaryID) Equal

func (b *BinaryID) Equal(b2 *BinaryID) bool

func (*BinaryID) FlipBit

func (b *BinaryID) FlipBit(n int)

Flip the n'th bit from 0 to 1 or 1 to 0. Does nothing if n > length

func (*BinaryID) GetBit

func (b *BinaryID) GetBit(n int) (int, error)

Returns if n'th bit is 0 or 1. Error if n > Length n'th bit from the left. So for 1011 the 1'st bit is the first 1 on the left

func (*BinaryID) GreaterThan

func (b *BinaryID) GreaterThan(b2 *BinaryID) bool

func (*BinaryID) String

func (b *BinaryID) String() string

Pretty printing function for debugging. Not for encoding.

func (*BinaryID) TruncateLastBit

func (b *BinaryID) TruncateLastBit()

type ComputeOpts

type ComputeOpts struct {
	Commitment     []byte
	CommitmentHash []byte
	Hash           HashFunc
	Store          StorageIO
	T              uint
	N              int
}

type FileIO

type FileIO struct {
	// contains filtered or unexported fields
}

func NewFileIO

func NewFileIO() (f *FileIO)

func (*FileIO) GetLabel

func (f *FileIO) GetLabel(b *BinaryID) (label []byte, err error)

func (*FileIO) LabelCalculated

func (f *FileIO) LabelCalculated(b *BinaryID) (bool, error)

func (*FileIO) SetDAGSize

func (f *FileIO) SetDAGSize(size int)

func (*FileIO) StoreLabel

func (f *FileIO) StoreLabel(b *BinaryID, label []byte) error

type HashFunc

type HashFunc interface {
	HashVals(vs ...[]byte) []byte
}

func NewSHA256

func NewSHA256() HashFunc

type Hasher

type Hasher struct {
	BaseHash hash.Hash
}

func (*Hasher) HashVals

func (h *Hasher) HashVals(vs ...[]byte) (b []byte)

TODO: Will need to Benchmark this along with Unit testing. Could have significant speed upgrades by using the sha256 package correctly. Need to research that package and use more completely.

type Prover

type Prover struct {
	// contains filtered or unexported fields
}

This type will provide the inteface to the Prover. It implements the io.ReadWriter interface, which will allow it to sit behind an RPC Server or be linked directly to a verifier. CurrentState is used to

func NewProver

func NewProver() *Prover

func (*Prover) CalcChallengeProof

func (p *Prover) CalcChallengeProof(gamma []byte) error

CalcChallengeProof

func (*Prover) CalcCommitProof

func (p *Prover) CalcCommitProof(commitment []byte) error

CalcCommitProof calculates the proof of seqeuntial work

func (*Prover) CalcNIPCommitProof

func (p *Prover) CalcNIPCommitProof() error

CalcNIPCommitProof proof created by computing openH for the challenge TODO: modify so that each Hx(phi, i) is used to calc challenge (first n bits)

func (*Prover) ChallengeProof

func (p *Prover) ChallengeProof() (b [][]byte, err error)

SendChallengeProof

func (*Prover) ChangeDAGSize

func (p *Prover) ChangeDAGSize(size int)

Can only call this before the DAG has started to be calculated. Need to add a flag and check for this. TODO: might be cleaner to have n as a field in the Prover struct. Also would need to have it as a field in BinaryID as well in that case.

func (*Prover) ChangeHashFunc

func (p *Prover) ChangeHashFunc(hfunc HashFunc)

func (*Prover) ChangeT

func (p *Prover) ChangeT(t uint)

func (*Prover) Clean

func (p *Prover) Clean()

func (*Prover) CommitProof

func (p *Prover) CommitProof() (b []byte, err error)

CommitProof returns phi (root Hash)

func (*Prover) ShowDAG

func (p *Prover) ShowDAG()

type SetDAGSizer

type SetDAGSizer interface {
	SetDAGSize(size int)
}

Some storageIO implementations need to know about the DAG Size (n) Calls to change DAG size will check if the storageIO can change DAG size then will forward call this interface function.

type StorageIO

type StorageIO interface {
	StoreLabel(b *BinaryID, label []byte) error
	GetLabel(*BinaryID) (label []byte, err error)
	LabelCalculated(*BinaryID) (bool, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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