Skip to content

Commit

Permalink
refactor: resolve stack too deep, add back _isSim var
Browse files Browse the repository at this point in the history
  • Loading branch information
BenSparksCode committed Nov 18, 2024
1 parent 67388e7 commit fcb02f3
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/contracts/atlas/Atlas.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,25 @@ contract Atlas is Escrow, Factory {
? gasleft() + _BASE_TRANSACTION_GAS_USED + (msg.data.length * _CALLDATA_LENGTH_PREMIUM)
: gasleft() + IL2GasCalculator(L2_GAS_CALCULATOR).initialGasUsed(msg.data.length);

address _bundler = msg.sender == SIMULATOR ? dAppOp.bundler : msg.sender;
bool _isSimulation = msg.sender == SIMULATOR;
address _bundler = _isSimulation ? dAppOp.bundler : msg.sender;
(address _executionEnvironment, DAppConfig memory _dConfig) = _getOrCreateExecutionEnvironment(userOp);

ValidCallsResult _validCallsResult = VERIFICATION.validateCalls(
_dConfig, userOp, solverOps, dAppOp, msg.value, _bundler, msg.sender == SIMULATOR
);
if (_validCallsResult != ValidCallsResult.Valid) {
if (msg.sender == SIMULATOR) revert VerificationSimFail(_validCallsResult);
{
ValidCallsResult _validCallsResult =
VERIFICATION.validateCalls(_dConfig, userOp, solverOps, dAppOp, msg.value, _bundler, _isSimulation);
if (_validCallsResult != ValidCallsResult.Valid) {
if (_isSimulation) revert VerificationSimFail(_validCallsResult);

// Gracefully return for results that need nonces to be stored and prevent replay attacks
if (uint8(_validCallsResult) >= _GRACEFUL_RETURN_THRESHOLD && !_dConfig.callConfig.allowsReuseUserOps()) {
return false;
}
// Gracefully return for results that need nonces to be stored and prevent replay attacks
if (uint8(_validCallsResult) >= _GRACEFUL_RETURN_THRESHOLD && !_dConfig.callConfig.allowsReuseUserOps())
{
return false;
}

// Revert for all other results
revert ValidCalls(_validCallsResult);
// Revert for all other results
revert ValidCalls(_validCallsResult);
}
}

// Initialize the environment lock and accounting values
Expand All @@ -95,9 +98,8 @@ contract Atlas is Escrow, Factory {
// userOpHash has already been calculated and verified in validateCalls at this point, so rather
// than re-calculate it, we can simply take it from the dAppOp here. It's worth noting that this will
// be either a TRUSTED or DEFAULT hash, depending on the allowsTrustedOpHash setting.
try this.execute(
_dConfig, userOp, solverOps, _executionEnvironment, _bundler, dAppOp.userOpHash, msg.sender == SIMULATOR
) returns (Context memory ctx) {
try this.execute(_dConfig, userOp, solverOps, _executionEnvironment, _bundler, dAppOp.userOpHash, _isSimulation)
returns (Context memory ctx) {
// Gas Refund to sender only if execution is successful
(uint256 _ethPaidToBundler, uint256 _netGasSurcharge) = _settle(
ctx, _dConfig.solverGasLimit, gasRefundBeneficiary != address(0) ? gasRefundBeneficiary : msg.sender
Expand Down

0 comments on commit fcb02f3

Please sign in to comment.