@@ -17,6 +17,7 @@ import (
1717 "github.com/ethereum/go-ethereum/eth/filters"
1818 "github.com/ethereum/go-ethereum/rlp"
1919 ethrpc "github.com/ethereum/go-ethereum/rpc"
20+ "github.com/oasisprotocol/oasis-core/go/common/cbor"
2021 "github.com/oasisprotocol/oasis-core/go/common/logging"
2122 "github.com/oasisprotocol/oasis-sdk/client-sdk/go/client"
2223 "github.com/oasisprotocol/oasis-sdk/client-sdk/go/crypto/signature/secp256k1"
@@ -108,13 +109,14 @@ type API interface {
108109}
109110
110111type publicAPI struct {
111- client client.RuntimeClient
112- archiveClient * archive.Client
113- backend indexer.Backend
114- gasPriceOracle gas.Backend
115- chainID uint32
116- Logger * logging.Logger
117- methodLimits * conf.MethodLimits
112+ client client.RuntimeClient
113+ archiveClient * archive.Client
114+ backend indexer.Backend
115+ gasPriceOracle gas.Backend
116+ chainID uint32
117+ Logger * logging.Logger
118+ methodLimits * conf.MethodLimits
119+ allowUnencryptedTxs bool
118120}
119121
120122// NewPublicAPI creates an instance of the public ETH Web3 API.
@@ -126,15 +128,17 @@ func NewPublicAPI(
126128 backend indexer.Backend ,
127129 gasPriceOracle gas.Backend ,
128130 methodLimits * conf.MethodLimits ,
131+ allowUnencryptedTxes bool ,
129132) API {
130133 return & publicAPI {
131- client : client ,
132- archiveClient : archiveClient ,
133- chainID : chainID ,
134- Logger : logger ,
135- backend : backend ,
136- gasPriceOracle : gasPriceOracle ,
137- methodLimits : methodLimits ,
134+ client : client ,
135+ archiveClient : archiveClient ,
136+ chainID : chainID ,
137+ Logger : logger ,
138+ backend : backend ,
139+ gasPriceOracle : gasPriceOracle ,
140+ methodLimits : methodLimits ,
141+ allowUnencryptedTxs : allowUnencryptedTxes ,
138142 }
139143}
140144
@@ -463,6 +467,13 @@ func (api *publicAPI) SendRawTransaction(ctx context.Context, data hexutil.Bytes
463467 return common.Hash {}, ErrMalformedTransaction
464468 }
465469
470+ if ! api .checkOasisTxEncrypted (ethTx .Data ()) {
471+ logger .Debug ("dropped unencrypted transaction" , "hash" , ethTx .Hash ())
472+ return common.Hash {}, ErrInvalidRequest
473+ }
474+
475+ ethTx .Data ()
476+
466477 // Generate an Ethereum transaction that is handled by the EVM module.
467478 utx := types.UnverifiedTransaction {
468479 Body : data ,
@@ -751,3 +762,28 @@ func (api *publicAPI) getBlockRound(ctx context.Context, logger *logging.Logger,
751762 return 0 , nil
752763 }
753764}
765+
766+ // checkOasisTxEncrypted checks, if the Oasis transaction wrapped inside Ethereum tx is encrypted.
767+ func (api * publicAPI ) checkOasisTxEncrypted (data []byte ) bool {
768+ if api .allowUnencryptedTxs {
769+ // Unencrypted transactions are allowed or encryption not supported by the gateway.
770+ return true
771+ }
772+ if data == nil {
773+ // Transaction is not Oasis transaction, ignore.
774+ return true
775+ }
776+
777+ var tx types.Transaction
778+ if err := cbor .Unmarshal (data , & tx ); err != nil {
779+ // Transaction is not Oasis transaction, ignore.
780+ return true
781+ }
782+
783+ if tx .Call .Format == types .CallFormatPlain {
784+ return false
785+ }
786+
787+ // Transaction marked as encrypted.
788+ return true
789+ }
0 commit comments