Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds callback support to the abort function #197

Merged
merged 3 commits into from
Jun 6, 2024
Merged

Conversation

0xJem
Copy link
Contributor

@0xJem 0xJem commented May 24, 2024

  • Call the onCancel callback during abort()
  • Bury any errors from the callback

@0xJem 0xJem self-assigned this May 24, 2024
@0xJem 0xJem requested a review from Oighty May 24, 2024 07:19
/// @notice Calls the `onCancel()` callback
/// @dev This function is written to circumvent a limitation in solidity that
/// prevents calling internal functions from within a try/catch block.
/// It is inspired by: https://ethereum.stackexchange.com/a/148922
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this works, but there is another option which I think are simpler here. It relies on two facts:

  1. We are already doing an external call, but it's hidden by the Callbacks library. We can ignore the library and just call it directly on the callback.
  2. We can use a low-level call and ignore the returned (bool success, bytes memory returnData) variables.
// onCancel callback invocation without revert

// Assemble the calldata
bytes memory cd = abi.encodeWithSelector(
    ICallback.onCancel.selector,
    lotId_,
    refund_,
    lotRouting[lotId_].callbacks.hasPermission(Callbacks.SEND_BASE_TOKENS_FLAG),
    callbackData_
);

// Call the onCancel callback and ignore the return variables
address(lotRouting[lotId_].callbacks).call(cd);

Originally, I was thinking we might have to specify a gas limit to prevent transactions that exceed the block gas limit, but you can set a manual limit on the transaction. The auction house will retain 1 / 64 of the gas remaining when the call is made, so there will always be some left, even if the callback reverts due to OOG. Since this is the last thing called in the abort function, I think we're ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

@0xJem 0xJem requested a review from Oighty May 30, 2024 13:24
@etherSky111
Copy link
Collaborator

All good.

@Oighty Oighty merged commit 1267172 into develop Jun 6, 2024
1 check passed
@Oighty Oighty deleted the abort-callback branch June 6, 2024 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants