Skip to content

Commit

Permalink
initial contract created from Yoav's pseudocode
Browse files Browse the repository at this point in the history
  • Loading branch information
kristofgazso committed Jul 25, 2021
0 parents commit 894034e
Show file tree
Hide file tree
Showing 8 changed files with 27,938 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules

#Hardhat files
cache
artifacts
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# account-abstraction

https://notes.ethereum.org/@vbuterin/alt_abstraction
53 changes: 53 additions & 0 deletions contracts/Singleton.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

contract Singleton {

uint256 MAX_CHECK_GAS = 100_000;
uint256 POST_CALL_GAS_OVERHEAD = 50_000;

struct UserOperation {
bytes20 target;
uint64 callGas;
uint64 postCallGas;
uint256 gasPrice;
bytes callData;
bytes signature;
}

function handleOps(UserOperation[] calldata ops, uint256 minimumGasPrice) public {
//require(msg.sender == block.coinbase);
uint256 savedBalance = address(this).balance;
for(uint i=0;i<ops.length;i++){
UserOperation calldata op = ops[i];
if (gasleft() <= op.callGas + op.postCallGas + MAX_CHECK_GAS + POST_CALL_GAS_OVERHEAD){
break;
}
handleOp(op, minimumGasPrice);
}
payable(address(msg.sender)).transfer(address(this).balance-savedBalance);
}

function handleOp(UserOperation calldata op, uint256 minimumGasPrice) public {
uint256 savedGas = gasleft();

require(op.gasPrice >= minimumGasPrice);
require(gasleft()-op.callGas+op.postCallGas >= POST_CALL_GAS_OVERHEAD);

ISmartContractWallet smartContractWallet = ISmartContractWallet(address(op.target));
smartContractWallet.payForOp{gas:MAX_CHECK_GAS}(op.callGas, op.postCallGas, op.callData, op.signature);

require(address(this).balance >= op.gasPrice*(op.callGas+op.postCallGas));
(bool success,) = address(smartContractWallet).call{gas:op.callGas}(op.callData);
require(success);
smartContractWallet.handleRefundGas{gas:op.postCallGas,value:(savedGas-gasleft()-op.postCallGas)*tx.gasprice};
}
}

interface ISmartContractWallet {

// callGas, postCallGas, callData, signature
function payForOp(uint64, uint64, bytes calldata, bytes calldata) external;

function handleRefundGas() payable external;
}
21 changes: 21 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require("@nomiclabs/hardhat-waffle");

// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
const accounts = await hre.ethers.getSigners();

for (const account of accounts) {
console.log(account.address);
}
});

// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more

/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
solidity: "0.8.4",
};
Loading

0 comments on commit 894034e

Please sign in to comment.