-
Notifications
You must be signed in to change notification settings - Fork 23
Atlas: bubble app error data while preserving 4-byte Atlas selector #500
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
Open
0x1NotMe
wants to merge
4
commits into
atlas-v1.6.3
Choose a base branch
from
feat/atlas-bubble-app-errors
base: atlas-v1.6.3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1c8fcb5
atlas: bubble underlying app revert data in Atlas errors while preser…
0x1NotMe 7bcaa0e
execution env: include underlying DApp revert payload after Atlas err…
0x1NotMe 71d4a92
test: assert Atlas revert payload preserves selector and app error bu…
0x1NotMe b06c22b
refactor(execution env): reuse single error variable for pre/post sol…
0x1NotMe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity 0.8.28; | ||
|
|
||
| import "forge-std/Test.sol"; | ||
| import { console2 } from "forge-std/console2.sol"; | ||
|
|
||
| import { BaseTest } from "./base/BaseTest.t.sol"; | ||
| import { DummyDAppControl } from "./base/DummyDAppControl.sol"; | ||
| import { DummyDAppControlBuilder } from "./helpers/DummyDAppControlBuilder.sol"; | ||
| import { CallConfigBuilder } from "./helpers/CallConfigBuilder.sol"; | ||
| import { UserOperationBuilder } from "./base/builders/UserOperationBuilder.sol"; | ||
| import { SolverOperationBuilder } from "./base/builders/SolverOperationBuilder.sol"; | ||
| import { DAppOperationBuilder } from "./base/builders/DAppOperationBuilder.sol"; | ||
|
|
||
| import { AtlasErrors } from "../src/contracts/types/AtlasErrors.sol"; | ||
| import { IDAppControl } from "../src/contracts/interfaces/IDAppControl.sol"; | ||
| import { CallConfig } from "../src/contracts/types/ConfigTypes.sol"; | ||
|
|
||
| import "../src/contracts/types/UserOperation.sol"; | ||
| import "../src/contracts/types/SolverOperation.sol"; | ||
| import "../src/contracts/types/DAppOperation.sol"; | ||
|
|
||
| contract NoopSolver { | ||
| function atlasSolverCall( | ||
| address, | ||
| address, | ||
| address, | ||
| uint256, | ||
| bytes calldata, | ||
| bytes calldata | ||
| ) external payable { } | ||
| } | ||
|
|
||
| contract AtlasErrorBubbleTest is BaseTest { | ||
|
|
||
| DummyDAppControl dAppControl; | ||
| NoopSolver noopSolver; | ||
|
|
||
| function _deployControl(CallConfig memory callConfig) internal returns (DummyDAppControl) { | ||
| return new DummyDAppControlBuilder() | ||
| .withEscrow(address(atlas)) | ||
| .withGovernance(governanceEOA) | ||
| .withCallConfig(callConfig) | ||
| .buildAndIntegrate(atlasVerification); | ||
| } | ||
|
|
||
| function test_bubbles_app_revert_inside_atlas_errors_preOps() public { | ||
0x1NotMe marked this conversation as resolved.
Show resolved
Hide resolved
0x1NotMe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Require preOps and allow reuse so Atlas reverts and bubbles the revert payload | ||
| CallConfig memory cfg = new CallConfigBuilder() | ||
| .withRequirePreOps(true) | ||
| .withReuseUserOp(true) | ||
| .build(); | ||
|
|
||
| dAppControl = _deployControl(cfg); | ||
| noopSolver = new NoopSolver(); | ||
|
|
||
| // Configure DAppControl to revert during preOps | ||
| dAppControl.setPreOpsShouldRevert(true); | ||
|
|
||
| // Build a minimal metacall | ||
| UserOperation memory userOp = new UserOperationBuilder() | ||
| .withFrom(userEOA) | ||
| .withTo(address(atlas)) | ||
| .withValue(0) | ||
| .withGas(1_000_000) | ||
| .withMaxFeePerGas(tx.gasprice + 1) | ||
| .withNonce(address(atlasVerification), userEOA) | ||
| .withDeadline(block.number + 2) | ||
| .withDapp(address(dAppControl)) | ||
| .withControl(address(dAppControl)) | ||
| .withCallConfig(IDAppControl(address(dAppControl)).CALL_CONFIG()) | ||
| .withDAppGasLimit(IDAppControl(address(dAppControl)).getDAppGasLimit()) | ||
| .withSolverGasLimit(IDAppControl(address(dAppControl)).getSolverGasLimit()) | ||
| .withBundlerSurchargeRate(IDAppControl(address(dAppControl)).getBundlerSurchargeRate()) | ||
| .withSessionKey(address(0)) | ||
| .withData("") | ||
| .signAndBuild(address(atlasVerification), userPK); | ||
|
|
||
| SolverOperation[] memory solverOps = new SolverOperation[](1); | ||
| solverOps[0] = new SolverOperationBuilder() | ||
| .withFrom(solverOneEOA) | ||
| .withTo(address(atlas)) | ||
| .withValue(0) | ||
| .withGas(1_000_000) | ||
| .withMaxFeePerGas(userOp.maxFeePerGas) | ||
| .withDeadline(userOp.deadline) | ||
| .withSolver(address(noopSolver)) | ||
| .withControl(userOp.control) | ||
| .withUserOpHash(userOp) | ||
| .withBidToken(userOp) | ||
| .withBidAmount(0) | ||
| .withData("") | ||
| .signAndBuild(address(atlasVerification), solverOnePK); | ||
|
|
||
| DAppOperation memory dappOp = new DAppOperationBuilder() | ||
| .withFrom(governanceEOA) | ||
| .withTo(address(atlas)) | ||
| .withNonce(address(atlasVerification), governanceEOA) | ||
| .withDeadline(userOp.deadline) | ||
| .withControl(userOp.control) | ||
| .withBundler(address(0)) | ||
| .withUserOpHash(userOp) | ||
| .withCallChainHash(userOp, solverOps) | ||
| .signAndBuild(address(atlasVerification), governancePK); | ||
|
|
||
| uint256 gasLim = _gasLim(userOp, solverOps); | ||
|
|
||
| // Execute and capture revert data | ||
| vm.prank(userEOA); | ||
| try atlas.metacall{ gas: gasLim }(userOp, solverOps, dappOp, address(0)) returns (bool) { | ||
0x1NotMe marked this conversation as resolved.
Show resolved
Hide resolved
0x1NotMe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fail(); | ||
| } catch (bytes memory revertData) { | ||
| console2.logBytes(revertData); | ||
0x1NotMe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assertGt(revertData.length, 8, "revert payload too short"); | ||
| // Top-level Atlas error selector must be first 4 bytes | ||
| bytes4 top = bytes4(revertData); | ||
| assertEq(top, AtlasErrors.PreOpsFail.selector, "top-level selector"); | ||
|
|
||
| // Next 4 bytes should be the ExecutionEnvironment's Atlas error selector | ||
| // PreOpsDelegatecallFail | ||
| bytes4 inner; | ||
| { | ||
| uint64 head64; | ||
| assembly { | ||
| head64 := shr(192, mload(add(revertData, 32))) | ||
| } | ||
| inner = bytes4(uint32(head64)); | ||
| } | ||
| assertEq(inner, AtlasErrors.PreOpsDelegatecallFail.selector, "inner EE selector"); | ||
|
|
||
| // Remaining bytes include the app revert payload (e.g., Error(string)) | ||
| assertGt(revertData.length, 8, "missing app payload after selectors"); | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI these changes push Atlas over the contract size limit by about 185 bytes. If we go with these changes we will need to lower
optimizer_runsto get it back under.But also try to cut down contract size in the modified areas if possible. There might be a Solady lib function that could do this, not sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, there's this helper. We should probably use it once we've build the bytes revertData in each case we want to bubble up
https://github.com/Vectorized/solady/blob/main/src/utils/LibCall.sol#L201
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this would actually reduce contract size but I can add the fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
183 bytes without Solady and 209 bytes over the limit using
LibCall.bubbleUpRevertThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oof okay. Was hoping it would reduce code duplication.