Skip to content

Commit

Permalink
feat: timeout fuzz tests after 10 minutes (#13207)
Browse files Browse the repository at this point in the history
* feat: timeout fuzz tests after 10 minutes

Uses the new fuzz test timeout feature that we merged into foundry
to limit individual test runs to 10 minutes. Simplifies how we
need to deal with heavy fuzz testing.

* fix: improve bounds for OptimismPortal tests

Improves the fuzz bounds for the OptimismPortal tests so that
they can complete 20000 runs without throwing.
  • Loading branch information
smartcontracts authored and sigma committed Dec 19, 2024
1 parent d90394f commit 914f3af
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2.1
parameters:
ci_builder_image:
type: string
default: us-docker.pkg.dev/oplabs-tools-artifacts/images/ci-builder:v0.54.0
default: us-docker.pkg.dev/oplabs-tools-artifacts/images/ci-builder:v0.55.0
ci_builder_rust_image:
type: string
default: us-docker.pkg.dev/oplabs-tools-artifacts/images/ci-builder-rust:latest
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts-bedrock/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ depth = 32

[profile.ciheavy.fuzz]
runs = 20000
timeout = 600

[profile.ciheavy.invariant]
runs = 128
depth = 512
timeout = 600

################################################################
# PROFILE: LITE #
Expand Down
24 changes: 12 additions & 12 deletions packages/contracts-bedrock/test/L1/OptimismPortal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ contract OptimismPortal_Test is CommonTest {
}

/// @dev Tests that `depositTransaction` succeeds when msg.sender == tx.origin and non-custom gas is used.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositTransaction_senderIsOrigin_succeeds(
address _to,
uint256 _mint,
Expand All @@ -227,7 +226,6 @@ contract OptimismPortal_Test is CommonTest {
}

/// @dev Tests that `depositTransaction` succeeds when msg.sender != tx.origin and non-custom gas is used.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositTransaction_senderNotOrigin_succeeds(
address _to,
uint256 _mint,
Expand Down Expand Up @@ -310,7 +308,6 @@ contract OptimismPortal_Test is CommonTest {
}

/// @dev Tests that `depositTransaction` succeeds for an EOA.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositTransaction_eoa_succeeds(
address _to,
uint64 _gasLimit,
Expand Down Expand Up @@ -355,7 +352,6 @@ contract OptimismPortal_Test is CommonTest {
}

/// @dev Tests that `depositTransaction` succeeds for a contract.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositTransaction_contract_succeeds(
address _to,
uint64 _gasLimit,
Expand Down Expand Up @@ -1214,7 +1210,6 @@ contract OptimismPortal_FinalizeWithdrawal_Test is CommonTest {
}

/// @dev Tests that `finalizeWithdrawalTransaction` succeeds.
/// forge-config: ciheavy.fuzz.runs = 8192
function testDiff_finalizeWithdrawalTransaction_succeeds(
address _sender,
address _target,
Expand Down Expand Up @@ -1337,7 +1332,6 @@ contract OptimismPortalResourceFuzz_Test is CommonTest {
uint256 constant MAX_GAS_LIMIT = 30_000_000;

/// @dev Test that various values of the resource metering config will not break deposits.
/// forge-config: ciheavy.fuzz.runs = 10000
function testFuzz_systemConfigDeposit_succeeds(
uint32 _maxResourceLimit,
uint8 _elasticityMultiplier,
Expand All @@ -1356,20 +1350,30 @@ contract OptimismPortalResourceFuzz_Test is CommonTest {
uint64 gasLimit = systemConfig.gasLimit();

// Bound resource config
_systemTxMaxGas = uint32(bound(_systemTxMaxGas, 0, gasLimit - 21000));
_maxResourceLimit = uint32(bound(_maxResourceLimit, 21000, MAX_GAS_LIMIT / 8));
_maxResourceLimit = uint32(bound(_maxResourceLimit, 21000, gasLimit - _systemTxMaxGas));
_maximumBaseFee = uint128(bound(_maximumBaseFee, 1, type(uint128).max));
_minimumBaseFee = uint32(bound(_minimumBaseFee, 0, _maximumBaseFee - 1));
_gasLimit = uint64(bound(_gasLimit, 21000, _maxResourceLimit));
_gasLimit = uint64(bound(_gasLimit, 0, gasLimit));
_prevBaseFee = uint128(bound(_prevBaseFee, 0, 3 gwei));
_prevBoughtGas = uint64(bound(_prevBoughtGas, 0, _maxResourceLimit - _gasLimit));
_blockDiff = uint8(bound(_blockDiff, 0, 3));
_baseFeeMaxChangeDenominator = uint8(bound(_baseFeeMaxChangeDenominator, 2, type(uint8).max));
_elasticityMultiplier = uint8(bound(_elasticityMultiplier, 1, type(uint8).max));

// Prevent values that would cause reverts
vm.assume(gasLimit >= _gasLimit);
vm.assume(_minimumBaseFee < _maximumBaseFee);
vm.assume(uint256(_maxResourceLimit) + uint256(_systemTxMaxGas) <= gasLimit);
vm.assume(((_maxResourceLimit / _elasticityMultiplier) * _elasticityMultiplier) == _maxResourceLimit);

// Although we typically want to limit the usage of vm.assume, we've constructed the above
// bounds to satisfy the assumptions listed in this specific section. These assumptions
// serve only to act as an additional sanity check on top of the bounds and should not
// result in an unnecessary number of test rejections.
vm.assume(gasLimit >= _gasLimit);
vm.assume(_minimumBaseFee < _maximumBaseFee);

// Base fee can increase quickly and mean that we can't buy the amount of gas we want.
// Here we add a VM assumption to bound the potential increase.
// Compute the maximum possible increase in base fee.
Expand Down Expand Up @@ -1472,7 +1476,6 @@ contract OptimismPortalWithMockERC20_Test is OptimismPortal_FinalizeWithdrawal_T
}

/// @dev Tests that `depositERC20Transaction` succeeds when msg.sender == tx.origin.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositERC20Transaction_senderIsOrigin_succeeds(
address _to,
uint256 _mint,
Expand All @@ -1498,7 +1501,6 @@ contract OptimismPortalWithMockERC20_Test is OptimismPortal_FinalizeWithdrawal_T
}

/// @dev Tests that `depositERC20Transaction` succeeds when msg.sender != tx.origin.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositERC20Transaction_senderNotOrigin_succeeds(
address _to,
uint256 _mint,
Expand Down Expand Up @@ -1697,7 +1699,6 @@ contract OptimismPortalWithMockERC20_Test is OptimismPortal_FinalizeWithdrawal_T
}

/// @dev Tests that `depositTransaction` succeeds when a custom gas token is used but the msg.value is zero.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositTransaction_customGasTokenWithNoValueAndSenderIsOrigin_succeeds(
address _to,
uint256 _value,
Expand All @@ -1721,7 +1722,6 @@ contract OptimismPortalWithMockERC20_Test is OptimismPortal_FinalizeWithdrawal_T
}

/// @dev Tests that `depositTransaction` succeeds when a custom gas token is used but the msg.value is zero.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositTransaction_customGasTokenWithNoValueAndSenderNotOrigin_succeeds(
address _to,
uint256 _value,
Expand Down
23 changes: 12 additions & 11 deletions packages/contracts-bedrock/test/L1/OptimismPortal2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ contract OptimismPortal2_Test is CommonTest {
}

/// @dev Tests that `depositTransaction` succeeds for an EOA.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositTransaction_eoa_succeeds(
address _to,
uint64 _gasLimit,
Expand Down Expand Up @@ -256,7 +255,6 @@ contract OptimismPortal2_Test is CommonTest {
}

/// @dev Tests that `depositTransaction` succeeds for a contract.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositTransaction_contract_succeeds(
address _to,
uint64 _gasLimit,
Expand Down Expand Up @@ -1326,7 +1324,6 @@ contract OptimismPortal2_FinalizeWithdrawal_Test is CommonTest {
}

/// @dev Tests that `finalizeWithdrawalTransaction` succeeds.
/// forge-config: ciheavy.fuzz.runs = 8192
function testDiff_finalizeWithdrawalTransaction_succeeds(
address _sender,
address _target,
Expand Down Expand Up @@ -1610,7 +1607,6 @@ contract OptimismPortal2_ResourceFuzz_Test is CommonTest {
}

/// @dev Test that various values of the resource metering config will not break deposits.
/// forge-config: ciheavy.fuzz.runs = 10000
function testFuzz_systemConfigDeposit_succeeds(
uint32 _maxResourceLimit,
uint8 _elasticityMultiplier,
Expand All @@ -1629,21 +1625,30 @@ contract OptimismPortal2_ResourceFuzz_Test is CommonTest {
uint64 gasLimit = systemConfig.gasLimit();

// Bound resource config
_systemTxMaxGas = uint32(bound(_systemTxMaxGas, 0, gasLimit - 21000));
_maxResourceLimit = uint32(bound(_maxResourceLimit, 21000, MAX_GAS_LIMIT / 8));
_maxResourceLimit = uint32(bound(_maxResourceLimit, 21000, gasLimit - _systemTxMaxGas));
_maximumBaseFee = uint128(bound(_maximumBaseFee, 1, type(uint128).max));
_minimumBaseFee = uint32(bound(_minimumBaseFee, 0, _maximumBaseFee - 1));
_gasLimit = uint64(bound(_gasLimit, 21000, _maxResourceLimit));
_gasLimit = uint64(bound(_gasLimit, 0, gasLimit));
_prevBaseFee = uint128(bound(_prevBaseFee, 0, 3 gwei));
_prevBoughtGas = uint64(bound(_prevBoughtGas, 0, _maxResourceLimit - _gasLimit));
_blockDiff = uint8(bound(_blockDiff, 0, 3));
_baseFeeMaxChangeDenominator = uint8(bound(_baseFeeMaxChangeDenominator, 2, type(uint8).max));
_elasticityMultiplier = uint8(bound(_elasticityMultiplier, 1, type(uint8).max));

// Prevent values that would cause reverts
vm.assume(gasLimit >= _gasLimit);
vm.assume(_minimumBaseFee < _maximumBaseFee);
vm.assume(_baseFeeMaxChangeDenominator > 1);
vm.assume(uint256(_maxResourceLimit) + uint256(_systemTxMaxGas) <= gasLimit);
vm.assume(((_maxResourceLimit / _elasticityMultiplier) * _elasticityMultiplier) == _maxResourceLimit);

// Although we typically want to limit the usage of vm.assume, we've constructed the above
// bounds to satisfy the assumptions listed in this specific section. These assumptions
// serve only to act as an additional sanity check on top of the bounds and should not
// result in an unnecessary number of test rejections.
vm.assume(gasLimit >= _gasLimit);
vm.assume(_minimumBaseFee < _maximumBaseFee);

// Base fee can increase quickly and mean that we can't buy the amount of gas we want.
// Here we add a VM assumption to bound the potential increase.
// Compute the maximum possible increase in base fee.
Expand Down Expand Up @@ -1746,7 +1751,6 @@ contract OptimismPortal2WithMockERC20_Test is OptimismPortal2_FinalizeWithdrawal
}

/// @dev Tests that `depositERC20Transaction` succeeds when msg.sender == tx.origin.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositERC20Transaction_senderIsOrigin_succeeds(
address _to,
uint256 _mint,
Expand All @@ -1772,7 +1776,6 @@ contract OptimismPortal2WithMockERC20_Test is OptimismPortal2_FinalizeWithdrawal
}

/// @dev Tests that `depositERC20Transaction` succeeds when msg.sender != tx.origin.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositERC20Transaction_senderNotOrigin_succeeds(
address _to,
uint256 _mint,
Expand Down Expand Up @@ -1980,7 +1983,6 @@ contract OptimismPortal2WithMockERC20_Test is OptimismPortal2_FinalizeWithdrawal
}

/// @dev Tests that `depositTransaction` succeeds when a custom gas token is used but the msg.value is zero.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositTransaction_customGasTokenWithNoValueAndSenderIsOrigin_succeeds(
address _to,
uint256 _value,
Expand All @@ -2004,7 +2006,6 @@ contract OptimismPortal2WithMockERC20_Test is OptimismPortal2_FinalizeWithdrawal
}

