rpcfuzz

package
v0.1.99 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 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,
	PersistentPreRun: func(cmd *cobra.Command, args []string) {
		rpcUrlPtr := flag_loader.GetRpcUrlFlagValue(cmd)
		rpcUrl = *rpcUrlPtr
		privateKeyPtr := flag_loader.GetPrivateKeyFlagValue(cmd)
		testPrivateHexKey = *privateKeyPtr
	},
	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 ...any) func() []any

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 ...any) func() []any

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 ...any) func() []any

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 ...any) func() []any

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 ...any) func() []any

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 ...any) func() []any

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

func ArgsRawBlock

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

ArgsRawBlock will inject raw block RLP data into the arguments

func ArgsSignTransaction

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

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

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

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() []any

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() []any

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() []any

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

func CallRPCAndValidate

func CallRPCAndValidate(ctx context.Context, rpcClient *rpc.Client, wrappedHTTPClient wrappedHttpClient, currTest RPCTest) streamer.TestExecution

func CallRPCWithFuzzAndValidate

func CallRPCWithFuzzAndValidate(ctx context.Context, rpcClient *rpc.Client, currTest RPCTest, outputStreamer streamer.OutputStreamer) streamer.TestSummary

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(any) error) func(result any) error

func RequireAny

func RequireAny(validators ...func(any) error) func(result any) error

func ValidateBlockHash

func ValidateBlockHash() func(result any) 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 any) error

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

func ValidateErrorMsgString

func ValidateErrorMsgString(errorMessageRegex string) func(result any) error

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

func ValidateExact

func ValidateExact(expected any) func(result any) error

ValidateExact will validate against the exact value expected.

func ValidateExactJSON

func ValidateExactJSON(expected string) func(result any) error

func ValidateHashedResponse

func ValidateHashedResponse(expectedHash string) func(result any) 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 any) error

ValidateJSONSchema is used to validate the response against a JSON Schema

func ValidateRegexString

func ValidateRegexString(regEx string) func(result any) error

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

func ValidateTransactionHash

func ValidateTransactionHash() func(result any) error

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

Types

type RPCJSONError

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

RPCJSONError can be used to unmarshal a raw error response.

func (*RPCJSONError) Error

func (r *RPCJSONError) Error() string

type RPCJSONResponse

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() []any

	// Validate will return an error of the result fails validation
	Validate(result any) 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() []any
	Validator func(result any) 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() []any

func (*RPCTestDynamicArgs) GetMethod

func (r *RPCTestDynamicArgs) GetMethod() string

func (*RPCTestDynamicArgs) GetName

func (r *RPCTestDynamicArgs) GetName() string

func (*RPCTestDynamicArgs) Validate

func (r *RPCTestDynamicArgs) Validate(result any) error

type RPCTestFilterArgs

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

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

type RPCTestFlag

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      []any
	Validator func(result any) 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() []any

func (*RPCTestGeneric) GetMethod

func (r *RPCTestGeneric) GetMethod() string

func (*RPCTestGeneric) GetName

func (r *RPCTestGeneric) GetName() string

func (*RPCTestGeneric) Validate

func (r *RPCTestGeneric) Validate(result any) error

type RPCTestRawHTTP

type RPCTestRawHTTP struct {
	Name       string
	HTTPMethod string
	Args       []any
	Validator  func(result any) 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

func (r *RPCTestRawHTTP) ExpectError() bool

func (*RPCTestRawHTTP) GetArgs

func (r *RPCTestRawHTTP) GetArgs() []any

func (*RPCTestRawHTTP) GetMethod

func (r *RPCTestRawHTTP) GetMethod() string

func (*RPCTestRawHTTP) GetName

func (r *RPCTestRawHTTP) GetName() string

func (*RPCTestRawHTTP) Validate

func (r *RPCTestRawHTTP) Validate(result any) 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.

Jump to

Keyboard shortcuts

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