Skip to content

Commit

Permalink
Merge branch 'develop' into executeUserOp
Browse files Browse the repository at this point in the history
  • Loading branch information
drortirosh committed Jan 3, 2024
2 parents ff5ffd7 + 346ab2d commit bee9759
Show file tree
Hide file tree
Showing 27 changed files with 172 additions and 727 deletions.
2 changes: 0 additions & 2 deletions .solcover.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module.exports = {
skipFiles: [
"test",
"samples/bls/lib",
//solc-coverage fails to compile our Manager module.
"samples/gnosis",
"utils/Exec.sol"
],
configureYulOptimizer: true,
Expand Down
10 changes: 9 additions & 1 deletion contracts/core/BasePaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.12;
/* solhint-disable reason-string */

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import "../interfaces/IPaymaster.sol";
import "../interfaces/IEntryPoint.sol";
import "./Helpers.sol";
Expand All @@ -16,10 +17,17 @@ import "./Helpers.sol";
abstract contract BasePaymaster is IPaymaster, Ownable {
IEntryPoint public immutable entryPoint;

constructor(IEntryPoint _entryPoint) {
constructor(IEntryPoint _entryPoint) Ownable(msg.sender) {
_validateEntryPointInterface(_entryPoint);
entryPoint = _entryPoint;
}

//sanity check: make sure this EntryPoint was compiled against the same
// IEntryPoint of this paymaster
function _validateEntryPointInterface(IEntryPoint _entryPoint) internal virtual {
require(IERC165(address(_entryPoint)).supportsInterface(type(IEntryPoint).interfaceId), "IEntryPoint interface mismatch");
}

/// @inheritdoc IPaymaster
function validatePaymasterUserOp(
UserOperation calldata userOp,
Expand Down
5 changes: 2 additions & 3 deletions contracts/core/EntryPoint.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.12;

pragma solidity ^0.8.23;
/* solhint-disable avoid-low-level-calls */
/* solhint-disable no-inline-assembly */

Expand All @@ -18,7 +17,7 @@ import "./UserOperationLib.sol";

// we also require '@gnosis.pm/safe-contracts' and both libraries have 'IERC165.sol', leading to conflicts
import "@openzeppelin/contracts/utils/introspection/ERC165.sol" as OpenZeppelin;
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

/*
* Account-Abstraction (EIP-4337) singleton EntryPoint implementation.
Expand Down
1 change: 0 additions & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"url": "https://github.com/eth-infinitism/account-abstraction/issues"
},
"devDependencies": {
"@gnosis.pm/safe-contracts": "^1.3.0",
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@uniswap/v3-periphery": "^1.4.3"
Expand Down
15 changes: 6 additions & 9 deletions contracts/samples/SimpleAccount.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.12;
pragma solidity ^0.8.23;

/* solhint-disable avoid-low-level-calls */
/* solhint-disable no-inline-assembly */
/* solhint-disable reason-string */

import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";

import "../core/BaseAccount.sol";
import "./callback/TokenCallbackHandler.sol";

Expand All @@ -19,8 +19,6 @@ import "./callback/TokenCallbackHandler.sol";
* has a single signer that can send requests through the entryPoint.
*/
contract SimpleAccount is BaseAccount, TokenCallbackHandler, UUPSUpgradeable, Initializable {
using ECDSA for bytes32;

address public owner;

IEntryPoint private immutable _entryPoint;
Expand All @@ -37,7 +35,6 @@ contract SimpleAccount is BaseAccount, TokenCallbackHandler, UUPSUpgradeable, In
return _entryPoint;
}


// solhint-disable-next-line no-empty-blocks
receive() external payable {}

Expand Down Expand Up @@ -99,14 +96,14 @@ contract SimpleAccount is BaseAccount, TokenCallbackHandler, UUPSUpgradeable, In
/// implement template method of BaseAccount
function _validateSignature(UserOperation calldata userOp, bytes32 userOpHash)
internal override virtual returns (uint256 validationData) {
bytes32 hash = userOpHash.toEthSignedMessageHash();
if (owner != hash.recover(userOp.signature))
bytes32 hash = MessageHashUtils.toEthSignedMessageHash(userOpHash);
if (owner != ECDSA.recover(hash, userOp.signature))
return SIG_VALIDATION_FAILED;
return 0;
}

function _call(address target, uint256 value, bytes memory data) internal {
(bool success, bytes memory result) = target.call{value : value}(data);
(bool success, bytes memory result) = target.call{value: value}(data);
if (!success) {
assembly {
revert(add(result, 32), mload(result))
Expand All @@ -125,7 +122,7 @@ contract SimpleAccount is BaseAccount, TokenCallbackHandler, UUPSUpgradeable, In
* deposit more funds for this account in the entryPoint
*/
function addDeposit() public payable {
entryPoint().depositTo{value : msg.value}(address(this));
entryPoint().depositTo{value: msg.value}(address(this));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions contracts/samples/VerifyingPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pragma solidity ^0.8.12;
import "../core/BasePaymaster.sol";
import "../core/UserOperationLib.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
/**
* A sample paymaster that uses external service to decide whether to pay for the UserOp.
* The paymaster trusts an external signer to sign the transaction.
Expand All @@ -18,7 +19,6 @@ import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
*/
contract VerifyingPaymaster is BasePaymaster {

using ECDSA for bytes32;
using UserOperationLib for UserOperation;

address public immutable verifyingSigner;
Expand Down Expand Up @@ -78,7 +78,7 @@ contract VerifyingPaymaster is BasePaymaster {
//ECDSA library supports both 64 and 65-byte long signatures.
// we only "require" it here so that the revert reason on invalid signature will be of "VerifyingPaymaster", and not "ECDSA"
require(signature.length == 64 || signature.length == 65, "VerifyingPaymaster: invalid signature length in paymasterAndData");
bytes32 hash = ECDSA.toEthSignedMessageHash(getHash(userOp, validUntil, validAfter));
bytes32 hash = MessageHashUtils.toEthSignedMessageHash(getHash(userOp, validUntil, validAfter));

//don't revert on signature failure: return SIG_VALIDATION_FAILED
if (verifyingSigner != ECDSA.recover(hash, signature)) {
Expand Down
12 changes: 1 addition & 11 deletions contracts/samples/callback/TokenCallbackHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,14 @@ pragma solidity ^0.8.12;
/* solhint-disable no-empty-blocks */

import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import "@openzeppelin/contracts/token/ERC777/IERC777Recipient.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol";

/**
* Token callback handler.
* Handles supported tokens' callbacks, allowing account receiving these tokens.
*/
contract TokenCallbackHandler is IERC777Recipient, IERC721Receiver, IERC1155Receiver {
function tokensReceived(
address,
address,
address,
uint256,
bytes calldata,
bytes calldata
) external pure override {
}
contract TokenCallbackHandler is IERC721Receiver, IERC1155Receiver {

function onERC721Received(
address,
Expand Down
89 changes: 0 additions & 89 deletions contracts/samples/gnosis/EIP4337Fallback.sol

This file was deleted.

Loading

0 comments on commit bee9759

Please sign in to comment.