Skip to content
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

Require MsgWirePayForData and MsgPayForData txs to sign over all relevant square sizes to be considered valid #620

Closed
evan-forbes opened this issue Aug 17, 2022 · 5 comments · Fixed by #666
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@evan-forbes
Copy link
Member

Currently, someone can easily modify the code to not sign over any square sizes, or only sign over a single square size. Transaction with only a single singed square size will tend to get stuck in mempools, and txs with no signed over square sizes will get stuck in the mempool.

To prevent this, we could add a check to the ValidateBasic methods to ensure that all relevant shares are signed over. This will ensure that WirePayForData transactions do not get stuck in mempools.

more info in relevant square sizes can be found in #236

@evan-forbes evan-forbes added bug Something isn't working good first issue Good for newcomers C: Celestia app labels Aug 17, 2022
@rootulp
Copy link
Collaborator

rootulp commented Aug 24, 2022

I agree that these transactions need to sign over at least one message square to be considered valid. However it seems possible for there to be only one valid square size that a user signs over when the message they send can only fit in the largest possible square k=128 (based on specs and this line). Therefore, it's not clear to me how we should handle the case where only one square size is signed over. I don't think we should throw an error from ValidateBasic() for this scenario because it's valid but unlikely.

@rootulp rootulp self-assigned this Aug 24, 2022
@adlerjohn
Copy link
Member

adlerjohn commented Aug 24, 2022

There being only one valid configuration isn't contradictory to "we could add a check to the ValidateBasic methods to ensure that all relevant shares are signed over." If it turns out there's only one, then them's the breaks.

@rootulp
Copy link
Collaborator

rootulp commented Aug 24, 2022

we could add a check to the ValidateBasic methods to ensure that all relevant shares are signed over.

Sorry I don't understand what check needs to be added. Is this not sufficient?

for idx, commit := range msg.MessageShareCommitment {
// check that each commit is valid
if !powerOf2(commit.K) {
return ErrCommittedSquareSizeNotPowOf2.Wrapf("committed to square size: %d", commit.K)
}
calculatedCommit, err := CreateCommitment(commit.K, msg.GetMessageNameSpaceId(), msg.Message)
if err != nil {
return ErrCalculateCommit.Wrap(err.Error())
}
if !bytes.Equal(calculatedCommit, commit.ShareCommitment) {
return ErrInvalidShareCommit.Wrapf("for square size %d and commit number %v", commit.K, idx)
}
}

@evan-forbes
Copy link
Member Author

evan-forbes commented Aug 24, 2022

ideally we would have a function that determines all of the possible square sizes to sign over, not unlike

// AllSquareSizes calculates all of the square sizes that message could possibly
// fit in
func AllSquareSizes(msgSize int) []uint64 {
allSizes := allSquareSizes
fitSizes := []uint64{}
shareCount := MsgSharesUsed(msgSize)
for _, size := range allSizes {
// if the number of shares is larger than that in the square, throw an error
// note, we use k*k-1 here because at least a single share will be reserved
// for the transaction paying for the message, therefore the max number of
// shares a message can be is number of shares in square -1.
if shareCount > (size*size)-1 {
continue
}
fitSizes = append(fitSizes, uint64(size))
}
return fitSizes
}

so the extra check would check that these sizes are signed over

related but separate is an optimized version of this

from #236

This does not account for the fact that commitments do not change if the largest power of two that is smaller than the message can fit on a single row. Meaning that if the largest power of 2 that fits in a message can fit on a single row of square size x, then that commitment is valid for all square sizes >= x.

@rootulp
Copy link
Collaborator

rootulp commented Aug 29, 2022

Thanks for clarifying @adlerjohn @evan-forbes ! I understand now and think #666 should resolve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants