Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

feat: Add expected valid app hash #10

Merged
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func (app *BaseApp) VerifyFraudProof(req abci.RequestVerifyFraudProof) (res abci
appFromFraudProof.InitChain(abci.RequestInitChain{})
appHash := appFromFraudProof.GetAppHash(abci.RequestGetAppHash{}).AppHash

if !bytes.Equal(fraudProof.appHash, appHash) {
if !bytes.Equal(fraudProof.preStateAppHash, appHash) {
return abci.ResponseVerifyFraudProof{
Success: false,
}
Expand All @@ -304,7 +304,7 @@ func (app *BaseApp) VerifyFraudProof(req abci.RequestVerifyFraudProof) (res abci
}

appHash = appFromFraudProof.GetAppHash(abci.RequestGetAppHash{}).AppHash
success = bytes.Equal(appHash, req.ExpectedAppHash)
success = bytes.Equal(appHash, req.ExpectedValidAppHash)
Manav-Aggarwal marked this conversation as resolved.
Show resolved Hide resolved
}
res = abci.ResponseVerifyFraudProof{
Success: success,
Expand Down
2 changes: 1 addition & 1 deletion baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ func (app *BaseApp) getFraudProof(storeKeyToWitnessData map[string][]iavltree.Wi
if err != nil {
return FraudProof{}, err
}
fraudProof.appHash = appHash
fraudProof.preStateAppHash = appHash
for storeKeyName := range storeKeyToWitnessData {
iavlStore, err := cms.GetIAVLStore(storeKeyName)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2362,7 +2362,7 @@ func TestGenerateAndLoadFraudProof(t *testing.T) {
fraudProof := FraudProof{}
err = fraudProof.fromABCI(*resp.FraudProof)
require.Nil(t, err)
require.Equal(t, appHashB1, fraudProof.appHash)
require.Equal(t, appHashB1, fraudProof.preStateAppHash)
fraudProofVerified, err := fraudProof.verifyFraudProof()
require.Nil(t, err)
require.True(t, fraudProofVerified)
Expand Down Expand Up @@ -2448,8 +2448,8 @@ func TestABCIEndToEndFraudProof(t *testing.T) {
// Light Client
verifyResp := appB1.VerifyFraudProof(
abci.RequestVerifyFraudProof{
FraudProof: generateResp.FraudProof,
ExpectedAppHash: appHashAfterFraud,
FraudProof: generateResp.FraudProof,
ExpectedValidAppHash: appHashAfterFraud,
},
)
require.True(t, verifyResp.Success)
Expand Down
13 changes: 8 additions & 5 deletions baseapp/fraudproof.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ type FraudProof struct {

// TODO: Add Proof that appHash is inside merklized ISRs in block header at block height

appHash []byte
preStateAppHash []byte
expectedValidAppHash []byte
// A map from module name to state witness
stateWitness map[string]StateWitness

Expand Down Expand Up @@ -162,8 +163,8 @@ func (fraudProof *FraudProof) verifyFraudProof() (bool, error) {
if err != nil {
return false, err
}
if !bytes.Equal(appHash[0], fraudProof.appHash) {
return false, fmt.Errorf("got appHash: %s, expected: %s", string(fraudProof.appHash), string(fraudProof.appHash))
if !bytes.Equal(appHash[0], fraudProof.preStateAppHash) {
return false, fmt.Errorf("got appHash: %s, expected: %s", string(fraudProof.preStateAppHash), string(fraudProof.preStateAppHash))
}

// Fraudproof verification on a substore level
Expand Down Expand Up @@ -238,7 +239,8 @@ func (fraudProof *FraudProof) toABCI() (*abci.FraudProof, error) {
}
return &abci.FraudProof{
BlockHeight: fraudProof.blockHeight,
AppHash: fraudProof.appHash,
PreStateAppHash: fraudProof.preStateAppHash,
ExpectedValidAppHash: fraudProof.expectedValidAppHash,
StateWitness: abciStateWitness,
FraudulentBeginBlock: fraudProof.fraudulentBeginBlock,
FraudulentDeliverTx: fraudProof.fraudulentDeliverTx,
Expand Down Expand Up @@ -270,7 +272,8 @@ func (fraudProof *FraudProof) fromABCI(abciFraudProof abci.FraudProof) error {
}
}
fraudProof.blockHeight = abciFraudProof.BlockHeight
fraudProof.appHash = abciFraudProof.AppHash
fraudProof.preStateAppHash = abciFraudProof.PreStateAppHash
fraudProof.expectedValidAppHash = abciFraudProof.ExpectedValidAppHash
fraudProof.stateWitness = stateWitness
fraudProof.fraudulentBeginBlock = abciFraudProof.FraudulentBeginBlock
fraudProof.fraudulentDeliverTx = abciFraudProof.FraudulentDeliverTx
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ replace (
// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.7.0
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/tendermint/tendermint => github.com/celestiaorg/tendermint v0.34.22-0.20221129185527-17adf5012374
github.com/tendermint/tendermint => github.com/celestiaorg/tendermint v0.34.22-0.20221202214355-3605c597500d
)

retract v0.46.2
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ github.com/celestiaorg/rollmint v0.4.0 h1:+eu2m25ALhlHj9pbAElzq2pSg6WJ4Bn8/WqL2H
github.com/celestiaorg/rollmint v0.4.0/go.mod h1:EBnqxgmcH0MIgNgiI8NyVa1sNSzCyCpvAlAHd9myhk4=
github.com/celestiaorg/smt v0.3.0 h1:Hc6m8fIVRajrg/Saf8ivX4xw551LHzOs8kqeadd6h9s=
github.com/celestiaorg/smt v0.3.0/go.mod h1:/sdYDakowo/XaxS2Fl7CBqtuf/O2uTqF2zmAUFAtAiw=
github.com/celestiaorg/tendermint v0.34.22-0.20221129185527-17adf5012374 h1:AoxKmsmDDZdbiP+0BtOa8cXaztA8BnD8mbcsfTksdeQ=
github.com/celestiaorg/tendermint v0.34.22-0.20221129185527-17adf5012374/go.mod h1:zoyyiiihvTW8DnOr63YLxhYn/WK/QmE74CeIpS++hBE=
github.com/celestiaorg/tendermint v0.34.22-0.20221202214355-3605c597500d h1:OH9dp6WWotp53aG58xSdLWd+F1Znf3DhA0BadyJO4Aw=
github.com/celestiaorg/tendermint v0.34.22-0.20221202214355-3605c597500d/go.mod h1:zoyyiiihvTW8DnOr63YLxhYn/WK/QmE74CeIpS++hBE=
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/cenkalti/backoff/v4 v4.1.1 h1:G2HAfAmvm/GcKan2oOQpBXOd2tT2G57ZnZGWa1PxPBQ=
Expand Down