rpcfuzz

package
v0.1.43 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2024 License: AGPL-3.0 Imports: 32 Imported by: 0

README

Current list of RPCs:

- [X] ~debug_getBadBlocks~
- [X] ~debug_getRawBlock~
- [X] ~debug_getRawHeader~
- [X] ~debug_getRawReceipts~
- [X] ~debug_getRawTransaction~
- [X] ~debug_traceBlockByHash~
- [X] ~debug_traceBlockByNumber~
- [X] ~debug_traceBlock~
- [X] ~debug_traceCall~
- [X] ~debug_traceTransaction~
- [ ] ~engine_exchangeCapabilities~
- [ ] ~engine_exchangeTransitionConfigurationV1~
- [ ] ~engine_forkchoiceUpdatedV1~
- [ ] ~engine_forkchoiceUpdatedV2~
- [ ] ~engine_getPayloadBodiesByHashV1~
- [ ] ~engine_getPayloadBodiesByRangeV1~
- [ ] ~engine_getPayloadV1~
- [ ] ~engine_getPayloadV2~
- [ ] ~engine_newPayloadV1~
- [ ] ~engine_newPayloadV2~
- [X] ~eth_createAccessList~
- [X] ~eth_feeHistory~
- [X] ~eth_getProof~
- [X] ~eth_maxPriorityFeePerGas~
- [X] ~eth_accounts~
- [X] ~eth_blockNumber~
- [X] ~eth_call~
- [X] ~eth_chainId~
- [X] ~eth_coinbase~
- [X] ~eth_estimateGas~
- [X] ~eth_gasPrice~
- [X] ~eth_getBalance~
- [X] ~eth_getBlockByHash~
- [X] ~eth_getBlockByNumber~
- [X] ~eth_getBlockTransactionCountByHash~
- [X] ~eth_getBlockTransactionCountByNumber~
- [X] ~eth_getCode~
- [X] ~eth_getFilterChanges~
- [X] ~eth_getFilterLogs~
- [X] ~eth_getLogs~
- [X] ~eth_getStorageAt~
- [X] ~eth_getTransactionByBlockHashAndIndex~
- [X] ~eth_getTransactionByBlockNumberAndIndex~
- [X] ~eth_getTransactionByHash~
- [X] ~eth_getTransactionCount~
- [X] ~eth_getTransactionReceipt~
- [X] ~eth_getUncleCountByBlockHash~
- [X] ~eth_getUncleCountByBlockNumber~
- [X] ~eth_getWork~
- [X] ~eth_hashrate~
- [X] ~eth_mining~
- [X] ~eth_newBlockFilter~
- [X] ~eth_newFilter~
- [X] ~eth_newPendingTransactionFilter~
- [X] ~eth_sendRawTransaction~
- [X] ~eth_sendTransaction~
- [X] ~eth_signTransaction~
- [X] ~eth_sign~
- [X] ~eth_submitHashrate~
- [X] ~eth_submitWork~
- [X] ~eth_syncing~
- [X] ~eth_uninstallFilter~

TODO:
- Add post merge tags
  - latest
  - earliest
  - pending
  - safe
  - finalized
- Add batch calls to confirm batch behaviors
- Add nonce behavioral issues
  - Replacement
  - Duplicate
  - Too low
  - Huge gap

Documentation

Overview

Package rpcfuzz is meant to have some basic RPC fuzzing and conformance tests. Each test is meant to be self-contained i.e. the success or failure of a test should have no impact on other tests. The benefit here is that each test is an object and can be modified, decorated, fuzzed, etc.

The conformance test should also run successful on a network that is or isn't isolated. In some circumstances, it might be better to run the conformance test in once process while there is load being applied. The only consideration is that you shouldn't use the same key to load test as is used to run the conformance tests.

Index

Constants

This section is empty.

Variables

View Source
var RPCFuzzCmd = &cobra.Command{
	Use:   "rpcfuzz",
	Short: "Continually run a variety of RPC calls and fuzzers.",
	Long:  usage,
	Args:  cobra.NoArgs,
	PreRunE: func(cmd *cobra.Command, args []string) error {
		return checkFlags()
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		return runRpcFuzz(cmd.Context())
	},
}

