From 40f1facd975e93332f222bf2d746b131b47a27f2 Mon Sep 17 00:00:00 2001 From: Erik Grinaker Date: Thu, 2 Jul 2020 15:20:20 +0200 Subject: [PATCH] proof: migrate ProofOp encoding to Protobuf (#287) Fixes #242. Switches ProofOp encoding from Amino to Protobuf, but retains the same byte layout for backwards compatibility. This is not strictly Protobuf since the proofs are length-prefixed, but that's what Amino did so that's what we'll keep doing. The Protobuf types need to be moved to a separate package and cleaned up: they conflict with the native types, and we're making the same mistake as before by leaking Protobuf types through public APIs. I'll submit a separate PR for this. --- CHANGELOG.md | 4 + encoding.go | 8 + go.mod | 2 - go.sum | 4 - proof.go | 50 ++ proof_iavl_absence.go | 32 +- proof_iavl_test.go | 102 +++ proof_iavl_value.go | 32 +- proof_range.go | 60 ++ proof_test.go | 30 +- proto/iavl/types.proto | 43 ++ types.pb.go | 1673 +++++++++++++++++++++++++++++++++++++--- wire.go | 17 - 13 files changed, 1918 insertions(+), 139 deletions(-) create mode 100644 proof_iavl_test.go delete mode 100644 wire.go diff --git a/CHANGELOG.md b/CHANGELOG.md index f2580de15..53892a73c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ https://github.com/cosmos/iavl. This also affects the module import path, which - The module path has changed from `github.com/tendermint/iavl` to `github.com/cosmos/iavl`. +### Improvements + +- Proofs are now encoded using Protobuf instead of Amino. The binary encoding is identical. + ## 0.14.0 (July 2, 2020) **Important information:** the pruning functionality introduced with IAVL 0.13.0 via the options diff --git a/encoding.go b/encoding.go index 1f2f153aa..27c10fe1f 100644 --- a/encoding.go +++ b/encoding.go @@ -1,6 +1,7 @@ package iavl import ( + "bytes" "encoding/binary" "errors" "fmt" @@ -68,6 +69,13 @@ func encodeBytes(w io.Writer, bz []byte) error { return err } +// encodeBytesSlice length-prefixes the byte slice and returns it. +func encodeBytesSlice(bz []byte) ([]byte, error) { + var buf bytes.Buffer + err := encodeBytes(&buf, bz) + return buf.Bytes(), err +} + // encodeBytesSize returns the byte size of the given slice including length-prefixing. func encodeBytesSize(bz []byte) int { return encodeUvarintSize(uint64(len(bz))) + len(bz) diff --git a/go.mod b/go.mod index 7be542108..a4f566950 100644 --- a/go.mod +++ b/go.mod @@ -5,11 +5,9 @@ go 1.13 require ( github.com/gogo/protobuf v1.3.1 github.com/golang/protobuf v1.4.2 // indirect - github.com/google/gofuzz v1.0.0 // indirect github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.6.1 - github.com/tendermint/go-amino v0.14.1 github.com/tendermint/tm-db v0.6.0 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 golang.org/x/text v0.3.2 // indirect diff --git a/go.sum b/go.sum index f08dc31b8..2b2bd1781 100644 --- a/go.sum +++ b/go.sum @@ -46,8 +46,6 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= -github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U= @@ -78,8 +76,6 @@ github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d h1:gZZadD8H+fF+ github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA= github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c h1:g+WoO5jjkqGAzHWCjJB1zZfXPIAaDpzXIEJ0eS6B5Ok= github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c/go.mod h1:ahpPrc7HpcfEWDQRZEmnXMzHY03mLDYMCxeDzy46i+8= -github.com/tendermint/go-amino v0.14.1 h1:o2WudxNfdLNBwMyl2dqOJxiro5rfrEaU0Ugs6offJMk= -github.com/tendermint/go-amino v0.14.1/go.mod h1:i/UKE5Uocn+argJJBb12qTZsCDBcAYMbR92AaJVmKso= github.com/tendermint/tm-db v0.6.0 h1:Us30k7H1UDcdqoSPhmP8ztAW/SWV6c6OfsfeCiboTC4= github.com/tendermint/tm-db v0.6.0/go.mod h1:xj3AWJ08kBDlCHKijnhJ7mTcDMOikT1r8Poxy2pJn7Q= go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0= diff --git a/proof.go b/proof.go index c2607bb09..6014ab189 100644 --- a/proof.go +++ b/proof.go @@ -4,6 +4,7 @@ import ( "bytes" "crypto/sha256" "fmt" + "math" "github.com/pkg/errors" @@ -89,6 +90,34 @@ func (pin ProofInnerNode) Hash(childHash []byte) []byte { return hasher.Sum(nil) } +// toProto converts the inner node proof to Protobuf, for use in ProofOps. +func (pin ProofInnerNode) toProto() *ProofOpInner { + return &ProofOpInner{ + Height: int32(pin.Height), + Size_: pin.Size, + Version: pin.Version, + Left: pin.Left, + Right: pin.Right, + } +} + +// proofInnerNodeFromProto converts a Protobuf ProofOpInner to a ProofInnerNode. +func proofInnerNodeFromProto(pbInner *ProofOpInner) (ProofInnerNode, error) { + if pbInner == nil { + return ProofInnerNode{}, errors.New("inner node cannot be nil") + } + if pbInner.Height > math.MaxInt8 || pbInner.Height < math.MinInt8 { + return ProofInnerNode{}, fmt.Errorf("height must fit inside an int8, got %v", pbInner.Height) + } + return ProofInnerNode{ + Height: int8(pbInner.Height), + Size: pbInner.Size_, + Version: pbInner.Version, + Left: pbInner.Left, + Right: pbInner.Right, + }, nil +} + //---------------------------------------- type ProofLeafNode struct { @@ -142,6 +171,27 @@ func (pln ProofLeafNode) Hash() []byte { return hasher.Sum(nil) } +// toProto converts the leaf node proof to Protobuf, for use in ProofOps. +func (pln ProofLeafNode) toProto() *ProofOpLeaf { + return &ProofOpLeaf{ + Key: pln.Key, + ValueHash: pln.ValueHash, + Version: pln.Version, + } +} + +// proofLeafNodeFromProto converts a Protobuf ProofOpInner to a ProofLeafNode. +func proofLeafNodeFromProto(pbLeaf *ProofOpLeaf) (ProofLeafNode, error) { + if pbLeaf == nil { + return ProofLeafNode{}, errors.New("leaf node cannot be nil") + } + return ProofLeafNode{ + Key: pbLeaf.Key, + ValueHash: pbLeaf.ValueHash, + Version: pbLeaf.Version, + }, nil +} + //---------------------------------------- // If the key does not exist, returns the path to the next leaf left of key (w/ diff --git a/proof_iavl_absence.go b/proof_iavl_absence.go index 6eeaada74..c2d569313 100644 --- a/proof_iavl_absence.go +++ b/proof_iavl_absence.go @@ -3,6 +3,7 @@ package iavl import ( "fmt" + proto "github.com/gogo/protobuf/proto" "github.com/pkg/errors" ) @@ -35,16 +36,37 @@ func AbsenceOpDecoder(pop ProofOp) (ProofOperator, error) { if pop.Type != ProofOpIAVLAbsence { return nil, errors.Errorf("unexpected ProofOp.Type; got %v, want %v", pop.Type, ProofOpIAVLAbsence) } - var op AbsenceOp // a bit strange as we'll discard this, but it works. - err := cdc.UnmarshalBinaryLengthPrefixed(pop.Data, &op) + // Strip the varint length prefix, used for backwards compatibility with Amino. + bz, n, err := decodeBytes(pop.Data) if err != nil { - return nil, errors.Wrap(err, "decoding ProofOp.Data into IAVLAbsenceOp") + return nil, err } - return NewAbsenceOp(pop.Key, op.Proof), nil + if n != len(pop.Data) { + return nil, fmt.Errorf("unexpected bytes, expected %v got %v", n, len(pop.Data)) + } + pbProofOp := &ProofOpAbsence{} + err = proto.Unmarshal(bz, pbProofOp) + if err != nil { + return nil, err + } + proof, err := rangeProofFromProto(pbProofOp.Proof) + if err != nil { + return nil, err + } + return NewAbsenceOp(pop.Key, &proof), nil } func (op AbsenceOp) ProofOp() ProofOp { - bz := cdc.MustMarshalBinaryLengthPrefixed(op) + pbProof := ProofOpAbsence{Proof: op.Proof.toProto()} + bz, err := pbProof.Marshal() + if err != nil { + panic(err) + } + // We length-prefix the byte slice to retain backwards compatibility with the Amino proofs. + bz, err = encodeBytesSlice(bz) + if err != nil { + panic(err) + } return ProofOp{ Type: ProofOpIAVLAbsence, Key: op.key, diff --git a/proof_iavl_test.go b/proof_iavl_test.go new file mode 100644 index 000000000..5a8b6a1ed --- /dev/null +++ b/proof_iavl_test.go @@ -0,0 +1,102 @@ +package iavl + +import ( + "encoding/hex" + "fmt" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + db "github.com/tendermint/tm-db" +) + +func TestProofOp(t *testing.T) { + tree, err := NewMutableTreeWithOpts(db.NewMemDB(), 0, nil) + require.NoError(t, err) + keys := []byte{0x0a, 0x11, 0x2e, 0x32, 0x50, 0x72, 0x99, 0xa1, 0xe4, 0xf7} // 10 total. + for _, ikey := range keys { + key := []byte{ikey} + tree.Set(key, key) + } + root := tree.WorkingHash() + + testcases := []struct { + key byte + expectPresent bool + expectProofOp string + }{ + {0x00, false, "aa010aa7010a280808100a18012a2022b4e34a1778d6a03aac39f00d89deb886e0cc37454e300b7aebeb4f4939c0790a280804100418012a20734fad809673ab2b9672453a8b2bc8c9591e2d1d97933df5b4c3b0531bf82e720a280802100218012a20154b101a72acffe0f5e65d1e144a57dc6f97758d2049821231f02b6a5b44fe811a270a010a122001ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b1801"}, + {0x0a, true, "aa010aa7010a280808100a18012a2022b4e34a1778d6a03aac39f00d89deb886e0cc37454e300b7aebeb4f4939c0790a280804100418012a20734fad809673ab2b9672453a8b2bc8c9591e2d1d97933df5b4c3b0531bf82e720a280802100218012a20154b101a72acffe0f5e65d1e144a57dc6f97758d2049821231f02b6a5b44fe811a270a010a122001ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b1801"}, + {0x0b, false, "d5010ad2010a280808100a18012a2022b4e34a1778d6a03aac39f00d89deb886e0cc37454e300b7aebeb4f4939c0790a280804100418012a20734fad809673ab2b9672453a8b2bc8c9591e2d1d97933df5b4c3b0531bf82e720a280802100218012a20154b101a72acffe0f5e65d1e144a57dc6f97758d2049821231f02b6a5b44fe8112001a270a010a122001ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b18011a270a011112204a64a107f0cb32536e5bce6c98c393db21cca7f4ea187ba8c4dca8b51d4ea80a1801"}, + {0x11, true, "aa010aa7010a280808100a18012a2022b4e34a1778d6a03aac39f00d89deb886e0cc37454e300b7aebeb4f4939c0790a280804100418012a20734fad809673ab2b9672453a8b2bc8c9591e2d1d97933df5b4c3b0531bf82e720a28080210021801222053d2828f35e33aecab8e411a40afb0475288973b96aed2220e9894f43a5375ad1a270a011112204a64a107f0cb32536e5bce6c98c393db21cca7f4ea187ba8c4dca8b51d4ea80a1801"}, + {0x60, false, "d5010ad2010a280808100a18012220e39776faa9ef2b83ae828860d24f807efab321d02b78081c0e68e1bf801b0e220a280806100618012a20631b10ce49ece4cc9130befac927865742fb11caf2e8fc08fc00a4a25e4bc7940a280802100218012a207a4a97f565ae0b3ea8abf175208f176ac8301665ac2d26c89be3664f90e23da612001a270a015012205c62e091b8c0565f1bafad0dad5934276143ae2ccef7a5381e8ada5b1a8d26d218011a270a01721220454349e422f05297191ead13e21d3db520e5abef52055e4964b82fb213f593a11801"}, + {0x72, true, "aa010aa7010a280808100a18012220e39776faa9ef2b83ae828860d24f807efab321d02b78081c0e68e1bf801b0e220a280806100618012a20631b10ce49ece4cc9130befac927865742fb11caf2e8fc08fc00a4a25e4bc7940a28080210021801222035f8ea805390e084854f399b42ccdeaea33a1dedc115638ac48d0600637dba1f1a270a01721220454349e422f05297191ead13e21d3db520e5abef52055e4964b82fb213f593a11801"}, + {0x99, true, "d4010ad1010a280808100a18012220e39776faa9ef2b83ae828860d24f807efab321d02b78081c0e68e1bf801b0e220a2808061006180122201d6b29f2c439fc9f15703eb7031e4a216002ea36ee9496583f97b20302b6a74e0a280804100418012a2043b83a6acefd4fd33970d1bc8fc47bed81220c752b8de7053e8ee082a2c7c1290a280802100218012a208f69a1db006c0ee9fad3c7c624b92acc88e9ed00771976ea24a64796c236fef01a270a01991220fd9528b920d6d3956e9e16114523e1889c751e8c1e040182116d4c906b43f5581801"}, + {0xaa, false, "a9020aa6020a280808100a18012220e39776faa9ef2b83ae828860d24f807efab321d02b78081c0e68e1bf801b0e220a2808061006180122201d6b29f2c439fc9f15703eb7031e4a216002ea36ee9496583f97b20302b6a74e0a280804100418012a2043b83a6acefd4fd33970d1bc8fc47bed81220c752b8de7053e8ee082a2c7c1290a280802100218012220a303930ca8831618ac7e4ddd10546cfc366fb730d6630c030a97226bbefc6935122a0a280802100218012a2077ad141b2010cf7107de941aac5b46f44fa4f41251076656a72308263a964fb91a270a01a112208a8950f7623663222542c9469c73be3c4c81bbdf019e2c577590a61f2ce9a15718011a270a01e412205e1effe9b7bab73dce628ccd9f0cbbb16c1e6efc6c4f311e59992a467bc119fd1801"}, + {0xe4, true, "d4010ad1010a280808100a18012220e39776faa9ef2b83ae828860d24f807efab321d02b78081c0e68e1bf801b0e220a2808061006180122201d6b29f2c439fc9f15703eb7031e4a216002ea36ee9496583f97b20302b6a74e0a2808041004180122208bc4764843fdd745dc853fa62f2fac0001feae9e46136192f466c09773e2ed050a280802100218012a2077ad141b2010cf7107de941aac5b46f44fa4f41251076656a72308263a964fb91a270a01e412205e1effe9b7bab73dce628ccd9f0cbbb16c1e6efc6c4f311e59992a467bc119fd1801"}, + {0xf7, true, "d4010ad1010a280808100a18012220e39776faa9ef2b83ae828860d24f807efab321d02b78081c0e68e1bf801b0e220a2808061006180122201d6b29f2c439fc9f15703eb7031e4a216002ea36ee9496583f97b20302b6a74e0a2808041004180122208bc4764843fdd745dc853fa62f2fac0001feae9e46136192f466c09773e2ed050a28080210021801222032af6e3eec2b63d5fe1bd992a89ef3467b3cee639c068cace942f01326098f171a270a01f7122050868f20258bbc9cce0da2719e8654c108733dd2f663b8737c574ec0ead93eb31801"}, + {0xfe, false, "d4010ad1010a280808100a18012220e39776faa9ef2b83ae828860d24f807efab321d02b78081c0e68e1bf801b0e220a2808061006180122201d6b29f2c439fc9f15703eb7031e4a216002ea36ee9496583f97b20302b6a74e0a2808041004180122208bc4764843fdd745dc853fa62f2fac0001feae9e46136192f466c09773e2ed050a28080210021801222032af6e3eec2b63d5fe1bd992a89ef3467b3cee639c068cace942f01326098f171a270a01f7122050868f20258bbc9cce0da2719e8654c108733dd2f663b8737c574ec0ead93eb31801"}, + //{0xff, false, ""}, // FIXME This panics, see https://github.com/cosmos/iavl/issues/286 + } + + for _, tc := range testcases { + tc := tc + t.Run(fmt.Sprintf("%02x", tc.key), func(t *testing.T) { + key := []byte{tc.key} + value, proof, err := tree.GetWithProof(key) + require.NoError(t, err) + + // Verify that proof is valid. + err = proof.Verify(root) + require.NoError(t, err) + + // Encode and decode proof, either ValueOp or AbsentOp depending on key existence. + expectBytes, err := hex.DecodeString(tc.expectProofOp) + require.NoError(t, err) + + if tc.expectPresent { + require.NotNil(t, value) + err = proof.VerifyItem(key, value) + require.NoError(t, err) + + valueOp := NewValueOp(key, proof) + proofOp := valueOp.ProofOp() + assert.Equal(t, ProofOp{ + Type: ProofOpIAVLValue, + Key: key, + Data: expectBytes, + }, proofOp) + + //t.Logf("Expect: %x", expectBytes) + //t.Logf("Actual: %x", proofOp.Data) + + d, e := ValueOpDecoder(proofOp) + require.NoError(t, e) + decoded := d.(ValueOp) + err = decoded.Proof.Verify(root) + require.NoError(t, err) + assert.Equal(t, valueOp, decoded) + + } else { + require.Nil(t, value) + err = proof.VerifyAbsence(key) + require.NoError(t, err) + + absenceOp := NewAbsenceOp(key, proof) + proofOp := absenceOp.ProofOp() + assert.Equal(t, ProofOp{ + Type: ProofOpIAVLAbsence, + Key: key, + Data: expectBytes, + }, proofOp) + + d, e := AbsenceOpDecoder(proofOp) + require.NoError(t, e) + decoded := d.(AbsenceOp) + err = decoded.Proof.Verify(root) + require.NoError(t, err) + assert.Equal(t, absenceOp, decoded) + } + }) + } +} diff --git a/proof_iavl_value.go b/proof_iavl_value.go index a511e58be..485e758ae 100644 --- a/proof_iavl_value.go +++ b/proof_iavl_value.go @@ -3,6 +3,7 @@ package iavl import ( "fmt" + proto "github.com/gogo/protobuf/proto" "github.com/pkg/errors" ) @@ -36,16 +37,37 @@ func ValueOpDecoder(pop ProofOp) (ProofOperator, error) { if pop.Type != ProofOpIAVLValue { return nil, errors.Errorf("unexpected ProofOp.Type; got %v, want %v", pop.Type, ProofOpIAVLValue) } - var op ValueOp // a bit strange as we'll discard this, but it works. - err := cdc.UnmarshalBinaryLengthPrefixed(pop.Data, &op) + // Strip the varint length prefix, used for backwards compatibility with Amino. + bz, n, err := decodeBytes(pop.Data) if err != nil { - return nil, errors.Wrap(err, "decoding ProofOp.Data into IAVLValueOp") + return nil, err } - return NewValueOp(pop.Key, op.Proof), nil + if n != len(pop.Data) { + return nil, fmt.Errorf("unexpected bytes, expected %v got %v", n, len(pop.Data)) + } + pbProofOp := &ProofOpValue{} + err = proto.Unmarshal(bz, pbProofOp) + if err != nil { + return nil, err + } + proof, err := rangeProofFromProto(pbProofOp.Proof) + if err != nil { + return nil, err + } + return NewValueOp(pop.Key, &proof), nil } func (op ValueOp) ProofOp() ProofOp { - bz := cdc.MustMarshalBinaryLengthPrefixed(op) + pbProof := ProofOpValue{Proof: op.Proof.toProto()} + bz, err := pbProof.Marshal() + if err != nil { + panic(err) + } + // We length-prefix the byte slice to retain backwards compatibility with the Amino proofs. + bz, err = encodeBytesSlice(bz) + if err != nil { + panic(err) + } return ProofOp{ Type: ProofOpIAVLValue, Key: op.key, diff --git a/proof_range.go b/proof_range.go index 3e7e3ac1c..61d3f95ad 100644 --- a/proof_range.go +++ b/proof_range.go @@ -305,6 +305,66 @@ func (proof *RangeProof) _computeRootHash() (rootHash []byte, treeEnd bool, err return rootHash, treeEnd, nil } +// toProto converts the proof to a Protobuf representation, for use in ValueOp and AbsenceOp. +func (proof *RangeProof) toProto() *ProofOpRange { + pb := &ProofOpRange{ + LeftPath: make([]*ProofOpInner, 0, len(proof.LeftPath)), + InnerNodes: make([]*ProofOpPath, 0, len(proof.InnerNodes)), + Leaves: make([]*ProofOpLeaf, 0, len(proof.Leaves)), + } + for _, inner := range proof.LeftPath { + pb.LeftPath = append(pb.LeftPath, inner.toProto()) + } + for _, path := range proof.InnerNodes { + pbPath := make([]*ProofOpInner, 0, len(path)) + for _, inner := range path { + pbPath = append(pbPath, inner.toProto()) + } + pb.InnerNodes = append(pb.InnerNodes, &ProofOpPath{Inners: pbPath}) + } + for _, leaf := range proof.Leaves { + pb.Leaves = append(pb.Leaves, leaf.toProto()) + } + + return pb +} + +// rangeProofFromProto generates a RangeProof from a Protobuf ProofOpRange. +func rangeProofFromProto(pbProof *ProofOpRange) (RangeProof, error) { + proof := RangeProof{} + + for _, pbInner := range pbProof.LeftPath { + inner, err := proofInnerNodeFromProto(pbInner) + if err != nil { + return proof, err + } + proof.LeftPath = append(proof.LeftPath, inner) + } + + for _, pbPath := range pbProof.InnerNodes { + var path PathToLeaf // leave as nil unless populated, for Amino compatibility + if pbPath != nil { + for _, pbInner := range pbPath.Inners { + inner, err := proofInnerNodeFromProto(pbInner) + if err != nil { + return proof, err + } + path = append(path, inner) + } + } + proof.InnerNodes = append(proof.InnerNodes, path) + } + + for _, pbLeaf := range pbProof.Leaves { + leaf, err := proofLeafNodeFromProto(pbLeaf) + if err != nil { + return proof, err + } + proof.Leaves = append(proof.Leaves, leaf) + } + return proof, nil +} + /////////////////////////////////////////////////////////////////////////////// // keyStart is inclusive and keyEnd is exclusive. diff --git a/proof_test.go b/proof_test.go index 21f96e7bb..8e9d05717 100644 --- a/proof_test.go +++ b/proof_test.go @@ -5,11 +5,11 @@ import ( "bytes" "testing" + proto "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" cmn "github.com/cosmos/iavl/common" - amino "github.com/tendermint/go-amino" ) func TestTreeGetWithProof(t *testing.T) { @@ -205,27 +205,39 @@ func TestTreeKeyInRangeProofs(t *testing.T) { } } +func encodeProof(proof *RangeProof) ([]byte, error) { + return proof.toProto().Marshal() +} + +func decodeProof(bz []byte) (*RangeProof, error) { + proofOp := &ProofOpRange{} + err := proto.Unmarshal(bz, proofOp) + if err != nil { + return nil, err + } + proof, err := rangeProofFromProto(proofOp) + return &proof, err +} + func verifyProof(t *testing.T, proof *RangeProof, root []byte) { // Proof must verify. require.NoError(t, proof.Verify(root)) // Write/Read then verify. - cdc := amino.NewCodec() - proofBytes := cdc.MustMarshalBinaryLengthPrefixed(proof) - var proof2 = new(RangeProof) - err := cdc.UnmarshalBinaryLengthPrefixed(proofBytes, proof2) - require.Nil(t, err, "Failed to read KeyExistsProof from bytes: %v", err) + proofBytes, err := encodeProof(proof) + require.NoError(t, err) + _, err = decodeProof(proofBytes) + require.NoError(t, err) // Random mutations must not verify for i := 0; i < 1e4; i++ { badProofBytes := cmn.MutateByteSlice(proofBytes) - var badProof = new(RangeProof) - err := cdc.UnmarshalBinaryLengthPrefixed(badProofBytes, badProof) + badProof, err := decodeProof(badProofBytes) if err != nil { continue // couldn't even decode. } // re-encode to make sure it's actually different. - badProofBytes2 := cdc.MustMarshalBinaryLengthPrefixed(badProof) + badProofBytes2, err := encodeProof(badProof) if bytes.Equal(proofBytes, badProofBytes2) { continue // didn't mutate successfully. } diff --git a/proto/iavl/types.proto b/proto/iavl/types.proto index 7a020fe7e..387b2875b 100644 --- a/proto/iavl/types.proto +++ b/proto/iavl/types.proto @@ -16,3 +16,46 @@ message ProofOp { message Proof { repeated ProofOp ops = 1; } + +// ProofOpValue is a value proof, used internally to encode and decode ValueOp. +message ProofOpValue { + ProofOpRange proof = 1; +} + +// ProofOpValue is a value proof, used internally to encode and decode ValueOp. +message ProofOpAbsence { + ProofOpRange proof = 1; +} + + +// ProofOpRange is used internally to encode and decode ValueOp and +// AbsenceOp proof operations. +message ProofOpRange { + repeated ProofOpInner left_path = 1; + repeated ProofOpPath inner_nodes = 2; + repeated ProofOpLeaf leaves = 3; +} + +// ProofOpPath is used internally to encode and decode leaf +// node paths for ProofOpRange. +message ProofOpPath { + repeated ProofOpInner inners = 1; +} + +// ProofOpInner is used internally to encode and decode inner nodes +// for ProofOpRange. +message ProofOpInner { + sint32 height = 1; + int64 size = 2; + int64 version = 3; + bytes left = 4; + bytes right = 5; +} + +// ProofOpLeaf is used internally to encode and decode leaf nodes +// for ProofOpRange. +message ProofOpLeaf { + bytes key = 1; + bytes value_hash = 2; + int64 version = 3; +} diff --git a/types.pb.go b/types.pb.go index ced1f48f7..ee8325fc4 100644 --- a/types.pb.go +++ b/types.pb.go @@ -130,26 +130,385 @@ func (m *Proof) GetOps() []*ProofOp { return nil } +// ProofOpValue is a value proof, used internally to encode and decode ValueOp. +type ProofOpValue struct { + Proof *ProofOpRange `protobuf:"bytes,1,opt,name=proof,proto3" json:"proof,omitempty"` +} + +func (m *ProofOpValue) Reset() { *m = ProofOpValue{} } +func (m *ProofOpValue) String() string { return proto.CompactTextString(m) } +func (*ProofOpValue) ProtoMessage() {} +func (*ProofOpValue) Descriptor() ([]byte, []int) { + return fileDescriptor_7ef37c124502d49e, []int{2} +} +func (m *ProofOpValue) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ProofOpValue) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ProofOpValue.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ProofOpValue) XXX_Merge(src proto.Message) { + xxx_messageInfo_ProofOpValue.Merge(m, src) +} +func (m *ProofOpValue) XXX_Size() int { + return m.Size() +} +func (m *ProofOpValue) XXX_DiscardUnknown() { + xxx_messageInfo_ProofOpValue.DiscardUnknown(m) +} + +var xxx_messageInfo_ProofOpValue proto.InternalMessageInfo + +func (m *ProofOpValue) GetProof() *ProofOpRange { + if m != nil { + return m.Proof + } + return nil +} + +// ProofOpValue is a value proof, used internally to encode and decode ValueOp. +type ProofOpAbsence struct { + Proof *ProofOpRange `protobuf:"bytes,1,opt,name=proof,proto3" json:"proof,omitempty"` +} + +func (m *ProofOpAbsence) Reset() { *m = ProofOpAbsence{} } +func (m *ProofOpAbsence) String() string { return proto.CompactTextString(m) } +func (*ProofOpAbsence) ProtoMessage() {} +func (*ProofOpAbsence) Descriptor() ([]byte, []int) { + return fileDescriptor_7ef37c124502d49e, []int{3} +} +func (m *ProofOpAbsence) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ProofOpAbsence) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ProofOpAbsence.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ProofOpAbsence) XXX_Merge(src proto.Message) { + xxx_messageInfo_ProofOpAbsence.Merge(m, src) +} +func (m *ProofOpAbsence) XXX_Size() int { + return m.Size() +} +func (m *ProofOpAbsence) XXX_DiscardUnknown() { + xxx_messageInfo_ProofOpAbsence.DiscardUnknown(m) +} + +var xxx_messageInfo_ProofOpAbsence proto.InternalMessageInfo + +func (m *ProofOpAbsence) GetProof() *ProofOpRange { + if m != nil { + return m.Proof + } + return nil +} + +// ProofOpRange is used internally to encode and decode ValueOp and +// AbsenceOp proof operations. +type ProofOpRange struct { + LeftPath []*ProofOpInner `protobuf:"bytes,1,rep,name=left_path,json=leftPath,proto3" json:"left_path,omitempty"` + InnerNodes []*ProofOpPath `protobuf:"bytes,2,rep,name=inner_nodes,json=innerNodes,proto3" json:"inner_nodes,omitempty"` + Leaves []*ProofOpLeaf `protobuf:"bytes,3,rep,name=leaves,proto3" json:"leaves,omitempty"` +} + +func (m *ProofOpRange) Reset() { *m = ProofOpRange{} } +func (m *ProofOpRange) String() string { return proto.CompactTextString(m) } +func (*ProofOpRange) ProtoMessage() {} +func (*ProofOpRange) Descriptor() ([]byte, []int) { + return fileDescriptor_7ef37c124502d49e, []int{4} +} +func (m *ProofOpRange) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ProofOpRange) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ProofOpRange.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ProofOpRange) XXX_Merge(src proto.Message) { + xxx_messageInfo_ProofOpRange.Merge(m, src) +} +func (m *ProofOpRange) XXX_Size() int { + return m.Size() +} +func (m *ProofOpRange) XXX_DiscardUnknown() { + xxx_messageInfo_ProofOpRange.DiscardUnknown(m) +} + +var xxx_messageInfo_ProofOpRange proto.InternalMessageInfo + +func (m *ProofOpRange) GetLeftPath() []*ProofOpInner { + if m != nil { + return m.LeftPath + } + return nil +} + +func (m *ProofOpRange) GetInnerNodes() []*ProofOpPath { + if m != nil { + return m.InnerNodes + } + return nil +} + +func (m *ProofOpRange) GetLeaves() []*ProofOpLeaf { + if m != nil { + return m.Leaves + } + return nil +} + +// ProofOpPath is used internally to encode and decode leaf +// node paths for ProofOpRange. +type ProofOpPath struct { + Inners []*ProofOpInner `protobuf:"bytes,1,rep,name=inners,proto3" json:"inners,omitempty"` +} + +func (m *ProofOpPath) Reset() { *m = ProofOpPath{} } +func (m *ProofOpPath) String() string { return proto.CompactTextString(m) } +func (*ProofOpPath) ProtoMessage() {} +func (*ProofOpPath) Descriptor() ([]byte, []int) { + return fileDescriptor_7ef37c124502d49e, []int{5} +} +func (m *ProofOpPath) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ProofOpPath) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ProofOpPath.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ProofOpPath) XXX_Merge(src proto.Message) { + xxx_messageInfo_ProofOpPath.Merge(m, src) +} +func (m *ProofOpPath) XXX_Size() int { + return m.Size() +} +func (m *ProofOpPath) XXX_DiscardUnknown() { + xxx_messageInfo_ProofOpPath.DiscardUnknown(m) +} + +var xxx_messageInfo_ProofOpPath proto.InternalMessageInfo + +func (m *ProofOpPath) GetInners() []*ProofOpInner { + if m != nil { + return m.Inners + } + return nil +} + +// ProofOpInner is used internally to encode and decode inner nodes +// for ProofOpRange. +type ProofOpInner struct { + Height int32 `protobuf:"zigzag32,1,opt,name=height,proto3" json:"height,omitempty"` + Size_ int64 `protobuf:"varint,2,opt,name=size,proto3" json:"size,omitempty"` + Version int64 `protobuf:"varint,3,opt,name=version,proto3" json:"version,omitempty"` + Left []byte `protobuf:"bytes,4,opt,name=left,proto3" json:"left,omitempty"` + Right []byte `protobuf:"bytes,5,opt,name=right,proto3" json:"right,omitempty"` +} + +func (m *ProofOpInner) Reset() { *m = ProofOpInner{} } +func (m *ProofOpInner) String() string { return proto.CompactTextString(m) } +func (*ProofOpInner) ProtoMessage() {} +func (*ProofOpInner) Descriptor() ([]byte, []int) { + return fileDescriptor_7ef37c124502d49e, []int{6} +} +func (m *ProofOpInner) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ProofOpInner) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ProofOpInner.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ProofOpInner) XXX_Merge(src proto.Message) { + xxx_messageInfo_ProofOpInner.Merge(m, src) +} +func (m *ProofOpInner) XXX_Size() int { + return m.Size() +} +func (m *ProofOpInner) XXX_DiscardUnknown() { + xxx_messageInfo_ProofOpInner.DiscardUnknown(m) +} + +var xxx_messageInfo_ProofOpInner proto.InternalMessageInfo + +func (m *ProofOpInner) GetHeight() int32 { + if m != nil { + return m.Height + } + return 0 +} + +func (m *ProofOpInner) GetSize_() int64 { + if m != nil { + return m.Size_ + } + return 0 +} + +func (m *ProofOpInner) GetVersion() int64 { + if m != nil { + return m.Version + } + return 0 +} + +func (m *ProofOpInner) GetLeft() []byte { + if m != nil { + return m.Left + } + return nil +} + +func (m *ProofOpInner) GetRight() []byte { + if m != nil { + return m.Right + } + return nil +} + +// ProofOpLeaf is used internally to encode and decode leaf nodes +// for ProofOpRange. +type ProofOpLeaf struct { + Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + ValueHash []byte `protobuf:"bytes,2,opt,name=value_hash,json=valueHash,proto3" json:"value_hash,omitempty"` + Version int64 `protobuf:"varint,3,opt,name=version,proto3" json:"version,omitempty"` +} + +func (m *ProofOpLeaf) Reset() { *m = ProofOpLeaf{} } +func (m *ProofOpLeaf) String() string { return proto.CompactTextString(m) } +func (*ProofOpLeaf) ProtoMessage() {} +func (*ProofOpLeaf) Descriptor() ([]byte, []int) { + return fileDescriptor_7ef37c124502d49e, []int{7} +} +func (m *ProofOpLeaf) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ProofOpLeaf) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ProofOpLeaf.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ProofOpLeaf) XXX_Merge(src proto.Message) { + xxx_messageInfo_ProofOpLeaf.Merge(m, src) +} +func (m *ProofOpLeaf) XXX_Size() int { + return m.Size() +} +func (m *ProofOpLeaf) XXX_DiscardUnknown() { + xxx_messageInfo_ProofOpLeaf.DiscardUnknown(m) +} + +var xxx_messageInfo_ProofOpLeaf proto.InternalMessageInfo + +func (m *ProofOpLeaf) GetKey() []byte { + if m != nil { + return m.Key + } + return nil +} + +func (m *ProofOpLeaf) GetValueHash() []byte { + if m != nil { + return m.ValueHash + } + return nil +} + +func (m *ProofOpLeaf) GetVersion() int64 { + if m != nil { + return m.Version + } + return 0 +} + func init() { proto.RegisterType((*ProofOp)(nil), "iavl.ProofOp") proto.RegisterType((*Proof)(nil), "iavl.Proof") + proto.RegisterType((*ProofOpValue)(nil), "iavl.ProofOpValue") + proto.RegisterType((*ProofOpAbsence)(nil), "iavl.ProofOpAbsence") + proto.RegisterType((*ProofOpRange)(nil), "iavl.ProofOpRange") + proto.RegisterType((*ProofOpPath)(nil), "iavl.ProofOpPath") + proto.RegisterType((*ProofOpInner)(nil), "iavl.ProofOpInner") + proto.RegisterType((*ProofOpLeaf)(nil), "iavl.ProofOpLeaf") } func init() { proto.RegisterFile("iavl/types.proto", fileDescriptor_7ef37c124502d49e) } var fileDescriptor_7ef37c124502d49e = []byte{ - // 165 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xc8, 0x4c, 0x2c, 0xcb, - 0xd1, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x01, 0x89, - 0x28, 0x39, 0x73, 0xb1, 0x07, 0x14, 0xe5, 0xe7, 0xa7, 0xf9, 0x17, 0x08, 0x09, 0x71, 0xb1, 0x80, - 0xe4, 0x25, 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0xc0, 0x6c, 0x21, 0x01, 0x2e, 0xe6, 0xec, 0xd4, - 0x4a, 0x09, 0x26, 0x05, 0x46, 0x0d, 0x9e, 0x20, 0x10, 0x13, 0xa4, 0x2a, 0x25, 0xb1, 0x24, 0x51, - 0x82, 0x19, 0x2c, 0x04, 0x66, 0x2b, 0x69, 0x70, 0xb1, 0x82, 0x0d, 0x11, 0x92, 0xe7, 0x62, 0xce, - 0x2f, 0x28, 0x96, 0x60, 0x54, 0x60, 0xd6, 0xe0, 0x36, 0xe2, 0xd5, 0x03, 0xd9, 0xa0, 0x07, 0x35, - 0x3e, 0x08, 0x24, 0xe3, 0x24, 0x77, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, - 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, - 0x60, 0xe7, 0x24, 0xb1, 0x81, 0xdd, 0x66, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xf4, 0x60, 0x5f, - 0xd3, 0xaf, 0x00, 0x00, 0x00, + // 409 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x92, 0xcd, 0x6e, 0xd3, 0x40, + 0x10, 0xc7, 0xb3, 0x71, 0xec, 0x90, 0x71, 0x40, 0xc9, 0x0a, 0xa1, 0xbd, 0x60, 0x22, 0x9f, 0x0c, + 0x87, 0x44, 0x0a, 0x17, 0xe0, 0x06, 0x5c, 0x40, 0x42, 0x10, 0xed, 0x01, 0x21, 0x2e, 0xd1, 0x86, + 0x6c, 0x62, 0x0b, 0xcb, 0xb6, 0xbc, 0xae, 0xa5, 0xf4, 0xd0, 0x67, 0xe8, 0x13, 0xf4, 0x79, 0x7a, + 0xcc, 0xb1, 0xc7, 0x2a, 0x79, 0x91, 0x6a, 0x26, 0x9b, 0xb4, 0x91, 0xda, 0x4a, 0xbd, 0xcd, 0xfc, + 0xf7, 0x37, 0x5f, 0x3b, 0x03, 0xbd, 0x44, 0xd5, 0xe9, 0xa8, 0x5a, 0x15, 0xda, 0x0c, 0x8b, 0x32, + 0xaf, 0x72, 0xde, 0x42, 0x25, 0xfc, 0x0a, 0xed, 0x49, 0x99, 0xe7, 0x8b, 0x5f, 0x05, 0xe7, 0xd0, + 0xc2, 0x77, 0xc1, 0x06, 0x2c, 0xea, 0x48, 0xb2, 0x79, 0x0f, 0x9c, 0xff, 0x7a, 0x25, 0x9a, 0x03, + 0x16, 0x75, 0x25, 0x9a, 0x48, 0xcd, 0x55, 0xa5, 0x84, 0x43, 0x12, 0xd9, 0x61, 0x04, 0x2e, 0x25, + 0xe1, 0x6f, 0xc0, 0xc9, 0x0b, 0x23, 0xd8, 0xc0, 0x89, 0xfc, 0xf1, 0xf3, 0x21, 0x56, 0x18, 0xda, + 0xf4, 0x12, 0x5f, 0xc2, 0x0f, 0xd0, 0xb5, 0xfe, 0x6f, 0x95, 0x9e, 0x68, 0x1e, 0x81, 0x5b, 0xa0, + 0x4f, 0x45, 0xfd, 0x31, 0x3f, 0x0e, 0x51, 0xd9, 0x52, 0xcb, 0x1d, 0x10, 0x7e, 0x82, 0x17, 0x56, + 0xfe, 0x3c, 0x33, 0x3a, 0xfb, 0xf7, 0x94, 0xd8, 0x0b, 0x76, 0x28, 0x4b, 0x3a, 0x1f, 0x41, 0x27, + 0xd5, 0x8b, 0x6a, 0x5a, 0xa8, 0x2a, 0xb6, 0xdd, 0x1e, 0x87, 0x7f, 0xcf, 0x32, 0x5d, 0xca, 0x67, + 0x08, 0x4d, 0x54, 0x15, 0xf3, 0x31, 0xf8, 0x09, 0x4a, 0xd3, 0x2c, 0x9f, 0x6b, 0x23, 0x9a, 0x14, + 0xd2, 0x3f, 0x0a, 0x41, 0x4e, 0x02, 0x51, 0x3f, 0x11, 0xe2, 0x6f, 0xc1, 0x4b, 0xb5, 0xaa, 0xb5, + 0x11, 0xce, 0x3d, 0xf8, 0x0f, 0xad, 0x16, 0xd2, 0x02, 0xe1, 0x47, 0xf0, 0xef, 0x64, 0xe1, 0xef, + 0xc0, 0xa3, 0x3c, 0xe6, 0x91, 0xde, 0x2c, 0x11, 0x9e, 0x1d, 0x46, 0x23, 0x9d, 0xbf, 0x02, 0x2f, + 0xd6, 0xc9, 0x32, 0xae, 0xe8, 0x5b, 0xfa, 0xd2, 0x7a, 0xb8, 0x37, 0x93, 0x9c, 0x6a, 0x5a, 0xa5, + 0x23, 0xc9, 0xe6, 0x02, 0xda, 0xb5, 0x2e, 0x4d, 0x92, 0x67, 0xb4, 0x4e, 0x47, 0xee, 0x5d, 0xa4, + 0x71, 0x76, 0xd1, 0xda, 0x6d, 0x19, 0x6d, 0xfe, 0x12, 0xdc, 0x92, 0x12, 0xbb, 0x24, 0xee, 0x9c, + 0xf0, 0xcf, 0xa1, 0x75, 0x9c, 0x68, 0x7f, 0x30, 0xec, 0xf6, 0x60, 0x5e, 0x03, 0xd4, 0xb8, 0xeb, + 0x69, 0xac, 0x4c, 0x6c, 0x2f, 0xa9, 0x43, 0xca, 0x37, 0x65, 0xe2, 0x87, 0x7b, 0xf8, 0x12, 0x5c, + 0x6e, 0x02, 0xb6, 0xde, 0x04, 0xec, 0x7a, 0x13, 0xb0, 0xf3, 0x6d, 0xd0, 0x58, 0x6f, 0x83, 0xc6, + 0xd5, 0x36, 0x68, 0xfc, 0xa5, 0xd3, 0x9d, 0x79, 0x74, 0xc7, 0xef, 0x6f, 0x02, 0x00, 0x00, 0xff, + 0xff, 0x42, 0xff, 0x1b, 0xf3, 0xdb, 0x02, 0x00, 0x00, } func (m *ProofOp) Marshal() (dAtA []byte, err error) { @@ -226,67 +585,1020 @@ func (m *Proof) MarshalToSizedBuffer(dAtA []byte) (int, error) { i -= size i = encodeVarintTypes(dAtA, i, uint64(size)) } - i-- - dAtA[i] = 0xa + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *ProofOpValue) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ProofOpValue) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ProofOpValue) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Proof != nil { + { + size, err := m.Proof.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ProofOpAbsence) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ProofOpAbsence) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ProofOpAbsence) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Proof != nil { + { + size, err := m.Proof.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ProofOpRange) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ProofOpRange) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ProofOpRange) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Leaves) > 0 { + for iNdEx := len(m.Leaves) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Leaves[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.InnerNodes) > 0 { + for iNdEx := len(m.InnerNodes) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.InnerNodes[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.LeftPath) > 0 { + for iNdEx := len(m.LeftPath) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.LeftPath[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *ProofOpPath) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ProofOpPath) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ProofOpPath) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Inners) > 0 { + for iNdEx := len(m.Inners) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Inners[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *ProofOpInner) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ProofOpInner) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ProofOpInner) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Right) > 0 { + i -= len(m.Right) + copy(dAtA[i:], m.Right) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Right))) + i-- + dAtA[i] = 0x2a + } + if len(m.Left) > 0 { + i -= len(m.Left) + copy(dAtA[i:], m.Left) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Left))) + i-- + dAtA[i] = 0x22 + } + if m.Version != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Version)) + i-- + dAtA[i] = 0x18 + } + if m.Size_ != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Size_)) + i-- + dAtA[i] = 0x10 + } + if m.Height != 0 { + i = encodeVarintTypes(dAtA, i, uint64((uint32(m.Height)<<1)^uint32((m.Height>>31)))) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *ProofOpLeaf) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ProofOpLeaf) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ProofOpLeaf) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Version != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Version)) + i-- + dAtA[i] = 0x18 + } + if len(m.ValueHash) > 0 { + i -= len(m.ValueHash) + copy(dAtA[i:], m.ValueHash) + i = encodeVarintTypes(dAtA, i, uint64(len(m.ValueHash))) + i-- + dAtA[i] = 0x12 + } + if len(m.Key) > 0 { + i -= len(m.Key) + copy(dAtA[i:], m.Key) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Key))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { + offset -= sovTypes(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *ProofOp) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Type) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.Key) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.Data) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func (m *Proof) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Ops) > 0 { + for _, e := range m.Ops { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + return n +} + +func (m *ProofOpValue) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Proof != nil { + l = m.Proof.Size() + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func (m *ProofOpAbsence) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Proof != nil { + l = m.Proof.Size() + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func (m *ProofOpRange) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.LeftPath) > 0 { + for _, e := range m.LeftPath { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + if len(m.InnerNodes) > 0 { + for _, e := range m.InnerNodes { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + if len(m.Leaves) > 0 { + for _, e := range m.Leaves { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + return n +} + +func (m *ProofOpPath) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Inners) > 0 { + for _, e := range m.Inners { + l = e.Size() + n += 1 + l + sovTypes(uint64(l)) + } + } + return n +} + +func (m *ProofOpInner) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Height != 0 { + n += 1 + sozTypes(uint64(m.Height)) + } + if m.Size_ != 0 { + n += 1 + sovTypes(uint64(m.Size_)) + } + if m.Version != 0 { + n += 1 + sovTypes(uint64(m.Version)) + } + l = len(m.Left) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.Right) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func (m *ProofOpLeaf) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Key) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.ValueHash) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if m.Version != 0 { + n += 1 + sovTypes(uint64(m.Version)) + } + return n +} + +func sovTypes(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTypes(x uint64) (n int) { + return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *ProofOp) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ProofOp: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ProofOp: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Type = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) + if m.Key == nil { + m.Key = []byte{} + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) + if m.Data == nil { + m.Data = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Proof) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Proof: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Proof: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Ops", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Ops = append(m.Ops, &ProofOp{}) + if err := m.Ops[len(m.Ops)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ProofOpValue) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ProofOpValue: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ProofOpValue: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Proof", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Proof == nil { + m.Proof = &ProofOpRange{} + } + if err := m.Proof.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ProofOpAbsence) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ProofOpAbsence: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ProofOpAbsence: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Proof", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Proof == nil { + m.Proof = &ProofOpRange{} + } + if err := m.Proof.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ProofOpRange) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ProofOpRange: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ProofOpRange: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LeftPath", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.LeftPath = append(m.LeftPath, &ProofOpInner{}) + if err := m.LeftPath[len(m.LeftPath)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InnerNodes", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.InnerNodes = append(m.InnerNodes, &ProofOpPath{}) + if err := m.InnerNodes[len(m.InnerNodes)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Leaves", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Leaves = append(m.Leaves, &ProofOpLeaf{}) + if err := m.Leaves[len(m.Leaves)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy } } - return len(dAtA) - i, nil -} - -func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { - offset -= sovTypes(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *ProofOp) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Type) - if l > 0 { - n += 1 + l + sovTypes(uint64(l)) - } - l = len(m.Key) - if l > 0 { - n += 1 + l + sovTypes(uint64(l)) - } - l = len(m.Data) - if l > 0 { - n += 1 + l + sovTypes(uint64(l)) - } - return n -} -func (m *Proof) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.Ops) > 0 { - for _, e := range m.Ops { - l = e.Size() - n += 1 + l + sovTypes(uint64(l)) - } + if iNdEx > l { + return io.ErrUnexpectedEOF } - return n -} - -func sovTypes(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozTypes(x uint64) (n int) { - return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) + return nil } -func (m *ProofOp) Unmarshal(dAtA []byte) error { +func (m *ProofOpPath) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -309,17 +1621,17 @@ func (m *ProofOp) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: ProofOp: wiretype end group for non-group") + return fmt.Errorf("proto: ProofOpPath: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: ProofOp: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: ProofOpPath: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Inners", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -329,27 +1641,141 @@ func (m *ProofOp) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - m.Type = string(dAtA[iNdEx:postIndex]) + m.Inners = append(m.Inners, &ProofOpInner{}) + if err := m.Inners[len(m.Inners)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ProofOpInner) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ProofOpInner: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ProofOpInner: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + var v int32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + v = int32((uint32(v) >> 1) ^ uint32(((v&1)<<31)>>31)) + m.Height = v case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Size_", wireType) + } + m.Size_ = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Size_ |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Version", wireType) + } + m.Version = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Version |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Left", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -376,14 +1802,14 @@ func (m *ProofOp) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) - if m.Key == nil { - m.Key = []byte{} + m.Left = append(m.Left[:0], dAtA[iNdEx:postIndex]...) + if m.Left == nil { + m.Left = []byte{} } iNdEx = postIndex - case 3: + case 5: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Right", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -410,9 +1836,9 @@ func (m *ProofOp) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) - if m.Data == nil { - m.Data = []byte{} + m.Right = append(m.Right[:0], dAtA[iNdEx:postIndex]...) + if m.Right == nil { + m.Right = []byte{} } iNdEx = postIndex default: @@ -439,7 +1865,7 @@ func (m *ProofOp) Unmarshal(dAtA []byte) error { } return nil } -func (m *Proof) Unmarshal(dAtA []byte) error { +func (m *ProofOpLeaf) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -462,17 +1888,17 @@ func (m *Proof) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: Proof: wiretype end group for non-group") + return fmt.Errorf("proto: ProofOpLeaf: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: Proof: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: ProofOpLeaf: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Ops", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) } - var msglen int + var byteLen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowTypes @@ -482,26 +1908,79 @@ func (m *Proof) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + byteLen |= int(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + if byteLen < 0 { return ErrInvalidLengthTypes } - postIndex := iNdEx + msglen + postIndex := iNdEx + byteLen if postIndex < 0 { return ErrInvalidLengthTypes } if postIndex > l { return io.ErrUnexpectedEOF } - m.Ops = append(m.Ops, &ProofOp{}) - if err := m.Ops[len(m.Ops)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err + m.Key = append(m.Key[:0], dAtA[iNdEx:postIndex]...) + if m.Key == nil { + m.Key = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValueHash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValueHash = append(m.ValueHash[:0], dAtA[iNdEx:postIndex]...) + if m.ValueHash == nil { + m.ValueHash = []byte{} } iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Version", wireType) + } + m.Version = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Version |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipTypes(dAtA[iNdEx:]) diff --git a/wire.go b/wire.go deleted file mode 100644 index d4443c862..000000000 --- a/wire.go +++ /dev/null @@ -1,17 +0,0 @@ -package iavl - -import ( - amino "github.com/tendermint/go-amino" -) - -var cdc = amino.NewCodec() - -func init() { - // NOTE: It's important that there be no conflicts here, - // as that would change the canonical representations. - RegisterWire(cdc) -} - -func RegisterWire(cdc *amino.Codec) { - // TODO -}