Skip to main content
This page provides detailed reference documentation for all backtesting configuration options, API methods, and data structures.
New to backtesting? Start with the Backtesting Guide to understand the basics before diving into this reference.

Configuration Parameters

targetContract

The address of the contract (Assertion Adopter) to test assertions against. The backtesting tool will find all transactions that interact with this contract, including both direct calls and internal calls (e.g., through routers or aggregators).

endBlock

The last block in the range to test. The tool runs on the block range from endBlock - blockRange to endBlock.

blockRange

Number of blocks to test, counting backwards from endBlock. The tool will test blocks from endBlock - blockRange to endBlock.
To test against a specific transaction, set blockRange: 1 with the block number containing that transaction. This is useful for validating assertions against known exploit transactions. See the Balancer V2 Rate Manipulation Exploit for a real-world example.

assertionCreationCode

The bytecode of your assertion contract. Use type(YourAssertion).creationCode to get this value.

assertionSelector

The function selector of the assertion function to trigger. This determines which assertion method runs during validation.

rpcUrl

The RPC endpoint URL to use for fetching blockchain data. Can also be set via the RPC_URL environment variable.

forkByTxHash

Controls how the EVM state is forked for each transaction replay. This parameter is kept for interface compatibility but is effectively always true internally to ensure correct pre-transaction state.

detailedBlocks

Controls logging verbosity. Currently reserved for future functionality.

API Reference

executeBacktest

Executes a backtest with the provided configuration and returns detailed results.
Parameters:
  • config: Configuration struct containing all backtesting parameters
Returns:
  • results: Results struct containing test execution statistics
Example:

executeBacktestForTransaction

Executes a backtest for a single transaction specified by its hash. This is useful for:
  • Testing assertions against specific known transactions (such as historical exploits)
  • Debugging potential false positives reported during staging (see Testing Strategy for more on the staging workflow)
  • Quickly validating assertion behavior on a problematic transaction without specifying a block range
Parameters:
  • txHash: The transaction hash to backtest
  • targetContract: The target contract address (assertion adopter)
  • assertionCreationCode: The assertion contract creation code
  • assertionSelector: The assertion function selector
  • rpcUrl: The RPC URL to use
Returns:
  • results: Results struct containing test execution statistics
Example:

BacktestingConfig

Configuration struct for backtesting parameters.
Field Descriptions:

BacktestingResults

Results struct returned after backtesting execution.
Field Descriptions: Interpreting Results: The assertionFailures field indicates how many transactions triggered assertion reverts. Since backtesting runs against historical transactions, non-zero values most commonly indicate false positives in your assertion logic rather than actual exploits.
Common Causes of Assertion Failures:
  • False positives: Assertion logic incorrectly flags legitimate protocol behavior (most common)
  • Gas limit exceeded: Assertion ran out of gas (300k limit) during complex operations
  • Assertion bugs: Logic errors in the assertion code
  • Known exploits: If testing against historical exploit blocks, failures may be expected
See the Understanding Results section in the Backtesting Guide for detailed information on all result categories.

Example Configurations

Standard Configuration

Basic configuration suitable for most backtesting scenarios:
See the Backtesting Guide for more configuration examples including debugging and quick test scenarios.

Learn More

Full API Reference

Autogenerated API documentation for backtesting

Backtesting Guide

Learn how to use backtesting to validate assertions

Testing Assertions

Basic testing guide for assertions

CI/CD Integration

Automate your testing workflow

Fuzz Testing

Use fuzz testing to test assertions