Skip to content

Commit

Permalink
Merge pull request #18 from datachainlab/misbehaviour
Browse files Browse the repository at this point in the history
Bump lcp to v0.2.6 and add misbehaviour support

Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele authored Feb 6, 2024
2 parents 2da41cf + 7cd36f7 commit 32cca20
Show file tree
Hide file tree
Showing 13 changed files with 405 additions and 189 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ lcp-go includes the followings:

## Dependencies

- [lcp v0.2.5](https://github.com/datachainlab/lcp/releases/tag/v0.2.5)
- [lcp v0.2.6](https://github.com/datachainlab/lcp/releases/tag/v0.2.6)
- [ibc-go v7.2](https://github.com/cosmos/ibc-go/releases/tag/v7.2.0)
- [yui-relayer v0.4.21](https://github.com/hyperledger-labs/yui-relayer/releases/tag/v0.4.21)

Expand Down
2 changes: 1 addition & 1 deletion lcp
Submodule lcp updated 59 files
+185 −53 Cargo.lock
+5 −5 enclave-modules/ecall-handler/src/enclave_manage/attestation.rs
+3 −3 enclave-modules/ecall-handler/src/enclave_manage/enclave.rs
+9 −7 enclave-modules/ecall-handler/src/enclave_manage/router.rs
+14 −14 enclave-modules/ecall-handler/src/light_client/aggregate_messages.rs
+3 −3 enclave-modules/ecall-handler/src/light_client/init_client.rs
+3 −3 enclave-modules/ecall-handler/src/light_client/query.rs
+3 −3 enclave-modules/ecall-handler/src/light_client/router.rs
+36 −22 enclave-modules/ecall-handler/src/light_client/update_client.rs
+9 −9 enclave-modules/ecall-handler/src/light_client/verify_state.rs
+2 −2 enclave-modules/ecall-handler/src/router.rs
+2 −2 enclave-modules/environment/Cargo.toml
+2 −2 enclave-modules/environment/src/environment_impl.rs
+36 −4 enclave-modules/host-api/src/store.rs
+4 −4 enclave-modules/runtime/src/ecalls.rs
+0 −8 enclave-modules/store/Cargo.toml
+0 −23 enclave-modules/store/src/lib.rs
+0 −24 enclave-modules/store/src/store.rs
+280 −46 enclave/Cargo.lock
+1 −1 modules/commitments/Cargo.toml
+22 −84 modules/commitments/src/context.rs
+24 −61 modules/commitments/src/encoder.rs
+29 −10 modules/commitments/src/errors.rs
+2 −2 modules/commitments/src/lib.rs
+139 −90 modules/commitments/src/message.rs
+119 −0 modules/commitments/src/message/misbehaviour.rs
+63 −119 modules/commitments/src/message/update_state.rs
+41 −70 modules/commitments/src/message/verify_membership.rs
+14 −47 modules/commitments/src/proof.rs
+4 −2 modules/commitments/src/prover.rs
+4 −0 modules/commitments/src/state.rs
+5 −5 modules/ecall-commands/src/commands.rs
+7 −7 modules/ecall-commands/src/enclave_manage.rs
+9 −9 modules/ecall-commands/src/lib.rs
+13 −13 modules/ecall-commands/src/light_client.rs
+16 −16 modules/ecall-commands/src/msgs.rs
+30 −27 modules/enclave-api/src/api/command.rs
+4 −4 modules/enclave-api/src/api/primitive.rs
+148 −35 modules/lcp-client/src/client_def.rs
+17 −9 modules/lcp-client/src/client_state.rs
+5 −69 modules/lcp-client/src/message.rs
+36 −7 modules/light-client/src/client.rs
+2 −2 modules/light-client/src/lib.rs
+103 −33 modules/mock-lc/src/client.rs
+0 −40 modules/mock-lc/src/header.rs
+2 −2 modules/mock-lc/src/lib.rs
+96 −0 modules/mock-lc/src/message.rs
+122 −0 modules/store/src/cache.rs
+1 −0 modules/store/src/lib.rs
+1 −0 modules/tendermint-lc/Cargo.toml
+189 −127 modules/tendermint-lc/src/client.rs
+0 −49 modules/tendermint-lc/src/header.rs
+3 −1 modules/tendermint-lc/src/lib.rs
+123 −0 modules/tendermint-lc/src/message.rs
+120 −0 modules/tendermint-lc/src/verifier.rs
+7 −6 proto/definitions/ibc/lightclients/lcp/v1/lcp.proto
+ proto/src/descriptor.bin
+10 −8 proto/src/prost/ibc.lightclients.lcp.v1.rs
+3 −3 tests/integration/src/lib.rs
11 changes: 2 additions & 9 deletions light-clients/lcp/types/client_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@ func (cs ClientState) ExportMetadata(_ sdk.KVStore) []exported.GenesisMetadata {
panic("not implemented") // TODO: Implement
}

func (cs ClientState) CheckForMisbehaviour(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, msg exported.ClientMessage) bool {
return false
}

func (cs ClientState) UpdateStateOnMisbehaviour(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, _ exported.ClientMessage) {
}

func (cs ClientState) CheckSubstituteAndUpdateState(
ctx sdk.Context, cdc codec.BinaryCodec, subjectClientStore,
substituteClientStore sdk.KVStore, substituteClient exported.ClientState,
Expand Down Expand Up @@ -157,11 +150,11 @@ func (cs ClientState) VerifyMembership(
if err != nil {
return err
}
m, err := commitmentProof.GetELCMessage()
m, err := commitmentProof.GetMessage()
if err != nil {
return err
}
msg, err := m.GetVerifyMembershipMessage()
msg, err := m.GetVerifyMembershipProxyMessage()
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions light-clients/lcp/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ var (
ErrProcessedTimeNotFound = sdkerrors.Register(ModuleName, 4, "processed time not found")
ErrProcessedHeightNotFound = sdkerrors.Register(ModuleName, 5, "processed height not found")
ErrDelayPeriodNotPassed = sdkerrors.Register(ModuleName, 6, "packet-specified delay period has not been reached")
ErrInvalidMisbehaviour = sdkerrors.Register(ModuleName, 7, "invalid misbehaviour")
)
37 changes: 24 additions & 13 deletions light-clients/lcp/types/header.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,54 @@
package types

import (
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
"fmt"

"github.com/cosmos/ibc-go/v7/modules/core/exported"
)

type ProxyMessage interface{}

var _ exported.ClientMessage = (*UpdateClientMessage)(nil)

func (UpdateClientMessage) ClientType() string {
return ClientTypeLCP
}

func (ucm UpdateClientMessage) GetHeight() exported.Height {
m, err := ucm.GetELCMessage()
m, err := ucm.GetProxyMessage()
if err != nil {
panic(err)
}
return m.PostHeight
switch m := m.(type) {
case *UpdateStateProxyMessage:
return m.PostHeight
default:
panic(fmt.Errorf("unexpected message type: %T", m))
}
}

func (ucm UpdateClientMessage) ValidateBasic() error {
if _, err := ucm.GetELCMessage(); err != nil {
if _, err := ucm.GetProxyMessage(); err != nil {
return err
}
return nil
}

func (ucm UpdateClientMessage) GetELCMessage() (*ELCUpdateClientMessage, error) {
m, err := EthABIDecodeHeaderedMessage(ucm.ElcMessage)
func (ucm UpdateClientMessage) GetProxyMessage() (ProxyMessage, error) {
m, err := EthABIDecodeHeaderedProxyMessage(ucm.ProxyMessage)
if err != nil {
return nil, err
}
return m.GetUpdateClientMessage()
if m.Version != LCPMessageVersion {
return nil, fmt.Errorf("unexpected commitment version: expected=%v actual=%v", LCPMessageVersion, m.Version)
}
if m.Type == LCPMessageTypeUpdateState {
return m.GetUpdateStateProxyMessage()
} else if m.Type == LCPMessageTypeMisbehaviour {
return m.GetMisbehaviourProxyMessage()
} else {
return nil, fmt.Errorf("unexpected message type: %v", m.Type)
}
}

var _ exported.ClientMessage = (*RegisterEnclaveKeyMessage)(nil)
Expand All @@ -40,12 +57,6 @@ func (RegisterEnclaveKeyMessage) ClientType() string {
return ClientTypeLCP
}

func (RegisterEnclaveKeyMessage) GetHeight() exported.Height {
// XXX: the header doesn't have height info, so return zero
// this is just workaround until this function removed
return clienttypes.ZeroHeight()
}

func (RegisterEnclaveKeyMessage) ValidateBasic() error {
return nil
}
Loading

0 comments on commit 32cca20

Please sign in to comment.