5
5
"errors"
6
6
"fmt"
7
7
8
- cmtcrypto "github.com/cometbft/cometbft/ proto/tendermint/crypto "
8
+ wire "github.com/celestiaorg/go-square/merkle/ proto/gen/merkle/v1 "
9
9
)
10
10
11
11
//----------------------------------------
@@ -21,7 +21,7 @@ import (
21
21
type ProofOperator interface {
22
22
Run ([][]byte ) ([][]byte , error )
23
23
GetKey () []byte
24
- ProofOp () cmtcrypto .ProofOp
24
+ ProofOp () wire .ProofOp
25
25
}
26
26
27
27
//----------------------------------------
@@ -101,7 +101,7 @@ func (poz ProofOperators) VerifyFromKeys(root []byte, keys [][]byte, args [][]by
101
101
//----------------------------------------
102
102
// ProofRuntime - main entrypoint
103
103
104
- type OpDecoder func (cmtcrypto .ProofOp ) (ProofOperator , error )
104
+ type OpDecoder func (* wire .ProofOp ) (ProofOperator , error )
105
105
106
106
type ProofRuntime struct {
107
107
decoders map [string ]OpDecoder
@@ -121,15 +121,18 @@ func (prt *ProofRuntime) RegisterOpDecoder(typ string, dec OpDecoder) {
121
121
prt .decoders [typ ] = dec
122
122
}
123
123
124
- func (prt * ProofRuntime ) Decode (pop cmtcrypto .ProofOp ) (ProofOperator , error ) {
124
+ func (prt * ProofRuntime ) Decode (pop * wire .ProofOp ) (ProofOperator , error ) {
125
125
decoder := prt .decoders [pop .Type ]
126
126
if decoder == nil {
127
127
return nil , fmt .Errorf ("unrecognized proof type %v" , pop .Type )
128
128
}
129
+ if pop == nil {
130
+ return nil , errors .New ("nil ProofOp" )
131
+ }
129
132
return decoder (pop )
130
133
}
131
134
132
- func (prt * ProofRuntime ) DecodeProof (proof * cmtcrypto .ProofOps ) (ProofOperators , error ) {
135
+ func (prt * ProofRuntime ) DecodeProof (proof * wire .ProofOps ) (ProofOperators , error ) {
133
136
poz := make (ProofOperators , 0 , len (proof .Ops ))
134
137
for _ , pop := range proof .Ops {
135
138
operator , err := prt .Decode (pop )
@@ -141,21 +144,21 @@ func (prt *ProofRuntime) DecodeProof(proof *cmtcrypto.ProofOps) (ProofOperators,
141
144
return poz , nil
142
145
}
143
146
144
- func (prt * ProofRuntime ) VerifyValue (proof * cmtcrypto .ProofOps , root []byte , keypath string , value []byte ) (err error ) {
147
+ func (prt * ProofRuntime ) VerifyValue (proof * wire .ProofOps , root []byte , keypath string , value []byte ) (err error ) {
145
148
return prt .Verify (proof , root , keypath , [][]byte {value })
146
149
}
147
150
148
- func (prt * ProofRuntime ) VerifyValueFromKeys (proof * cmtcrypto .ProofOps , root []byte , keys [][]byte , value []byte ) (err error ) {
151
+ func (prt * ProofRuntime ) VerifyValueFromKeys (proof * wire .ProofOps , root []byte , keys [][]byte , value []byte ) (err error ) {
149
152
return prt .VerifyFromKeys (proof , root , keys , [][]byte {value })
150
153
}
151
154
152
155
// TODO In the long run we'll need a method of classification of ops,
153
156
// whether existence or absence or perhaps a third?
154
- func (prt * ProofRuntime ) VerifyAbsence (proof * cmtcrypto .ProofOps , root []byte , keypath string ) (err error ) {
157
+ func (prt * ProofRuntime ) VerifyAbsence (proof * wire .ProofOps , root []byte , keypath string ) (err error ) {
155
158
return prt .Verify (proof , root , keypath , nil )
156
159
}
157
160
158
- func (prt * ProofRuntime ) Verify (proof * cmtcrypto .ProofOps , root []byte , keypath string , args [][]byte ) (err error ) {
161
+ func (prt * ProofRuntime ) Verify (proof * wire .ProofOps , root []byte , keypath string , args [][]byte ) (err error ) {
159
162
poz , err := prt .DecodeProof (proof )
160
163
if err != nil {
161
164
return fmt .Errorf ("decoding proof: %w" , err )
@@ -166,7 +169,7 @@ func (prt *ProofRuntime) Verify(proof *cmtcrypto.ProofOps, root []byte, keypath
166
169
// VerifyFromKeys performs the same verification logic as the normal Verify
167
170
// method, except it does not perform any processing on the keypath. This is
168
171
// useful when using keys that have split or escape points as a part of the key.
169
- func (prt * ProofRuntime ) VerifyFromKeys (proof * cmtcrypto .ProofOps , root []byte , keys [][]byte , args [][]byte ) (err error ) {
172
+ func (prt * ProofRuntime ) VerifyFromKeys (proof * wire .ProofOps , root []byte , keys [][]byte , args [][]byte ) (err error ) {
170
173
poz , err := prt .DecodeProof (proof )
171
174
if err != nil {
172
175
return fmt .Errorf ("decoding proof: %w" , err )
0 commit comments