Skip to content

Commit

Permalink
make limit configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Jun 13, 2023
1 parent ae80657 commit 31c1bc3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
14 changes: 14 additions & 0 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ const (

// DefaultReturnDataLimit is maximum number of bytes returned from eth_call or similar invocations
DefaultReturnDataLimit = 100000

// DefaultBatchRequestLimit is maximum number of requests in a batch
DefaultBatchRequestLimit = 1000

// DefaultBatchResponseMaxSize maximum number of bytes returned from a batched call
DefaultBatchResponseMaxSize = 25 * 1000 * 1000
)

var evmTracers = []string{"json", "markdown", "struct", "access_list"}
Expand Down Expand Up @@ -126,6 +132,10 @@ type JSONRPCConfig struct {
MetricsAddress string `mapstructure:"metrics-address"`
// ReturnDataLimit defines maximum number of bytes returned from `eth_call` or similar invocations
ReturnDataLimit int64 `mapstructure:"return-data-limit"`
// BatchRequestLimit maximum number of requests in a batch
BatchRequestLimit int64 `mapstructure:"batch-request-limit"`
// BatchResponseMaxSize maximum number of bytes returned from a batched call
BatchResponseMaxSize int64 `mapstructure:"batch-response-max-size"`
// FixRevertGasRefundHeight defines the upgrade height for fix of revert gas refund logic when transaction reverted
FixRevertGasRefundHeight int64 `mapstructure:"fix-revert-gas-refund-height"`
}
Expand Down Expand Up @@ -231,6 +241,8 @@ func DefaultJSONRPCConfig() *JSONRPCConfig {
EnableIndexer: false,
MetricsAddress: DefaultJSONRPCMetricsAddress,
ReturnDataLimit: DefaultReturnDataLimit,
BatchRequestLimit: DefaultBatchRequestLimit,
BatchResponseMaxSize: DefaultBatchResponseMaxSize,
FixRevertGasRefundHeight: DefaultFixRevertGasRefundHeight,
}
}
Expand Down Expand Up @@ -343,6 +355,8 @@ func GetConfig(v *viper.Viper) (Config, error) {
MetricsAddress: v.GetString("json-rpc.metrics-address"),
ReturnDataLimit: v.GetInt64("json-rpc.return-data-limit"),
FixRevertGasRefundHeight: v.GetInt64("json-rpc.fix-revert-gas-refund-height"),
BatchRequestLimit: v.GetInt64("json-rpc.batch-request-limit"),
BatchResponseMaxSize: v.GetInt64("json-rpc.batch-response-max-size"),

Check warning on line 359 in server/config/config.go

View check run for this annotation

Codecov / codecov/patch

server/config/config.go#L358-L359

Added lines #L358 - L359 were not covered by tests
},
TLS: TLSConfig{
CertificatePath: v.GetString("tls.certificate-path"),
Expand Down
6 changes: 6 additions & 0 deletions server/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ metrics-address = "{{ .JSONRPC.MetricsAddress }}"
# Maximum number of bytes returned from eth_call or similar invocations.
return-data-limit = {{ .JSONRPC.ReturnDataLimit }}
# Maximum number of requests in a batch.
batch-request-limit = {{ .JSONRPC.BatchRequestLimit }}
# Maximum number of bytes returned from a batched call.
batch-response-max-size = {{ .JSONRPC.BatchResponseMaxSize }}
# Upgrade height for fix of revert gas refund logic when transaction reverted.
fix-revert-gas-refund-height = {{ .JSONRPC.FixRevertGasRefundHeight }}
Expand Down
2 changes: 2 additions & 0 deletions server/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ const (
// https://github.com/ethereum/go-ethereum/blob/master/metrics/metrics.go#L35-L55
JSONRPCEnableMetrics = "metrics"
JSONRPCReturnDataLimit = "json-rpc.return-data-limit"
JSONRPCBatchRequestLimit = "json-rpc.batch-request-limit"
JSONRPCBatchResponseMaxSize = "json-rpc.batch-response-max-size"
JSONRPCFixRevertGasRefundHeight = "json-rpc.fix-revert-gas-refund-height"
)

Expand Down
2 changes: 1 addition & 1 deletion server/json_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func StartJSONRPC(ctx *server.Context,
}))

rpcServer := ethrpc.NewServer()
rpcServer.SetBatchLimits(2, 1) // add 0x: (3594240 + 2) * 4
rpcServer.SetBatchLimits(int(config.JSONRPC.BatchRequestLimit), int(config.JSONRPC.BatchResponseMaxSize)) // add 0x: (3594240 + 2) * 4
allowUnprotectedTxs := config.JSONRPC.AllowUnprotectedTxs
rpcAPIArr := config.JSONRPC.API

Expand Down
2 changes: 2 additions & 0 deletions tests/integration_tests/configs/exploit.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ config {
'app-config'+: {
'json-rpc'+: {
'return-data-limit': 3594241, // memory_byte_size + 1
'batch-request-limit': 2,
'batch-response-max-size': 10,
},
},
},
Expand Down

0 comments on commit 31c1bc3

Please sign in to comment.