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(crypto/multisig): set compat.AminoBz when unpacking interfaces #20972

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 7 additions & 0 deletions crypto/keys/multisig/multisig.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ func (m *LegacyAminoPubKey) UnpackInterfaces(unpacker types.AnyUnpacker) error {
if err != nil {
return err
}

if pk != nil {
// sets the compat.aminoBz value
if err = any.UnmarshalAmino(pk.Bytes()); err != nil {
return err
}
}
Comment on lines +160 to +165
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure proper error handling and nil checks in UnpackInterfaces.

The changes introduced in the UnpackInterfaces method are crucial for maintaining symmetry between constructed and unmarshalled pubkeys. The conditional block that sets compat.AminoBz is well-placed and correctly checks for pk != nil before proceeding. However, it's important to ensure that pk.Bytes() does not return nil or cause a panic. Consider adding a nil check or error handling for pk.Bytes().

Additionally, the use of UnpackAny and UnmarshalAmino should be closely monitored for performance implications, especially in a loop, as these operations can be costly.

- if err = any.UnmarshalAmino(pk.Bytes()); err != nil {
+ bytes := pk.Bytes()
+ if bytes == nil {
+     return fmt.Errorf("pk.Bytes() returned nil")
+ }
+ if err = any.UnmarshalAmino(bytes); err != nil {
    return err
}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if pk != nil {
// sets the compat.aminoBz value
if err = any.UnmarshalAmino(pk.Bytes()); err != nil {
return err
}
}
if pk != nil {
// sets the compat.aminoBz value
bytes := pk.Bytes()
if bytes == nil {
return fmt.Errorf("pk.Bytes() returned nil")
}
if err = any.UnmarshalAmino(bytes); err != nil {
return err
}
}

}
return nil
}
Expand Down
Loading