Skip to content

Commit

Permalink
feat: cosmos v16 support
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrl-Felix committed Aug 6, 2023
1 parent f03aee6 commit 66ef45b
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 102 deletions.
26 changes: 16 additions & 10 deletions compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import re
import subprocess
import sys

parser = argparse.ArgumentParser(description="Aggregate all protobuf files")
parser.add_argument(
"-p",
Expand Down Expand Up @@ -113,19 +112,26 @@ def remove_all_compiled_python_files(directory):
def rename_any_proto_imports(directory):
for root, dirs, files in os.walk(directory):
for filename in files:
with open(os.path.join(root, filename), "r") as file:
with open(os.path.join(root, filename), "r+") as file:
lines = file.readlines()

if 'import "google/protobuf/any.proto";\n' in lines:
with open(os.path.join(root, filename), "w") as file:
for line in lines:
file.write(
re.sub(
r'^import "google/protobuf/any.proto";\n',
'import "google/protobuf/cosmos_any.proto";\n',
line,
))
for line in lines:
file.write(
re.sub(
r'^import "google/protobuf/any.proto";\n',
'import "google/protobuf/cosmos_any.proto";\n',
line,
))

if 'import "google/protobuf/any.proto";\n' in lines:
for line in lines:
file.write(
re.sub(
r'^import "google/protobuf/any.proto";\n',
'import "google/protobuf/cosmos_any.proto";\n',
line,
))

# rename_any_proto_imports(package_name)
remove_all_compiled_python_files(package_name)
Expand Down
26 changes: 16 additions & 10 deletions configs/osmosis.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
{
"https://github.com/osmosis-labs/osmosis.git": {
"include": true,
"branch": "v10.0.0",
"branch": "v16.1.2",
"paths": ["proto/osmosis"]
},
"https://github.com/cosmos/cosmos-sdk.git": {
"include": true,
"branch": "v0.45.4",
"branch": "v0.47.3",
"paths": ["proto/cosmos"]
},
"https://github.com/tendermint/tendermint.git": {
"https://github.com/informalsystems/tendermint.git": {
"include": true,
"branch": "v0.34.19",
"branch": "v0.34.24",
"paths": ["proto/tendermint"]
},
"https://github.com/cosmos/ibc-go": {
"include": true,
"branch": "v3.0.0",
"branch": "v4.2.0",
"paths": ["proto/ibc", "third_party/proto/google"]
},
"https://github.com/cosmos/cosmos-proto.git": {
"include": true,
"branch": "main",
"branch": "v1.0.0-beta.2",
"paths": ["proto/cosmos_proto"]
},
"https://github.com/cosmos/gogoproto.git": {
"https://github.com/regen-network/protobuf": {
"include": true,
"branch": "master",
"branch": "v1.3.3-alpha.regen.1",
"paths": ["gogoproto"]
},
"https://github.com/confio/ics23.git": {
"https://github.com/cosmos/ics23.git": {
"include": true,
"branch": "master",
"branch": "release/v0.9.x",
"paths": ["proofs.proto"]
},
"https://github.com/osmosis-labs/wasmd.git": {
"include": true,
"branch": "v0.31.0-osmo-v16",
"paths": ["proto/cosmwasm/wasm/v1"]
}

}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "cosmospy_protobuf"
version = "0.2.0"
version = "0.3.0"
description = "This package contains a compiled python version of all cosmos protobuf files with their dependencies"
authors = [
{ name = "ctrl-felix", email = "[email protected]" },
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
grpcio-tools ==1.46.3
grpcio-tools>=1.46.3
4 changes: 2 additions & 2 deletions src/cosmospy_protobuf/gogoproto/gogo.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Protocol Buffers for Go with Gadgets
//
// Copyright (c) 2013, The GoGo Authors. All rights reserved.
// http://github.com/cosmos/gogoproto
// http://github.com/gogo/protobuf
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
Expand Down Expand Up @@ -33,7 +33,7 @@ import "google/protobuf/descriptor.proto";

option java_package = "com.google.protobuf";
option java_outer_classname = "GoGoProtos";
option go_package = "github.com/cosmos/gogoproto/gogoproto";
option go_package = "github.com/gogo/protobuf/gogoproto";

extend google.protobuf.EnumOptions {
optional bool goproto_enum_prefix = 62001;
Expand Down
3 changes: 3 additions & 0 deletions src/cosmospy_protobuf/google/protobuf/any.proto
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ message Any {
bytes value = 2;

option (gogoproto.typedecl) = false;
option (gogoproto.goproto_stringer) = false;
option (gogoproto.gostring) = false;
option (gogoproto.stringer) = false;
}

option (gogoproto.goproto_registration) = false;
150 changes: 75 additions & 75 deletions src/cosmospy_protobuf/proofs.proto
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
syntax = "proto3";

package cosmos.ics23.v1;

option go_package = "github.com/cosmos/ics23/go;ics23";
package ics23;

enum HashOp {
// NO_HASH is the default if no data passed. Note this is an illegal argument some places.
NO_HASH = 0;
SHA256 = 1;
SHA512 = 2;
KECCAK = 3;
RIPEMD160 = 4;
BITCOIN = 5; // ripemd160(sha256(x))
SHA512_256 = 6;
// NO_HASH is the default if no data passed. Note this is an illegal argument some places.
NO_HASH = 0;
SHA256 = 1;
SHA512 = 2;
KECCAK = 3;
RIPEMD160 = 4;
BITCOIN = 5; // ripemd160(sha256(x))
SHA512_256 = 6;
}

/**
Expand All @@ -22,24 +20,24 @@ algorithm, the length will be prepended to the key and value bytes.
(Each one with it's own encoded length)
*/
enum LengthOp {
// NO_PREFIX don't include any length info
NO_PREFIX = 0;
// VAR_PROTO uses protobuf (and go-amino) varint encoding of the length
VAR_PROTO = 1;
// VAR_RLP uses rlp int encoding of the length
VAR_RLP = 2;
// FIXED32_BIG uses big-endian encoding of the length as a 32 bit integer
FIXED32_BIG = 3;
// FIXED32_LITTLE uses little-endian encoding of the length as a 32 bit integer
FIXED32_LITTLE = 4;
// FIXED64_BIG uses big-endian encoding of the length as a 64 bit integer
FIXED64_BIG = 5;
// FIXED64_LITTLE uses little-endian encoding of the length as a 64 bit integer
FIXED64_LITTLE = 6;
// REQUIRE_32_BYTES is like NONE, but will fail if the input is not exactly 32 bytes (sha256 output)
REQUIRE_32_BYTES = 7;
// REQUIRE_64_BYTES is like NONE, but will fail if the input is not exactly 64 bytes (sha512 output)
REQUIRE_64_BYTES = 8;
// NO_PREFIX don't include any length info
NO_PREFIX = 0;
// VAR_PROTO uses protobuf (and go-amino) varint encoding of the length
VAR_PROTO = 1;
// VAR_RLP uses rlp int encoding of the length
VAR_RLP = 2;
// FIXED32_BIG uses big-endian encoding of the length as a 32 bit integer
FIXED32_BIG = 3;
// FIXED32_LITTLE uses little-endian encoding of the length as a 32 bit integer
FIXED32_LITTLE = 4;
// FIXED64_BIG uses big-endian encoding of the length as a 64 bit integer
FIXED64_BIG = 5;
// FIXED64_LITTLE uses little-endian encoding of the length as a 64 bit integer
FIXED64_LITTLE = 6;
// REQUIRE_32_BYTES is like NONE, but will fail if the input is not exactly 32 bytes (sha256 output)
REQUIRE_32_BYTES = 7;
// REQUIRE_64_BYTES is like NONE, but will fail if the input is not exactly 64 bytes (sha512 output)
REQUIRE_64_BYTES = 8;
}

/**
Expand All @@ -64,10 +62,10 @@ in the ProofSpec is valuable to prevent this mutability. And why all trees shoul
length-prefix the data before hashing it.
*/
message ExistenceProof {
bytes key = 1;
bytes value = 2;
LeafOp leaf = 3;
repeated InnerOp path = 4;
bytes key = 1;
bytes value = 2;
LeafOp leaf = 3;
repeated InnerOp path = 4;
}

/*
Expand All @@ -76,21 +74,21 @@ one right of the desired key. If both proofs are valid AND they are neighbors,
then there is no valid proof for the given key.
*/
message NonExistenceProof {
bytes key = 1; // TODO: remove this as unnecessary??? we prove a range
ExistenceProof left = 2;
ExistenceProof right = 3;
bytes key = 1; // TODO: remove this as unnecessary??? we prove a range
ExistenceProof left = 2;
ExistenceProof right = 3;
}

/*
CommitmentProof is either an ExistenceProof or a NonExistenceProof, or a Batch of such messages
*/
message CommitmentProof {
oneof proof {
ExistenceProof exist = 1;
NonExistenceProof nonexist = 2;
BatchProof batch = 3;
CompressedBatchProof compressed = 4;
}
oneof proof {
ExistenceProof exist = 1;
NonExistenceProof nonexist = 2;
BatchProof batch = 3;
CompressedBatchProof compressed = 4;
}
}

/**
Expand All @@ -110,13 +108,13 @@ Then combine the bytes, and hash it
output = hash(prefix || length(hkey) || hkey || length(hvalue) || hvalue)
*/
message LeafOp {
HashOp hash = 1;
HashOp prehash_key = 2;
HashOp prehash_value = 3;
LengthOp length = 4;
// prefix is a fixed bytes that may optionally be included at the beginning to differentiate
// a leaf node from an inner node.
bytes prefix = 5;
HashOp hash = 1;
HashOp prehash_key = 2;
HashOp prehash_value = 3;
LengthOp length = 4;
// prefix is a fixed bytes that may optionally be included at the beginning to differentiate
// a leaf node from an inner node.
bytes prefix = 5;
}

/**
Expand All @@ -137,11 +135,12 @@ some value to differentiate from leaf nodes, should be included in prefix and su
If either of prefix or suffix is empty, we just treat it as an empty string
*/
message InnerOp {
HashOp hash = 1;
bytes prefix = 2;
bytes suffix = 3;
HashOp hash = 1;
bytes prefix = 2;
bytes suffix = 3;
}


/**
ProofSpec defines what the expected parameters are for a given proof type.
This can be stored in the client and used to validate any incoming proofs.
Expand All @@ -156,8 +155,8 @@ tree format server uses. But not in code, rather a configuration object.
*/
message ProofSpec {
// any field in the ExistenceProof must be the same as in this spec.
// except Prefix, which is just the first bytes of prefix (spec can be longer)
LeafOp leaf_spec = 1;
// except Prefix, which is just the first bytes of prefix (spec can be longer)
LeafOp leaf_spec = 1;
InnerSpec inner_spec = 2;
// max_depth (if > 0) is the maximum number of InnerOps allowed (mainly for fixed-depth tries)
int32 max_depth = 3;
Expand All @@ -176,17 +175,17 @@ This enables:
isLeftNeighbor(spec: InnerSpec, left: InnerOp, right: InnerOp)
*/
message InnerSpec {
// Child order is the ordering of the children node, must count from 0
// iavl tree is [0, 1] (left then right)
// merk is [0, 2, 1] (left, right, here)
repeated int32 child_order = 1;
int32 child_size = 2;
int32 min_prefix_length = 3;
int32 max_prefix_length = 4;
// empty child is the prehash image that is used when one child is nil (eg. 20 bytes of 0)
bytes empty_child = 5;
// hash is the algorithm that must be used for each InnerOp
HashOp hash = 6;
// Child order is the ordering of the children node, must count from 0
// iavl tree is [0, 1] (left then right)
// merk is [0, 2, 1] (left, right, here)
repeated int32 child_order = 1;
int32 child_size = 2;
int32 min_prefix_length = 3;
int32 max_prefix_length = 4;
// empty child is the prehash image that is used when one child is nil (eg. 20 bytes of 0)
bytes empty_child = 5;
// hash is the algorithm that must be used for each InnerOp
HashOp hash = 6;
}

/*
Expand All @@ -199,36 +198,37 @@ message BatchProof {
// Use BatchEntry not CommitmentProof, to avoid recursion
message BatchEntry {
oneof proof {
ExistenceProof exist = 1;
ExistenceProof exist = 1;
NonExistenceProof nonexist = 2;
}
}


/****** all items here are compressed forms *******/

message CompressedBatchProof {
repeated CompressedBatchEntry entries = 1;
repeated InnerOp lookup_inners = 2;
repeated CompressedBatchEntry entries = 1;
repeated InnerOp lookup_inners = 2;
}

// Use BatchEntry not CommitmentProof, to avoid recursion
message CompressedBatchEntry {
oneof proof {
CompressedExistenceProof exist = 1;
CompressedExistenceProof exist = 1;
CompressedNonExistenceProof nonexist = 2;
}
}

message CompressedExistenceProof {
bytes key = 1;
bytes value = 2;
LeafOp leaf = 3;
bytes key = 1;
bytes value = 2;
LeafOp leaf = 3;
// these are indexes into the lookup_inners table in CompressedBatchProof
repeated int32 path = 4;
repeated int32 path = 4;
}

message CompressedNonExistenceProof {
bytes key = 1; // TODO: remove this as unnecessary??? we prove a range
CompressedExistenceProof left = 2;
bytes key = 1; // TODO: remove this as unnecessary??? we prove a range
CompressedExistenceProof left = 2;
CompressedExistenceProof right = 3;
}
2 changes: 1 addition & 1 deletion src/cosmospy_protobuf/tendermint/abci/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ message ResponseCheckTx {
string sender = 9;
int64 priority = 10;

// mempool_error is set by Tendermint.
// mempool_error is set by CometBFT.
// ABCI applictions creating a ResponseCheckTX should not set mempool_error.
string mempool_error = 11;
}
Expand Down
Loading

0 comments on commit 66ef45b

Please sign in to comment.