/// @dev Tests that `depositTransaction` succeeds when a custom gas token is used but the msg.value is zero.
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_depositTransaction_customGasTokenWithNoValueAndSenderNotOrigin_succeeds(
address _to,
uint256 _value,
Expand Down
3 changes: 0 additions & 3 deletions packages/contracts-bedrock/test/cannon/PreimageOracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,6 @@ contract PreimageOracle_LargePreimageProposals_Test is Test {

/// @notice Tests that squeezing a large preimage proposal after the challenge period has passed always succeeds and
/// persists the correct data.
/// forge-config: ciheavy.fuzz.runs = 512
function testFuzz_squeezeLPP_succeeds(uint256 _numBlocks, uint32 _partOffset) public {
_numBlocks = bound(_numBlocks, 1, 2 ** 8);
_partOffset = uint32(bound(_partOffset, 0, _numBlocks * LibKeccak.BLOCK_SIZE_BYTES + 8 - 1));
Expand Down Expand Up @@ -1087,7 +1086,6 @@ contract PreimageOracle_LargePreimageProposals_Test is Test {

/// @notice Tests that challenging the first divergence in a large preimage proposal at an arbitrary location
/// in the leaf values always succeeds.
/// forge-config: ciheavy.fuzz.runs = 512
function testFuzz_challenge_arbitraryLocation_succeeds(uint256 _lastCorrectLeafIdx, uint256 _numBlocks) public {
_numBlocks = bound(_numBlocks, 1, 2 ** 8);
_lastCorrectLeafIdx = bound(_lastCorrectLeafIdx, 0, _numBlocks - 1);
Expand Down Expand Up @@ -1140,7 +1138,6 @@ contract PreimageOracle_LargePreimageProposals_Test is Test {
}

/// @notice Tests that challenging the a divergence in a large preimage proposal at the first leaf always succeeds.
/// forge-config: ciheavy.fuzz.runs = 1024
function testFuzz_challengeFirst_succeeds(uint256 _numBlocks) public {
_numBlocks = bound(_numBlocks, 1, 2 ** 8);

Expand Down
1 change: 0 additions & 1 deletion packages/contracts-bedrock/test/safe/LivenessGuard.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ contract LivenessGuard_FuzzOwnerManagement_Test is StdCheats, StdUtils, Liveness
mapping(address => uint256) privateKeys;

/// @dev Tests that the guard correctly manages the lastLive mapping when owners are added, removed, or swapped
/// forge-config: ciheavy.fuzz.runs = 8192
function testFuzz_ownerManagement_works(
uint256 initialOwners,
uint256 threshold,
Expand Down
2 changes: 0 additions & 2 deletions packages/contracts-bedrock/test/setup/DeployVariations.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ contract DeployVariations_Test is CommonTest {
}
}

/// forge-config: ciheavy.fuzz.runs = 512
/// @dev It should be possible to enable Fault Proofs with any mix of CGT and Alt-DA.
function testFuzz_enableFaultProofs_succeeds(bool _enableCGT, bool _enableAltDa) public virtual {
enableAddOns(_enableCGT, _enableAltDa);

super.setUp();
}

/// forge-config: ciheavy.fuzz.runs = 512
/// @dev It should be possible to enable Fault Proofs and Interop with any mix of CGT and Alt-DA.
function test_enableInteropAndFaultProofs_succeeds(bool _enableCGT, bool _enableAltDa) public virtual {
enableAddOns(_enableCGT, _enableAltDa);
Expand Down

0 comments on commit 914f3af

Please sign in to comment.