Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enclave: no panic for bad rlp format #1679

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions go/enclave/rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,16 @@ func (s *RPCServer) InitEnclave(_ context.Context, request *generated.InitEnclav
}

func (s *RPCServer) SubmitL1Block(_ context.Context, request *generated.SubmitBlockRequest) (*generated.SubmitBlockResponse, error) {
bl := s.decodeBlock(request.EncodedBlock)
receipts := s.decodeReceipts(request.EncodedReceipts)
bl, err := s.decodeBlock(request.EncodedBlock)
if err != nil {
s.logger.Error("Error decoding block", log.ErrKey, err)
return nil, err
}
receipts, err := s.decodeReceipts(request.EncodedReceipts)
if err != nil {
s.logger.Error("Error decoding receipts", log.ErrKey, err)
return nil, err
}
blockSubmissionResponse, err := s.enclave.SubmitL1Block(bl, receipts, request.IsLatest)
if err != nil {
var rejErr *errutil.BlockRejectError
Expand Down Expand Up @@ -439,25 +447,25 @@ func (s *RPCServer) EnclavePublicConfig(_ context.Context, _ *generated.EnclaveP
return &generated.EnclavePublicConfigResponse{L2MessageBusAddress: enclaveCfg.L2MessageBusAddress.Bytes()}, nil
}

func (s *RPCServer) decodeBlock(encodedBlock []byte) types.Block {
func (s *RPCServer) decodeBlock(encodedBlock []byte) (types.Block, error) {
block := types.Block{}
err := rlp.DecodeBytes(encodedBlock, &block)
if err != nil {
s.logger.Info("failed to decode block sent to enclave", log.ErrKey, err)
return types.Block{}, fmt.Errorf("unable to decode block, bytes=%x, err=%w", encodedBlock, err)
}
return block
return block, nil
}

// decodeReceipts - converts the rlp encoded bytes to receipts if possible.
func (s *RPCServer) decodeReceipts(encodedReceipts []byte) types.Receipts {
func (s *RPCServer) decodeReceipts(encodedReceipts []byte) (types.Receipts, error) {
receipts := make(types.Receipts, 0)

err := rlp.DecodeBytes(encodedReceipts, &receipts)
if err != nil {
s.logger.Crit("failed to decode receipts sent to enclave", log.ErrKey, err)
return nil, fmt.Errorf("unable to decode receipts, bytes=%x, err=%w", encodedReceipts, err)
}

return receipts
return receipts, nil
}

func toRPCError(err common.SystemError) *generated.SystemError {
Expand Down
Loading