Skip to content

Commit

Permalink
verify encoding of shares in case when axis is fully reconstructed fr…
Browse files Browse the repository at this point in the history
…om orthogonal
  • Loading branch information
walldiss committed Apr 9, 2024
1 parent 2df5f8a commit 753d463
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions extendeddatacrossword.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,7 @@ func (eds *ExtendedDataSquare) solveCrosswordRow(

// Prepare shares
shares := make([][]byte, eds.width)
vectorData := eds.row(uint(r))
for c := 0; c < int(eds.width); c++ {
shares[c] = vectorData[c]
}
copy(shares, eds.row(uint(r)))

// Attempt rebuild the row
rebuiltShares, isDecoded, err := eds.rebuildShares(shares)
Expand Down Expand Up @@ -177,6 +174,10 @@ func (eds *ExtendedDataSquare) solveCrosswordRow(
}
return false, false, err
}

if eds.verifyEncoding(col, r, rebuiltShares[c]) != nil {
return false, false, &ErrByzantineData{Col, uint(c), col}

Check warning on line 179 in extendeddatacrossword.go

View check run for this annotation

Codecov / codecov/patch

extendeddatacrossword.go#L179

Added line #L179 was not covered by tests
}
}
}

Expand Down Expand Up @@ -211,10 +212,7 @@ func (eds *ExtendedDataSquare) solveCrosswordCol(

// Prepare shares
shares := make([][]byte, eds.width)
vectorData := eds.col(uint(c))
for r := 0; r < int(eds.width); r++ {
shares[r] = vectorData[r]
}
copy(shares, eds.col(uint(c)))

// Attempt rebuild
rebuiltShares, isDecoded, err := eds.rebuildShares(shares)
Expand Down Expand Up @@ -250,6 +248,10 @@ func (eds *ExtendedDataSquare) solveCrosswordCol(
}
return false, false, err
}

if eds.verifyEncoding(row, c, rebuiltShares[r]) != nil {
return false, false, &ErrByzantineData{Row, uint(r), row}

Check warning on line 253 in extendeddatacrossword.go

View check run for this annotation

Codecov / codecov/patch

extendeddatacrossword.go#L252-L253

Added lines #L252 - L253 were not covered by tests
}
}
}

Expand Down Expand Up @@ -468,3 +470,22 @@ func (eds *ExtendedDataSquare) computeSharesRootWithRebuiltShare(shares [][]byte
}
return tree.Root()
}

func (eds *ExtendedDataSquare) verifyEncoding(data [][]byte, rebuiltIndex int, rebuiltShare []byte) error {
data[rebuiltIndex] = rebuiltShare
half := len(data) / 2
original := data[:half]
parity, err := eds.codec.Encode(original)
if err != nil {
return err

Check warning on line 480 in extendeddatacrossword.go

View check run for this annotation

Codecov / codecov/patch

extendeddatacrossword.go#L480

Added line #L480 was not covered by tests
}

for i := half; i < len(data); i++ {
if !bytes.Equal(data[i], parity[i-half]) {
data[rebuiltIndex] = nil
return errors.New("parity data does not match encoded data")

Check warning on line 486 in extendeddatacrossword.go

View check run for this annotation

Codecov / codecov/patch

extendeddatacrossword.go#L485-L486

Added lines #L485 - L486 were not covered by tests
}
}

return nil
}

0 comments on commit 753d463

Please sign in to comment.