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

Enforce solo machine signature type uniqueness #7394

Merged
merged 26 commits into from
Oct 1, 2020

Conversation

colin-axner
Copy link
Contributor

@colin-axner colin-axner commented Sep 25, 2020

Description

closes: #7277


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

@codecov
Copy link

codecov bot commented Sep 25, 2020

Codecov Report

Merging #7394 into master will increase coverage by 0.07%.
The diff coverage is 83.87%.

@@            Coverage Diff             @@
##           master    #7394      +/-   ##
==========================================
+ Coverage   54.99%   55.07%   +0.07%     
==========================================
  Files         588      588              
  Lines       36664    36760      +96     
==========================================
+ Hits        20163    20245      +82     
- Misses      14409    14417       +8     
- Partials     2092     2098       +6     

Adjusts SignatureAndData proto definition to take in a DataType. Updates misbehaviour basic validation to do checks on the data type. Adds unmarshaling tests.
@colin-axner colin-axner mentioned this pull request Sep 28, 2020
9 tasks
Rename CanUnmarshalDataByType -> UnmarshalDataByType. Return a new interface and error. Refactor tests to work. Refactor misbehaviour_handle.go to check unmarshaling of the data and DRY code by separating signature and data checks into its own function. Update godoc.
Copy link
Contributor Author

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

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

I think this is the cleanest way of handling DataType atm. This is one step closer to converting SignBytes to an interface/Any.

Changing SignBytes to an Any would reduce one marshaling layer and isn't too far of a step now that I have added the Data interface, but it also would make each proto data definition have sequence, timestamp, diversifier, and data type fields which is pretty redundant since we have like 9 types of data definitions. I'm not really sure what is better.

clientPrefixedPath := "clients/" + counterpartyClientIdentifier + "/" + host.ClientStatePath()
path, err := commitmenttypes.ApplyPrefix(prefix, clientPrefixedPath)
suite.Require().NoError(err)
path := suite.solomachine.GetClientStatePath(counterpartyClientIdentifier)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think ideally we abstract this in host for all path type's so the users doesn't need to call ApplyPrefix. I only abstracted this in solo machine because I started to write dup code and then figured I might as well do it for all path types

// unmarshaled into the specified data type.
func verifySignatureAndData(cdc codec.BinaryMarshaler, clientState ClientState, misbehaviour *Misbehaviour, sigAndData *SignatureAndData) error {
// ensure data can be unmarshaled to the specified data type
if _, err := UnmarshalDataByType(cdc, sigAndData.DataType, sigAndData.Data); err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this cannot be done in misbehaviour.validate basic because we need a codec that has registered the client state/consensus state interface

@@ -96,6 +99,29 @@ func ClientStateSignBytes(
diversifier string,
path commitmenttypes.MerklePath, // nolint: interfacer
clientState exported.ClientState,
) ([]byte, error) {
dataBz, err := ClientStateDataBytes(cdc, path, clientState)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

splitting this is useful testing and external callers

)

// Interface implementation checks.
var _, _, _, _ codectypes.UnpackInterfacesMessage = &ClientState{}, &ConsensusState{}, &Header{}, &HeaderData{}

// Data is an interface used for all the signature data bytes proto definitions.
type Data interface{}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is added just so I can return the unmarshaled data in UnmarshalDataByType

@@ -28,3 +32,13 @@ func (h Header) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
func (hd HeaderData) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
return unpacker.UnpackAny(hd.NewPubKey, new(crypto.PubKey))
}

// UnpackInterfaces implements the UnpackInterfaceMessages.UnpackInterfaces method
func (csd ClientStateData) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we should do a sweep of all proto structs with Any to ensure these funcs are there. They are hard to debug we you run into the error

@colin-axner colin-axner marked this pull request as ready for review September 30, 2020 11:37
x/ibc/light-clients/solomachine/spec/01_concepts.md Outdated Show resolved Hide resolved
x/ibc/light-clients/solomachine/spec/01_concepts.md Outdated Show resolved Hide resolved
x/ibc/light-clients/solomachine/types/codec_test.go Outdated Show resolved Hide resolved
x/ibc/light-clients/solomachine/types/misbehaviour.go Outdated Show resolved Hide resolved
x/ibc/light-clients/solomachine/types/proof.go Outdated Show resolved Hide resolved
x/ibc/light-clients/solomachine/types/proof.go Outdated Show resolved Hide resolved
@colin-axner colin-axner requested a review from fedekunze October 1, 2020 09:05
Copy link
Collaborator

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

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

ACK

@fedekunze fedekunze added the A:automerge Automatically merge PR once all prerequisites pass. label Oct 1, 2020
Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

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

ACK 🎉

@fedekunze
Copy link
Collaborator

@colin-axner the async acks PR created some conflicts, can you fix them so it auto merges the PR 🙏

@colin-axner
Copy link
Contributor Author

colin-axner commented Oct 1, 2020

@colin-axner the async acks PR created some conflicts, can you fix them so it auto merges the PR 🙏

currently working on it. It'd be good to double check my diffs, the conflicts are non-trivial

@mergify mergify bot merged commit a32e2a0 into master Oct 1, 2020
@mergify mergify bot deleted the colin/7277-solo-uniqueness branch October 1, 2020 11:40
@colin-axner colin-axner mentioned this pull request Oct 30, 2020
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass. C:Encoding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Alter solo machine signature types to ensure uniqueness
3 participants