Skip to content

Commit

Permalink
verification flags
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Apr 2, 2024
1 parent 3547c79 commit 50d7610
Show file tree
Hide file tree
Showing 17 changed files with 1,082 additions and 71 deletions.
28 changes: 27 additions & 1 deletion docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27604,7 +27604,6 @@ paths:
- Query
/zeta-chain/lightclient/prove:
get:
summary: Prove performs merkle proof verification
operationId: Query_Prove
responses:
"200":
Expand Down Expand Up @@ -27667,6 +27666,20 @@ paths:
format: int64
tags:
- Query
/zeta-chain/lightclient/verification_flags:
get:
operationId: Query_VerificationFlags
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/lightclientQueryVerificationFlagsResponse'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
tags:
- Query
/zeta-chain/observer/TSS:
get:
summary: Queries a tSS by index.
Expand Down Expand Up @@ -54385,6 +54398,19 @@ definitions:
properties:
chain_state:
$ref: '#/definitions/lightclientChainState'
lightclientQueryVerificationFlagsResponse:
type: object
properties:
verification_flags:
$ref: '#/definitions/lightclientVerificationFlags'
lightclientVerificationFlags:
type: object
properties:
ethTypeChainEnabled:
type: boolean
btcTypeChainEnabled:
type: boolean
title: VerificationFlags is a structure containing information which chain types are enabled for block header verification
observerAdmin_Policy:
type: object
properties:
Expand Down
2 changes: 2 additions & 0 deletions proto/lightclient/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package zetachain.zetacore.lightclient;

import "gogoproto/gogo.proto";
import "lightclient/chain_state.proto";
import "lightclient/verification_flags.proto";
import "pkg/proofs/proofs.proto";

option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types";
Expand All @@ -11,4 +12,5 @@ option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types";
message GenesisState {
repeated proofs.BlockHeader block_headers = 1 [(gogoproto.nullable) = false];
repeated ChainState chain_states = 2 [(gogoproto.nullable) = false];
VerificationFlags verification_flags = 3 [(gogoproto.nullable) = false];
}
12 changes: 11 additions & 1 deletion proto/lightclient/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "cosmos/base/query/v1beta1/pagination.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "lightclient/chain_state.proto";
import "lightclient/verification_flags.proto";
import "pkg/proofs/proofs.proto";

option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types";
Expand All @@ -27,10 +28,13 @@ service Query {
option (google.api.http).get = "/zeta-chain/lightclient/chain_state/{chain_id}";
}

// Prove performs merkle proof verification
rpc Prove(QueryProveRequest) returns (QueryProveResponse) {
option (google.api.http).get = "/zeta-chain/lightclient/prove";
}

rpc VerificationFlags(QueryVerificationFlagsRequest) returns (QueryVerificationFlagsResponse) {
option (google.api.http).get = "/zeta-chain/lightclient/verification_flags";
}
}

message QueryAllBlockHeaderRequest {
Expand Down Expand Up @@ -78,3 +82,9 @@ message QueryProveRequest {
message QueryProveResponse {
bool valid = 1;
}

message QueryVerificationFlagsRequest {}

message QueryVerificationFlagsResponse {
VerificationFlags verification_flags = 1 [(gogoproto.nullable) = false];
}
10 changes: 10 additions & 0 deletions proto/lightclient/verification_flags.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
syntax = "proto3";
package zetachain.zetacore.lightclient;

option go_package = "github.com/zeta-chain/zetacore/x/lightclient/types";

// VerificationFlags is a structure containing information which chain types are enabled for block header verification
message VerificationFlags {
bool ethTypeChainEnabled = 1;
bool btcTypeChainEnabled = 2;
}
6 changes: 6 additions & 0 deletions typescript/lightclient/genesis_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialM
import { Message, proto3 } from "@bufbuild/protobuf";
import type { BlockHeader } from "../pkg/proofs/proofs_pb.js";
import type { ChainState } from "./chain_state_pb.js";
import type { VerificationFlags } from "./verification_flags_pb.js";

/**
* GenesisState defines the lightclient module's genesis state.
Expand All @@ -24,6 +25,11 @@ export declare class GenesisState extends Message<GenesisState> {
*/
chainStates: ChainState[];

/**
* @generated from field: zetachain.zetacore.lightclient.VerificationFlags verification_flags = 3;
*/
verificationFlags?: VerificationFlags;

constructor(data?: PartialMessage<GenesisState>);

static readonly runtime: typeof proto3;
Expand Down
1 change: 1 addition & 0 deletions typescript/lightclient/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./chain_state_pb";
export * from "./genesis_pb";
export * from "./query_pb";
export * from "./verification_flags_pb";
44 changes: 44 additions & 0 deletions typescript/lightclient/query_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Message, proto3 } from "@bufbuild/protobuf";
import type { PageRequest, PageResponse } from "../cosmos/base/query/v1beta1/pagination_pb.js";
import type { BlockHeader, Proof } from "../pkg/proofs/proofs_pb.js";
import type { ChainState } from "./chain_state_pb.js";
import type { VerificationFlags } from "./verification_flags_pb.js";

/**
* @generated from message zetachain.zetacore.lightclient.QueryAllBlockHeaderRequest
Expand Down Expand Up @@ -279,3 +280,46 @@ export declare class QueryProveResponse extends Message<QueryProveResponse> {
static equals(a: QueryProveResponse | PlainMessage<QueryProveResponse> | undefined, b: QueryProveResponse | PlainMessage<QueryProveResponse> | undefined): boolean;
}

/**
* @generated from message zetachain.zetacore.lightclient.QueryVerificationFlagsRequest
*/
export declare class QueryVerificationFlagsRequest extends Message<QueryVerificationFlagsRequest> {
constructor(data?: PartialMessage<QueryVerificationFlagsRequest>);

static readonly runtime: typeof proto3;
static readonly typeName = "zetachain.zetacore.lightclient.QueryVerificationFlagsRequest";
static readonly fields: FieldList;

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): QueryVerificationFlagsRequest;

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): QueryVerificationFlagsRequest;

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): QueryVerificationFlagsRequest;

