Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
672e202
Add cosmos/ics23 proto into local proto with conversion
h5law Jul 20, 2023
513005c
Add makefile auto download and sed on proto
h5law Jul 21, 2023
bd6e08c
Create ClientManager interface and Client interface definitions
h5law Jul 11, 2023
900e270
Use current height for read context and pass uint64 heights into getters
h5law Jul 14, 2023
f3789a9
Remove Height field from IBCEvent proto definition
h5law Jul 14, 2023
5558994
Add emit event functions for the client submodule
h5law Jul 14, 2023
ab63e71
Implement CreateClient method
h5law Jul 14, 2023
e132323
Implement UpdateClient method
h5law Jul 14, 2023
99d9efd
Implement UpgradeClient method
h5law Jul 17, 2023
06ea1c9
Shorted log lines
h5law Jul 17, 2023
08fb832
Add WASM specific implementations for client interfaces
h5law Jul 17, 2023
c019120
Allow setting nil keys
h5law Jul 18, 2023
d9fe6b4
Add error returns
h5law Jul 18, 2023
abddd3c
Use clientID prefixed client store
h5law Jul 18, 2023
757c8c8
Add Wasm Client protobuf implementations
h5law Jul 18, 2023
7e741c4
Add Pocket specific Client and Consensus State types
h5law Jul 18, 2023
3831db0
Allow host introspection of its own ConsensusState
h5law Jul 18, 2023
88428db
Add GetHostClientState()
h5law Jul 19, 2023
22f63ad
Add VerifyHostClientState method
h5law Jul 20, 2023
c69b41e
Add nolint lines for unused types
h5law Jul 18, 2023
0080786
Add ICS-02 documentation
h5law Jul 20, 2023
2c52775
Add client query tests
h5law Jul 21, 2023
8a8b78d
Add basic type tests
h5law Jul 21, 2023
8aadf1d
prog: introspectiont tests
h5law Jul 21, 2023
481a7f7
Remove implementation code
Olshansk Jul 21, 2023
52db173
Remove implementation code
Olshansk Jul 21, 2023
0405806
Bring back proofs
Olshansk Jul 21, 2023
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
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ CWD ?= CURRENT_WORKING_DIRECTIONRY_NOT_SUPPLIED
# `VERBOSE_TEST="" make test_persistence` is an easy way to run the same tests without verbose output
VERBOSE_TEST ?= -v

# Detect OS using the $(shell uname -s) command
ifeq ($(shell uname -s),Darwin)
# Add macOS-specific commands here
SEDI = sed -i ''
else ifeq ($(shell uname -s),Linux)
# Add Linux-specific commands here
SEDI = sed -i
endif

.SILENT:

