Skip to content

Commit 8e0b48c

Browse files
committed
feat(eth): drop unencrypted transactions by default
1 parent 508ca6b commit 8e0b48c

File tree

6 files changed

+97
-17
lines changed

6 files changed

+97
-17
lines changed

.github/workflows/ci-test.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ jobs:
142142
run: tests/tools/spinup-oasis-stack.sh > /dev/null &
143143

144144
- name: Unit tests with coverage
145-
run: go test -race -coverpkg=./... -coverprofile=coverage.txt -covermode=atomic -v ./...
145+
run: |
146+
cp conf/tests-c10l.yml conf/tests.yml
147+
go test -race -coverpkg=./... -coverprofile=coverage.txt -covermode=atomic -v ./...
146148
147149
- name: Shutdown oasis-node
148150
run: killall oasis-node

conf/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ type GatewayConfig struct {
134134

135135
// OasisRPCs controls whether to enable the `oasis_*` methods. Default is not exposed.
136136
ExposeOasisRPCs bool `koanf:"oasis_rpcs"`
137+
138+
// AllowUnencryptedTxs also accepts transacions with CallFormat=0. Default is false.
139+
AllowUnencryptedTxs bool `koanf:"allow_unencrypted_txs"`
137140
}
138141

139142
// GatewayMonitoringConfig is the gateway prometheus configuration.

conf/server.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ gateway:
3636
port: 9999
3737
method_limits:
3838
get_logs_max_rounds: 100
39-
oasis_rpcs: false
39+
oasis_rpcs: true
40+
allow_unencrypted_txs: false

conf/tests-c10l.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
runtime_id: "8000000000000000000000000000000000000000000000000000000000000000"
2+
node_address: "unix:/tmp/eth-runtime-test/net-runner/network/client-0/internal.sock"
3+
4+
log:
5+
level: debug
6+
format: json
7+
8+
cache:
9+
block_size: 10
10+
metrics: true
11+
12+
database:
13+
host: "127.0.0.1"
14+
port: 5432
15+
db: "postgres"
16+
user: "postgres"
17+
password: "postgres"
18+
dial_timeout: 5
19+
read_timeout: 10
20+
write_timeout: 5
21+
max_open_conns: 0
22+
23+
gateway:
24+
chain_id: 42262
25+
http:
26+
host: "localhost"
27+
port: 8545
28+
ws:
29+
host: "localhost"
30+
port: 8546
31+
monitoring:
32+
host: "localhost"
33+
port: 9999
34+
method_limits:
35+
get_logs_max_rounds: 100
36+
oasis_rpcs: true
37+
allow_unencrypted_txs: false
38+

rpc/apis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func GetRPCAPIs(
3434
var apis []ethRpc.API
3535

3636
web3Service := web3.NewPublicAPI()
37-
ethService := eth.NewPublicAPI(client, archiveClient, logging.GetLogger("eth_rpc"), config.ChainID, backend, gasPriceOracle, config.MethodLimits)
37+
ethService := eth.NewPublicAPI(client, archiveClient, logging.GetLogger("eth_rpc"), config.ChainID, backend, gasPriceOracle, config.MethodLimits, !config.ExposeOasisRPCs || config.AllowUnencryptedTxs)
3838
netService := net.NewPublicAPI(config.ChainID)
3939
txpoolService := txpool.NewPublicAPI()
4040
filtersService := filters.NewPublicAPI(client, logging.GetLogger("eth_filters"), backend, eventSystem)

rpc/eth/api.go

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

110111
type 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

Comments
 (0)