Skip to content

Commit

Permalink
refactor: _handleErrors for size cuts
Browse files Browse the repository at this point in the history
  • Loading branch information
BenSparksCode committed Nov 18, 2024
1 parent 7092834 commit 2ae3777
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/contracts/atlas/Atlas.sol
Original file line number Diff line number Diff line change
Expand Up @@ -322,34 +322,32 @@ contract Atlas is Escrow, Factory {
/// @param callConfig The CallConfig of the current metacall tx.
function _handleErrors(bytes memory revertData, uint32 callConfig) internal view {
bytes4 _errorSwitch = bytes4(revertData);

if (msg.sender == SIMULATOR) {
// Simulation
if (_errorSwitch == PreOpsSimFail.selector) {
revert PreOpsSimFail();
} else if (_errorSwitch == UserOpSimFail.selector) {
revert UserOpSimFail();
} else if (_errorSwitch == SolverSimFail.selector) {
if (_errorSwitch == SolverSimFail.selector) {
// Expects revertData in form [bytes4, uint256]
uint256 _solverOutcomeResult;
assembly {
let dataLocation := add(revertData, 0x20)
_solverOutcomeResult := mload(add(dataLocation, sub(mload(revertData), 32)))
}
revert SolverSimFail(_solverOutcomeResult);
} else if (_errorSwitch == AllocateValueSimFail.selector) {
revert AllocateValueSimFail();
} else if (_errorSwitch == PostOpsSimFail.selector) {
revert PostOpsSimFail();
} else if (
_errorSwitch == PreOpsSimFail.selector || _errorSwitch == UserOpSimFail.selector
|| _errorSwitch == AllocateValueSimFail.selector || _errorSwitch == PostOpsSimFail.selector
) {
assembly {
mstore(0, _errorSwitch)
revert(0, 4)
}
}
}
if (_errorSwitch == UserNotFulfilled.selector) {
revert UserNotFulfilled();
}
// If allowReuseUserOps = true, it reverts and bubbles up whatever the error
// was that it caught. This is to prevent storing the nonce as used so the userOp
// can be reused. Otherwise, the whole metacall doesn't revert but the inner

// NOTE: If error was UserNotFulfilled, we revert and bubble up the error.
// For any other error, we only bubble up the revert if allowReuseUserOps = true. This is to prevent storing the
// nonce as used so the userOp can be reused. Otherwise, the whole metacall doesn't revert but the inner
// execute() does so, no operation changes are persisted.
if (callConfig.allowsReuseUserOps()) {
if (_errorSwitch == UserNotFulfilled.selector || callConfig.allowsReuseUserOps()) {
assembly {
mstore(0, _errorSwitch)
revert(0, 4)
Expand Down

0 comments on commit 2ae3777

Please sign in to comment.