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

Auto create EE in metacall if needed #61

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions src/contracts/atlas/Atlas.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,18 @@ contract Atlas is Escrow {
{ }

function createExecutionEnvironment(address dAppControl) external returns (address executionEnvironment) {
executionEnvironment = IAtlasFactory(FACTORY).createExecutionEnvironment(msg.sender, dAppControl);
IAtlasVerification(VERIFICATION).initializeNonce(msg.sender);
executionEnvironment = createExecutionEnvironment(msg.sender, dAppControl);
}

function createExecutionEnvironment(
address user,
address dAppControl
)
internal
returns (address executionEnvironment)
{
executionEnvironment = IAtlasFactory(FACTORY).createExecutionEnvironment(user, dAppControl);
IAtlasVerification(VERIFICATION).initializeNonce(user);
}

function metacall( // <- Entrypoint Function
Expand All @@ -57,10 +67,13 @@ contract Atlas is Escrow {
// TODO: Combine this w/ call to get executionEnvironment
DAppConfig memory dConfig = IDAppControl(userOp.control).getDAppConfig(userOp);

// Get the execution environment
address executionEnvironment = IAtlasFactory(FACTORY).getExecutionEnvironmentCustom(
userOp.from, dAppOp.control.codehash, userOp.control, dConfig.callConfig
);
// Get or create the execution environment
(address executionEnvironment,, bool exists) =
IAtlasFactory(FACTORY).getExecutionEnvironment(userOp.from, userOp.control);

if (!exists) {
executionEnvironment = createExecutionEnvironment(userOp.from, userOp.control);
jj1980a marked this conversation as resolved.
Show resolved Hide resolved
}

// Gracefully return if not valid. This allows signature data to be stored, which helps prevent
// replay attacks.
Expand Down
32 changes: 32 additions & 0 deletions test/MainTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,38 @@ contract MainTest is BaseTest {
);
}

function testExecutionEnvironmentAutoCreation() public {
uint8 v;
bytes32 r;
bytes32 s;

UserOperation memory userOp = helper.buildUserOperation(POOL_ONE, POOL_TWO, userEOA, TOKEN_ONE);
// User does not sign their own operation when bundling

SolverOperation[] memory solverOps = new SolverOperation[](1);
bytes memory solverOpData = helper.buildV2SolverOperationData(POOL_TWO, POOL_ONE);
solverOps[0] = helper.buildSolverOperation(userOp, solverOpData, solverOneEOA, address(solverOne), 2e17);
(v, r, s) = vm.sign(solverOnePK, atlasVerification.getSolverPayload(solverOps[0]));
solverOps[0].signature = abi.encodePacked(r, s, v);

DAppOperation memory dAppOp = helper.buildDAppOperation(governanceEOA, userOp, solverOps);
(v, r, s) = vm.sign(governancePK, atlasVerification.getDAppOperationPayload(dAppOp));
dAppOp.signature = abi.encodePacked(r, s, v);

// Execution environment should not exist yet
(,, bool exists) = atlasFactory.getExecutionEnvironment(userEOA, address(control));
assertFalse(exists, "ExecutionEnvironment already exists");

vm.startPrank(userEOA);
ERC20(TOKEN_ONE).approve(address(atlas), type(uint256).max);
atlas.metacall(userOp, solverOps, dAppOp);
vm.stopPrank();

// Execution environment should exist now
(,, exists) = atlasFactory.getExecutionEnvironment(userEOA, address(control));
assertTrue(exists, "ExecutionEnvironment wasn't created");
}

function testTestUserOperation() public {
uint8 v;
bytes32 r;
Expand Down
Loading