Documentation ¶
Index ¶
- Constants
- Variables
- func ProofPositions(targets []uint64, numLeaves uint64, forestRows uint8, proofPositions *[]uint64) int64
- type BatchProof
- func (bp *BatchProof) Deserialize(r io.Reader) (err error)
- func (bp *BatchProof) Reconstruct(numleaves uint64, forestRows uint8) (map[uint64]Hash, error)
- func (bp *BatchProof) Serialize(w io.Writer) (err error)
- func (bp *BatchProof) SerializeBytes() ([]byte, error)
- func (bp *BatchProof) SerializeSize() int
- func (bp *BatchProof) ToString() string
- type Forest
- func (f *Forest) Add(adds []Leaf)
- func (f *Forest) AssertEqual(compareForest *Forest) error
- func (f *Forest) BuildUndoData(numadds uint64, dels []uint64) *UndoBlock
- func (f *Forest) FindLeaf(leaf Hash) bool
- func (f *Forest) GetRoots() []Hash
- func (f *Forest) Modify(adds []Leaf, delsUn []uint64) (*UndoBlock, error)
- func (f *Forest) PosMapSanity() error
- func (f *Forest) PrintPositionMap() string
- func (f *Forest) Prove(wanted Hash) (Proof, error)
- func (f *Forest) ProveBatch(hs []Hash) (BatchProof, error)
- func (f *Forest) ProveMany(hs []Hash) ([]Proof, error)
- func (f *Forest) Stats() string
- func (f *Forest) ToString() string
- func (f *Forest) Undo(ub UndoBlock) error
- func (f *Forest) Verify(p Proof) bool
- func (f *Forest) VerifyBatchProof(toProve []Hash, bp BatchProof) error
- func (f *Forest) VerifyMany(ps []Proof) bool
- func (f *Forest) WriteForestToDisk(dumpFile *os.File, ram, cow bool) error
- func (f *Forest) WriteMiscData(miscForestFile *os.File) error
- type ForestData
- type ForestType
- type Hash
- type Leaf
- type MiniHash
- type Pollard
- func (p *Pollard) Deserialize(serialized []byte) error
- func (p *Pollard) GetRoots() (h []Hash)
- func (p *Pollard) GetTotalCount() int64
- func (p *Pollard) IngestBatchProof(toProve []Hash, bp BatchProof, rememberAll bool) error
- func (p *Pollard) Modify(adds []Leaf, delsUn []uint64) error
- func (p *Pollard) NumLeaves() uint64
- func (p *Pollard) PosMapSanity() error
- func (p *Pollard) PrintRemembers() (string, error)
- func (p *Pollard) ProveBatch(hs []Hash) (BatchProof, error)
- func (p *Pollard) PruneAll()
- func (p *Pollard) ReconstructStats() (uint64, uint8)
- func (p *Pollard) RestorePollard(r io.Reader) error
- func (p *Pollard) Serialize() ([]byte, error)
- func (p *Pollard) Stats() string
- func (p *Pollard) ToString() string
- func (p *Pollard) VerifyBatchProof(toProve []Hash, bp BatchProof) error
- func (p *Pollard) WritePollard(w io.Writer) error
- type PositionList
- type Proof
- type UndoBlock
Constants ¶
const ( ErrorNotEnoughTrees uint32 = iota ErrorNoPollardNode )
Variables ¶
var (
ErrorCorruptManifest = errors.New("Manifest is corrupted. Recovery needed")
)
var ErrorStrings = map[uint32]error{ ErrorNotEnoughTrees: fmt.Errorf("ErrorNotEnoughTrees"), ErrorNoPollardNode: fmt.Errorf("ErrorNoPollardNode"), }
Functions ¶
Types ¶
type BatchProof ¶
type BatchProof struct { // Targets are the ist of leaf locations to delete. These are the bottommost leaves. // With the tree below, the Targets can only consist of one of these: 00, 01, 02, 03 // // 06 // |-------\ // 04 05 // |---\ |---\ // 00 01 02 03 Targets []uint64 // All the nodes in the tree that are needed to hash up to the root of // the tree. Here, the root is 06. If Targets are [00, 01], then Proof // would be [05] as you need 04 and 05 to hash to 06. 04 can be calculated // by hashing 00 and 01. // // 06 // |-------\ // 04 05 // |---\ |---\ // 00 01 02 03 Proof []Hash }
BatchProof is the inclusion-proof for multiple leaves.
func DeserializeBPFromBytes ¶
func DeserializeBPFromBytes(serialized []byte) (*BatchProof, error)
DeserializeBPFromBytes, given serialized bytes, returns a pointer to the deserialized batchproof. The deserialization is the same as Deserialize() method on BatchProof
func (*BatchProof) Deserialize ¶
func (bp *BatchProof) Deserialize(r io.Reader) (err error)
Deserialize gives a BatchProof back from a reader.
func (*BatchProof) Reconstruct ¶
Reconstruct takes a number of leaves and rows, and turns a block proof back into a partial proof tree. Should leave bp intact
func (*BatchProof) Serialize ¶
func (bp *BatchProof) Serialize(w io.Writer) (err error)
Serialize serializes a batchproof to a writer.
func (*BatchProof) SerializeBytes ¶
func (bp *BatchProof) SerializeBytes() ([]byte, error)
SerializeBytes serializes and returns the batchproof as raw bytes the serialization is the same as Serialize() method
func (*BatchProof) SerializeSize ¶
func (bp *BatchProof) SerializeSize() int
SerializeSize returns the number of bytes it would take to serialize the BatchProof.
func (*BatchProof) ToString ¶
func (bp *BatchProof) ToString() string
ToString for debugging, shows the blockproof
type Forest ¶
type Forest struct {
// contains filtered or unexported fields
}
Forest is the entire accumulator of the UTXO set as either a: 1) slice if the forest is stored in memory. 2) single file if the forest is stored in disk. A leaf represents a UTXO with additional data for verification. This leaf is numbered from bottom left to right. Example of a forest with 4 numLeaves:
06 |------\ 04......05 |---\...|---\ 00..01..02..03
04 is the concatenation and the hash of 00 and 01. 06 is the root This tree would have a row of 2.
func NewForest ¶
NewForest initializes a Forest and returns it. The given arguments determine what type of forest it will be.
func RestoreForest ¶
func RestoreForest( miscForestFile *os.File, forestFile *os.File, toRAM, cached bool, cow string, cowMaxCache int) (*Forest, error)
RestoreForest restores the forest on restart. Needed when resuming after exiting. miscForestFile is where numLeaves and rows is stored
func (*Forest) AssertEqual ¶
AssertEqual compares the two forests. Returns an error if the forests are not equal. The data meant for statics are not checked and the function will return true if all other fields are equal.
func (*Forest) BuildUndoData ¶
BuildUndoData makes an undoBlock from the same data that you'd give to Modify
func (*Forest) Modify ¶
Modify changes the forest, adding and deleting leaves and updating internal nodes. Note that this does not modify in place! All deletes occur simultaneous with adds, which show up on the right. Also, the deletes need there to be correct proof data, so you should first call Verify().
func (*Forest) PosMapSanity ¶
PosMapSanity is costly / slow: check that everything in posMap is correct
func (*Forest) PrintPositionMap ¶
func (*Forest) ProveBatch ¶
func (f *Forest) ProveBatch(hs []Hash) (BatchProof, error)
ProveBatch gets proofs (in the form of a node slice) for a bunch of leaves The ordering of Targets is the same as the ordering of hashes given as argument.
NOTE: The order in which the hashes are given matter when verifying (aka permutation matters).
func (*Forest) Stats ¶
Stats returns the current forest statics as a string. This includes number of total leaves, historic hashes, length of the position map, and the size of the forest
func (*Forest) VerifyBatchProof ¶
func (f *Forest) VerifyBatchProof(toProve []Hash, bp BatchProof) error
VerifyBatchProof is just a wrapper around verifyBatchProof
func (*Forest) VerifyMany ¶
VerifyMany is like verify but more.
func (*Forest) WriteForestToDisk ¶
WriteForestToDisk writes the whole forest to disk this only makes sense to do if the forest is in ram. So it'll return an error if it's not a ramForestData
type ForestData ¶
type ForestData interface {
// contains filtered or unexported methods
}
ForestData is the thing that holds all the hashes in the forest. Could be in a file, or in ram, or maybe something else.
type ForestType ¶
type ForestType int
ForestType defines the 4 type of forests: DiskForest, RamForest, CacheForest, CowForest
const ( // DiskForest - keeps the entire forest on disk as a flat file. Is the slowest // of them all. Pass an os.File as forestFile to create a DiskForest. DiskForest ForestType = iota // RamForest - keeps the entire forest on ram as a slice. Is the fastest but // takes up a lot of ram. Is compatible with DiskForest (as in you // can restart as RamForest even if you created a DiskForest. Pass // nil, as the forestFile to create a RamForest. RamForest // CacheForest - keeps the entire forest on disk but caches recent nodes. It's // faster than disk. Is compatible with the above two forest types. // Pass cached = true to create a cacheForest. CacheForest // CowForest - A copy-on-write (really a redirect on write) forest. It strikes // a balance between ram usage and speed. Not compatible with other // forest types though (meaning there isn't functionality implemented // to convert a CowForest to DiskForest and vise-versa). Pass a filepath // and cowMaxCache(how much MB to use in ram) to create a CowForest. CowForest )
type Hash ¶
type Hash [32]byte
Hash is the 32 bytes of a sha256 hash
func HashFromString ¶
HashFromString takes a string and hashes with sha256
type Leaf ¶
Leaf contains a hash and a hint about whether it should be saved to memory or not during ibdsim.
type Pollard ¶
type Pollard struct { // Lookahead is the threshold that sets which leaves should be cached. // TODO not currently implemented yet. Lookahead int32 // contains filtered or unexported fields }
Pollard is the sparse representation of the utreexo forest, represented as a collection of binary trees.
func NewFullPollard ¶
func NewFullPollard() Pollard
NewFullPollard gives you a Pollard with an activated
func (*Pollard) Deserialize ¶
Deserialize decodes the bytes into a Pollard
func (*Pollard) GetTotalCount ¶
GetTotalCount returns the count of all the polNodes in the pollard.
func (*Pollard) IngestBatchProof ¶
func (p *Pollard) IngestBatchProof(toProve []Hash, bp BatchProof, rememberAll bool) error
IngestBatchProof populates the Pollard with all needed data to delete the targets in the block proof. If rememberAll is true, pollard will mark all the proofs given in the batchproof to be remembered.
NOTE: The order in which the hashes are given matter (aka permutation matters). The hashes being verified should be in the same order as they were proven.
func (*Pollard) PosMapSanity ¶
PosMapSanity is costly / slow: check that everything in posMap is correct
func (*Pollard) PrintRemembers ¶
PrintRemembers prints all the nodes and their remember status. Useful for debugging.
func (*Pollard) ProveBatch ¶
func (p *Pollard) ProveBatch(hs []Hash) (BatchProof, error)
ProveBatch but for pollard.
NOTE: The order in which the hashes are given matter when verifying (aka permutation matters).
func (*Pollard) PruneAll ¶
func (p *Pollard) PruneAll()
PruneAll prunes the accumulator down to the roots.
func (*Pollard) ReconstructStats ¶
ReconstructStats returns numleaves and row so that batch proofs can be reconstructed and hashes can be matches.
TODO Replace this with proofs that do not include the things being proven, and take the proved leaves as a separate argument
func (*Pollard) RestorePollard ¶
RestorePollard restores the pollard from the given reader
func (*Pollard) Serialize ¶
Serialize serializes the numLeaves field and only the roots into a byte slice. Cached leaves are not included in the byte slice
func (*Pollard) ToString ¶
ToString returns a string visualization of the Pollard that can be printed
func (*Pollard) VerifyBatchProof ¶
func (p *Pollard) VerifyBatchProof(toProve []Hash, bp BatchProof) error
VerifyBatchProof verifies the hash and the proof passed in. It does not make any modifications to the pollard.
NOTE: The order in which the hashes are given matter (aka permutation matters). The hashes being verified should be in the same order as they were proven.
type PositionList ¶
type PositionList struct {
// contains filtered or unexported fields
}
PositionList is a wrapper around slice of ints.
func NewPositionList ¶
func NewPositionList() *PositionList
NewPositionList returns a slice of uint64 from the pool
func (*PositionList) Free ¶
func (pl *PositionList) Free()
Free returns the slice of uint64 back to the pool
type Proof ¶
type Proof struct { Position uint64 // where at the bottom of the tree it sits Payload Hash // hash of the thing itself (what's getting proved) Siblings []Hash // slice of siblings up to a root }
Proof :
type UndoBlock ¶
type UndoBlock struct { Height int32 // height of block // contains filtered or unexported fields }
blockUndo is all the data needed to undo a block: number of adds, and all the hashes that got deleted and where they were from
func (*UndoBlock) Deserialize ¶
Deserialize decodes an undoblock from the reader.
func (*UndoBlock) SerializeSize ¶
SerializeSize returns how many bytes it would take to serialize this undoblock.