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

adding verifiers to ProofService #5

Merged
merged 6 commits into from
Jun 22, 2023

Conversation

gupadhyaya
Copy link
Contributor

@gupadhyaya gupadhyaya commented Jun 9, 2023

Fixes #4. As part of rollkit/rollkit#982, we would like to have a facility to invoke a state machine verifier as part of Proof.Validate, such that we can move the proxyApp.VerifyFraudProofSync to Proof.Validate. If the state machine verifier is not passed (or nil), Proof.Validate can safely ignore it. An example, usage is:

func(fraudProof fraud.Proof) (bool, error) {
	stateFraudProof, ok := fraudProof.(*types.StateFraudProof)
	if !ok {
		return false, errors.New("unknown fraud proof")
	}
	resp, err := proxyApp.Consensus().VerifyFraudProofSync(
		abci.RequestVerifyFraudProof{
			FraudProof: &stateFraudProof.FraudProof, 
			ExpectedValidAppHash: stateFraudProof.ExpectedValidAppHash,
		},
	)
	if err != nil {
		return false, err
	}
	return resp.Success, nil
}

@vgonkivs
Copy link
Member

Hello @gupadhyaya, I have a suggestion how we can improve your approach. The problem here is that extending input arguments is not the generic way that me and @Wondertan were trying to achieve in the library. For example, in celestia-node we don't need statemachine verifier but with these changes we will have to keep nil.
My suggestion is to have a Verifier type and have an ability to register custom verifiers as we have done with Marshalers. So,you will have the same result but without breaking an interface.

@Wondertan
Copy link
Member

Agree with @vgonkivs. Also:

  • Stateful verification on the method of a stateless object is an antipattern(not blockchain state)
  • StateMachineValidator is implementation specific; not all FPs need Blockchain state machine.
  • It's interface breaking

Instead, I suggest adding a new method to FraudService. Something like AddVerifier that takes the fraud type and the verification func. It's essentially the same as @vgonkivs proposed but without the global state of register approach.

@gupadhyaya
Copy link
Contributor Author

@vgonkivs @Wondertan thanks for your suggestion. agree that we should keep the validate interface stateless. will update the FraudService with AddVerifier approach and invoke the verifier as part of processingIncoming.

@gupadhyaya
Copy link
Contributor Author

@vgonkivs @Wondertan ready for re-review. thanks.

Copy link
Member

@vgonkivs vgonkivs left a comment

Choose a reason for hiding this comment

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

  1. What if we will allow to register multiple verifiers per proofType? wdyt?
  2. Please add a mutex for verifiers(verifiersLK sync.RWMutex)

@gupadhyaya
Copy link
Contributor Author

@vgonkivs

  1. I thought about it, but for now we don't need multiple verifiers. In future if needed, we will extend it.
  2. Done.

fraudserv/service.go Show resolved Hide resolved
fraudserv/service.go Show resolved Hide resolved
fraudserv/service.go Show resolved Hide resolved
fraudserv/service.go Outdated Show resolved Hide resolved
@gupadhyaya gupadhyaya changed the title adding state machine verifier to be invoked as part of Proof.Validate adding state machine verifier to ProofService Jun 21, 2023
@gupadhyaya gupadhyaya changed the title adding state machine verifier to ProofService adding verifiers to ProofService Jun 21, 2023
fraudserv/service.go Outdated Show resolved Hide resolved
@gupadhyaya gupadhyaya requested review from vgonkivs and renaynay June 21, 2023 13:47
Copy link
Member

@vgonkivs vgonkivs left a comment

Choose a reason for hiding this comment

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

LGTM. Lets wait for @Wondertan review and merge

fraudserv/service.go Show resolved Hide resolved
fraudserv/service.go Show resolved Hide resolved
fraudserv/service.go Outdated Show resolved Hide resolved
fraudserv/service.go Outdated Show resolved Hide resolved
fraudserv/service.go Outdated Show resolved Hide resolved
fraudserv/service_test.go Outdated Show resolved Hide resolved
@gupadhyaya gupadhyaya requested review from vgonkivs and Wondertan June 21, 2023 20:34
@gupadhyaya gupadhyaya requested a review from MSevey June 21, 2023 20:34
Copy link
Member

@Wondertan Wondertan left a comment

Choose a reason for hiding this comment

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

LGTM now.
Thank you, @gupadhyaya!

@gupadhyaya
Copy link
Contributor Author

@Wondertan @vgonkivs could you merge and make a release? thanks.

@gupadhyaya gupadhyaya merged commit a9cd22c into celestiaorg:main Jun 22, 2023
@Wondertan
Copy link
Member

@gupadhyaya, I was in the series of calls, so could not do, but glad that you have permissions now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

state machine access in Proof.Validate
5 participants