-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
217 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,25 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
pragma solidity ^0.8.23; | ||
|
||
abstract contract Base6900 { | ||
/** | ||
* @notice Address of this contract | ||
*/ | ||
address public immutable SELF; | ||
|
||
/** | ||
* @notice Constructor | ||
*/ | ||
constructor() { | ||
SELF = address(this); | ||
} | ||
|
||
/** | ||
* @notice Modifier to make a function callable via delegatecall only. | ||
* If the function is called via a regular call, it will revert. | ||
*/ | ||
modifier onlyDelegateCall() { | ||
require(address(this) != SELF, "must only be called via delegatecall"); | ||
_; | ||
} | ||
} |
This file contains 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 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 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,66 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
pragma solidity ^0.8.23; | ||
|
||
import {Safe4337Module} from "@safe-global/safe-4337/contracts/Safe4337Module.sol"; | ||
import {PackedUserOperation} from "@account-abstraction/contracts/interfaces/PackedUserOperation.sol"; | ||
import {ISafe} from "../interfaces/ISafe.sol"; | ||
import {Base6900} from "./Base6900.sol"; | ||
|
||
contract Safe4337 is Safe4337Module, Base6900 { | ||
constructor(address _entryPoint) Safe4337Module(_entryPoint) {} | ||
|
||
function validateUserOp( | ||
PackedUserOperation calldata userOp, | ||
bytes32, | ||
uint256 missingAccountFunds | ||
) external override onlySupportedEntryPoint returns (uint256 validationData) { | ||
(bool success, bytes memory data) = ISafe(userOp.sender).execTransactionFromModuleReturnData( | ||
payable(address(this)), | ||
0, | ||
abi.encodeWithSelector(Safe4337.validateUserOpDelegatecallReciever.selector, userOp, missingAccountFunds), | ||
1 // delegatecall | ||
); | ||
|
||
if (!success) { | ||
if (data.length == 0) revert(); | ||
assembly { | ||
// We use Yul's revert() to bubble up errors from the target contract. | ||
revert(add(32, data), mload(data)) | ||
} | ||
} | ||
|
||
validationData = abi.decode(data, (uint256)); | ||
} | ||
|
||
function validateUserOpDelegatecallReciever( | ||
PackedUserOperation calldata userOp, | ||
bytes32, | ||
uint256 missingAccountFunds | ||
) external onlyDelegateCall returns (uint256 validationData) { | ||
address payable safeAddress = payable(userOp.sender); | ||
// The entry point address is appended to the calldata by the Safe in the `FallbackManager` contract, | ||
// following ERC-2771. Because of this, the relayer may manipulate the entry point address, therefore | ||
// we have to verify that the sender is the Safe specified in the userOperation. | ||
if (safeAddress != msg.sender) { | ||
revert InvalidCaller(); | ||
} | ||
|
||
// We check the execution function signature to make sure the entry point can't call any other function | ||
// and make sure the execution of the user operation is handled by the module | ||
bytes4 selector = bytes4(userOp.callData); | ||
if (selector != this.executeUserOp.selector && selector != this.executeUserOpWithErrorString.selector) { | ||
revert UnsupportedExecutionFunction(selector); | ||
} | ||
|
||
// The userOp nonce is validated in the entry point (for 0.6.0+), therefore we will not check it again | ||
validationData = _validateSignatures(userOp); | ||
|
||
// We trust the entry point to set the correct prefund value, based on the operation params | ||
// We need to perform this even if the signature is not valid, else the simulation function of the entry point will not work. | ||
if (missingAccountFunds != 0) { | ||
// We intentionally ignore errors in paying the missing account funds, as the entry point is responsible for | ||
// verifying the prefund has been paid. This behaviour matches the reference base account implementation. | ||
ISafe(safeAddress).execTransactionFromModule(SUPPORTED_ENTRYPOINT, missingAccountFunds, "", 0); | ||
} | ||
} | ||
} |
This file contains 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.