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

fix: add validation on demand order id max length #656

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Changes from all commits
Commits
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
14 changes: 13 additions & 1 deletion x/eibc/types/tx.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import (
"encoding/hex"

sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand Down Expand Up @@ -37,7 +39,7 @@
}

func (m *MsgFulfillOrder) ValidateBasic() error {
if m.OrderId == "" {
if !m.isValidOrderId(m.OrderId) {
return ErrInvalidOrderID
}
_, err := sdk.AccAddressFromBech32(m.FulfillerAddress)
Expand All @@ -47,6 +49,16 @@
return nil
}

func (m *MsgFulfillOrder) isValidOrderId(orderId string) bool {
hashBytes, err := hex.DecodeString(orderId)
if err != nil {
// The string is not a valid hexadecimal string
return false
}

Check warning on line 57 in x/eibc/types/tx.go

View check run for this annotation

Codecov / codecov/patch

x/eibc/types/tx.go#L55-L57

Added lines #L55 - L57 were not covered by tests
// SHA-256 hashes are 32 bytes long
return len(hashBytes) == 32
}

func (m *MsgFulfillOrder) Validate() error {
if err := m.ValidateBasic(); err != nil {
return err
Expand Down
Loading