Functions

func ArgsBlockFilterID

func ArgsBlockFilterID(ctx context.Context, rpcClient *rpc.Client, extraArgs ...interface{}) func() []interface{}

ArgsBlockFilterID will inject an argument that's a filter id corresponding to a block filte

func ArgsCoinbase

func ArgsCoinbase(ctx context.Context, rpcClient *rpc.Client, extraArgs ...interface{}) func() []interface{}

ArgsCoinbase would return arguments where the first argument is now the coinbase

func ArgsCoinbaseTransaction

func ArgsCoinbaseTransaction(ctx context.Context, rpcClient *rpc.Client, tx *RPCTestTransactionArgs, extraArgs ...interface{}) func() []interface{}

ArgsCoinbaseTransaction will return arguments where the from is replace with the current coinbase

func ArgsFilterID

func ArgsFilterID(ctx context.Context, rpcClient *rpc.Client, filterArgs RPCTestFilterArgs, extraArgs ...interface{}) func() []interface{}

ArgsFilterID will inject an argument that's a filter id corresponding to the provide filter args

func ArgsLatestBlockHash

func ArgsLatestBlockHash(ctx context.Context, rpcClient *rpc.Client, extraArgs ...interface{}) func() []interface{}

ArgsLatestBlockHash is meant to generate an argument with the latest block hash for testing

func ArgsLatestBlockNumber

func ArgsLatestBlockNumber(ctx context.Context, rpcClient *rpc.Client, extraArgs ...interface{}) func() []interface{}

ArgsLatestBlockNumber will inject arguments that correspond to the most recent block's number

func ArgsRawBlock added in v0.1.28

func ArgsRawBlock(ctx context.Context, rpcClient *rpc.Client, blockNumOrHash string, extraArgs ...interface{}) func() []interface{}

ArgsRawBlock will inject raw block RLP data into the arguments

func ArgsSignTransaction

func ArgsSignTransaction(ctx context.Context, rpcClient *rpc.Client, tx *RPCTestTransactionArgs, extraArgs ...interface{}) func() []interface{}

ArgsSignTransaction will take the junk transaction type that we've created, convert it to a geth style dynamic fee transaction and sign it with the user provide key.

func ArgsSignTransactionWithNonce added in v0.1.28

func ArgsSignTransactionWithNonce(ctx context.Context, rpcClient *rpc.Client, tx *RPCTestTransactionArgs, nonce uint64, extraArgs ...interface{}) func() []interface{}

ArgsSignTransactionWithNonce can be used to manipulate the nonce directly in order to create some error cases

func ArgsTransactionBlockHashAndIndex

func ArgsTransactionBlockHashAndIndex(ctx context.Context, rpcClient *rpc.Client, tx *RPCTestTransactionArgs) func() []interface{}

ArgsTransactionBlockHashAndIndex will execute the provided transaction and return the block hash and index of the given transaction

func ArgsTransactionBlockNumberAndIndex

func ArgsTransactionBlockNumberAndIndex(ctx context.Context, rpcClient *rpc.Client, tx *RPCTestTransactionArgs) func() []interface{}

ArgsTransactionBlockNumberAndIndex will execute the provided transaction and return the block number and index of the given transaction

func ArgsTransactionHash

func ArgsTransactionHash(ctx context.Context, rpcClient *rpc.Client, tx *RPCTestTransactionArgs) func() []interface{}

ArgsTransactionHash will execute the provided transaction and return the transaction hash as an argument to be used in other tests.

func CallRPCAndValidate added in v0.1.29

func CallRPCAndValidate(ctx context.Context, rpcClient *rpc.Client, wrappedHttpClient wrappedHttpClient, currTest RPCTest) testreporter.TestResult

func CallRPCWithFuzzAndValidate added in v0.1.29

func CallRPCWithFuzzAndValidate(ctx context.Context, rpcClient *rpc.Client, currTest RPCTest) testreporter.TestResult

func GenericTransactionToDynamicFeeTx

func GenericTransactionToDynamicFeeTx(tx *RPCTestTransactionArgs) ethtypes.DynamicFeeTx

