Skip to content

Commit 6226fd0

Browse files
committed
use safe converstion to prevent panic on hash size missmatch
1 parent c0af8bf commit 6226fd0

File tree

1 file changed

+21
-4
lines changed
  • pkg/loop/internal/relayer

1 file changed

+21
-4
lines changed

pkg/loop/internal/relayer/evm.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,14 @@ func (e *EVMClient) SubmitTransaction(ctx context.Context, txRequest evmtypes.Su
5555
return nil, net.WrapRPCErr(err)
5656
}
5757

58+
h, err := evmpb.ConvertHashFromProto(reply.TxHash)
59+
if err != nil {
60+
return nil, net.WrapRPCErr(err)
61+
}
62+
5863
return &evmtypes.TransactionResult{
5964
TxStatus: evmpb.ConvertTxStatusFromProto(reply.TxStatus),
60-
TxHash: evmtypes.Hash(reply.TxHash),
65+
TxHash: h,
6166
TxIdempotencyKey: reply.TxIdempotencyKey,
6267
}, nil
6368
}
@@ -284,13 +289,17 @@ func (e *EVMClient) GetLatestLPBlock(ctx context.Context) (*evmtypes.LPBlock, er
284289
if err != nil {
285290
return nil, net.WrapRPCErr(err)
286291
}
292+
h, err := evmpb.ConvertHashFromProto(reply.GetLpBlock().GetHash())
293+
if err != nil {
294+
return nil, net.WrapRPCErr(err)
295+
}
287296

288297
return &evmtypes.LPBlock{
289298
BlockTimestamp: reply.GetLpBlock().GetBlockTimestamp(),
290299
LatestBlockNumber: reply.GetLpBlock().GetLatestBlockNumber(),
291300
FinalizedBlockNumber: reply.GetLpBlock().GetFinalizedBlockNumber(),
292301
SafeBlockNumber: reply.GetLpBlock().GetSafeBlockNumber(),
293-
BlockHash: evmtypes.Hash(reply.GetLpBlock().GetHash()),
302+
BlockHash: h,
294303
}, nil
295304
}
296305

@@ -412,8 +421,12 @@ func (e *evmServer) EstimateGas(ctx context.Context, request *evmpb.EstimateGasR
412421
}
413422

414423
func (e *evmServer) GetTransactionByHash(ctx context.Context, request *evmpb.GetTransactionByHashRequest) (*evmpb.GetTransactionByHashReply, error) {
424+
h, err := evmpb.ConvertHashFromProto(request.GetHash())
425+
if err != nil {
426+
return nil, err
427+
}
415428
tx, err := e.impl.GetTransactionByHash(ctx, evmtypes.GetTransactionByHashRequest{
416-
Hash: evmtypes.Hash(request.GetHash()),
429+
Hash: h,
417430
IsExternal: request.IsExternal,
418431
})
419432
if err != nil {
@@ -429,8 +442,12 @@ func (e *evmServer) GetTransactionByHash(ctx context.Context, request *evmpb.Get
429442
}
430443

431444
func (e *evmServer) GetTransactionReceipt(ctx context.Context, request *evmpb.GetTransactionReceiptRequest) (*evmpb.GetTransactionReceiptReply, error) {
445+
h, err := evmpb.ConvertHashFromProto(request.GetHash())
446+
if err != nil {
447+
return nil, err
448+
}
432449
receipt, err := e.impl.GetTransactionReceipt(ctx, evmtypes.GeTransactionReceiptRequest{
433-
Hash: evmtypes.Hash(request.GetHash()),
450+
Hash: h,
434451
IsExternal: request.IsExternal,
435452
})
436453
if err != nil {

0 commit comments

Comments
 (0)