// PKGPATH: gno.land/r/aib/main package main import ( "encoding/hex" "time" "gno.land/p/aib/ibc/lightclient/tendermint" tmtesting "gno.land/p/aib/ibc/lightclient/tendermint/testing" "gno.land/p/aib/ibc/types" "gno.land/p/aib/ics23" "gno.land/r/aib/ibc/core" ) // UpgradeClient success: verify upgraded client + consensus state proofs // generated by `go run -C ./cmd/gen-proof . upgrade` and apply the upgrade // to the existing client. func main(cur realm) { core.SetAdmin(cross(cur), "g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm") core.AddRelayer(cross(cur), "g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm") // NOTE code generated by: // go run -C ./cmd/gen-proof . upgrade // // Plan height: 100 // Upgraded chain id: chain-after-upgrade-2 // Upgraded latest height: 2-1 // Upgraded timestamp (unix): 1700000000 // Multistore root (apphash): f798f6bd56268e30a1f6ceb223e3330ee47d992f5a888de5b78dfd934e344a27 apphash, _ := hex.DecodeString("f798f6bd56268e30a1f6ceb223e3330ee47d992f5a888de5b78dfd934e344a27") specs := ics23.IavlSpec() // Current client at the upgrade plan height; consensus root is the // multistore apphash gen-proof committed. currentChainID := "current-chain-1" currentHeight := types.NewHeight(1, 100) clientState := tmtesting.NewClientState(currentChainID, currentHeight) clientState.UpgradePath = []string{"upgrade", "upgradedIBCState"} consensusState := tendermint.ConsensusState{ Timestamp: time.Now().UTC(), Root: tendermint.NewMerkleRoot(apphash), NextValidatorsHash: tmtesting.GenValset().Hash(), } clientID := core.CreateClient(cross(cur), clientState, consensusState) // The upgraded states the relayer submits must reconstruct the same // bytes the counterparty committed (Any-wrapped, ZeroCustomFields for // the client). Use values matching the gen-proof scenario. nextValsHash := make([]byte, 32) for i := range nextValsHash { nextValsHash[i] = byte(i + 1) } upgradedClient := tendermint.ClientState{ ChainID: "chain-after-upgrade-2", TrustLevel: tendermint.NewFraction(1, 3), TrustingPeriod: 2 * 7 * 24 * time.Hour, UnbondingPeriod: 3 * 7 * 24 * time.Hour, MaxClockDrift: 10 * time.Second, LatestHeight: types.NewHeight(2, 1), ProofSpecs: ics23.GetSDKProofSpecs(), UpgradePath: []string{"upgrade", "upgradedIBCState"}, } upgradedConsState := tendermint.ConsensusState{ Timestamp: time.Unix(1700000000, 0).UTC(), Root: tendermint.NewMerkleRoot([]byte(tendermint.SentinelRoot)), NextValidatorsHash: nextValsHash, } clientProof := []ics23.CommitmentProof{ // iavl proof ics23.CommitmentProof_Exist{ Exist: &ics23.ExistenceProof{ Key: []byte("\x75\x70\x67\x72\x61\x64\x65\x64\x49\x42\x43\x53\x74\x61\x74\x65\x2f\x31\x30\x30\x2f\x75\x70\x67\x72\x61\x64\x65\x64\x43\x6c\x69\x65\x6e\x74"), Value: []byte("\x0a\x2b\x2f\x69\x62\x63\x2e\x6c\x69\x67\x68\x74\x63\x6c\x69\x65\x6e\x74\x73\x2e\x74\x65\x6e\x64\x65\x72\x6d\x69\x6e\x74\x2e\x76\x31\x2e\x43\x6c\x69\x65\x6e\x74\x53\x74\x61\x74\x65\x12\x7c\x0a\x15\x63\x68\x61\x69\x6e\x2d\x61\x66\x74\x65\x72\x2d\x75\x70\x67\x72\x61\x64\x65\x2d\x32\x12\x00\x1a\x00\x22\x04\x08\x80\xdf\x6e\x2a\x00\x32\x00\x3a\x04\x08\x02\x10\x01\x42\x19\x0a\x09\x08\x01\x18\x01\x20\x01\x2a\x01\x00\x12\x0c\x0a\x02\x00\x01\x10\x21\x18\x04\x20\x0c\x30\x01\x42\x19\x0a\x09\x08\x01\x18\x01\x20\x01\x2a\x01\x00\x12\x0c\x0a\x02\x00\x01\x10\x20\x18\x01\x20\x01\x30\x01\x4a\x07\x75\x70\x67\x72\x61\x64\x65\x4a\x10\x75\x70\x67\x72\x61\x64\x65\x64\x49\x42\x43\x53\x74\x61\x74\x65"), Leaf: &ics23.LeafOp{ Hash: specs.LeafSpec.Hash, PrehashKey: specs.LeafSpec.PrehashKey, PrehashValue: specs.LeafSpec.PrehashValue, Length: specs.LeafSpec.Length, Prefix: []byte("\x00\x02\x02"), }, Path: []*ics23.InnerOp{ { Hash: specs.InnerSpec.Hash, Prefix: []byte("\x02\x04\x02\x20"), Suffix: []byte("\x20\x9c\x29\x97\x40\x53\xa4\x0c\x45\xb4\x4b\xce\x96\x00\xfa\x17\xfa\xeb\xa1\xfa\xa0\xc7\x2e\xa5\x75\x63\x80\x70\x02\x79\xef\x8b\xee"), }, { Hash: specs.InnerSpec.Hash, Prefix: []byte("\x04\x06\x02\x20"), Suffix: []byte("\x20\xa3\x03\x93\x0c\xa8\x83\x16\x18\xac\x7e\x4d\xdd\x10\x54\x6c\xfc\x36\x6f\xb7\x30\xd6\x63\x0c\x03\x0a\x97\x22\x6b\xbe\xfc\x69\x35"), }, { Hash: specs.InnerSpec.Hash, Prefix: []byte("\x06\x0e\x02\x20\x7b\x0d\x2c\x83\x0d\xb3\xa2\x71\xb1\x1a\x3a\xda\xc5\x21\x99\x66\x8d\x86\x3b\x38\xb1\xcb\x4f\xd2\x4f\xe7\x4d\x3f\x30\x20\x41\x5d\x20"), Suffix: []byte(""), }, }, }, }, // rootmulti proof ics23.CommitmentProof_Exist{ Exist: &ics23.ExistenceProof{ Key: []byte("\x75\x70\x67\x72\x61\x64\x65"), Value: []byte("\xe5\x58\x62\xc7\x50\x66\x4f\xa8\xcc\xe2\x3b\x36\x65\xbe\x8d\x52\xb9\x51\x08\xfc\x48\x12\x33\xf0\x24\x68\x02\xfd\x18\x93\x5e\xfc"), Leaf: &ics23.LeafOp{ Hash: specs.LeafSpec.Hash, PrehashKey: specs.LeafSpec.PrehashKey, PrehashValue: specs.LeafSpec.PrehashValue, Length: specs.LeafSpec.Length, Prefix: []byte("\x00"), }, Path: []*ics23.InnerOp{}, }, }, } consStateProof := []ics23.CommitmentProof{ // iavl proof ics23.CommitmentProof_Exist{ Exist: &ics23.ExistenceProof{ Key: []byte("\x75\x70\x67\x72\x61\x64\x65\x64\x49\x42\x43\x53\x74\x61\x74\x65\x2f\x31\x30\x30\x2f\x75\x70\x67\x72\x61\x64\x65\x64\x43\x6f\x6e\x73\x53\x74\x61\x74\x65"), Value: []byte("\x0a\x2e\x2f\x69\x62\x63\x2e\x6c\x69\x67\x68\x74\x63\x6c\x69\x65\x6e\x74\x73\x2e\x74\x65\x6e\x64\x65\x72\x6d\x69\x6e\x74\x2e\x76\x31\x2e\x43\x6f\x6e\x73\x65\x6e\x73\x75\x73\x53\x74\x61\x74\x65\x12\x3b\x0a\x06\x08\x80\xe2\xcf\xaa\x06\x12\x0f\x0a\x0d\x73\x65\x6e\x74\x69\x6e\x65\x6c\x5f\x72\x6f\x6f\x74\x1a\x20\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20"), Leaf: &ics23.LeafOp{ Hash: specs.LeafSpec.Hash, PrehashKey: specs.LeafSpec.PrehashKey, PrehashValue: specs.LeafSpec.PrehashValue, Length: specs.LeafSpec.Length, Prefix: []byte("\x00\x02\x02"), }, Path: []*ics23.InnerOp{ { Hash: specs.InnerSpec.Hash, Prefix: []byte("\x02\x04\x02\x20\xb8\xd1\x78\xec\x21\x73\xd5\x34\x83\xa7\x2b\xd0\x34\xcc\xbd\xbc\xaf\x7b\x63\x7c\xba\x52\xd8\xf1\x5c\x9f\xd6\x24\xb9\xe9\xc3\x9a\x20"), Suffix: []byte(""), }, { Hash: specs.InnerSpec.Hash, Prefix: []byte("\x04\x06\x02\x20"), Suffix: []byte("\x20\xa3\x03\x93\x0c\xa8\x83\x16\x18\xac\x7e\x4d\xdd\x10\x54\x6c\xfc\x36\x6f\xb7\x30\xd6\x63\x0c\x03\x0a\x97\x22\x6b\xbe\xfc\x69\x35"), }, { Hash: specs.InnerSpec.Hash, Prefix: []byte("\x06\x0e\x02\x20\x7b\x0d\x2c\x83\x0d\xb3\xa2\x71\xb1\x1a\x3a\xda\xc5\x21\x99\x66\x8d\x86\x3b\x38\xb1\xcb\x4f\xd2\x4f\xe7\x4d\x3f\x30\x20\x41\x5d\x20"), Suffix: []byte(""), }, }, }, }, // rootmulti proof ics23.CommitmentProof_Exist{ Exist: &ics23.ExistenceProof{ Key: []byte("\x75\x70\x67\x72\x61\x64\x65"), Value: []byte("\xe5\x58\x62\xc7\x50\x66\x4f\xa8\xcc\xe2\x3b\x36\x65\xbe\x8d\x52\xb9\x51\x08\xfc\x48\x12\x33\xf0\x24\x68\x02\xfd\x18\x93\x5e\xfc"), Leaf: &ics23.LeafOp{ Hash: specs.LeafSpec.Hash, PrehashKey: specs.LeafSpec.PrehashKey, PrehashValue: specs.LeafSpec.PrehashValue, Length: specs.LeafSpec.Length, Prefix: []byte("\x00"), }, Path: []*ics23.InnerOp{}, }, }, } core.UpgradeClient(cross(cur), clientID, upgradedClient, upgradedConsState, clientProof, consStateProof) println("upgrade succeeded") } // Output: // upgrade succeeded