-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: verify encoding of shares in case when axis is fully reconstructed from orthogonal #313
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,10 +138,7 @@ | |
|
||
// 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) | ||
|
@@ -177,6 +174,10 @@ | |
} | ||
return false, false, err | ||
} | ||
|
||
if eds.verifyEncoding(col, r, rebuiltShares[c]) != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something worth consideration is the the precedence of these returned errors i.e., 1) root mismatch (due to the call to |
||
return false, false, &ErrByzantineData{Col, uint(c), col} | ||
} | ||
} | ||
} | ||
|
||
|
@@ -211,10 +212,7 @@ | |
|
||
// 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) | ||
|
@@ -250,6 +248,10 @@ | |
} | ||
return false, false, err | ||
} | ||
|
||
if eds.verifyEncoding(row, c, rebuiltShares[r]) != nil { | ||
return false, false, &ErrByzantineData{Row, uint(r), row} | ||
} | ||
} | ||
} | ||
|
||
|
@@ -468,3 +470,23 @@ | |
} | ||
return tree.Root() | ||
} | ||
|
||
// verifyEncoding checks the Reed-Solomon encoding of the provided data. | ||
func (eds *ExtendedDataSquare) verifyEncoding(data [][]byte, rebuiltIndex int, rebuiltShare []byte) error { | ||
staheri14 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
data[rebuiltIndex] = rebuiltShare | ||
half := len(data) / 2 | ||
original := data[:half] | ||
parity, err := eds.codec.Encode(original) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
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") | ||
} | ||
} | ||
|
||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated, just small simplification change to use builtin func instead of loop