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

Add square sizes flag to the payForMessage cli command #202

Merged
merged 25 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1fecce2
add new flags
toanngosy Feb 5, 2022
41f9319
add celestia flags
toanngosy Feb 5, 2022
ecec3f0
use square size in cli wirepayformessage
toanngosy Feb 5, 2022
de95c78
add square size in app
toanngosy Feb 7, 2022
ff0637e
update test for arbitrary square size
toanngosy Feb 7, 2022
962b407
refactor flags
toanngosy Feb 9, 2022
8b1ec7f
shorten flags file
toanngosy Feb 11, 2022
e5f4b35
update nwpfm to receive list of square sizes
toanngosy Feb 11, 2022
f18fc52
add a new test case for list of square sizes
toanngosy Feb 11, 2022
8f30563
add back square size
toanngosy Feb 11, 2022
c71313c
unchange abci
toanngosy Feb 11, 2022
78b9fd4
refactor parse uint to uint64
toanngosy Feb 11, 2022
bb2c8db
add power of 2 check
toanngosy Feb 11, 2022
ae9f466
add test case for invalid square size
toanngosy Feb 11, 2022
b08447b
update description flags
toanngosy Feb 11, 2022
08ea197
move and update powerof2 func
toanngosy Feb 12, 2022
d3cca6f
update powerOf2 func
toanngosy Feb 12, 2022
5498a55
add test to powerOf2
toanngosy Feb 12, 2022
c94130c
delete gap
toanngosy Feb 13, 2022
33c7791
move check power of 2 first
toanngosy Feb 13, 2022
2d58081
move flag to wirepayformessage
toanngosy Feb 13, 2022
27928a7
move const FlagSquareSizes to wirepayformessage
toanngosy Feb 13, 2022
6da8dc9
add test for invalid square size in pfm ValidateBasic
toanngosy Feb 13, 2022
28bb0c4
add 1 more test where change square size to another power of 2 number
toanngosy Feb 13, 2022
80b52ab
change squaresize to 4 to pass the test
toanngosy Feb 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions x/payment/client/cli/wirepayformessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ func CmdWirePayForMessage() *cobra.Command {
return err
}

squareSizes64 := make([]uint64, len(squareSizes))
for i := range squareSizes {
squareSizes64[i] = uint64(squareSizes[i])
}
squareSizes64 := parseSquareSizes(squareSizes)
pfmMsg, err := types.NewWirePayForMessage(namespace, message, squareSizes64...)

evan-forbes marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
Expand Down Expand Up @@ -116,3 +113,11 @@ func CmdWirePayForMessage() *cobra.Command {

return cmd
}

func parseSquareSizes(squareSizes []uint) []uint64 {
squareSizes64 := make([]uint64, len(squareSizes))
for i := range squareSizes {
squareSizes64[i] = uint64(squareSizes[i])
}
return squareSizes64
}
13 changes: 13 additions & 0 deletions x/payment/client/testutil/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ func (s *IntegrationTestSuite) TestSubmitWirePayForMessage() {
},
false, 0, &sdk.TxResponse{},
},
{
"invalid transaction list of square sizes",
[]string{
hexNS,
hexMsg,
fmt.Sprintf("--from=%s", username),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2))).String()),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", cflags.FlagSquareSizes, "256,123,64"),
},
true, 0, &sdk.TxResponse{},
},
evan-forbes marked this conversation as resolved.
Show resolved Hide resolved
}

for _, tc := range testCases {
Expand Down
17 changes: 17 additions & 0 deletions x/payment/types/wirepayformessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ func NewWirePayForMessage(namespace, message []byte, sizes ...uint64) (*MsgWireP

// generate the share commitments
for i, size := range sizes {
if !powerOf2(size) {
return nil, fmt.Errorf("Invalid square size, the size must be power of 2: %d", size)
}
commit, err := CreateCommitment(size, namespace, message)
if err != nil {
return nil, err
Expand Down Expand Up @@ -106,6 +109,10 @@ func (msg *MsgWirePayForMessage) ValidateBasic() error {
return err
}

if !powerOf2(commit.K) {
return fmt.Errorf("invalid square size, the size must be power of 2: %d", commit.K)
}
evan-forbes marked this conversation as resolved.
Show resolved Hide resolved
evan-forbes marked this conversation as resolved.
Show resolved Hide resolved

if string(calculatedCommit) != string(commit.ShareCommitment) {
return fmt.Errorf("invalid commit for square size %d", commit.K)
}
Expand Down Expand Up @@ -206,3 +213,13 @@ func ProcessWirePayForMessage(msg *MsgWirePayForMessage, squareSize uint64) (*tm

return &coreMsg, pfm, shareCommit.Signature, nil
}


// Check if number is power of 2
func powerOf2(size uint64) bool {
if size & (size-1) == 0 {
return true
} else {
return false
}
}
evan-forbes marked this conversation as resolved.
Show resolved Hide resolved