-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement proving that key is in hashmap (merkle proof)
- Loading branch information
1 parent
d1a4f3e
commit e0c3e01
Showing
4 changed files
with
179 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package boc | ||
|
||
type MerkleProver struct { | ||
root *immutableCell | ||
|
||
pruned map[*immutableCell]struct{} | ||
} | ||
|
||
func NewMerkleProver(root *Cell) (*MerkleProver, error) { | ||
immRoot, err := newImmutableCell(root, make(map[*Cell]*immutableCell)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &MerkleProver{root: immRoot, pruned: make(map[*immutableCell]struct{})}, nil | ||
} | ||
|
||
type Cursor struct { | ||
cell *immutableCell | ||
prover *MerkleProver | ||
} | ||
|
||
func (p *MerkleProver) Cursor() *Cursor { | ||
return &Cursor{cell: p.root, prover: p} | ||
} | ||
|
||
func (p *MerkleProver) CreateProof() ([]byte, error) { | ||
immRoot, err := p.root.pruneCells(p.pruned) | ||
if err != nil { | ||
return nil, err | ||
} | ||
mp := NewCell() | ||
mp.cellType = MerkleProofCell | ||
if err := mp.WriteUint(3, 8); err != nil { | ||
return nil, err | ||
} | ||
if err := mp.WriteBytes(p.root.Hash(0)); err != nil { | ||
return nil, err | ||
} | ||
if err := mp.WriteUint(uint64(p.root.Depth(0)), 16); err != nil { | ||
return nil, err | ||
} | ||
if err := mp.AddRef(immRoot); err != nil { | ||
return nil, err | ||
} | ||
mp.ResetCounters() | ||
return SerializeBoc(mp, false, false, false, 0) | ||
} | ||
|
||
func (c *Cursor) Prune() { | ||
c.prover.pruned[c.cell] = struct{}{} | ||
} | ||
|
||
func (c *Cursor) Ref(ref int) *Cursor { | ||
return &Cursor{cell: c.cell.refs[ref], prover: c.prover} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters