Skip to content

Commit f7d80d0

Browse files
Fix when decoding strings using hex.DecodeString by stripping 0x … (#946) (#949)
* Fix bug when decoding strings using hex.DecodeString by stripping 0x prefix. * Remove 0x prefix from value in SubmitValue and NoStakeReport messages. (cherry picked from commit 16f2791) Co-authored-by: akrem <71235284+akremstudy@users.noreply.github.com>
1 parent 5ce5fb6 commit f7d80d0

8 files changed

Lines changed: 20 additions & 13 deletions

app/extend_vote.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/spf13/viper"
1818
bridgetypes "github.com/tellor-io/layer/x/bridge/types"
1919
oracletypes "github.com/tellor-io/layer/x/oracle/types"
20+
registrytypes "github.com/tellor-io/layer/x/registry/types"
2021

2122
"cosmossdk.io/collections"
2223
"cosmossdk.io/log"
@@ -376,7 +377,7 @@ func (h *VoteExtHandler) GetValidatorIndexInValset(ctx context.Context, evmAddre
376377

377378
func (h *VoteExtHandler) EncodeAndSignMessage(checkpointString string) ([]byte, error) {
378379
// Encode the checkpoint string to bytes
379-
checkpoint, err := hex.DecodeString(checkpointString)
380+
checkpoint, err := hex.DecodeString(registrytypes.Remove0xPrefix(checkpointString))
380381
if err != nil {
381382
h.logger.Error("Failed to decode checkpoint", "error", err)
382383
return nil, err

x/bridge/keeper/attestation_slashing.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/ethereum/go-ethereum/common"
1212
"github.com/tellor-io/layer/x/bridge/types"
13+
registrytypes "github.com/tellor-io/layer/x/registry/types"
1314

1415
"cosmossdk.io/collections"
1516
"cosmossdk.io/math"
@@ -43,11 +44,11 @@ func (k Keeper) CheckAttestationEvidence(ctx context.Context, request types.MsgS
4344
}
4445

4546
// determine the snapshot from the inputted params
46-
queryId, err := hex.DecodeString(request.QueryId)
47+
queryId, err := hex.DecodeString(registrytypes.Remove0xPrefix(request.QueryId))
4748
if err != nil {
4849
return err
4950
}
50-
checkpoint, err := hex.DecodeString(request.ValsetCheckpoint)
51+
checkpoint, err := hex.DecodeString(registrytypes.Remove0xPrefix(request.ValsetCheckpoint))
5152
if err != nil {
5253
return err
5354
}
@@ -127,7 +128,7 @@ func (k Keeper) CheckAttestationEvidence(ctx context.Context, request types.MsgS
127128
}
128129

129130
func (k Keeper) GetOperatorAddressFromSignature(ctx context.Context, msg []byte, sig string) (types.OperatorAddress, error) {
130-
sigBytes, err := hex.DecodeString(sig)
131+
sigBytes, err := hex.DecodeString(registrytypes.Remove0xPrefix(sig))
131132
if err != nil {
132133
return types.OperatorAddress{}, err
133134
}

x/bridge/keeper/claim_deposit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/tellor-io/layer/lib/metrics"
1515
layer "github.com/tellor-io/layer/types"
1616
"github.com/tellor-io/layer/x/bridge/types"
17+
registrytypes "github.com/tellor-io/layer/x/registry/types"
1718

1819
"cosmossdk.io/collections"
1920

@@ -166,8 +167,7 @@ func (k Keeper) DecodeDepositReportValue(ctx context.Context, reportValue string
166167
{Type: Uint256Type},
167168
{Type: Uint256Type},
168169
}
169-
// decode report value
170-
reportValueBytes, err := hex.DecodeString(reportValue)
170+
reportValueBytes, err := hex.DecodeString(registrytypes.Remove0xPrefix(reportValue))
171171
if err != nil {
172172
k.Logger(ctx).Error("DecodeDepositReportValue", "error", fmt.Errorf("failed to decode report value, err: %w", err))
173173
return nil, sdk.Coins{}, sdk.Coins{}, err

x/bridge/keeper/keeper.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
layertypes "github.com/tellor-io/layer/types"
2121
"github.com/tellor-io/layer/x/bridge/types"
2222
oracletypes "github.com/tellor-io/layer/x/oracle/types"
23+
registrytypes "github.com/tellor-io/layer/x/registry/types"
2324

2425
"cosmossdk.io/collections"
2526
storetypes "cosmossdk.io/core/store"
@@ -789,7 +790,7 @@ func (k Keeper) SetBridgeValsetSignature(ctx context.Context, operatorAddress st
789790
return err
790791
}
791792
// decode the signature hex
792-
signatureBytes, err := hex.DecodeString(signature)
793+
signatureBytes, err := hex.DecodeString(registrytypes.Remove0xPrefix(signature))
793794
if err != nil {
794795
k.Logger(ctx).Info("Error decoding signature hex", "error", err)
795796
return err
@@ -1177,8 +1178,7 @@ func (k Keeper) EncodeOracleAttestationData(
11771178
var queryIdBytes32 [32]byte
11781179
copy(queryIdBytes32[:], queryId)
11791180

1180-
// Convert value to bytes
1181-
valueBytes, err := hex.DecodeString(value)
1181+
valueBytes, err := hex.DecodeString(registrytypes.Remove0xPrefix(value))
11821182
if err != nil {
11831183
return nil, err
11841184
}
@@ -1317,7 +1317,7 @@ func (k Keeper) CreateNoStakeSnapshot(ctx context.Context, report *oracletypes.N
13171317
{Type: bytesType},
13181318
{Type: stringType},
13191319
}
1320-
valBz, err := hex.DecodeString(report.Value)
1320+
valBz, err := hex.DecodeString(registrytypes.Remove0xPrefix(report.Value))
13211321
if err != nil {
13221322
return err
13231323
}

x/bridge/keeper/msg_server_request_attestations.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
"github.com/tellor-io/layer/x/bridge/types"
10+
registrytypes "github.com/tellor-io/layer/x/registry/types"
1011
"google.golang.org/grpc/codes"
1112
"google.golang.org/grpc/status"
1213

@@ -26,7 +27,7 @@ func (k msgServer) RequestAttestations(ctx context.Context, msg *types.MsgReques
2627
return nil, err
2728
}
2829

29-
queryId, err := hex.DecodeString(msg.QueryId)
30+
queryId, err := hex.DecodeString(registrytypes.Remove0xPrefix(msg.QueryId))
3031
if err != nil {
3132
k.Keeper.Logger(sdkCtx).Error("failed to decode query id", "error", err)
3233
return nil, status.Error(codes.InvalidArgument, err.Error())

x/bridge/keeper/valset_sig_slashing.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strconv"
1010

1111
"github.com/tellor-io/layer/x/bridge/types"
12+
registrytypes "github.com/tellor-io/layer/x/registry/types"
1213

1314
"cosmossdk.io/collections"
1415

@@ -40,7 +41,7 @@ func (k Keeper) CheckValsetSignatureEvidence(ctx context.Context, request types.
4041
}
4142

4243
// get the checkpoint from the inputted params
43-
valsetHashBytes, err := hex.DecodeString(request.ValsetHash)
44+
valsetHashBytes, err := hex.DecodeString(registrytypes.Remove0xPrefix(request.ValsetHash))
4445
if err != nil {
4546
return err
4647
}

x/oracle/keeper/msg_no_stake_report.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/tellor-io/layer/utils"
88
"github.com/tellor-io/layer/x/oracle/types"
9+
registrytypes "github.com/tellor-io/layer/x/registry/types"
910

1011
"cosmossdk.io/collections"
1112
errorsmod "cosmossdk.io/errors"
@@ -21,7 +22,7 @@ func (k msgServer) NoStakeReport(ctx context.Context, msg *types.MsgNoStakeRepor
2122
}
2223

2324
queryData := msg.QueryData
24-
value := msg.Value
25+
value := registrytypes.Remove0xPrefix(msg.Value)
2526
timestamp := sdkCtx.BlockTime().UnixMilli()
2627
queryId := utils.QueryIDFromData(queryData)
2728

x/oracle/keeper/msg_server_submit_value.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
layertypes "github.com/tellor-io/layer/types"
99
"github.com/tellor-io/layer/utils"
1010
"github.com/tellor-io/layer/x/oracle/types"
11+
registrytypes "github.com/tellor-io/layer/x/registry/types"
1112

1213
"cosmossdk.io/collections"
1314
errorsmod "cosmossdk.io/errors"
@@ -34,6 +35,7 @@ import (
3435
// 7. Set queryMeta.HasRevealedReports to true
3536
// 8. Emit an event for the new report
3637
func (k msgServer) SubmitValue(ctx context.Context, msg *types.MsgSubmitValue) (res *types.MsgSubmitValueResponse, err error) {
38+
msg.Value = registrytypes.Remove0xPrefix(msg.Value)
3739
sdkCtx := sdk.UnwrapSDKContext(ctx)
3840
err = validateSubmitValue(msg)
3941
if err != nil {

0 commit comments

Comments
 (0)