GenericTransactionToDynamicFeeTx convert the simple tx representation that we have into a standard eth type

func GetCurrentChainID

func GetCurrentChainID(ctx context.Context, rpcClient *rpc.Client) (*big.Int, error)

GetCurrentChainID will attempt to determine the chain for the current network

func GetTestAccountNonce

func GetTestAccountNonce(ctx context.Context, rpcClient *rpc.Client) (uint64, error)

GetTestAccountNonce will attempt to get the current nonce for the current test account

func RequireAll

func RequireAll(validators ...func(interface{}) error) func(result interface{}) error

func RequireAny

func RequireAny(validators ...func(interface{}) error) func(result interface{}) error

func ValidateBlockHash added in v0.1.28

func ValidateBlockHash() func(result interface{}) error

ValidateBlockHash will convert the result into a block and compute the header in order to verify that the rpc header matches the computed header.

func ValidateError

func ValidateError(code int, errorMessageRegex string) func(result interface{}) error

ValidateError will check the status code and error message text against the provide regular expression

func ValidateErrorMsgString added in v0.1.37

func ValidateErrorMsgString(errorMessageRegex string) func(result interface{}) error

ValidateErrorMsgString will check the error message text against the provide regular expression

func ValidateExact

func ValidateExact(expected interface{}) func(result interface{}) error

ValidateExact will validate against the exact value expected.

func ValidateExactJSON

func ValidateExactJSON(expected string) func(result interface{}) error

func ValidateHashedResponse

func ValidateHashedResponse(expectedHash string) func(result interface{}) error

ValidateHashedResponse will take a hex encoded hash and return a function that will validate that a given result has the same hash. The expected hash does not start with 0x

func ValidateJSONSchema

func ValidateJSONSchema(schema string) func(result interface{}) error

ValidateJSONSchema is used to validate the response against a JSON Schema

func ValidateRegexString

func ValidateRegexString(regEx string) func(result interface{}) error

ValidateRegexString will match a string from the json response against a regular expression

func ValidateTransactionHash added in v0.1.28

func ValidateTransactionHash() func(result interface{}) error

ValidateTransactionHash will compare the rpc transaction hash to the computed transaction hash

Types

type RPCJSONError added in v0.1.28

type RPCJSONError struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

RPCJSONError can be used to unmarshal a raw error response.

func (*RPCJSONError) Error added in v0.1.28

func (r *RPCJSONError) Error() string

type RPCJSONResponse added in v0.1.35

type RPCJSONResponse struct {
	Version string        `json:"jsonrpc"`
	Result  any           `json:"result,omitempty"`
	Error   *RPCJSONError `json:"error,omitempty"`
	ID      any           `json:"id"`
}

RPCJSONResponse can be used to unmarshal a raw response.

type RPCTest

type RPCTest interface {
	// GetName returns a more descriptive name of the test being executed
	GetName() string

	// GetMethod returns the json rpc method name
	GetMethod() string

	// GetArgs will return the list of arguments that will be used when calling the rpc
	GetArgs() []interface{}

	// Validate will return an error of the result fails validation
	Validate(result interface{}) error

	// ExpectError is used by the validation code to understand of the test typically returns an error
	ExpectError() bool
}

RPCTest is the common interface for a test. In the future we'll need some addition methods in particular if don't want to run tests that require unlocked accounts or if we want to skip certain namespaces

type RPCTestDynamicArgs

type RPCTestDynamicArgs struct {
	Name      string
	Method    string
	Args      func() []interface{}
	Validator func(result interface{}) error
	Flags     RPCTestFlag
}

RPCTestDynamicArgs is a simple implementation of the RPCTest that requires a function for Args which will be used to generate the args for testing.

func (*RPCTestDynamicArgs) ExpectError

func (r *RPCTestDynamicArgs) ExpectError() bool

func (*RPCTestDynamicArgs) GetArgs

func (r *RPCTestDynamicArgs) GetArgs() []interface{}

func (*RPCTestDynamicArgs) GetMethod

func (r *RPCTestDynamicArgs) GetMethod() string

func (*RPCTestDynamicArgs) GetName

func (r *RPCTestDynamicArgs) GetName() string

func (*RPCTestDynamicArgs) Validate

func (r *RPCTestDynamicArgs) Validate(result interface{}) error

type RPCTestFilterArgs

type RPCTestFilterArgs struct {
	FromBlock string        `json:"fromBlock,omitempty"`
	ToBlock   string        `json:"toBlock,omitempty"`
	Address   string        `json:"address,omitempty"`
	Topics    []interface{} `json:"topics,omitempty"`
}

RPCTestFilterArgs is a simplified type to contain the flag needed to create a filter

type RPCTestFlag added in v0.1.28

type RPCTestFlag uint64

RPCTestFlag is meant for bitmasking various flags to understand properties of the test

const (
	FlagStrictValidation RPCTestFlag = 1 << iota // strict means the test is unsuitable for fuzzing / mutation because it most likely won't match
	FlagErrorValidation                          // error validation means the result is expected to be an error
	FlagRequiresUnlock                           // unlock means the test depends on unlocked accounts
	FlagEIP1559                                  // tests that would only exist with EIP-1559 enabled
	FlagOrderDependent                           // This flag indicates that the particular test might fail if shuffled

)

type RPCTestGeneric

type RPCTestGeneric struct {
	Name      string
	Method    string
	Args      []interface{}
	Validator func(result interface{}) error
	Flags     RPCTestFlag
}

RPCTestGeneric is the simplest implementation of the RPCTest. Basically the implementation of the interface is managed by just returning hard coded values for method, args, validator, and error

func (*RPCTestGeneric) ExpectError

func (r *RPCTestGeneric) ExpectError() bool

func (*RPCTestGeneric) GetArgs

func (r *RPCTestGeneric) GetArgs() []interface{}

func (*RPCTestGeneric) GetMethod

func (r *RPCTestGeneric) GetMethod() string

func (*RPCTestGeneric) GetName

func (r *RPCTestGeneric) GetName() string

func (*RPCTestGeneric) Validate

func (r *RPCTestGeneric) Validate(result interface{}) error

type RPCTestRawHTTP added in v0.1.35

type RPCTestRawHTTP struct {
	Name       string
	HTTPMethod string
	Args       []interface{}
	Validator  func(result interface{}) error
	Flags      RPCTestFlag
}

RPCTestRawHTTP is a raw RPCTest performed using HTTP requests. It does not leverage advanced HTTP libraries like `github.com/ethereum/go-ethereum/rpc`.

func (*RPCTestRawHTTP) ExpectError added in v0.1.35

func (r *RPCTestRawHTTP) ExpectError() bool

func (*RPCTestRawHTTP) GetArgs added in v0.1.35

func (r *RPCTestRawHTTP) GetArgs() []interface{}

func (*RPCTestRawHTTP) GetMethod added in v0.1.35

func (r *RPCTestRawHTTP) GetMethod() string

func (*RPCTestRawHTTP) GetName added in v0.1.35

func (r *RPCTestRawHTTP) GetName() string

func (*RPCTestRawHTTP) Validate added in v0.1.35

func (r *RPCTestRawHTTP) Validate(result interface{}) error

type RPCTestTransactionArgs

type RPCTestTransactionArgs struct {
	From                 string `json:"from,omitempty"`
	To                   string `json:"to,omitempty"`
	Gas                  string `json:"gas,omitempty"`
	GasPrice             string `json:"gasPrice,omitempty"`
	MaxFeePerGas         string `json:"maxFeePerGas,omitempty"`
	MaxPriorityFeePerGas string `json:"maxPriorityFeePerGas,omitempty"`
	Value                string `json:"value,omitempty"`
	Nonce                string `json:"nonce,omitempty"`
	Data                 string `json:"data"`
}

RPCTestTransactionArgs is used to send transactions

Directories

Path Synopsis
Package argfuzz implements the randomizers, mutators, and fuzzers that can be utilized by gofuzz.
Package argfuzz implements the randomizers, mutators, and fuzzers that can be utilized by gofuzz.
Package testreporter provides the utilities to capture, report, and log test results.
Package testreporter provides the utilities to capture, report, and log test results.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL