99)
1010
1111const (
12+ uint64TypeLength uint64 = 8
1213 precompileContractInputMetaDataLength uint64 = 32
1314 consensusStateLengthBytesLength uint64 = 32
1415
@@ -20,7 +21,7 @@ const (
2021// consensus state length | consensus state | tendermint header |
2122// 32 bytes | | |
2223func decodeTendermintHeaderValidationInput (input []byte ) (* lightclient.ConsensusState , * lightclient.Header , error ) {
23- csLen := binary .BigEndian .Uint64 (input [consensusStateLengthBytesLength - 8 : consensusStateLengthBytesLength ])
24+ csLen := binary .BigEndian .Uint64 (input [consensusStateLengthBytesLength - uint64TypeLength : consensusStateLengthBytesLength ])
2425 if uint64 (len (input )) <= consensusStateLengthBytesLength + csLen {
2526 return nil , nil , fmt .Errorf ("expected payload size %d, actual size: %d" , consensusStateLengthBytesLength + csLen , len (input ))
2627 }
@@ -55,7 +56,7 @@ func (c *tmHeaderValidate) Run(input []byte) (result []byte, err error) {
5556 return nil , fmt .Errorf ("invalid input" )
5657 }
5758
58- payloadLength := binary .BigEndian .Uint64 (input [precompileContractInputMetaDataLength - 8 : precompileContractInputMetaDataLength ])
59+ payloadLength := binary .BigEndian .Uint64 (input [precompileContractInputMetaDataLength - uint64TypeLength : precompileContractInputMetaDataLength ])
5960 if uint64 (len (input )) != payloadLength + precompileContractInputMetaDataLength {
6061 return nil , fmt .Errorf ("invalid input: input size should be %d, actual the size is %d" , payloadLength + precompileContractInputMetaDataLength , len (input ))
6162 }
@@ -83,7 +84,7 @@ func (c *tmHeaderValidate) Run(input []byte) (result []byte, err error) {
8384 copy (lengthBytes [:1 ], []byte {0x01 })
8485 }
8586 consensusStateBytesLength := uint64 (len (consensusStateBytes ))
86- binary .BigEndian .PutUint64 (lengthBytes [tmHeaderValidateResultMetaDataLength - 8 :], consensusStateBytesLength )
87+ binary .BigEndian .PutUint64 (lengthBytes [tmHeaderValidateResultMetaDataLength - uint64TypeLength :], consensusStateBytesLength )
8788
8889 result = append (lengthBytes , consensusStateBytes ... )
8990
@@ -113,7 +114,7 @@ func (c *iavlMerkleProofValidate) Run(input []byte) (result []byte, err error) {
113114 return nil , fmt .Errorf ("invalid input: input should include %d bytes payload length and payload" , precompileContractInputMetaDataLength )
114115 }
115116
116- payloadLength := binary .BigEndian .Uint64 (input [precompileContractInputMetaDataLength - 8 : precompileContractInputMetaDataLength ])
117+ payloadLength := binary .BigEndian .Uint64 (input [precompileContractInputMetaDataLength - uint64TypeLength : precompileContractInputMetaDataLength ])
117118 if uint64 (len (input )) != payloadLength + precompileContractInputMetaDataLength {
118119 return nil , fmt .Errorf ("invalid input: input size should be %d, actual the size is %d" , payloadLength + precompileContractInputMetaDataLength , len (input ))
119120 }
@@ -129,6 +130,6 @@ func (c *iavlMerkleProofValidate) Run(input []byte) (result []byte, err error) {
129130 }
130131
131132 result = make ([]byte , merkleProofValidateResultLength )
132- binary .BigEndian .PutUint64 (result [merkleProofValidateResultLength - 8 :], 0x01 )
133+ binary .BigEndian .PutUint64 (result [merkleProofValidateResultLength - uint64TypeLength :], 0x01 )
133134 return result , nil
134135}
0 commit comments