.PHONY: list ## List all make targets
Expand Down Expand Up @@ -309,13 +318,26 @@ protogen_local: go_protoc-go-inject-tag ## Generate go structures for all of the
$(PROTOC_SHARED) -I=./p2p/types/proto --go_out=./p2p/types ./p2p/types/proto/*.proto

# IBC
make copy_ics23_proto
$(PROTOC_SHARED) -I=./ibc/types/proto --go_out=./ibc/types ./ibc/types/proto/*.proto
$(PROTOC_SHARED) -I=./ibc/client/types/proto --go_out=./ibc/client/types ./ibc/client/types/proto/*.proto
$(PROTOC_SHARED) -I=./ibc/client/types/proto -I=./ibc/client/light_clients/types/proto -I=./shared/core/types/proto -I=./ibc/types/proto --go_out=./ibc/client/light_clients/types ./ibc/client/light_clients/types/proto/*.proto

# echo "View generated proto files by running: make protogen_show"

# CONSIDERATION: Some proto files contain unused gRPC services so we may need to add the following
# if/when we decide to include it: `grpc--go-grpc_opt=paths=source_relative --go-grpc_out=./output/path`

.PHONY: copy_ics23_proto
copy_ics23_proto:
echo "Downloading cosmos/ics23 proto definitions..."
curl -s -o ./ibc/types/proto/proofs.proto https://raw.githubusercontent.com/cosmos/ics23/master/proto/cosmos/ics23/v1/proofs.proto && \
$(SEDI) \
-e '/^package/{N;d;}' \
-e '[email protected]/.*"@github.com/pokt-network/pocket/ibc/types"@g' \
./ibc/types/proto/proofs.proto && \
awk 'BEGIN { print "// ===== !! THIS IS CLONED FROM cosmos/ics23 !! =====\n" } { print }' ./ibc/types/proto/proofs.proto > tmpfile && mv tmpfile ./ibc/types/proto/proofs.proto

.PHONY: protogen_docker_m1
## TECHDEBT: Test, validate & update.
protogen_docker_m1: docker_check
Expand Down
58 changes: 58 additions & 0 deletions ibc/client/light_clients/types/proto/pocket.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
syntax = "proto3";

package core;

option go_package = "github.com/pokt-network/pocket/ibc/client/light_client/types";

import "google/protobuf/timestamp.proto";
import "google/protobuf/duration.proto";
import "proofs.proto";
import "wasm.proto";
import "block.proto";

// PocketConsensusState defines the ibc client consensus state for Pocket
message PocketConsensusState {
google.protobuf.Timestamp timestamp = 1; // unixnano timestamp of the block
string state_hash = 2; // hex encoded root state tree hash
map<string, string> state_tree_hashes = 3; // map of state tree hashes; map[TreeName]hex(TreeRootHash)
string next_val_set_hash = 4; // hex encoded sha3_256 hash of the next validator set
}

// PocketClientState defines the ibc client state for Pocket
message PocketClientState {
string network_id = 1; // network identifier string
Fraction trust_level = 2; // fraction of the validator set that is required to sign off on new blocks
google.protobuf.Duration trusting_period = 3; // the duration of the period since the LastestTimestamp where the state can be upgraded
google.protobuf.Duration unbonding_period = 4; // the duration of the staking unbonding period
google.protobuf.Duration max_clock_drift = 5; // the max duration a new header's time can be in the future
Height latest_height = 6; // the latest height the client was updated to
uint64 frozen_height = 7; // the height at which the client was frozen due to a misbehaviour
ProofSpec proof_spec = 8; // ics23 proof spec used in verifying proofs
// RESEARCH: Figure out exactly what this is for in tendermint, why it is needed and if we need it also
// repeated string upgrade_path = 9; // the upgrade path for the new client state
}

// Fraction defines a positive rational number
message Fraction {
uint64 numerator = 1;
uint64 denominator = 2;
}

// PocketHeader defines the ibc client header for the Pocket network
message PocketHeader {
BlockHeader block_header = 1; // pocket consensus block header
ValidatorSet validator_set = 2; // new validator set for the updating client
// the consensus state at trusted_height must be within the unbonding_period to correctly verify the new header
Height trusted_height = 3; // height of the ConsensusState stored used to verify the new header
// trusted_validators must hash to the ConsensusState.NextValSetHash as this is the last trusted validator set
ValidatorSet trusted_validators = 4; // already stored validator set used to verify the update
}

// PocketMisbehaviour defines the ibc client misbehaviour for the Pocket network
//
// The two conflicting headers are submitted as evidence to verify the Pocket
// network has misbehaved.
message PocketMisbehaviour {
PocketHeader header_1 = 1; // the first header
PocketHeader header_2 = 2; // the second header
}
35 changes: 35 additions & 0 deletions ibc/client/types/proto/wasm.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
syntax = "proto3";

package core;

option go_package = "github.com/pokt-network/pocket/ibc/client/types";

// ClientState for a Wasm light client
message ClientState {
bytes data = 1; // opaque data passed to the wasm client
bytes wasm_checksum = 2; // checksum of the wasm client code
Height recent_height = 3; // latest height of the client
}

// ConsensusState for a Wasm light client
message ConsensusState {
bytes data = 1; // opaque data passed to the wasm client
uint64 timestamp = 2; // unix nano timestamp of the block
}

// Header for a Wasm light client
message Header {
bytes data = 1; // opaque data passed to the wasm client
Height height = 2; // height of the header
}

// Misbehaviour for a Wasm light client
message Misbehaviour {
bytes data = 1; // opaque data passed to the wasm client
}

// Height represents the height of a client
message Height {
uint64 revision_number = 1;
uint64 revision_height = 2;
}
107 changes: 107 additions & 0 deletions ibc/types/proofs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package types

import ics23 "github.com/cosmos/ics23/go"

var SmtSpec = &ProofSpec{
LeafSpec: &LeafOp{
Hash: HashOp_SHA256,
PrehashKey: HashOp_SHA256,
PrehashValue: HashOp_SHA256,
Length: LengthOp_NO_PREFIX,
Prefix: []byte{0},
},
InnerSpec: &InnerSpec{
ChildOrder: []int32{0, 1},
ChildSize: 32,
MinPrefixLength: 1,
MaxPrefixLength: 1,
EmptyChild: make([]byte, 32),
Hash: HashOp_SHA256,
},
MaxDepth: 256,
PrehashKeyBeforeComparison: true,
}

func (p *ProofSpec) ConvertToIcs23ProofSpec() *ics23.ProofSpec {
ics := new(ics23.ProofSpec)
ics.LeafSpec = p.LeafSpec.ConvertToIcs23LeafOp()
ics.InnerSpec = p.InnerSpec.ConvertToIcs23InnerSpec()
ics.MaxDepth = p.MaxDepth
ics.MinDepth = p.MinDepth
ics.PrehashKeyBeforeComparison = p.PrehashKeyBeforeComparison
return ics
}

func (l *LeafOp) ConvertToIcs23LeafOp() *ics23.LeafOp {
ics := new(ics23.LeafOp)
ics.Hash = l.Hash.ConvertToIcs23HashOp()
ics.PrehashKey = l.PrehashKey.ConvertToIcs23HashOp()
ics.PrehashValue = l.PrehashValue.ConvertToIcs23HashOp()
ics.Length = l.Length.ConvertToIcs23LenthOp()
ics.Prefix = l.Prefix
return ics
}

func (i *InnerSpec) ConvertToIcs23InnerSpec() *ics23.InnerSpec {
ics := new(ics23.InnerSpec)
ics.ChildOrder = i.ChildOrder
ics.MinPrefixLength = i.MinPrefixLength
ics.MaxPrefixLength = i.MaxPrefixLength
ics.EmptyChild = i.EmptyChild
ics.Hash = i.Hash.ConvertToIcs23HashOp()
return ics
}

func (h HashOp) ConvertToIcs23HashOp() ics23.HashOp {
switch h {
case HashOp_NO_HASH:
return ics23.HashOp_NO_HASH
case HashOp_SHA256:
return ics23.HashOp_SHA256
case HashOp_SHA512:
return ics23.HashOp_SHA512
case HashOp_KECCAK:
return ics23.HashOp_KECCAK
case HashOp_RIPEMD160:
return ics23.HashOp_RIPEMD160
case HashOp_BITCOIN:
return ics23.HashOp_BITCOIN
case HashOp_SHA512_256:
return ics23.HashOp_SHA512_256
default:
panic("unknown hash op")
}
}

func (l LengthOp) ConvertToIcs23LenthOp() ics23.LengthOp {
switch l {
case LengthOp_NO_PREFIX:
return ics23.LengthOp_NO_PREFIX
case LengthOp_VAR_PROTO:
return ics23.LengthOp_VAR_PROTO
case LengthOp_VAR_RLP:
return ics23.LengthOp_VAR_RLP
case LengthOp_FIXED32_BIG:
return ics23.LengthOp_FIXED32_BIG
case LengthOp_FIXED32_LITTLE:
return ics23.LengthOp_FIXED32_LITTLE
case LengthOp_FIXED64_BIG:
return ics23.LengthOp_FIXED64_BIG
case LengthOp_FIXED64_LITTLE:
return ics23.LengthOp_FIXED64_LITTLE
case LengthOp_REQUIRE_32_BYTES:
return ics23.LengthOp_REQUIRE_32_BYTES
case LengthOp_REQUIRE_64_BYTES:
return ics23.LengthOp_REQUIRE_64_BYTES
default:
panic("unknown length op")
}
}

func (i *InnerOp) ConvertToIcs23InnerOp() *ics23.InnerOp {
ics := new(ics23.InnerOp)
ics.Hash = i.Hash.ConvertToIcs23HashOp()
ics.Prefix = i.Prefix
ics.Suffix = i.Suffix
return ics
}
Loading