Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ contract DataAvailabilityChallengeTest is CommonTest {
// EntryPoint will revert if using amount > type(uint112).max.
vm.assume(sender != Preinstalls.EntryPoint_v060);
vm.assume(sender != address(dataAvailabilityChallenge));
vm.assume(sender.balance == 0);
vm.deal(sender, amount);

vm.prank(sender);
Expand All @@ -59,7 +58,6 @@ contract DataAvailabilityChallengeTest is CommonTest {
vm.assume(sender != Preinstalls.EntryPoint_v060);
vm.assume(sender != address(dataAvailabilityChallenge));
vm.assume(sender != deploy.mustGetAddress("DataAvailabilityChallenge"));
vm.assume(sender.balance == 0);
vm.deal(sender, amount);

vm.prank(sender);
Expand All @@ -86,10 +84,11 @@ contract DataAvailabilityChallengeTest is CommonTest {
vm.assume(challenger != address(0));

// Assume the block number is not close to the max uint256 value
vm.assume(
challengedBlockNumber
< type(uint256).max - dataAvailabilityChallenge.challengeWindow()
- dataAvailabilityChallenge.resolveWindow()
challengedBlockNumber = bound(
challengedBlockNumber,
0,
type(uint256).max - dataAvailabilityChallenge.challengeWindow() - dataAvailabilityChallenge.resolveWindow()
- 1
);
uint256 requiredBond = dataAvailabilityChallenge.bondSize();

Expand Down Expand Up @@ -139,10 +138,11 @@ contract DataAvailabilityChallengeTest is CommonTest {
vm.assume(challenger != address(0));

// Assume the block number is not close to the max uint256 value
vm.assume(
challengedBlockNumber
< type(uint256).max - dataAvailabilityChallenge.challengeWindow()
- dataAvailabilityChallenge.resolveWindow()
challengedBlockNumber = bound(
challengedBlockNumber,
0,
type(uint256).max - dataAvailabilityChallenge.challengeWindow() - dataAvailabilityChallenge.resolveWindow()
- 1
);
uint256 requiredBond = dataAvailabilityChallenge.bondSize();

Expand Down Expand Up @@ -265,10 +265,11 @@ contract DataAvailabilityChallengeTest is CommonTest {
dataAvailabilityChallenge.setResolverRefundPercentage(resolverRefundPercentage);

// Assume the block number is not close to the max uint256 value
vm.assume(
challengedBlockNumber
< type(uint256).max - dataAvailabilityChallenge.challengeWindow()
- dataAvailabilityChallenge.resolveWindow()
challengedBlockNumber = bound(
challengedBlockNumber,
0,
type(uint256).max - dataAvailabilityChallenge.challengeWindow() - dataAvailabilityChallenge.resolveWindow()
- 1
);
bytes memory challengedCommitment = computeCommitmentKeccak256(preImage);

Expand Down Expand Up @@ -356,10 +357,11 @@ contract DataAvailabilityChallengeTest is CommonTest {
dataAvailabilityChallenge.setResolverRefundPercentage(resolverRefundPercentage);

// Assume the block number is not close to the max uint256 value
vm.assume(
challengedBlockNumber
< type(uint256).max - dataAvailabilityChallenge.challengeWindow()
- dataAvailabilityChallenge.resolveWindow()
challengedBlockNumber = bound(
challengedBlockNumber,
0,
type(uint256).max - dataAvailabilityChallenge.challengeWindow() - dataAvailabilityChallenge.resolveWindow()
- 1
);
bytes memory challengedCommitment = computeCommitmentKeccak256(wrongPreImage);

Expand Down Expand Up @@ -458,10 +460,11 @@ contract DataAvailabilityChallengeTest is CommonTest {

function test_unlockBond_succeeds(bytes memory preImage, uint256 challengedBlockNumber) public {
// Assume the block number is not close to the max uint256 value
vm.assume(
challengedBlockNumber
< type(uint256).max - dataAvailabilityChallenge.challengeWindow()
- dataAvailabilityChallenge.resolveWindow()
challengedBlockNumber = bound(
challengedBlockNumber,
0,
type(uint256).max - dataAvailabilityChallenge.challengeWindow() - dataAvailabilityChallenge.resolveWindow()
- 1
);
bytes memory challengedCommitment = computeCommitmentKeccak256(preImage);

Expand Down
46 changes: 28 additions & 18 deletions packages/contracts-bedrock/test/L1/OptimismPortal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,16 @@ contract OptimismPortal_Test is CommonTest {
uint256 _value,
uint64 _gasLimit,
bool _isCreation,
bytes memory _data
bytes calldata _data
)
internal
{
if (_isCreation) {
_to = address(0);
}
vm.assume(_data.length <= 120_000);
if (_data.length > 120_000) {
_data = _data[0:120_000];
}
IResourceMetering.ResourceConfig memory rcfg = systemConfig.resourceConfig();
_gasLimit =
uint64(bound(_gasLimit, optimismPortal.minimumGasLimit(uint64(_data.length)), rcfg.maxResourceLimit));
Expand Down Expand Up @@ -207,7 +209,7 @@ contract OptimismPortal_Test is CommonTest {
uint256 _value,
uint64 _gasLimit,
bool _isCreation,
bytes memory _data
bytes calldata _data
)
external
{
Expand All @@ -232,7 +234,7 @@ contract OptimismPortal_Test is CommonTest {
uint256 _value,
uint64 _gasLimit,
bool _isCreation,
bytes memory _data
bytes calldata _data
)
external
{
Expand Down Expand Up @@ -476,13 +478,17 @@ contract OptimismPortal_Test is CommonTest {
/// `depositTransaction` function. This is a simple differential test.
function test_setGasPayingToken_correctEvent_succeeds(
address _token,
string memory _name,
string memory _symbol
string calldata _name,
string calldata _symbol
)
external
{
vm.assume(bytes(_name).length <= 32);
vm.assume(bytes(_symbol).length <= 32);
if (bytes(_name).length > 32) {
_name = _name[0:32];
}
if (bytes(_symbol).length > 32) {
_symbol = _symbol[0:32];
}

bytes32 name = GasPayingToken.sanitize(_name);
bytes32 symbol = GasPayingToken.sanitize(_symbol);
Expand Down Expand Up @@ -1371,8 +1377,8 @@ contract OptimismPortalResourceFuzz_Test is CommonTest {
// 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);
_gasLimit = uint64(bound(_gasLimit, 0, gasLimit));
Comment thread
smartcontracts marked this conversation as resolved.
Outdated
_minimumBaseFee = uint32(bound(_minimumBaseFee, 0, _maximumBaseFee - 1));

// 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.
Expand Down Expand Up @@ -1436,14 +1442,16 @@ contract OptimismPortalWithMockERC20_Test is OptimismPortal_FinalizeWithdrawal_T
uint256 _value,
uint64 _gasLimit,
bool _isCreation,
bytes memory _data
bytes calldata _data
)
internal
{
if (_isCreation) {
_to = address(0);
}
vm.assume(_data.length <= 120_000);
if (_data.length > 120_000) {
_data = _data[0:120_000];
}
IResourceMetering.ResourceConfig memory rcfg = systemConfig.resourceConfig();
_gasLimit =
uint64(bound(_gasLimit, optimismPortal.minimumGasLimit(uint64(_data.length)), rcfg.maxResourceLimit));
Expand Down Expand Up @@ -1482,7 +1490,7 @@ contract OptimismPortalWithMockERC20_Test is OptimismPortal_FinalizeWithdrawal_T
uint256 _value,
uint64 _gasLimit,
bool _isCreation,
bytes memory _data
bytes calldata _data
)
external
{
Expand All @@ -1507,7 +1515,7 @@ contract OptimismPortalWithMockERC20_Test is OptimismPortal_FinalizeWithdrawal_T
uint256 _value,
uint64 _gasLimit,
bool _isCreation,
bytes memory _data
bytes calldata _data
)
external
{
Expand Down Expand Up @@ -1663,14 +1671,16 @@ contract OptimismPortalWithMockERC20_Test is OptimismPortal_FinalizeWithdrawal_T
uint256 _value,
uint64 _gasLimit,
bool _isCreation,
bytes memory _data
bytes calldata _data
)
internal
{
if (_isCreation) {
_to = address(0);
}
vm.assume(_data.length <= 120_000);
if (_data.length > 120_000) {
_data = _data[0:120_000];
}
IResourceMetering.ResourceConfig memory rcfg = systemConfig.resourceConfig();
_gasLimit =
uint64(bound(_gasLimit, optimismPortal.minimumGasLimit(uint64(_data.length)), rcfg.maxResourceLimit));
Expand Down Expand Up @@ -1704,7 +1714,7 @@ contract OptimismPortalWithMockERC20_Test is OptimismPortal_FinalizeWithdrawal_T
uint256 _value,
uint64 _gasLimit,
bool _isCreation,
bytes memory _data
bytes calldata _data
)
external
{
Expand All @@ -1727,7 +1737,7 @@ contract OptimismPortalWithMockERC20_Test is OptimismPortal_FinalizeWithdrawal_T
uint256 _value,
uint64 _gasLimit,
bool _isCreation,
bytes memory _data
bytes calldata _data
)
external
{
Expand Down
37 changes: 23 additions & 14 deletions packages/contracts-bedrock/test/L1/OptimismPortal2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,17 @@ contract OptimismPortal2_Test is CommonTest {
/// `depositTransaction` function. This is a simple differential test.
function test_setGasPayingToken_correctEvent_succeeds(
address _token,
string memory _name,
string memory _symbol
string calldata _name,
string calldata _symbol
)
external
{
vm.assume(bytes(_name).length <= 32);
vm.assume(bytes(_symbol).length <= 32);
if (bytes(_name).length > 32) {
_name = _name[0:32];
}
if (bytes(_symbol).length > 32) {
_symbol = _symbol[0:32];
}

bytes32 name = GasPayingToken.sanitize(_name);
bytes32 symbol = GasPayingToken.sanitize(_symbol);
Expand Down Expand Up @@ -1646,8 +1650,8 @@ contract OptimismPortal2_ResourceFuzz_Test is CommonTest {
// 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);
_gasLimit = uint64(bound(_gasLimit, 0, gasLimit));
Comment thread
smartcontracts marked this conversation as resolved.
Outdated
_minimumBaseFee = uint32(bound(_minimumBaseFee, 0, _maximumBaseFee - 1));

// 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.
Expand Down Expand Up @@ -1711,14 +1715,16 @@ contract OptimismPortal2WithMockERC20_Test is OptimismPortal2_FinalizeWithdrawal
uint256 _value,
uint64 _gasLimit,
bool _isCreation,
bytes memory _data
bytes calldata _data
)
internal
{
if (_isCreation) {
_to = address(0);
}
vm.assume(_data.length <= 120_000);
if (_data.length > 120_000) {
_data = _data[0:120_000];
}
IResourceMetering.ResourceConfig memory rcfg = systemConfig.resourceConfig();
_gasLimit =
uint64(bound(_gasLimit, optimismPortal2.minimumGasLimit(uint64(_data.length)), rcfg.maxResourceLimit));
Expand Down Expand Up @@ -1757,7 +1763,7 @@ contract OptimismPortal2WithMockERC20_Test is OptimismPortal2_FinalizeWithdrawal
uint256 _value,
uint64 _gasLimit,
bool _isCreation,
bytes memory _data
bytes calldata _data
)
external
{
Expand All @@ -1782,7 +1788,7 @@ contract OptimismPortal2WithMockERC20_Test is OptimismPortal2_FinalizeWithdrawal
uint256 _value,
uint64 _gasLimit,
bool _isCreation,
bytes memory _data
bytes calldata _data
)
external
{
Expand Down Expand Up @@ -1947,14 +1953,17 @@ contract OptimismPortal2WithMockERC20_Test is OptimismPortal2_FinalizeWithdrawal
uint256 _value,
uint64 _gasLimit,
bool _isCreation,
bytes memory _data
bytes calldata _data
)
internal
{
if (_isCreation) {
_to = address(0);
}
vm.assume(_data.length <= 120_000);
if (_data.length > 120_000) {
_data = _data[0:120_000];
}

IResourceMetering.ResourceConfig memory rcfg = systemConfig.resourceConfig();
_gasLimit =
uint64(bound(_gasLimit, optimismPortal2.minimumGasLimit(uint64(_data.length)), rcfg.maxResourceLimit));
Expand Down Expand Up @@ -1988,7 +1997,7 @@ contract OptimismPortal2WithMockERC20_Test is OptimismPortal2_FinalizeWithdrawal
uint256 _value,
uint64 _gasLimit,
bool _isCreation,
bytes memory _data
bytes calldata _data
)
external
{
Expand All @@ -2011,7 +2020,7 @@ contract OptimismPortal2WithMockERC20_Test is OptimismPortal2_FinalizeWithdrawal
uint256 _value,
uint64 _gasLimit,
bool _isCreation,
bytes memory _data
bytes calldata _data
)
external
{
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts-bedrock/test/L1/SystemConfig.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,8 @@ contract SystemConfig_Setters_Test is SystemConfig_Init {

/// @dev Tests that `setEIP1559Params` updates the EIP1559 parameters successfully.
function testFuzz_setEIP1559Params_succeeds(uint32 _denominator, uint32 _elasticity) external {
vm.assume(_denominator > 1);
vm.assume(_elasticity > 1);
_denominator = uint32(bound(_denominator, 2, type(uint32).max));
_elasticity = uint32(bound(_elasticity, 2, type(uint32).max));

vm.expectEmit(address(systemConfig));
emit ConfigUpdate(
Expand Down
8 changes: 4 additions & 4 deletions packages/contracts-bedrock/test/L2/CrossL2Inbox.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ contract CrossL2InboxTest is Test {

/// @dev Tests that the `executeMessage` function reverts when called with an identifier with an invalid timestamp.
function testFuzz_executeMessage_invalidTimestamp_reverts(
Identifier calldata _id,
Identifier memory _id,
address _target,
bytes calldata _message,
uint256 _value
Expand All @@ -307,7 +307,7 @@ contract CrossL2InboxTest is Test {
setInteropStart
{
// Ensure that the id's timestamp is invalid (greater than the current block timestamp)
vm.assume(_id.timestamp > block.timestamp);
_id.timestamp = bound(_id.timestamp, block.timestamp + 1, type(uint256).max);

// Ensure is not a deposit transaction
vm.mockCall({
Expand Down Expand Up @@ -488,7 +488,7 @@ contract CrossL2InboxTest is Test {
/// @dev Tests that the `validateMessage` function reverts when called with an identifier with a timestamp later
/// than current block.timestamp.
function testFuzz_validateMessage_invalidTimestamp_reverts(
Identifier calldata _id,
Identifier memory _id,
bytes32 _messageHash
)
external
Expand All @@ -502,7 +502,7 @@ contract CrossL2InboxTest is Test {
});

// Ensure that the id's timestamp is invalid (greater than the current block timestamp)
vm.assume(_id.timestamp > block.timestamp);
_id.timestamp = bound(_id.timestamp, block.timestamp + 1, type(uint256).max);

// Expect a revert with the InvalidTimestamp selector
vm.expectRevert(InvalidTimestamp.selector);
Expand Down
Loading