static equals(a: QueryVerificationFlagsRequest | PlainMessage<QueryVerificationFlagsRequest> | undefined, b: QueryVerificationFlagsRequest | PlainMessage<QueryVerificationFlagsRequest> | undefined): boolean;
}

/**
* @generated from message zetachain.zetacore.lightclient.QueryVerificationFlagsResponse
*/
export declare class QueryVerificationFlagsResponse extends Message<QueryVerificationFlagsResponse> {
/**
* @generated from field: zetachain.zetacore.lightclient.VerificationFlags verification_flags = 1;
*/
verificationFlags?: VerificationFlags;

constructor(data?: PartialMessage<QueryVerificationFlagsResponse>);

static readonly runtime: typeof proto3;
static readonly typeName = "zetachain.zetacore.lightclient.QueryVerificationFlagsResponse";
static readonly fields: FieldList;

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): QueryVerificationFlagsResponse;

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): QueryVerificationFlagsResponse;

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): QueryVerificationFlagsResponse;

static equals(a: QueryVerificationFlagsResponse | PlainMessage<QueryVerificationFlagsResponse> | undefined, b: QueryVerificationFlagsResponse | PlainMessage<QueryVerificationFlagsResponse> | undefined): boolean;
}

39 changes: 39 additions & 0 deletions typescript/lightclient/verification_flags_pb.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// @generated by protoc-gen-es v1.3.0 with parameter "target=dts"
// @generated from file lightclient/verification_flags.proto (package zetachain.zetacore.lightclient, syntax proto3)
/* eslint-disable */
// @ts-nocheck

import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf";
import { Message, proto3 } from "@bufbuild/protobuf";

/**
* VerificationFlags is a structure containing information which chain types are enabled for block header verification
*
* @generated from message zetachain.zetacore.lightclient.VerificationFlags
*/
export declare class VerificationFlags extends Message<VerificationFlags> {
/**
* @generated from field: bool ethTypeChainEnabled = 1;
*/
ethTypeChainEnabled: boolean;

/**
* @generated from field: bool btcTypeChainEnabled = 2;
*/
btcTypeChainEnabled: boolean;

constructor(data?: PartialMessage<VerificationFlags>);

static readonly runtime: typeof proto3;
static readonly typeName = "zetachain.zetacore.lightclient.VerificationFlags";
static readonly fields: FieldList;

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): VerificationFlags;

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): VerificationFlags;

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): VerificationFlags;

static equals(a: VerificationFlags | PlainMessage<VerificationFlags> | undefined, b: VerificationFlags | PlainMessage<VerificationFlags> | undefined): boolean;
}

16 changes: 14 additions & 2 deletions x/lightclient/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,24 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
for _, elem := range genState.ChainStates {
k.SetChainState(ctx, elem)
}

// set verification flags
k.SetVerificationFlags(ctx, genState.VerificationFlags)
}

// ExportGenesis returns the lightclient module's exported genesis.
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
verificationFlags, found := k.GetVerificationFlags(ctx)
if !found {
verificationFlags = types.VerificationFlags{
EthTypeChainEnabled: false,
BtcTypeChainEnabled: false,
}
}

return &types.GenesisState{
BlockHeaders: k.GetAllBlockHeaders(ctx),
ChainStates: k.GetAllChainStates(ctx),
BlockHeaders: k.GetAllBlockHeaders(ctx),
ChainStates: k.GetAllChainStates(ctx),
VerificationFlags: verificationFlags,
}
}
25 changes: 25 additions & 0 deletions x/lightclient/keeper/grpc_query_verification_flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package keeper

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/zeta-chain/zetacore/x/lightclient/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

// VerificationFlags implements the Query/VerificationFlags gRPC method
func (k Keeper) VerificationFlags(c context.Context, req *types.QueryVerificationFlagsRequest) (*types.QueryVerificationFlagsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(c)

val, found := k.GetVerificationFlags(ctx)
if !found {
return nil, status.Error(codes.NotFound, "not found")
}

return &types.QueryVerificationFlagsResponse{VerificationFlags: val}, nil
}
27 changes: 27 additions & 0 deletions x/lightclient/keeper/verification_flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package keeper

import (
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/zeta-chain/zetacore/x/lightclient/types"
)

// SetVerificationFlags set the verification flags in the store
func (k Keeper) SetVerificationFlags(ctx sdk.Context, crosschainFlags types.VerificationFlags) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.VerificationFlagsKey))
b := k.cdc.MustMarshal(&crosschainFlags)
store.Set([]byte{0}, b)
}

// GetVerificationFlags returns the verification flags
func (k Keeper) GetVerificationFlags(ctx sdk.Context) (val types.VerificationFlags, found bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.VerificationFlagsKey))

b := store.Get([]byte{0})
if b == nil {
return val, false
}

k.cdc.MustUnmarshal(b, &val)
return val, true
}
4 changes: 4 additions & 0 deletions x/lightclient/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ func DefaultGenesis() *GenesisState {
return &GenesisState{
BlockHeaders: []proofs.BlockHeader{},
ChainStates: []ChainState{},
VerificationFlags: VerificationFlags{
EthTypeChainEnabled: false,
BtcTypeChainEnabled: false,
},
}
}

Expand Down
Loading

0 comments on commit 50d7610

Please sign in to comment.