Skip to content

Commit

Permalink
change name of CellIndex to SquareIndex to avoid using the same name
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-forbes committed Mar 27, 2021
1 parent ca5dd8e commit 1f35c00
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
8 changes: 4 additions & 4 deletions datasquare.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (ds *dataSquare) RowRoot(x uint) []byte {

tree := ds.createTreeFn()
for i, d := range ds.Row(x) {
tree.Push(d, CellIndex{CellIndex: uint(i), AxisIndex: x})
tree.Push(d, SquareIndex{Cell: uint(i), Axis: x})
}

return tree.Root()
Expand All @@ -191,7 +191,7 @@ func (ds *dataSquare) ColRoot(y uint) []byte {

tree := ds.createTreeFn()
for i, d := range ds.Column(y) {
tree.Push(d, CellIndex{CellIndex: uint(i), AxisIndex: y})
tree.Push(d, SquareIndex{Axis: y, Cell: uint(i)})
}

return tree.Root()
Expand All @@ -202,7 +202,7 @@ func (ds *dataSquare) computeRowProof(x uint, y uint) ([]byte, [][]byte, uint, u
data := ds.Row(x)

for i := uint(0); i < ds.width; i++ {
tree.Push(data[i], CellIndex{CellIndex: uint(i), AxisIndex: y})
tree.Push(data[i], SquareIndex{Axis: y, Cell: uint(i)})
}

merkleRoot, proof, proofIndex, numLeaves := tree.Prove(int(y))
Expand All @@ -214,7 +214,7 @@ func (ds *dataSquare) computeColumnProof(x uint, y uint) ([]byte, [][]byte, uint
data := ds.Column(y)

for i := uint(0); i < ds.width; i++ {
tree.Push(data[i], CellIndex{CellIndex: uint(i), AxisIndex: y})
tree.Push(data[i], SquareIndex{Axis: y, Cell: uint(i)})
}
// TODO(ismail): check for overflow when casting from uint -> int
merkleRoot, proof, proofIndex, numLeaves := tree.Prove(int(x))
Expand Down
11 changes: 5 additions & 6 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ import (
// TreeConstructorFn creates a fresh Tree instance to be used as the Merkle inside of rsmt2d.
type TreeConstructorFn = func() Tree

// CellIndex contains all information needed to identify the cell that is being
// SquareIndex contains all information needed to identify the cell that is being
// pushed
type CellIndex struct {
AxisIndex uint
CellIndex uint
type SquareIndex struct {
Axis, Cell uint
}

// Tree wraps merkle tree implementations to work with rsmt2d
type Tree interface {
Push(data []byte, idx CellIndex)
Push(data []byte, idx SquareIndex)
// TODO(ismail): is this general enough?
Prove(idx int) (merkleRoot []byte, proofSet [][]byte, proofIndex uint64, numLeaves uint64)
Root() []byte
Expand All @@ -40,7 +39,7 @@ func NewDefaultTree() Tree {
}
}

func (d *DefaultTree) Push(data []byte, _idx CellIndex) {
func (d *DefaultTree) Push(data []byte, _idx SquareIndex) {
// ignore the idx, as this implementation doesn't need that info
d.leaves = append(d.leaves, data)
}
Expand Down

0 comments on commit 1f35c00

Please sign in to comment.