@@ -10,7 +10,8 @@ import (
10
10
"github.com/tendermint/tendermint/crypto/merkle"
11
11
cmn "github.com/tendermint/tendermint/libs/common"
12
12
13
- "github.com/ethereum/go-ethereum/core/vm/lightclient"
13
+ v1 "github.com/ethereum/go-ethereum/core/vm/lightclient/v1"
14
+ v2 "github.com/ethereum/go-ethereum/core/vm/lightclient/v2"
14
15
"github.com/ethereum/go-ethereum/params"
15
16
)
16
17
@@ -26,7 +27,7 @@ const (
26
27
// input:
27
28
// consensus state length | consensus state | tendermint header |
28
29
// 32 bytes | | |
29
- func decodeTendermintHeaderValidationInput (input []byte ) (* lightclient .ConsensusState , * lightclient .Header , error ) {
30
+ func decodeTendermintHeaderValidationInput (input []byte ) (* v1 .ConsensusState , * v1 .Header , error ) {
30
31
csLen := binary .BigEndian .Uint64 (input [consensusStateLengthBytesLength - uint64TypeLength : consensusStateLengthBytesLength ])
31
32
32
33
if consensusStateLengthBytesLength + csLen < consensusStateLengthBytesLength {
@@ -37,19 +38,20 @@ func decodeTendermintHeaderValidationInput(input []byte) (*lightclient.Consensus
37
38
return nil , nil , fmt .Errorf ("expected payload size %d, actual size: %d" , consensusStateLengthBytesLength + csLen , len (input ))
38
39
}
39
40
40
- cs , err := lightclient .DecodeConsensusState (input [consensusStateLengthBytesLength : consensusStateLengthBytesLength + csLen ])
41
+ cs , err := v1 .DecodeConsensusState (input [consensusStateLengthBytesLength : consensusStateLengthBytesLength + csLen ])
41
42
if err != nil {
42
43
return nil , nil , err
43
44
}
44
- header , err := lightclient .DecodeHeader (input [consensusStateLengthBytesLength + csLen :])
45
+ header , err := v1 .DecodeHeader (input [consensusStateLengthBytesLength + csLen :])
45
46
if err != nil {
46
47
return nil , nil , err
47
48
}
48
49
49
50
return & cs , header , nil
50
51
}
51
52
52
- // tmHeaderValidate implemented as a native contract.
53
+ // tmHeaderValidate implemented as a native contract. Used to validate the light
54
+ // client's new header for tendermint v0.31.12 and its compatible version.
53
55
type tmHeaderValidate struct {}
54
56
55
57
func (c * tmHeaderValidate ) RequiredGas (input []byte ) uint64 {
@@ -169,7 +171,7 @@ func (c *iavlMerkleProofValidatePlanck) RequiredGas(_ []byte) uint64 {
169
171
}
170
172
171
173
func (c * iavlMerkleProofValidatePlanck ) Run (input []byte ) (result []byte , err error ) {
172
- c .basicIavlMerkleProofValidate .proofRuntime = lightclient .Ics23CompatibleProofRuntime ()
174
+ c .basicIavlMerkleProofValidate .proofRuntime = v1 .Ics23CompatibleProofRuntime ()
173
175
c .basicIavlMerkleProofValidate .verifiers = []merkle.ProofOpVerifier {
174
176
forbiddenAbsenceOpVerifier ,
175
177
singleValueOpVerifier ,
@@ -188,7 +190,7 @@ func successfulMerkleResult() []byte {
188
190
}
189
191
190
192
type basicIavlMerkleProofValidate struct {
191
- keyVerifier lightclient .KeyVerifier
193
+ keyVerifier v1 .KeyVerifier
192
194
opsVerifier merkle.ProofOpsVerifier
193
195
verifiers []merkle.ProofOpVerifier
194
196
proofRuntime * merkle.ProofRuntime
@@ -210,12 +212,12 @@ func (c *basicIavlMerkleProofValidate) Run(input []byte) (result []byte, err err
210
212
return nil , fmt .Errorf ("invalid input: input size should be %d, actual the size is %d" , payloadLength + precompileContractInputMetaDataLength , len (input ))
211
213
}
212
214
213
- kvmp , err := lightclient .DecodeKeyValueMerkleProof (input [precompileContractInputMetaDataLength :])
215
+ kvmp , err := v1 .DecodeKeyValueMerkleProof (input [precompileContractInputMetaDataLength :])
214
216
if err != nil {
215
217
return nil , err
216
218
}
217
219
if c .proofRuntime == nil {
218
- kvmp .SetProofRuntime (lightclient .DefaultProofRuntime ())
220
+ kvmp .SetProofRuntime (v1 .DefaultProofRuntime ())
219
221
} else {
220
222
kvmp .SetProofRuntime (c .proofRuntime )
221
223
}
@@ -255,7 +257,7 @@ func multiStoreOpVerifier(op merkle.ProofOperator) error {
255
257
if op == nil {
256
258
return nil
257
259
}
258
- if mop , ok := op .(lightclient .MultiStoreProofOp ); ok {
260
+ if mop , ok := op .(v1 .MultiStoreProofOp ); ok {
259
261
storeNames := make (map [string ]bool , len (mop .Proof .StoreInfos ))
260
262
for _ , store := range mop .Proof .StoreInfos {
261
263
if exist := storeNames [store .Name ]; exist {
@@ -291,25 +293,25 @@ func proofOpsVerifier(poz merkle.ProofOperators) error {
291
293
}
292
294
293
295
// for legacy proof type
294
- if _ , ok := poz [1 ].(lightclient .MultiStoreProofOp ); ok {
296
+ if _ , ok := poz [1 ].(v1 .MultiStoreProofOp ); ok {
295
297
if _ , ok := poz [0 ].(iavl.IAVLValueOp ); ! ok {
296
298
return cmn .NewError ("invalid proof op" )
297
299
}
298
300
return nil
299
301
}
300
302
301
303
// for ics23 proof type
302
- if op2 , ok := poz [1 ].(lightclient .CommitmentOp ); ok {
303
- if op2 .Type != lightclient .ProofOpSimpleMerkleCommitment {
304
+ if op2 , ok := poz [1 ].(v1 .CommitmentOp ); ok {
305
+ if op2 .Type != v1 .ProofOpSimpleMerkleCommitment {
304
306
return cmn .NewError ("invalid proof op" )
305
307
}
306
308
307
- op1 , ok := poz [0 ].(lightclient .CommitmentOp )
309
+ op1 , ok := poz [0 ].(v1 .CommitmentOp )
308
310
if ! ok {
309
311
return cmn .NewError ("invalid proof op" )
310
312
}
311
313
312
- if op1 .Type != lightclient .ProofOpIAVLCommitment {
314
+ if op1 .Type != v1 .ProofOpIAVLCommitment {
313
315
return cmn .NewError ("invalid proof op" )
314
316
}
315
317
return nil
@@ -327,3 +329,38 @@ func keyVerifier(key string) error {
327
329
}
328
330
return nil
329
331
}
332
+
333
+ // cometBFTLightBlockValidate implemented as a native contract. Used to validate the light blocks for CometBFT v0.37.0
334
+ // and its compatible version. Besides, in order to support the BLS cross-chain infrastructure, the SetRelayerAddress
335
+ // and SetBlsKey methods should be implemented for the validator.
336
+ type cometBFTLightBlockValidate struct {}
337
+
338
+ func (c * cometBFTLightBlockValidate ) RequiredGas (input []byte ) uint64 {
339
+ return params .CometBFTLightBlockValidateGas
340
+ }
341
+
342
+ func (c * cometBFTLightBlockValidate ) Run (input []byte ) (result []byte , err error ) {
343
+ defer func () {
344
+ if r := recover (); r != nil {
345
+ err = fmt .Errorf ("internal error: %v\n " , r )
346
+ }
347
+ }()
348
+
349
+ cs , block , err := v2 .DecodeLightBlockValidationInput (input )
350
+ if err != nil {
351
+ return nil , err
352
+ }
353
+
354
+ validatorSetChanged , err := cs .ApplyLightBlock (block )
355
+ if err != nil {
356
+ return nil , err
357
+ }
358
+
359
+ consensusStateBytes , err := cs .EncodeConsensusState ()
360
+ if err != nil {
361
+ return nil , err
362
+ }
363
+
364
+ result = v2 .EncodeLightBlockValidationResult (validatorSetChanged , consensusStateBytes )
365
+ return result , nil
366
+ }
0 commit comments