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

Make sure setters and getters cover edge cases #160

Closed
mpoke opened this issue Jun 21, 2022 · 9 comments
Closed

Make sure setters and getters cover edge cases #160

mpoke opened this issue Jun 21, 2022 · 9 comments
Labels
good first issue Good for newcomers

Comments

@mpoke
Copy link
Contributor

mpoke commented Jun 21, 2022

The methods used to access the CCV state (both on provider and consumer) should be callable with all kind of params without panic.

@mpoke mpoke added the scope: testing Code review, testing, making sure the code is following the specification. label Jun 21, 2022
@mpoke mpoke moved this to Todo in Replicated Security Jun 21, 2022
@mpoke mpoke added ccv-core good first issue Good for newcomers labels Jun 21, 2022
@danwt danwt self-assigned this Jun 26, 2022
@danwt danwt moved this from Todo to In Progress in Replicated Security Jun 26, 2022
@danwt
Copy link
Contributor

danwt commented Jun 26, 2022

IMO it's not always a good idea to program as defensively as this. Only the cases which can actually be called with nil, empty ect params should contain the checks.

Also, do we really want to not panic? There are some panics already, for example if byte or json decoding fails. It might be reasonable to panic in some places.

@danwt
Copy link
Contributor

danwt commented Jun 29, 2022

I think we should discuss this

@danwt danwt removed their assignment Jun 29, 2022
@danwt danwt moved this from In Progress to Todo in Replicated Security Jun 29, 2022
@shaspitz
Copy link
Contributor

shaspitz commented Aug 9, 2022

Regarding this issue, it seems that we all agree that every error should be handled in some place (linters enforce this). What's still unclear to me is if it's best to always panic when something unexpected happens within the app layer.

A good example relates to #254. We have two choices to handle the situation in which a duplicate proposal is passed (ie. a proposal for a consumer chainID that is already secured).

  1. We panic and halt the chain if such a duplicate proposal was passed
  2. We gracefully handle a duplicate proposal on-chain and discard it

Unless I'm missing something in my understanding of this specific case, it seems that the decision comes down to, do we want extra safety around proposal-related human errors and/or attack vectors? Or do we trust that provider validators would catch all "duplicate proposals" and reject them?

Thoughts?

@mpoke
Copy link
Contributor Author

mpoke commented Aug 9, 2022

We panic and halt the chain if such a duplicate proposal was passed

I don't think we should panic in such a case since there is no threat to the system. Dropping the duplicated proposal is the easiest way.

@mpoke
Copy link
Contributor Author

mpoke commented Aug 9, 2022

In general I think that

  • we should panic in case of programmer errors that shouldn't happen, e.g., using MustMarshal in setters;
  • we should return errors that are handled at a higher layer if it's something that can be triggered by data (i.e., user TXs), e.g., returning an error or false when looking for the channel ID for a consumer chain that was not registered.

The idea of this issue is to make sure that the code within setters / getters does not panic without us wanting that behavior, e.g., store.Get Panics on nil key (see https://github.com/cosmos/cosmos-sdk/blob/b6f867d0b674d62e56b27aa4d00f5b6042ebac9e/store/types/store.go#L197).

@shaspitz
Copy link
Contributor

shaspitz commented Aug 9, 2022

Got it, and thank you for the clarification of intention on this issue. Agreed on the points made here

@jtremback
Copy link
Contributor

All of the panics (with the exception below) on getters and setters in consumer and provider keeper.go are related to database corruption- i.e. there is stuff in the database that should not be in there, and there is no way for our program to recover from it. However, we are inconsistent. Some database corruption errors in some getters and setters are returned. We should probably at least be consistent about it.

Exception: This panic is in AfterUnbondingInitiated which is called by the staking module and then calls back into the staking module. It is unclear to me what the proper response would be here. Panic may still be the best option, because it is due to the staking module malfunctioning somehow and we cannot recover.

	// Call back into staking to tell it to stop this op from unbonding when the unbonding period is complete
	if err := h.k.stakingKeeper.PutUnbondingOnHold(ctx, ID); err != nil {
		panic(fmt.Errorf("unbonding could not be put on hold: %w", err))
	}

@jtremback jtremback removed the scope: testing Code review, testing, making sure the code is following the specification. label Sep 20, 2022
@danwt
Copy link
Contributor

danwt commented Oct 4, 2022

Agree ^: we should panic iff the situation is not recoverable.

@danwt
Copy link
Contributor

danwt commented Nov 30, 2022

Closing as there is no defined closing criteria

@danwt danwt closed this as completed Nov 30, 2022
Repository owner moved this from Todo to Done in Replicated Security Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
No open projects
Status: Done
Development

No branches or pull requests

4 participants