Skip to content

Commit 4c951e4

Browse files
gupadhyayaGanesha Upadhyaya
and
Ganesha Upadhyaya
authored
move proxyApp.VerifyFraudProofSync to ProofService (cosmos#1000)
Fixes cosmos#982 --------- Co-authored-by: Ganesha Upadhyaya <gupadhyaya@Ganeshas-MacBook-Pro-2.local>
1 parent ef9851e commit 4c951e4

File tree

4 files changed

+53
-34
lines changed

4 files changed

+53
-34
lines changed

block/manager.go

+22-34
Original file line numberDiff line numberDiff line change
@@ -258,42 +258,30 @@ func (m *Manager) ProcessFraudProof(ctx context.Context, cancel context.CancelFu
258258
}
259259
defer sub.Cancel()
260260

261-
// continuously process the fraud proofs received via subscription
262-
for {
263-
// sub.Proof is a blocking call that only returns on proof received or context ended
264-
proof, err := sub.Proof(ctx)
265-
if err != nil {
266-
m.logger.Error("failed to receive gossiped fraud proof", "error", err)
267-
return
268-
}
261+
// blocks until a valid fraud proof is received via subscription
262+
// sub.Proof is a blocking call that only returns on proof received or context ended
263+
proof, err := sub.Proof(ctx)
264+
if err != nil {
265+
m.logger.Error("failed to receive gossiped fraud proof", "error", err)
266+
return
267+
}
269268

270-
// only handle the state fraud proofs for now
271-
fraudProof, ok := proof.(*types.StateFraudProof)
272-
if !ok {
273-
m.logger.Error("unexpected type received for state fraud proof", "error", err)
274-
return
275-
}
276-
m.logger.Debug("fraud proof received",
277-
"block height", fraudProof.BlockHeight,
278-
"pre-state app hash", fraudProof.PreStateAppHash,
279-
"expected valid app hash", fraudProof.ExpectedValidAppHash,
280-
"length of state witness", len(fraudProof.StateWitness),
281-
)
282-
// TODO(light-client): Set up a new cosmos-sdk app
283-
// TODO: Add fraud proof window validation
284-
285-
success, err := m.executor.VerifyFraudProof(&fraudProof.FraudProof, fraudProof.ExpectedValidAppHash)
286-
if err != nil {
287-
m.logger.Error("failed to verify fraud proof", "error", err)
288-
continue
289-
}
290-
if success {
291-
// halt chain
292-
m.logger.Info("verified fraud proof, halting chain")
293-
cancel()
294-
return
295-
}
269+
// only handle the state fraud proofs for now
270+
fraudProof, ok := proof.(*types.StateFraudProof)
271+
if !ok {
272+
m.logger.Error("unexpected type received for state fraud proof", "error", err)
273+
return
296274
}
275+
m.logger.Debug("fraud proof received",
276+
"block height", fraudProof.BlockHeight,
277+
"pre-state app hash", fraudProof.PreStateAppHash,
278+
"expected valid app hash", fraudProof.ExpectedValidAppHash,
279+
"length of state witness", len(fraudProof.StateWitness),
280+
)
281+
282+
// halt chain
283+
m.logger.Info("verified fraud proof, halting chain")
284+
cancel()
297285
}
298286

299287
// SyncLoop is responsible for syncing blocks.

node/full.go

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"github.com/rollkit/rollkit/state/txindex"
3535
"github.com/rollkit/rollkit/state/txindex/kv"
3636
"github.com/rollkit/rollkit/store"
37+
"github.com/rollkit/rollkit/types"
3738
)
3839

3940
// prefixes used in KV store to separate main node data from DALC data
@@ -298,6 +299,9 @@ func (n *FullNode) OnStart() error {
298299
// since p2p pubsub and host are required to create ProofService,
299300
// we have to delay the construction until Start and use the help of ProofServiceFactory
300301
n.fraudService = n.proofServiceFactory.CreateProofService()
302+
if err := n.fraudService.AddVerifier(types.StateFraudProofType, VerifierFn(n.proxyApp)); err != nil {
303+
return fmt.Errorf("error while registering verifier for fraud service: %w", err)
304+
}
301305
if err = n.fraudService.Start(n.ctx); err != nil {
302306
return fmt.Errorf("error while starting fraud exchange service: %w", err)
303307
}

node/light.go

+3
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ func (ln *LightNode) OnStart() error {
118118
}
119119

120120
ln.fraudService = ln.proofServiceFactory.CreateProofService()
121+
if err := ln.fraudService.AddVerifier(types.StateFraudProofType, VerifierFn(ln.proxyApp)); err != nil {
122+
return fmt.Errorf("error while registering verifier for fraud service: %w", err)
123+
}
121124
if err := ln.fraudService.Start(ln.ctx); err != nil {
122125
return fmt.Errorf("error while starting fraud exchange service: %w", err)
123126
}

node/proof_service_factory.go

+24
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
11
package node
22

33
import (
4+
"errors"
5+
46
"github.com/celestiaorg/go-fraud"
57
"github.com/celestiaorg/go-fraud/fraudserv"
68
"github.com/ipfs/go-datastore"
9+
abci "github.com/tendermint/tendermint/abci/types"
10+
proxy "github.com/tendermint/tendermint/proxy"
711

812
"github.com/rollkit/rollkit/p2p"
13+
"github.com/rollkit/rollkit/types"
914
)
1015

16+
var VerifierFn = func(proxyApp proxy.AppConns) func(fraudProof fraud.Proof) (bool, error) {
17+
return func(fraudProof fraud.Proof) (bool, error) {
18+
stateFraudProof, ok := fraudProof.(*types.StateFraudProof)
19+
if !ok {
20+
return false, errors.New("unknown fraud proof")
21+
}
22+
resp, err := proxyApp.Consensus().VerifyFraudProofSync(
23+
abci.RequestVerifyFraudProof{
24+
FraudProof: &stateFraudProof.FraudProof,
25+
ExpectedValidAppHash: stateFraudProof.ExpectedValidAppHash,
26+
},
27+
)
28+
if err != nil {
29+
return false, err
30+
}
31+
return resp.Success, nil
32+
}
33+
}
34+
1135
type ProofServiceFactory struct {
1236
client *p2p.Client
1337
getter fraud.HeaderFetcher

0 commit comments

Comments
 (0)