Skip to content

Commit

Permalink
add mutation to trigger authorize revert
Browse files Browse the repository at this point in the history
  • Loading branch information
DJViau committed Feb 15, 2024
1 parent 192f6da commit ae43151
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 22 deletions.
35 changes: 27 additions & 8 deletions src/main/test/HashValidationZoneOfferer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ contract HashValidationZoneOfferer is
error IncorrectSeaportBalance(
uint256 expectedBalance, uint256 actualBalance
);
error HashValidationZoneOffererAuthorizeOrderReverts();
error HashValidationZoneOffererValidateOrderReverts();
error HashValidationZoneOffererRatifyOrderReverts();

Expand Down Expand Up @@ -219,18 +220,26 @@ contract HashValidationZoneOfferer is
bool public called = false;
uint256 public callCount = 0;

mapping(bytes32 => OffererZoneFailureReason) public failureReasons;
mapping(bytes32 => OffererZoneFailureReason) public authorizeFailureReasons;
mapping(bytes32 => OffererZoneFailureReason) public validateFailureReasons;

function setFailureReason(
function setAuthorizeFailureReason(
bytes32 orderHash,
OffererZoneFailureReason newFailureReason
) external {
failureReasons[orderHash] = newFailureReason;
authorizeFailureReasons[orderHash] = newFailureReason;
}

function setValidateFailureReason(
bytes32 orderHash,
OffererZoneFailureReason newFailureReason
) external {
validateFailureReasons[orderHash] = newFailureReason;
}

function authorizeOrder(ZoneParameters calldata zoneParameters)
public
returns (bytes4)
returns (bytes4 authorizeOrderReturnValue)
{
// Get the orderHash from zoneParameters
bytes32 orderHash = zoneParameters.orderHash;
Expand Down Expand Up @@ -258,7 +267,17 @@ contract HashValidationZoneOfferer is
// Emit a DataHash event with the hash of msg.data
emit AuthorizeOrderDataHash(calldataHash);

return this.authorizeOrder.selector;
if (
authorizeFailureReasons[orderHash]
== OffererZoneFailureReason.Zone_authorizeInvalidMagicValue
) {
authorizeOrderReturnValue = bytes4(0x12345678);
} else {
// Return the selector of authorizeOrder as the magic value.
authorizeOrderReturnValue = this.authorizeOrder.selector;
}

return authorizeOrderReturnValue;
}

/**
Expand All @@ -277,7 +296,7 @@ contract HashValidationZoneOfferer is
// Get the orderHash from zoneParameters
bytes32 orderHash = zoneParameters.orderHash;

if (failureReasons[orderHash] == OffererZoneFailureReason.Zone_reverts)
if (validateFailureReasons[orderHash] == OffererZoneFailureReason.Zone_reverts)
{
revert HashValidationZoneOffererValidateOrderReverts();
}
Expand Down Expand Up @@ -323,8 +342,8 @@ contract HashValidationZoneOfferer is
callCount++;

if (
failureReasons[orderHash]
== OffererZoneFailureReason.Zone_InvalidMagicValue
validateFailureReasons[orderHash]
== OffererZoneFailureReason.Zone_validateInvalidMagicValue
) {
validOrderMagicValue = bytes4(0x12345678);
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/main/test/OffererZoneFailureReason.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ enum OffererZoneFailureReason {
ContractOfferer_IncorrectMaximumSpent, // incorrect (too many, wrong token, etc.) maximum spent items
ContractOfferer_InvalidMagicValue, // Offerer did not return correct magic value
Zone_reverts, // Zone validateOrder call reverts
Zone_InvalidMagicValue // Zone validateOrder call returns invalid magic value
Zone_authorizeInvalidMagicValue, // Zone authorizeOrder call returns invalid magic value
Zone_validateInvalidMagicValue // Zone validateOrder call returns invalid magic value
}
28 changes: 21 additions & 7 deletions test/foundry/new/helpers/FuzzMutationSelectorLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ enum Failure {
InvalidContractOrder_ExcessMaximumSpent, // too many maximum spent items
InvalidContractOrder_IncorrectMaximumSpent, // incorrect (too many, wrong token, etc.) maximum spent items
InvalidContractOrder_InvalidMagicValue, // Offerer did not return correct magic value
InvalidRestrictedOrder_reverts, // Zone validateOrder call reverts
InvalidRestrictedOrder_InvalidMagicValue, // Zone validateOrder call returns invalid magic value
InvalidRestrictedOrder_validateReverts, // Zone validateOrder call reverts
InvalidRestrictedOrder_authorizeInvalidMagicValue, // Zone authorizeOrder call returns invalid magic value
InvalidRestrictedOrder_validateInvalidMagicValue, // Zone validateOrder call returns invalid magic value
NoContract, // Trying to transfer a token at an address that has no contract
UnusedItemParameters_Token, // Native item with non-zero token
UnusedItemParameters_Identifier, // Native or ERC20 item with non-zero identifier
Expand Down Expand Up @@ -346,8 +347,9 @@ library FuzzMutationSelectorLib {
.ineligibleWhenNotActiveTimeOrNotContractOrderOrNoConsideration
);

failuresAndFilters[i++] = Failure.InvalidRestrictedOrder_reverts.and(
Failure.InvalidRestrictedOrder_InvalidMagicValue
failuresAndFilters[i++] = Failure.InvalidRestrictedOrder_authorizeInvalidMagicValue.and(
Failure.InvalidRestrictedOrder_validateReverts)
.and(Failure.InvalidRestrictedOrder_validateInvalidMagicValue
).withOrder(
MutationFilters.ineligibleWhenNotAvailableOrNotRestrictedOrder
);
Expand Down Expand Up @@ -873,20 +875,32 @@ library FailureDetailsLib {
.HashValidationZoneOffererValidateOrderReverts
.selector
.withOrder(
"InvalidRestrictedOrder_reverts",
"InvalidRestrictedOrder_validateReverts",
FuzzMutations.mutation_invalidRestrictedOrderReverts.selector
);

failureDetailsArray[i++] = ZoneInteractionErrors
.InvalidRestrictedOrder
.selector
.withOrder(
"InvalidRestrictedOrder_InvalidMagicValue",
"InvalidRestrictedOrder_authorizeInvalidMagicValue",
FuzzMutations
.mutation_invalidRestrictedOrderInvalidMagicValue
.mutation_invalidRestrictedOrderAuthorizeInvalidMagicValue
.selector,
details_withOrderHash
);

failureDetailsArray[i++] = ZoneInteractionErrors
.InvalidRestrictedOrder
.selector
.withOrder(
"InvalidRestrictedOrder_validateInvalidMagicValue",
FuzzMutations
.mutation_invalidRestrictedOrderValidateInvalidMagicValue
.selector,
details_withOrderHash
);

failureDetailsArray[i++] = TokenTransferrerErrors
.NoContract
.selector
Expand Down
29 changes: 23 additions & 6 deletions test/foundry/new/helpers/FuzzMutations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1939,25 +1939,42 @@ contract FuzzMutations is Test, FuzzExecutor {
bytes32 orderHash = mutationState.selectedOrderHash;

// This mutation triggers a revert by setting a failure reason that gets
// stored in the HashCalldataContractOfferer.
// stored in the HashValidationZoneOfferer.
HashValidationZoneOfferer(payable(order.parameters.zone))
.setFailureReason(orderHash, OffererZoneFailureReason.Zone_reverts);
.setValidateFailureReason(orderHash, OffererZoneFailureReason.Zone_reverts);

exec(context);
}

function mutation_invalidRestrictedOrderInvalidMagicValue(
function mutation_invalidRestrictedOrderAuthorizeInvalidMagicValue(
FuzzTestContext memory context,
MutationState memory mutationState
) external {
AdvancedOrder memory order = mutationState.selectedOrder;
bytes32 orderHash = mutationState.selectedOrderHash;

// This mutation triggers a revert by setting a failure reason that gets
// stored in the HashCalldataContractOfferer.
// stored in the HashValidationZone.
HashValidationZoneOfferer(payable(order.parameters.zone))
.setFailureReason(
orderHash, OffererZoneFailureReason.Zone_InvalidMagicValue
.setAuthorizeFailureReason(
orderHash, OffererZoneFailureReason.Zone_authorizeInvalidMagicValue
);

exec(context);
}

function mutation_invalidRestrictedOrderValidateInvalidMagicValue(
FuzzTestContext memory context,
MutationState memory mutationState
) external {
AdvancedOrder memory order = mutationState.selectedOrder;
bytes32 orderHash = mutationState.selectedOrderHash;

// This mutation triggers a revert by setting a failure reason that gets
// stored in the HashValidationZone.
HashValidationZoneOfferer(payable(order.parameters.zone))
.setValidateFailureReason(
orderHash, OffererZoneFailureReason.Zone_validateInvalidMagicValue
);

exec(context);
Expand Down

0 comments on commit ae43151

Please sign in to comment.