Skip to content

Commit

Permalink
match auth revert bug repro
Browse files Browse the repository at this point in the history
  • Loading branch information
DJViau committed Feb 15, 2024
1 parent ae43151 commit e2efa14
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/core/lib/ZoneInteraction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ contract ZoneInteraction is
// Retrieve the parameters of the order in question.
OrderParameters memory parameters = advancedOrder.parameters;

// OrderType 2-3 require zone to be caller or approve via validateOrder.
// OrderType 2-3 require zone to be caller or approve via authorizeOrder.
if (
_isRestrictedAndCallerNotZone(parameters.orderType, parameters.zone)
) {
// Encode the `validateOrder` call in memory.
// Encode the `authorizeOrder` call in memory.
(MemoryPointer callData, uint256 size) = _encodeAuthorizeOrder(
orderHash,
parameters,
Expand Down
7 changes: 6 additions & 1 deletion src/main/test/HashValidationZoneOfferer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ contract HashValidationZoneOfferer is
// Get the orderHash from zoneParameters
bytes32 orderHash = zoneParameters.orderHash;

if (authorizeFailureReasons[orderHash] == OffererZoneFailureReason.Zone_authorizeRevertsMatchReverts)
{
revert HashValidationZoneOffererAuthorizeOrderReverts();
}

// Get the length of msg.data
uint256 dataLength = msg.data.length;

Expand Down Expand Up @@ -296,7 +301,7 @@ contract HashValidationZoneOfferer is
// Get the orderHash from zoneParameters
bytes32 orderHash = zoneParameters.orderHash;

if (validateFailureReasons[orderHash] == OffererZoneFailureReason.Zone_reverts)
if (validateFailureReasons[orderHash] == OffererZoneFailureReason.Zone_validateReverts)
{
revert HashValidationZoneOffererValidateOrderReverts();
}
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 @@ -11,7 +11,8 @@ enum OffererZoneFailureReason {
ContractOfferer_ExcessMaximumSpent, // too many maximum spent items
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_authorizeRevertsMatchReverts, // Zone authorizeOrder call reverts, which triggers a top level revert only on match*
Zone_validateReverts, // Zone validateOrder call reverts
Zone_authorizeInvalidMagicValue, // Zone authorizeOrder call returns invalid magic value
Zone_validateInvalidMagicValue // Zone validateOrder call returns invalid magic value
}
18 changes: 18 additions & 0 deletions test/foundry/new/helpers/FuzzMutationSelectorLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ 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_authorizeReverts_matchReverts, // Zone authorizeOrder call reverts and triggers a top level match* revert
InvalidRestrictedOrder_validateReverts, // Zone validateOrder call reverts
InvalidRestrictedOrder_authorizeInvalidMagicValue, // Zone authorizeOrder call returns invalid magic value
InvalidRestrictedOrder_validateInvalidMagicValue, // Zone validateOrder call returns invalid magic value
Expand Down Expand Up @@ -347,6 +348,12 @@ library FuzzMutationSelectorLib {
.ineligibleWhenNotActiveTimeOrNotContractOrderOrNoConsideration
);

failuresAndFilters[i++] = Failure
.InvalidRestrictedOrder_authorizeReverts_matchReverts
.withOrder(
MutationFilters.ineligibleWhenNotAvailableOrNotRestrictedOrNotMatch
);

failuresAndFilters[i++] = Failure.InvalidRestrictedOrder_authorizeInvalidMagicValue.and(
Failure.InvalidRestrictedOrder_validateReverts)
.and(Failure.InvalidRestrictedOrder_validateInvalidMagicValue
Expand Down Expand Up @@ -871,6 +878,17 @@ library FailureDetailsLib {
details_withOrderHash
);

failureDetailsArray[i++] = HashValidationZoneOfferer
.HashValidationZoneOffererAuthorizeOrderReverts
.selector
.withOrder(
"InvalidRestrictedOrder_authorizeReverts_matchReverts",
FuzzMutations
.mutation_invalidRestrictedOrderAuthorizeRevertsMatchReverts
.selector,
details_withOrderHash
);

failureDetailsArray[i++] = HashValidationZoneOfferer
.HashValidationZoneOffererValidateOrderReverts
.selector
Expand Down
36 changes: 35 additions & 1 deletion test/foundry/new/helpers/FuzzMutations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,22 @@ library MutationFilters {
return ineligibleWhenUnavailable(context, orderIndex);
}

function ineligibleWhenNotAvailableOrNotRestrictedOrNotMatch(
AdvancedOrder memory order,
uint256 orderIndex,
FuzzTestContext memory context
) internal view returns (bool) {
if (ineligibleWhenNotRestrictedOrder(order)) {
return true;
}

if (ineligibleWhenNotMatch(context)) {
return true;
}

return ineligibleWhenUnavailable(context, orderIndex);
}

function ineligibleWhenNotActiveTime(AdvancedOrder memory order)
internal
view
Expand Down Expand Up @@ -1931,6 +1947,24 @@ contract FuzzMutations is Test, FuzzExecutor {
exec(context);
}

function mutation_invalidRestrictedOrderAuthorizeRevertsMatchReverts(
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. Note that only match* functions
// revert at the seaport level when the zone reverts on authorize.
HashValidationZoneOfferer(payable(order.parameters.zone))
.setAuthorizeFailureReason(
orderHash, OffererZoneFailureReason.Zone_authorizeRevertsMatchReverts
);

exec(context);
}

function mutation_invalidRestrictedOrderReverts(
FuzzTestContext memory context,
MutationState memory mutationState
Expand All @@ -1941,7 +1975,7 @@ contract FuzzMutations is Test, FuzzExecutor {
// This mutation triggers a revert by setting a failure reason that gets
// stored in the HashValidationZoneOfferer.
HashValidationZoneOfferer(payable(order.parameters.zone))
.setValidateFailureReason(orderHash, OffererZoneFailureReason.Zone_reverts);
.setValidateFailureReason(orderHash, OffererZoneFailureReason.Zone_validateReverts);

exec(context);
}
Expand Down

0 comments on commit e2efa14

Please sign in to comment.